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

Public Member Functions

 VariedTextGM (bool effectiveClip, bool lcd)
 
- 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 onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
bool runAsBench () const 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

Draws text with random parameters. The text draws each get their own clip rect. It is also used as a bench to measure how well the GPU backend combines draw ops for text draws.

Definition at line 32 of file variedtext.cpp.

Constructor & Destructor Documentation

◆ VariedTextGM()

VariedTextGM::VariedTextGM ( bool  effectiveClip,
bool  lcd 
)
inline

Definition at line 34 of file variedtext.cpp.

35 : fEffectiveClip(effectiveClip)
36 , fLCD(lcd) {
37 }

Member Function Documentation

◆ getISize()

SkISize VariedTextGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 55 of file variedtext.cpp.

55{ return SkISize::Make(640, 480); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString VariedTextGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 40 of file variedtext.cpp.

40 {
41 SkString name("varied_text");
42 if (fEffectiveClip) {
43 name.append("_clipped");
44 } else {
45 name.append("_ignorable_clip");
46 }
47 if (fLCD) {
48 name.append("_lcd");
49 } else {
50 name.append("_no_lcd");
51 }
52 return name;
53 }
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ onDraw()

void VariedTextGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 116 of file variedtext.cpp.

116 {
117 for (int i = 0; i < kCnt; ++i) {
118 fPaint.setColor(fColors[i]);
119 fFont.setSize(fPtSizes[i]);
120 fFont.setTypeface(fTypefaces[fTypefaceIndices[i]]);
121
122 canvas->save();
123 canvas->clipRect(fClipRects[i]);
124 canvas->translate(fOffsets[i].fX, fOffsets[i].fY);
125 canvas->drawSimpleText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8,
126 0, 0, fFont, fPaint);
127 canvas->restore();
128 }
129
130 // Visualize the clips, but not in bench mode.
131 if (kBench_Mode != this->getMode()) {
132 SkPaint wirePaint;
133 wirePaint.setAntiAlias(true);
134 wirePaint.setStrokeWidth(0);
136 for (int i = 0; i < kCnt; ++i) {
137 canvas->drawRect(fClipRects[i], wirePaint);
138 }
139 }
140 }
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
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 translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void setTypeface(sk_sp< SkTypeface > tf)
Definition: SkFont.cpp:90
void setSize(SkScalar textSize)
Definition: SkFont.cpp:129
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
@ kBench_Mode
Definition: gm.h:121
Mode getMode() const
Definition: gm.h:125
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ onOnceBeforeDraw()

void VariedTextGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 57 of file variedtext.cpp.

57 {
58 fPaint.setAntiAlias(true);
60
61 SkISize size = this->getISize();
62 SkScalar w = SkIntToScalar(size.fWidth);
63 SkScalar h = SkIntToScalar(size.fHeight);
64
65 SkASSERTF(4 == std::size(fTypefaces), "typeface_cnt");
66 fTypefaces[0] = ToolUtils::CreatePortableTypeface("sans-serif", SkFontStyle());
67 fTypefaces[1] = ToolUtils::CreatePortableTypeface("sans-serif", SkFontStyle::Bold());
68 fTypefaces[2] = ToolUtils::CreatePortableTypeface("serif", SkFontStyle());
69 fTypefaces[3] = ToolUtils::CreatePortableTypeface("serif", SkFontStyle::Bold());
70
71 SkRandom random;
72 for (int i = 0; i < kCnt; ++i) {
73 int length = random.nextRangeU(kMinLength, kMaxLength);
74 char text[kMaxLength];
75 for (int j = 0; j < length; ++j) {
76 text[j] = (char)random.nextRangeU('!', 'z');
77 }
78 fStrings[i].set(text, length);
79
80 fColors[i] = random.nextU();
81 fColors[i] |= 0xFF000000;
82 fColors[i] = ToolUtils::color_to_565(fColors[i]);
83
84 constexpr SkScalar kMinPtSize = 8.f;
85 constexpr SkScalar kMaxPtSize = 32.f;
86
87 fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize);
88
89 fTypefaceIndices[i] = random.nextULessThan(std::size(fTypefaces));
90
91 SkRect r;
92 fPaint.setColor(fColors[i]);
93 fFont.setTypeface(fTypefaces[fTypefaceIndices[i]]);
94 fFont.setSize(fPtSizes[i]);
95
96 fFont.measureText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8, &r);
97 // The set of x,y offsets which place the bounding box inside the GM's border.
98 SkRect safeRect = SkRect::MakeLTRB(-r.fLeft, -r.fTop, w - r.fRight, h - r.fBottom);
99 if (safeRect.isEmpty()) {
100 // If the bounds don't fit then allow any offset in the GM's border.
101 safeRect = SkRect::MakeWH(w, h);
102 }
103 fOffsets[i].fX = random.nextRangeScalar(safeRect.fLeft, safeRect.fRight);
104 fOffsets[i].fY = random.nextRangeScalar(safeRect.fTop, safeRect.fBottom);
105
106 fClipRects[i] = r;
107 fClipRects[i].offset(fOffsets[i].fX, fOffsets[i].fY);
108 fClipRects[i].outset(2.f, 2.f);
109
110 if (fEffectiveClip) {
111 fClipRects[i].fRight -= 0.25f * fClipRects[i].width();
112 }
113 }
114 }
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:69
SkScalar measureText(const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const
Definition: SkFont.h:336
void setEdging(Edging edging)
Definition: SkFont.cpp:121
@ kAntiAlias
may have transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
uint32_t nextU()
Definition: SkRandom.h:42
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition: SkRandom.h:106
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80
void set(const SkString &src)
Definition: SkString.h:186
SkISize getISize() override
Definition: variedtext.cpp:55
float SkScalar
Definition: extension.cpp:12
size_t length
std::u16string text
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
SkScalar w
SkScalar h
Definition: SkSize.h:16
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
void outset(float dx, float dy)
Definition: SkRect.h:1077
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
void offset(float dx, float dy)
Definition: SkRect.h:1016
constexpr float width() const
Definition: SkRect.h:762
bool isEmpty() const
Definition: SkRect.h:693
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ runAsBench()

bool VariedTextGM::runAsBench ( ) const
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 142 of file variedtext.cpp.

142{ return true; }

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