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

Public Member Functions

 ColrV1GM (const char *testName, SkSpan< const uint32_t > codepoints, SkScalar skewX, SkScalar rotateDeg, std::initializer_list< SkFontArguments::VariationPosition::Coordinate > specifiedVariations)
 
- 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
 
bool onGetControls (SkMetaData *controls) override
 
void onSetControls (const SkMetaData &controls) override
 
SkISize getISize () override
 
sk_sp< SkTypefacemakeVariedTypeface ()
 
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 43 of file colrv1.cpp.

Constructor & Destructor Documentation

◆ ColrV1GM()

skiagm::ColrV1GM::ColrV1GM ( const char *  testName,
SkSpan< const uint32_t >  codepoints,
SkScalar  skewX,
SkScalar  rotateDeg,
std::initializer_list< SkFontArguments::VariationPosition::Coordinate specifiedVariations 
)
inline

Definition at line 45 of file colrv1.cpp.

51 : fTestName(testName), fCodepoints(codepoints), fSkewX(skewX), fRotateDeg(rotateDeg) {
52 fVariationPosition.coordinateCount = specifiedVariations.size();
53 fCoordinates = std::make_unique<SkFontArguments::VariationPosition::Coordinate[]>(
54 specifiedVariations.size());
55 for (size_t i = 0; i < specifiedVariations.size(); ++i) {
56 fCoordinates[i] = std::data(specifiedVariations)[i];
57 }
58
59 fVariationPosition.coordinates = fCoordinates.get();
60 }
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Member Function Documentation

◆ getISize()

SkISize skiagm::ColrV1GM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 102 of file colrv1.cpp.

102 {
103 // Sweep tests get a slightly wider canvas so that glyphs from one group fit in one row.
104 if (fTestName.equals("sweep_varsweep")) {
105 return SkISize::Make(xWidth + 500, xWidth);
106 }
107 return SkISize::Make(xWidth, xWidth);
108 }
bool equals(const SkString &) const
Definition: SkString.cpp:324
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

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

Implements skiagm::GM.

Definition at line 72 of file colrv1.cpp.

72 {
73 SkASSERT(!fTestName.isEmpty());
74 SkString gm_name = SkStringPrintf("colrv1_%s", fTestName.c_str());
75
76 if (fSkewX) {
77 gm_name.append(SkStringPrintf("_skew_%.2f", fSkewX));
78 }
79
80 if (fRotateDeg) {
81 gm_name.append(SkStringPrintf("_rotate_%.2f", fRotateDeg));
82 }
83
84 for (int i = 0; i < fVariationPosition.coordinateCount; ++i) {
86 fVariationPosition.coordinates[i].axis);
87 gm_name.append(SkStringPrintf(
88 "_%s_%.2f", tagName.c_str(), fVariationPosition.coordinates[i].value));
89 }
90
91 return gm_name;
92 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
bool isEmpty() const
Definition: SkString.h:130
void append(const char text[])
Definition: SkString.h:203
const char * c_str() const
Definition: SkString.h:133
static SkString tagToString(SkFourByteTag tag)
Definition: ToolUtils.cpp:563

◆ makeVariedTypeface()

sk_sp< SkTypeface > skiagm::ColrV1GM::makeVariedTypeface ( )
inlineprotected

Definition at line 110 of file colrv1.cpp.

110 {
111 if (!fTypeface) {
112 return nullptr;
113 }
115 fVariationSliders.getCoordinates();
116 SkFontArguments::VariationPosition varPos = {coords.data(),
117 static_cast<int>(coords.size())};
119 args.setVariationDesignPosition(varPos);
120 return fTypeface->makeClone(args);
121 }
constexpr T * data() const
Definition: SkSpan_impl.h:94
constexpr size_t size() const
Definition: SkSpan_impl.h:95
sk_sp< SkTypeface > makeClone(const SkFontArguments &) const
Definition: SkTypeface.cpp:190
SkSpan< const SkFontArguments::VariationPosition::Coordinate > getCoordinates()
Definition: ToolUtils.cpp:600
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ onDraw()

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

Reimplemented from skiagm::GM.

Definition at line 123 of file colrv1.cpp.

123 {
124 canvas->drawColor(SK_ColorWHITE);
126
127 canvas->translate(xTranslate, 20);
128
129 if (!fTypeface) {
130 *errorMsg = "Did not recognize COLR v1 font format.";
131 return DrawResult::kSkip;
132 }
133
134 canvas->rotate(fRotateDeg);
135 canvas->skew(fSkewX, 0);
136
138
139 SkFontMetrics metrics;
140 SkScalar y = 0;
141 std::vector<SkColor> paint_colors = {
143 auto paint_color_iterator = paint_colors.begin();
144 for (SkScalar textSize : kTextSizes) {
145 font.setSize(textSize);
146 font.getMetrics(&metrics);
147 font.setHinting(SkFontHinting::kNone);
148 SkScalar y_shift = -(metrics.fAscent + metrics.fDescent + metrics.fLeading) * 1.2;
149 y += y_shift;
150 paint.setColor(*paint_color_iterator);
151 int x = 0;
152 // Perform simple line breaking to fit more glyphs into the GM canvas.
153 for (size_t i = 0; i < fCodepoints.size(); ++i) {
154 SkScalar glyphAdvance = font.measureText(
155 &fCodepoints[i], sizeof(uint32_t), SkTextEncoding::kUTF32, nullptr);
156 if (0 < x && getISize().width() - xTranslate < x + glyphAdvance) {
157 y += y_shift;
158 x = 0;
159 }
160 canvas->drawSimpleText(&fCodepoints[i],
161 sizeof(uint32_t),
163 x,
164 y,
165 font,
166 paint);
167 x += glyphAdvance + glyphAdvance * 0.05f;
168 }
169 paint_color_iterator++;
170 }
171 return DrawResult::kOk;
172 }
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kNone
glyph outlines unchanged
@ kUTF32
uses four byte words to represent all of Unicode
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
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void skew(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1312
Definition: SkFont.h:35
sk_sp< SkTypeface > makeVariedTypeface()
Definition: colrv1.cpp:110
SkISize getISize() override
Definition: colrv1.cpp:102
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
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
constexpr int32_t width() const
Definition: SkSize.h:36

◆ onGetControls()

bool skiagm::ColrV1GM::onGetControls ( SkMetaData controls)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 94 of file colrv1.cpp.

94 {
95 return fVariationSliders.writeControls(controls);
96 }
bool writeControls(SkMetaData *controls)
Definition: ToolUtils.cpp:573

◆ onOnceBeforeDraw()

void skiagm::ColrV1GM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 63 of file colrv1.cpp.

63 {
64 if (fVariationPosition.coordinateCount) {
65 fTypeface = ToolUtils::CreateTypefaceFromResource(kTestFontNameVariable, 0);
66 } else {
67 fTypeface = ToolUtils::CreateTypefaceFromResource(kTestFontName, 0);
68 }
69 fVariationSliders = ToolUtils::VariationSliders(fTypeface.get(), fVariationPosition);
70 }
T * get() const
Definition: SkRefCnt.h:303
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)

◆ onSetControls()

void skiagm::ColrV1GM::onSetControls ( const SkMetaData controls)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 98 of file colrv1.cpp.

98 {
99 return fVariationSliders.readControls(controls);
100 }
void readControls(const SkMetaData &controls, bool *changed=nullptr)
Definition: ToolUtils.cpp:585

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