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

Public Member Functions

 TextBlobTransforms ()
 
- 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

void onOnceBeforeDraw () override
 
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 27 of file textblobtransforms.cpp.

Constructor & Destructor Documentation

◆ TextBlobTransforms()

skiagm::TextBlobTransforms::TextBlobTransforms ( )
inline

Definition at line 30 of file textblobtransforms.cpp.

30{}

Member Function Documentation

◆ getISize()

SkISize skiagm::TextBlobTransforms::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 65 of file textblobtransforms.cpp.

65{ return SkISize::Make(kWidth, kHeight); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::TextBlobTransforms::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 63 of file textblobtransforms.cpp.

63{ return SkString("textblobtransforms"); }

◆ onDraw()

void skiagm::TextBlobTransforms::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 67 of file textblobtransforms.cpp.

67 {
68
69 canvas->drawColor(SK_ColorGRAY);
70
72
73 SkRect bounds = fBlob->bounds();
74 canvas->translate(20, 20);
75
76 // Colors were chosen to map to pairs of canonical colors. The GPU Backend will cache A8
77 // Texture Blobs based on the canonical color they map to. Canonical colors are used to
78 // create masks. For A8 there are 8 of them.
79 //SkColor colors[] = {SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorYELLOW, SK_ColorWHITE};
80
81 SkScalar xOffset = SkScalarCeilToScalar(bounds.width());
82 SkScalar yOffset = SkScalarCeilToScalar(bounds.height());
83 // first translate
84 canvas->translate(xOffset, 2 * yOffset);
85 canvas->drawTextBlob(fBlob, 0, 0, paint);
86 canvas->translate(-xOffset, 0);
87 canvas->drawTextBlob(fBlob, 0, 0, paint);
88 canvas->translate(2 * xOffset, 0);
89 canvas->drawTextBlob(fBlob, 0, 0, paint);
90 canvas->translate(-xOffset, -yOffset);
91 canvas->drawTextBlob(fBlob, 0, 0, paint);
92 canvas->translate(0, 2 * yOffset);
93 canvas->drawTextBlob(fBlob, 0, 0, paint);
94
95 // now rotate
96 canvas->translate(4 * xOffset, -yOffset);
97 canvas->rotate(180.f);
98 canvas->drawTextBlob(fBlob, 0, 0, paint);
99 canvas->rotate(-180.f);
100 canvas->translate(0, -yOffset);
101 canvas->rotate(-180.f);
102 canvas->drawTextBlob(fBlob, 0, 0, paint);
103 canvas->rotate(270.f);
104 canvas->drawTextBlob(fBlob, 0, 0, paint);
105 canvas->rotate(-90.f);
106 canvas->translate(-xOffset, yOffset);
107 canvas->rotate(-90.f);
108 canvas->drawTextBlob(fBlob, 0, 0, paint);
109 canvas->rotate(90.f);
110
111 // and scales
112 canvas->translate(- 3 * xOffset, 3 * yOffset);
113 canvas->scale(1.5f, 1.5f);
114 canvas->drawTextBlob(fBlob, 0, 0, paint);
115 canvas->translate(xOffset, 0);
116 canvas->scale(.25f, .25f);
117 canvas->drawTextBlob(fBlob, 0, 0, paint);
118 canvas->translate(xOffset, 0);
119 canvas->scale(3.f, 2.f);
120 canvas->drawTextBlob(fBlob, 0, 0, paint);
121
122 // finally rotates, scales, and translates together
123 canvas->translate(xOffset, 0);
124 canvas->rotate(23.f);
125 canvas->scale(.33f, .5f);
126 canvas->drawTextBlob(fBlob, 0, 0, paint);
127
128 canvas->rotate(-46.f);
129 canvas->translate(xOffset, 0);
130 canvas->scale(1.2f, 1.1f);
131 canvas->drawTextBlob(fBlob, 0, 0, paint);
132
133 canvas->rotate(46.f);
134 canvas->translate(xOffset, 0);
135 canvas->scale(1.1f, 1.2f);
136 canvas->drawTextBlob(fBlob, 0, 0, paint);
137
138 canvas->rotate(46.f);
139 canvas->translate(xOffset, 0);
140 canvas->scale(.95f, 1.1f);
141 canvas->drawTextBlob(fBlob, 0, 0, paint);
142
143 canvas->rotate(46.f);
144 canvas->translate(xOffset, 0);
145 canvas->scale(1.3f, .7f);
146 canvas->drawTextBlob(fBlob, 0, 0, paint);
147
148 canvas->rotate(46.f);
149 canvas->translate(xOffset, 0);
150 canvas->scale(.8f, 1.1f);
151 canvas->drawTextBlob(fBlob, 0, 0, paint);
152
153 canvas->rotate(10.f);
154 canvas->translate(xOffset, 0);
155 canvas->scale(1.f, 5.f);
156 canvas->drawTextBlob(fBlob, 0, 0, paint);
157
158 canvas->rotate(5.f);
159 canvas->translate(xOffset, 0);
160 canvas->scale(5.f, 1.f);
161 canvas->drawTextBlob(fBlob, 0, 0, paint);
162 }
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
#define SkScalarCeilToScalar(x)
Definition: SkScalar.h:31
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
const SkRect & bounds() const
Definition: SkTextBlob.h:53
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ onOnceBeforeDraw()

void skiagm::TextBlobTransforms::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 33 of file textblobtransforms.cpp.

33 {
35
36 // make textblob. To stress distance fields, we choose sizes appropriately
39 const char* text = "A";
40
42 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
44
45 // Medium
46 SkScalar xOffset = bounds.width() + 5;
47 font.setSize(72);
48 text = "B";
50
51 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
52 SkScalar yOffset = bounds.height();
53
54 // Small
55 font.setSize(32);
56 text = "C";
57 ToolUtils::add_to_text_blob(&builder, text, font, xOffset, -yOffset - 10);
58
59 // build
60 fBlob = builder.make();
61 }
@ kUTF8
uses bytes to represent UTF-8 or ASCII
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
void add_to_text_blob(SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:228
font
Font Metadata and Metrics.

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