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

Public Types

enum class  TestMode { kConstColor , kModulateRGBA }
 

Public Member Functions

 ColorProcessor (TestMode mode)
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onOnceBeforeDraw () override
 
DrawResult onDraw (GrRecordingContext *rContext, SkCanvas *canvas, SkString *errorMsg) override
 

Detailed Description

This GM directly exercises Color and ModulateRGBA.

Definition at line 50 of file constcolorprocessor.cpp.

Member Enumeration Documentation

◆ TestMode

Enumerator
kConstColor 
kModulateRGBA 

Definition at line 52 of file constcolorprocessor.cpp.

52 {
53 kConstColor,
54 kModulateRGBA
55 };

Constructor & Destructor Documentation

◆ ColorProcessor()

skiagm::ColorProcessor::ColorProcessor ( TestMode  mode)
inline

Definition at line 57 of file constcolorprocessor.cpp.

57 : fMode(mode) {
58 this->setBGColor(0xFFDDDDDD);
59 }
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228

Member Function Documentation

◆ getISize()

SkISize skiagm::ColorProcessor::getISize ( )
inlineoverrideprotected

Definition at line 70 of file constcolorprocessor.cpp.

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

◆ getName()

SkString skiagm::ColorProcessor::getName ( ) const
inlineoverrideprotected

Definition at line 62 of file constcolorprocessor.cpp.

62 {
63 switch (fMode) {
64 case TestMode::kConstColor: return SkString("const_color_processor");
65 case TestMode::kModulateRGBA: return SkString("modulate_rgba");
66 }
68 }
#define SkUNREACHABLE
Definition: SkAssert.h:135

◆ onDraw()

DrawResult skiagm::ColorProcessor::onDraw ( GrRecordingContext rContext,
SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotected

Definition at line 79 of file constcolorprocessor.cpp.

79 {
81 if (!sdc) {
82 *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
83 return DrawResult::kSkip;
84 }
85
86 constexpr GrColor kColors[] = {
87 0xFFFFFFFF,
88 0xFFFF00FF,
89 0x80000000,
90 0x00000000,
91 };
92
93 constexpr GrColor kPaintColors[] = {
94 0xFFFFFFFF,
95 0xFF0000FF,
96 0x80000080,
97 0x00000000,
98 };
99
100 SkScalar y = kPad;
101 SkScalar x = kPad;
102 SkScalar maxW = 0;
103 for (size_t paintType = 0; paintType < std::size(kPaintColors) + 1; ++paintType) {
104 for (size_t procColor = 0; procColor < std::size(kColors); ++procColor) {
105 // translate by x,y for the canvas draws and the test target draws.
106 canvas->save();
107 canvas->translate(x, y);
108
109 // rect to draw
110 SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectSize);
111
112 // Create a base-layer FP for the const color processor to draw on top of.
113 std::unique_ptr<GrFragmentProcessor> baseFP;
114 if (paintType >= std::size(kPaintColors)) {
115 GrColorInfo colorInfo;
116 SkSurfaceProps props;
117 GrFPArgs args(rContext, &colorInfo, props, GrFPArgs::Scope::kDefault);
118 baseFP = GrFragmentProcessors::Make(fShader.get(), args, SkMatrix::I());
119 } else {
121 SkPMColor4f::FromBytes_RGBA(kPaintColors[paintType]));
122 }
123
124 // Layer a color/modulation FP on top of the base layer, using various colors.
125 std::unique_ptr<GrFragmentProcessor> colorFP;
126 switch (fMode) {
130 break;
131
134 std::move(baseFP), SkPMColor4f::FromBytes_RGBA(kColors[procColor]));
135 break;
136 }
137
138 // Render the FP tree.
139 if (auto op = sk_gpu_test::test_ops::MakeRect(rContext,
140 std::move(colorFP),
141 renderRect.makeOffset(x, y),
142 renderRect,
143 SkMatrix::I())) {
144 sdc->addDrawOp(std::move(op));
145 }
146
147 // Draw labels for the input to the processor and the processor to the right of
148 // the test rect. The input label appears above the processor label.
149 SkFont labelFont;
152 labelFont.setSize(10.f);
153 SkPaint labelPaint;
154 labelPaint.setAntiAlias(true);
155 SkString inputLabel("Input: ");
156 if (paintType >= std::size(kPaintColors)) {
157 inputLabel.append("gradient");
158 } else {
159 inputLabel.appendf("0x%08x", kPaintColors[paintType]);
160 }
161 SkString procLabel;
162 procLabel.printf("Proc: [0x%08x]", kColors[procColor]);
163
164 SkRect inputLabelBounds;
165 // get the bounds of the text in order to position it
166 labelFont.measureText(inputLabel.c_str(), inputLabel.size(),
167 SkTextEncoding::kUTF8, &inputLabelBounds);
168 canvas->drawString(inputLabel, renderRect.fRight + kPad, -inputLabelBounds.fTop,
169 labelFont, labelPaint);
170 // update the bounds to reflect the offset we used to draw it.
171 inputLabelBounds.offset(renderRect.fRight + kPad, -inputLabelBounds.fTop);
172
173 SkRect procLabelBounds;
174 labelFont.measureText(procLabel.c_str(), procLabel.size(),
175 SkTextEncoding::kUTF8, &procLabelBounds);
176 canvas->drawString(procLabel, renderRect.fRight + kPad,
177 inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop,
178 labelFont, labelPaint);
179 procLabelBounds.offset(renderRect.fRight + kPad,
180 inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop);
181
182 labelPaint.setStrokeWidth(0);
184 canvas->drawRect(renderRect, labelPaint);
185
186 canvas->restore();
187
188 // update x and y for the next test case.
189 SkScalar height = renderRect.height();
190 SkScalar width = std::max(inputLabelBounds.fRight, procLabelBounds.fRight);
191 maxW = std::max(maxW, width);
192 y += height + kPad;
193 if (y + height > kHeight) {
194 y = kPad;
195 x += maxW + kPad;
196 maxW = 0;
197 }
198 }
199 }
200
201 return DrawResult::kOk;
202 }
uint32_t GrColor
Definition: GrColor.h:25
@ kUTF8
uses bytes to represent UTF-8 or ASCII
constexpr int kPad
static std::unique_ptr< GrFragmentProcessor > MakeColor(SkPMColor4f color)
static std::unique_ptr< GrFragmentProcessor > ModulateRGBA(std::unique_ptr< GrFragmentProcessor > child, const SkPMColor4f &color)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
void setTypeface(sk_sp< SkTypeface > tf)
Definition: SkFont.cpp:90
SkScalar measureText(const void *text, size_t byteLength, SkTextEncoding encoding, SkRect *bounds=nullptr) const
Definition: SkFont.h:336
void setEdging(Edging edging)
Definition: SkFont.cpp:121
void setSize(SkScalar textSize)
Definition: SkFont.cpp:129
@ kAntiAlias
may have transparent pixels on glyph edges
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
T * get() const
Definition: SkRefCnt.h:303
float SkScalar
Definition: extension.cpp:12
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static float max(float r, float g, float b)
Definition: hsl.cpp:49
double y
double x
std::unique_ptr< GrFragmentProcessor > Make(const SkMaskFilter *maskfilter, const GrFPArgs &args, const SkMatrix &ctm)
sk_sp< SkTypeface > DefaultPortableTypeface()
const DlColor kColors[]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
GrOp::Owner MakeRect(GrRecordingContext *context, GrPaint &&paint, const SkRect &drawRect, const SkRect &localRect, const SkMatrix &localM)
Definition: TestOps.cpp:227
SurfaceDrawContext * TopDeviceSurfaceDrawContext(const SkCanvas *canvas)
Definition: GrCanvas.cpp:20
int32_t height
int32_t width
static SkRGBA4f FromBytes_RGBA(uint32_t color)
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
void offset(float dx, float dy)
Definition: SkRect.h:1016
constexpr float height() const
Definition: SkRect.h:769
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ onOnceBeforeDraw()

void skiagm::ColorProcessor::onOnceBeforeDraw ( )
inlineoverrideprotected

Definition at line 72 of file constcolorprocessor.cpp.

72 {
73 SkColor colors[] = { 0xFFFF0000, 0x2000FF00, 0xFF0000FF};
74 SkPoint pts[] = { SkPoint::Make(0, 0), SkPoint::Make(kRectSize, kRectSize) };
75 fShader = SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors),
77 }
uint32_t SkColor
Definition: SkColor.h:37
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
PODArray< SkColor > colors
Definition: SkRecords.h:276
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

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