Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
PerspTextGM Class Reference
Inheritance diagram for PerspTextGM:
skiagm::GM

Public Member Functions

 PerspTextGM (bool minimal)
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 30 of file persptext.cpp.

Constructor & Destructor Documentation

◆ PerspTextGM()

PerspTextGM::PerspTextGM ( bool  minimal)
inline

Definition at line 32 of file persptext.cpp.

32 : fMinimal(minimal) {
33 this->setBGColor(0xFFFFFFFF);
34 }
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ getISize()

SkISize PerspTextGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 41 of file persptext.cpp.

41{ return SkISize::Make(1024, 768); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString PerspTextGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 37 of file persptext.cpp.

37 {
38 return SkString(fMinimal ? "persptext_minimal" : "persptext");
39 }

◆ onDraw()

void PerspTextGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 45 of file persptext.cpp.

45 {
46
47 canvas->clear(0xffffffff);
48
50 paint.setAntiAlias(true);
51
53 font.setSubpixel(true);
54 font.setSize(32);
55 font.setBaselineSnap(false);
56
57 const char* text = "Hamburgefons";
58 const size_t textLen = strlen(text);
59
60 SkScalar textWidth = font.measureText(text, textLen, SkTextEncoding::kUTF8,
61 nullptr, nullptr);
62 SkScalar textHeight = font.getMetrics(nullptr);
63
64 SkScalar x = 10, y = textHeight + 5.f;
65 const int kSteps = 8;
66 float kMinimalFactor = fMinimal ? 32.f : 1.f;
67 for (auto pm : {PerspMode::kX, PerspMode::kY, PerspMode::kXY}) {
68 for (int i = 0; i < kSteps; ++i) {
69 canvas->save();
70#ifdef TEST_PERSP_CHECK
71 // draw non-perspective text in the background for comparison
72 paint.setColor(SK_ColorRED);
73 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint);
74#endif
75
76 SkMatrix persp = SkMatrix::I();
77 switch (pm) {
78 case PerspMode::kX:
79 if (fMinimal) {
80 persp.setPerspX(i*0.0005f/kSteps/kMinimalFactor);
81 } else {
82 persp.setPerspX(i*0.00025f/kSteps);
83 }
84 break;
85 case PerspMode::kY:
86 persp.setPerspY(i*0.0025f/kSteps/kMinimalFactor);
87 break;
88 case PerspMode::kXY:
89 persp.setPerspX(i*-0.00025f/kSteps/kMinimalFactor);
90 persp.setPerspY(i*-0.00125f/kSteps/kMinimalFactor);
91 break;
92 }
93 persp = SkMatrix::Concat(persp, SkMatrix::Translate(-x, -y));
94 persp = SkMatrix::Concat(SkMatrix::Translate(x, y), persp);
95 canvas->concat(persp);
96
97 paint.setColor(SK_ColorBLACK);
98#ifdef TEST_PERSP_CHECK
99 // Draw text as red if it is nearly affine
100 SkRect bounds = SkRect::MakeXYWH(0, -textHeight, textWidth, textHeight);
101 bounds.offset(x, y);
102 if (SkMatrixPriv::NearlyAffine(persp, bounds, SK_Scalar1/(1 << 4))) {
103 paint.setColor(SK_ColorRED);
104 }
105#endif
106 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, x, y, font, paint);
107
108 y += textHeight + 5.f;
109 canvas->restore();
110 }
111
112 x += textWidth + 10.f;
113 y = textHeight + 5.f;
114 }
115
116 }
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SK_Scalar1
Definition: SkScalar.h:18
void restore()
Definition: SkCanvas.cpp:461
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
Definition: SkFont.h:35
static bool NearlyAffine(const SkMatrix &m, const SkRect &bounds, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkMatrix.cpp:1820
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
SkMatrix & setPerspX(SkScalar v)
Definition: SkMatrix.h:537
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
SkMatrix & setPerspY(SkScalar v)
Definition: SkMatrix.h:544
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

The documentation for this class was generated from the following file: