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

Public Member Functions

 ColorEmojiGM (ToolUtils::EmojiFontFormat format)
 
- 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 Types

using INHERITED = GM
 

Protected Member Functions

void onOnceBeforeDraw () override
 
SkString getName () const override
 
SkISize getISize () override
 
void modifyGrContextOptions (GrContextOptions *ctxOptions) override
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) 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
 

Protected Attributes

ToolUtils::EmojiTestSample emojiFont
 
ToolUtils::EmojiFontFormat fFormat
 

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 75 of file coloremoji.cpp.

Member Typedef Documentation

◆ INHERITED

Definition at line 224 of file coloremoji.cpp.

Constructor & Destructor Documentation

◆ ColorEmojiGM()

skiagm::ColorEmojiGM::ColorEmojiGM ( ToolUtils::EmojiFontFormat  format)
inline

Definition at line 77 of file coloremoji.cpp.

77: fFormat(format) {}
ToolUtils::EmojiFontFormat fFormat
Definition: coloremoji.cpp:223
uint32_t uint32_t * format

Member Function Documentation

◆ getISize()

SkISize skiagm::ColorEmojiGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 89 of file coloremoji.cpp.

89{ return SkISize::Make(650, 1200); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 85 of file coloremoji.cpp.

85 {
86 return SkString("coloremoji_") += ToolUtils::NameForFontFormat(fFormat);
87 }
SkString NameForFontFormat(EmojiFontFormat format)

◆ modifyGrContextOptions()

void skiagm::ColorEmojiGM::modifyGrContextOptions ( GrContextOptions ctxOptions)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 91 of file coloremoji.cpp.

91 {
92 // This will force multitexturing to verify that color text works with this,
93 // as well as with any additional color transformations.
94 ctxOptions->fGlyphCacheTextureMaximumBytes = 256 * 256 * 4;
95 }
size_t fGlyphCacheTextureMaximumBytes

◆ onDraw()

DrawResult skiagm::ColorEmojiGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 105 of file coloremoji.cpp.

105 {
106 canvas->drawColor(SK_ColorGRAY);
107
108 if (!emojiFont.typeface) {
109 *errorMsg = SkStringPrintf("Unable to instantiate emoji test font of format %s.",
111 return DrawResult::kSkip;
112 }
113
115 char const * const text = emojiFont.sampleText;
116 size_t textLen = strlen(text);
117
118 // draw text at different point sizes
119 constexpr SkScalar textSizes[] = { 10, 30, 50 };
120 SkFontMetrics metrics;
121 SkScalar y = 0;
122 for (const bool& fakeBold : { false, true }) {
123 font.setEmbolden(fakeBold);
124 for (const SkScalar& textSize : textSizes) {
125 font.setSize(textSize);
126 font.getMetrics(&metrics);
127 y += -metrics.fAscent;
128 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8,
129 10, y, font, SkPaint());
130 y += metrics.fDescent + metrics.fLeading;
131 }
132 }
133
134 // draw one more big one to max out one Plot
135 font.setSize(256);
136 font.getMetrics(&metrics);
137 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8,
138 190, -metrics.fAscent, font, SkPaint());
139
140 y += 20;
141 SkScalar savedY = y;
142 // draw with shaders and image filters
143 for (int makeLinear = 0; makeLinear < 2; makeLinear++) {
144 for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
145 for (int makeGray = 0; makeGray < 2; makeGray++) {
146 for (int makeMode = 0; makeMode < 2; ++makeMode) {
147 for (int alpha = 0; alpha < 2; ++alpha) {
148 SkFont shaderFont(font.refTypeface());
149 SkPaint shaderPaint;
150 if (SkToBool(makeLinear)) {
151 shaderPaint.setShader(MakeLinear());
152 }
153
154 if (SkToBool(makeBlur) && SkToBool(makeGray)) {
155 sk_sp<SkImageFilter> grayScale(make_grayscale(nullptr));
156 sk_sp<SkImageFilter> blur(make_blur(3.0f, std::move(grayScale)));
157 shaderPaint.setImageFilter(std::move(blur));
158 } else if (SkToBool(makeBlur)) {
159 shaderPaint.setImageFilter(make_blur(3.0f, nullptr));
160 } else if (SkToBool(makeGray)) {
161 shaderPaint.setImageFilter(make_grayscale(nullptr));
162 }
163 if (makeMode) {
164 shaderPaint.setColorFilter(make_color_filter());
165 }
166 if (alpha) {
167 shaderPaint.setAlphaf(0.5f);
168 }
169 shaderFont.setSize(30);
170 shaderFont.getMetrics(&metrics);
171 y += -metrics.fAscent;
172 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 380, y,
173 shaderFont, shaderPaint);
174 y += metrics.fDescent + metrics.fLeading;
175 }
176 }
177 }
178 }
179 }
180 // setup work needed to draw text with different clips
181 canvas->translate(10, savedY);
182 font.setSize(40);
183
184 // compute the bounds of the text
186 font.measureText(text, textLen, SkTextEncoding::kUTF8, &bounds);
187
188 const SkScalar boundsHalfWidth = bounds.width() * SK_ScalarHalf;
189 const SkScalar boundsHalfHeight = bounds.height() * SK_ScalarHalf;
190 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf;
191 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf;
192
193 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(),
194 boundsHalfWidth, boundsHalfHeight);
195 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.centerY(),
196 boundsHalfWidth, boundsHalfHeight);
197 SkRect interiorClip = bounds;
198 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight);
199
200 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, interiorClip };
201
202 SkPaint clipHairline;
203 clipHairline.setColor(SK_ColorWHITE);
204 clipHairline.setStyle(SkPaint::kStroke_Style);
205
207 for (const SkRect& clipRect : clipRects) {
208 canvas->translate(0, bounds.height());
209 canvas->save();
210 canvas->drawRect(clipRect, clipHairline);
211 paint.setAlpha(0x20);
212 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
213 canvas->clipRect(clipRect);
214 paint.setAlphaf(1.0f);
215 canvas->drawSimpleText(text, textLen, SkTextEncoding::kUTF8, 0, 0, font, paint);
216 canvas->restore();
217 canvas->translate(0, SkIntToScalar(25));
218 }
219
220 return DrawResult::kOk;
221 }
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define SK_ScalarHalf
Definition: SkScalar.h:19
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
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
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
int save()
Definition: SkCanvas.cpp:447
Definition: SkFont.h:35
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setShader(sk_sp< SkShader > shader)
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
void setAlphaf(float a)
Definition: SkPaint.cpp:130
ToolUtils::EmojiTestSample emojiFont
Definition: coloremoji.cpp:80
const Paint & paint
Definition: color_source.cc:38
static sk_sp< SkImageFilter > make_grayscale(sk_sp< SkImageFilter > input)
Definition: coloremoji.cpp:53
static sk_sp< SkShader > MakeLinear()
Definition: coloremoji.cpp:45
static sk_sp< SkImageFilter > make_blur(float amount, sk_sp< SkImageFilter > input)
Definition: coloremoji.cpp:64
static sk_sp< SkColorFilter > make_color_filter()
Definition: coloremoji.cpp:68
float SkScalar
Definition: extension.cpp:12
std::u16string text
double y
Optional< SkRect > bounds
Definition: SkRecords.h:189
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
font
Font Metadata and Metrics.
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
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
sk_sp< SkTypeface > typeface
Definition: FontToolUtils.h:48

◆ onOnceBeforeDraw()

void skiagm::ColorEmojiGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 81 of file coloremoji.cpp.

81 {
83 }
EmojiTestSample EmojiSample()

Member Data Documentation

◆ emojiFont

ToolUtils::EmojiTestSample skiagm::ColorEmojiGM::emojiFont
protected

Definition at line 80 of file coloremoji.cpp.

◆ fFormat

ToolUtils::EmojiFontFormat skiagm::ColorEmojiGM::fFormat
protected

Definition at line 223 of file coloremoji.cpp.


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