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

Public Member Functions

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

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 36 of file textblobrandomfont.cpp.

Constructor & Destructor Documentation

◆ TextBlobRandomFont()

skiagm::TextBlobRandomFont::TextBlobRandomFont ( )
inline

Definition at line 40 of file textblobrandomfont.cpp.

40{ }

Member Function Documentation

◆ getISize()

SkISize skiagm::TextBlobRandomFont::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 101 of file textblobrandomfont.cpp.

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

◆ getName()

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

Implements skiagm::GM.

Definition at line 99 of file textblobrandomfont.cpp.

99{ return SkString("textblobrandomfont"); }

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 103 of file textblobrandomfont.cpp.

103 {
105 bool isGPU = SkToBool(dContext);
106
107#if defined(SK_GRAPHITE)
108 skgpu::graphite::Recorder* recorder = canvas->recorder();
109 isGPU = isGPU || SkToBool(recorder);
110#endif
111
112 if (!isGPU) {
115 }
116
117 // This GM uses ToolUtils::makeSurface which doesn't work well with vias.
118 // This GM uses SkRandomTypeface which doesn't work well with serialization.
119 canvas->drawColor(SK_ColorWHITE);
120
121 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, canvas->imageInfo().colorType(),
123 canvas->imageInfo().refColorSpace());
125 auto surface(ToolUtils::makeSurface(canvas, info, &props));
126 if (!surface) {
127 *errorMsg = "This test requires a surface";
128 return DrawResult::kFail;
129 }
130
132 paint.setAntiAlias(true);
133
134 SkCanvas* surfaceCanvas = surface->getCanvas();
135
136 SkScalar stride = SkScalarCeilToScalar(fBlob->bounds().height());
137 SkScalar yOffset = 5;
138
139 canvas->save();
140 // Originally we would alternate between rotating and not to force blob regeneration,
141 // but that code seems to have rotted. Keeping the rotate to match the old GM as
142 // much as possible, and it seems like a reasonable stress test for transformed
143 // color emoji.
144 canvas->rotate(-0.05f);
145 canvas->drawTextBlob(fBlob, 10, yOffset, paint);
146 yOffset += stride;
147 canvas->restore();
148
149 // Rotate in the surface canvas, not the final canvas, to avoid aliasing
150 surfaceCanvas->rotate(-0.05f);
151 surfaceCanvas->drawTextBlob(fBlob, 10, yOffset, paint);
152 surface->draw(canvas, 0, 0);
153 yOffset += stride;
154
155 if (dContext) {
156 // free gpu resources and verify
157 dContext->freeGpuResources();
158 }
159
160 canvas->rotate(-0.05f);
161 canvas->drawTextBlob(fBlob, 10, yOffset, paint);
162 yOffset += stride;
163 return DrawResult::kOk;
164 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkScalarCeilToScalar(x)
Definition: SkScalar.h:31
@ kUnknown_SkPixelGeometry
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void restore()
Definition: SkCanvas.cpp:461
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
int save()
Definition: SkCanvas.cpp:447
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
const SkRect & bounds() const
Definition: SkTextBlob.h:53
static constexpr char kErrorMsg_DrawSkippedGpuOnly[]
Definition: gm.h:127
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
sk_sp< SkColorSpace > refColorSpace() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkColorType colorType() const
Definition: SkImageInfo.h:373
constexpr float height() const
Definition: SkRect.h:769

◆ onOnceBeforeDraw()

void skiagm::TextBlobRandomFont::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 43 of file textblobrandomfont.cpp.

43 {
45
46 const char* text = "The quick brown fox jumps over the lazy dog.";
47
49 paint.setAntiAlias(true);
50 paint.setColor(SK_ColorMAGENTA);
51
52 // make textbloben
54 font.setSize(32);
56
57 // Setup our random scaler context
58 auto typeface = ToolUtils::CreatePortableTypeface("sans-serif", SkFontStyle::Bold());
59 SkASSERT(typeface);
60 font.setTypeface(sk_make_sp<SkRandomTypeface>(std::move(typeface), paint, false));
61
62 SkScalar y = 0;
64 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
65 y -= bounds.fTop;
67 y += bounds.fBottom;
68
69 // A8
70 const char* bigtext1 = "The quick brown fox";
71 const char* bigtext2 = "jumps over the lazy dog.";
72 font.setSize(160);
73 font.setSubpixel(false);
75 font.measureText(bigtext1, strlen(bigtext1), SkTextEncoding::kUTF8, &bounds);
76 y -= bounds.fTop;
78 y += bounds.fBottom;
79
80 font.measureText(bigtext2, strlen(bigtext2), SkTextEncoding::kUTF8, &bounds);
81 y -= bounds.fTop;
83 y += bounds.fBottom;
84
85 // color emoji
87 if (sample.typeface) {
88 font.setTypeface(sk_make_sp<SkRandomTypeface>(sample.typeface, paint, false));
89 font.measureText(sample.sampleText, strlen(sample.sampleText), SkTextEncoding::kUTF8, &bounds);
90 y -= bounds.fTop;
92 y += bounds.fBottom;
93 }
94
95 // build
96 fBlob = builder.make();
97 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static constexpr SkFontStyle Bold()
Definition: SkFontStyle.h:69
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
std::u16string text
double y
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
void add_to_text_blob(SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:228
EmojiTestSample EmojiSample()
font
Font Metadata and Metrics.
sk_sp< SkTypeface > typeface
Definition: FontToolUtils.h:48

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