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

Public Member Functions

 FontationsFtCompareGM (std::string testName, std::string fontNameFilterRegexp, std::string langFilterRegexp)
 
- 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
 
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 72 of file fontations_ft_compare.cpp.

Constructor & Destructor Documentation

◆ FontationsFtCompareGM()

skiagm::FontationsFtCompareGM::FontationsFtCompareGM ( std::string  testName,
std::string  fontNameFilterRegexp,
std::string  langFilterRegexp 
)
inline

Definition at line 74 of file fontations_ft_compare.cpp.

77 : fTestDataIterator(fontNameFilterRegexp, langFilterRegexp)
78 , fTestName(testName.c_str()) {
80 }
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ getISize()

SkISize skiagm::FontationsFtCompareGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 87 of file fontations_ft_compare.cpp.

87 {
89 fTestDataIterator.rewind();
90 fTestDataIterator.next(&testSet);
91
92 return SkISize::Make(kGmWidth,
93 testSet.langSamples.size() * kFontSize * kLangYIncrementScale + 100);
94 }
static const ConicPts testSet[]
bool next(TestSet *testSet)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 83 of file fontations_ft_compare.cpp.

83 {
84 return SkStringPrintf("fontations_compare_ft_%s", fTestName.c_str());
85 }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
const char * c_str() const
Definition: SkString.h:133

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 96 of file fontations_ft_compare.cpp.

96 {
98 paint.setColor(SK_ColorBLACK);
99
100 fTestDataIterator.rewind();
102
103 while (fTestDataIterator.next(&testSet)) {
105 SkStream::MakeFromFile(testSet.fontFilename.c_str()), SkFontArguments());
107 SkStream::MakeFromFile(testSet.fontFilename.c_str()), SkFontArguments());
108
109 if (!testTypeface || !ftTypeface) {
110 *errorMsg = "Unable to initialize typeface.";
111 return DrawResult::kSkip;
112 }
113
114 auto configureFont = [](SkFont& font) {
115 font.setSize(kFontSize);
117 font.setSubpixel(true);
118 font.setHinting(SkFontHinting::kNone);
119 };
120
121 SkFont font(testTypeface);
122 configureFont(font);
123
124 SkFont ftFont(ftTypeface);
125 configureFont(ftFont);
126 enum class DrawPhase { Fontations, FreeType, Comparison };
127
128 SkRect maxBounds = SkRect::MakeEmpty();
129 for (auto phase : {DrawPhase::Fontations, DrawPhase::FreeType, DrawPhase::Comparison}) {
130 SkScalar yCoord = kFontSize * 1.5f;
131
132 for (auto& langEntry : testSet.langSamples) {
133 auto shapeAndDrawToCanvas = [canvas, paint, langEntry](const SkFont& font,
134 SkPoint coord) {
135 std::string testString(langEntry.sampleShort.c_str(),
136 langEntry.sampleShort.size());
137 SkTextBlobBuilderRunHandler textBlobBuilder(testString.c_str(), {0, 0});
138 std::unique_ptr<SkShaper> shaper = SkShaper::Make();
139 shaper->shape(testString.c_str(),
140 testString.size(),
141 font,
142 true,
143 999999, /* Don't linebreak. */
144 &textBlobBuilder);
145 sk_sp<const SkTextBlob> blob = textBlobBuilder.makeBlob();
146 canvas->drawTextBlob(blob.get(), coord.x(), coord.y(), paint);
147 return blob->bounds();
148 };
149
150 auto roundToDevicePixels = [canvas](SkPoint& point) {
151 SkMatrix ctm = canvas->getLocalToDeviceAs3x3();
152 SkPoint mapped = ctm.mapPoint(point);
153 SkPoint mappedRounded =
154 SkPoint::Make(roundf(mapped.x()), roundf(mapped.y()));
155 SkMatrix inverse;
156 bool inverseExists = ctm.invert(&inverse);
157 SkASSERT(inverseExists);
158 if (inverseExists) {
159 point = inverse.mapPoint(mappedRounded);
160 }
161 };
162
163 auto fontationsCoord = [yCoord, roundToDevicePixels]() {
164 SkPoint fontationsCoord = SkPoint::Make(kMargin, yCoord);
165 roundToDevicePixels(fontationsCoord);
166 return fontationsCoord;
167 };
168
169 auto freetypeCoord = [yCoord, maxBounds, roundToDevicePixels]() {
170 SkPoint freetypeCoord = SkPoint::Make(
171 2 * kMargin + maxBounds.left() + maxBounds.width(), yCoord);
172 roundToDevicePixels(freetypeCoord);
173 return freetypeCoord;
174 };
175
176 switch (phase) {
177 case DrawPhase::Fontations: {
178 SkRect boundsFontations = shapeAndDrawToCanvas(font, fontationsCoord());
179 /* Determine maximum of column width across all language samples. */
180 boundsFontations.roundOut();
181 maxBounds.join(boundsFontations);
182 break;
183 }
184 case DrawPhase::FreeType: {
185 shapeAndDrawToCanvas(ftFont, freetypeCoord());
186 break;
187 }
188 case DrawPhase::Comparison: {
189 /* Read back pixels from equally sized rectangles from the space in
190 * SkCanvas where Fontations and FreeType sample texts were drawn,
191 * compare them using pixel comparisons similar to SkDiff, draw a
192 * comparison as faint pixel differences, and as an amplified
193 * visualization in which each differing pixel is drawn as white. */
194 SkPoint fontationsOrigin = fontationsCoord();
195 SkPoint freetypeOrigin = freetypeCoord();
196 SkRect fontationsBBox(maxBounds.makeOffset(fontationsOrigin));
197 SkRect freetypeBBox(maxBounds.makeOffset(freetypeOrigin));
198
199 SkMatrix ctm = canvas->getLocalToDeviceAs3x3();
200 ctm.mapRect(&fontationsBBox, fontationsBBox);
201 ctm.mapRect(&freetypeBBox, freetypeBBox);
202
203 SkIRect fontationsIBox(fontationsBBox.roundOut());
204 SkIRect freetypeIBox(freetypeBBox.roundOut());
205
206 SkISize pixelDimensions(fontationsIBox.size());
207 SkImageInfo canvasImageInfo = canvas->imageInfo();
208 SkImageInfo diffImageInfo =
209 SkImageInfo::Make(pixelDimensions,
210 SkColorType::kN32_SkColorType,
212
213 SkBitmap diffBitmap, highlightDiffBitmap;
214 diffBitmap.allocPixels(diffImageInfo, 0);
215 highlightDiffBitmap.allocPixels(diffImageInfo, 0);
216
217 // Workaround OveridePaintFilterCanvas limitations
218 // by getting pixel access through peekPixels()
219 // instead of readPixels(). Then use same pixmap to
220 // later write back the comparison results.
221 SkPixmap canvasPixmap;
222 if (!canvas->peekPixels(&canvasPixmap)) {
223 break;
224 }
225
226 SkPixmap fontationsPixmap, freetypePixmap;
227 if (!canvasPixmap.extractSubset(&fontationsPixmap, fontationsIBox) ||
228 !canvasPixmap.extractSubset(&freetypePixmap, freetypeIBox))
229 {
230 break;
231 }
232
233 comparePixels(fontationsPixmap, freetypePixmap,
234 &diffBitmap, &highlightDiffBitmap);
235
236 /* Place comparison results as two extra columns, shift up to account
237 for placement of rectangles vs. SkTextBlobs (baseline shift). */
238 SkPoint comparisonCoord = ctm.mapPoint(SkPoint::Make(
239 3 * kMargin + maxBounds.width() * 2, yCoord + maxBounds.top()));
240 SkPoint whiteCoord = ctm.mapPoint(SkPoint::Make(
241 4 * kMargin + maxBounds.width() * 3, yCoord + maxBounds.top()));
242
243 SkSurfaceProps canvasSurfaceProps = canvas->getBaseProps();
244 sk_sp<SkSurface> writeBackSurface =
245 SkSurfaces::WrapPixels(canvasPixmap, &canvasSurfaceProps);
246
247 writeBackSurface->writePixels(
248 diffBitmap, comparisonCoord.x(), comparisonCoord.y());
249 writeBackSurface->writePixels(
250 highlightDiffBitmap, whiteCoord.x(), whiteCoord.y());
251 break;
252 }
253 }
254
255 yCoord += font.getSize() * kLangYIncrementScale;
256 }
257 }
258 }
259
260 return DrawResult::kOk;
261 }
kUnpremul_SkAlphaType
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kNone
glyph outlines unchanged
SK_API sk_sp< SkTypeface > SkTypeface_Make_Fontations(std::unique_ptr< SkStreamAsset > fontData, const SkFontArguments &args)
constexpr int kMargin
Definition: aaxfermodes.cpp:31
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
bool peekPixels(SkPixmap *pixmap)
Definition: SkCanvas.cpp:1237
SkMatrix getLocalToDeviceAs3x3() const
Definition: SkCanvas.h:2222
SkSurfaceProps getBaseProps() const
Definition: SkCanvas.cpp:1218
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
SkPoint mapPoint(SkPoint pt) const
Definition: SkMatrix.h:1374
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
bool extractSubset(SkPixmap *subset, const SkIRect &area) const
Definition: SkPixmap.cpp:65
static std::unique_ptr< SkShaper > Make(sk_sp< SkFontMgr > fallback=nullptr)
Definition: SkShaper.cpp:36
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition: SkStream.cpp:922
void writePixels(const SkPixmap &src, int dstX, int dstY)
Definition: SkSurface.cpp:202
const SkRect & bounds() const
Definition: SkTextBlob.h:53
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
font
Font Metadata and Metrics.
Definition: SkRect.h:32
Definition: SkSize.h:16
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

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