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

Public Member Functions

 MixedTextBlobsGM ()
 
- 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 46 of file mixedtextblobs.cpp.

Constructor & Destructor Documentation

◆ MixedTextBlobsGM()

skiagm::MixedTextBlobsGM::MixedTextBlobsGM ( )
inline

Definition at line 48 of file mixedtextblobs.cpp.

48{ }

Member Function Documentation

◆ getISize()

SkISize skiagm::MixedTextBlobsGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 112 of file mixedtextblobs.cpp.

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

◆ getName()

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

Implements skiagm::GM.

Definition at line 110 of file mixedtextblobs.cpp.

110{ return SkString("mixedtextblobs"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 114 of file mixedtextblobs.cpp.

114 {
115
116 canvas->drawColor(SK_ColorGRAY);
117
119
120 // setup work needed to draw text with different clips
121 paint.setColor(SK_ColorBLACK);
122 canvas->translate(10, 40);
123
124 // compute the bounds of the text and setup some clips
125 SkRect bounds = fBlob->bounds();
126
127 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
128 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
129 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
130 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
131
132 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
133 boundsHalfWidth, boundsHalfHeight);
134 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
135 boundsHalfWidth, boundsHalfHeight);
136 SkRect interiorClip = bounds;
137 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
138
139 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip};
140
141 size_t count = sizeof(clipRects) / sizeof(SkRect);
142 for (size_t x = 0; x < count; ++x) {
143 draw_blob(canvas, fBlob.get(), paint, clipRects[x]);
144 if (x == (count >> 1) - 1) {
146 -(x * SkScalarFloorToScalar(bounds.height() +
147 SkIntToScalar(25))));
148 } else {
149 canvas->translate(0, SkScalarFloorToScalar(bounds.height() + SkIntToScalar(25)));
150 }
151 }
152 }
int count
Definition: FontMgrTest.cpp:50
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:30
#define SK_ScalarHalf
Definition: SkScalar.h:19
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
const SkRect & bounds() const
Definition: SkTextBlob.h:53
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
static void draw_blob(SkCanvas *canvas, const SkTextBlob *blob, const SkPaint &skPaint, const SkRect &clipRect)
void inset(float dx, float dy)
Definition: SkRect.h:1060
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onOnceBeforeDraw()

void skiagm::MixedTextBlobsGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 51 of file mixedtextblobs.cpp.

51 {
52 fEmojiTypeface = ToolUtils::PlanetTypeface();
53 fEmojiText = "♁♃";
54 fReallyBigATypeface = ToolUtils::CreateTypefaceFromResource("fonts/ReallyBigA.ttf");
55 if (!fReallyBigATypeface) {
56 fReallyBigATypeface = ToolUtils::DefaultPortableTypeface();
57 }
58
60
61 // make textblob
62 // Text so large we draw as paths
65 const char* text = "O";
66
68 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
69
70 SkScalar yOffset = bounds.height();
72 SkScalar corruptedAx = bounds.width();
73 SkScalar corruptedAy = yOffset;
74
75 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
76 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
77
78 SkScalar xOffset = boundsHalfWidth;
79 yOffset = boundsHalfHeight;
80
81 // LCD
82 font.setSize(32);
84 font.setSubpixel(true);
85 text = "LCD!!!!!";
86 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
88 text,
89 font,
90 xOffset - bounds.width() * 0.25f,
91 yOffset - bounds.height() * 0.5f);
92
93 // color emoji font with large glyph
94 if (fEmojiTypeface) {
96 font.setSubpixel(false);
97 font.setTypeface(fEmojiTypeface);
98 font.measureText(fEmojiText, strlen(fEmojiText), SkTextEncoding::kUTF8, &bounds);
99 ToolUtils::add_to_text_blob(&builder, fEmojiText, font, xOffset, yOffset);
100 }
101
102 // outline font with large glyph
103 font.setSize(12);
104 text = "aA";
105 font.setTypeface(fReallyBigATypeface);
106 ToolUtils::add_to_text_blob(&builder, text, font, corruptedAx, corruptedAy);
107 fBlob = builder.make();
108 }
@ kUTF8
uses bytes to represent UTF-8 or ASCII
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
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
sk_sp< SkTypeface > PlanetTypeface()
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)
font
Font Metadata and Metrics.

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