37
37
#include " src/gpu/GrRenderTargetContextPriv.h"
38
38
#include " src/gpu/SkGr.h"
39
39
#include " src/gpu/effects/generated/GrConstColorProcessor.h"
40
+ #include " src/gpu/effects/generated/GrModulateAlphaEffect.h"
41
+ #include " src/gpu/effects/generated/GrModulateRGBAEffect.h"
40
42
#include " src/gpu/ops/GrDrawOp.h"
41
43
#include " src/gpu/ops/GrFillRectOp.h"
42
44
#include " tools/ToolUtils.h"
46
48
47
49
namespace skiagm {
48
50
/* *
49
- * This GM directly exercises GrConstColorProcessor.
51
+ * This GM directly exercises GrConstColorProcessor, GrModulateRGBAEffect and GrModulateAlphaEffect .
50
52
*/
51
- class ConstColorProcessor : public GpuGM {
53
+ class ColorProcessor : public GpuGM {
52
54
public:
53
- ConstColorProcessor () {
55
+ enum class TestMode {
56
+ kConstColor ,
57
+ kModulateRGBA ,
58
+ kModulateAlpha
59
+ };
60
+
61
+ ColorProcessor (TestMode mode) : fMode (mode) {
54
62
this ->setBGColor (0xFFDDDDDD );
55
63
}
56
64
57
65
protected:
58
66
SkString onShortName () override {
59
- return SkString (" const_color_processor" );
67
+ switch (fMode ) {
68
+ case TestMode::kConstColor : return SkString (" const_color_processor" );
69
+ case TestMode::kModulateRGBA : return SkString (" modulate_rgba" );
70
+ case TestMode::kModulateAlpha : return SkString (" modulate_alpha" );
71
+ }
72
+ SkUNREACHABLE;
60
73
}
61
74
62
75
SkISize onISize () override {
@@ -86,106 +99,110 @@ class ConstColorProcessor : public GpuGM {
86
99
0x00000000 ,
87
100
};
88
101
89
- const char * kModeStrs [] {
90
- " kIgnore" ,
91
- " kModulateRGBA" ,
92
- " kModulateA" ,
93
- };
94
- static_assert (SK_ARRAY_COUNT (kModeStrs ) == GrConstColorProcessor::kInputModeCnt );
95
-
96
102
SkScalar y = kPad ;
97
103
SkScalar x = kPad ;
98
104
SkScalar maxW = 0 ;
99
105
for (size_t paintType = 0 ; paintType < SK_ARRAY_COUNT (kPaintColors ) + 1 ; ++paintType) {
100
106
for (size_t procColor = 0 ; procColor < SK_ARRAY_COUNT (kColors ); ++procColor) {
101
- for (int m = 0 ; m < GrConstColorProcessor::kInputModeCnt ; ++m) {
102
- // translate by x,y for the canvas draws and the test target draws.
103
- canvas->save ();
104
- canvas->translate (x, y);
105
-
106
- // rect to draw
107
- SkRect renderRect = SkRect::MakeXYWH (0 , 0 , kRectSize , kRectSize );
108
-
109
- // Create a base-layer FP for the const color processor to draw on top of.
110
- std::unique_ptr<GrFragmentProcessor> baseFP;
111
- if (paintType >= SK_ARRAY_COUNT (kPaintColors )) {
112
- GrColorInfo colorInfo;
113
- GrFPArgs args (context, SkSimpleMatrixProvider (SkMatrix::I ()),
114
- kHigh_SkFilterQuality , &colorInfo);
115
- baseFP = as_SB (fShader )->asFragmentProcessor (args);
116
- } else {
117
- baseFP = GrConstColorProcessor::Make (
118
- /* inputFP=*/ nullptr ,
119
- SkPMColor4f::FromBytes_RGBA (kPaintColors [paintType]),
120
- GrConstColorProcessor::InputMode::kIgnore );
121
- }
122
-
123
- // Layer a const-color FP on top of the base layer, using various modes/colors.
124
- auto constColorFP = GrConstColorProcessor::Make (
125
- std::move (baseFP), SkPMColor4f::FromBytes_RGBA (kColors [procColor]),
126
- GrConstColorProcessor::InputMode (m));
127
-
128
- // Render the FP tree.
129
- if (auto op = sk_gpu_test::test_ops::MakeRect (context,
130
- std::move (constColorFP),
131
- renderRect.makeOffset (x, y),
132
- renderRect,
133
- SkMatrix::I ())) {
134
- renderTargetContext->priv ().testingOnly_addDrawOp (std::move (op));
135
- }
136
-
137
- // Draw labels for the input to the processor and the processor to the right of
138
- // the test rect. The input label appears above the processor label.
139
- SkFont labelFont;
140
- labelFont.setTypeface (ToolUtils::create_portable_typeface ());
141
- labelFont.setEdging (SkFont::Edging::kAntiAlias );
142
- labelFont.setSize (10 .f );
143
- SkPaint labelPaint;
144
- labelPaint.setAntiAlias (true );
145
- SkString inputLabel;
146
- inputLabel.set (" Input: " );
147
- if (paintType >= SK_ARRAY_COUNT (kPaintColors )) {
148
- inputLabel.append (" gradient" );
149
- } else {
150
- inputLabel.appendf (" 0x%08x" , kPaintColors [paintType]);
151
- }
152
- SkString procLabel;
153
- procLabel.printf (" Proc: [0x%08x, %s]" , kColors [procColor], kModeStrs [m]);
154
-
155
- SkRect inputLabelBounds;
156
- // get the bounds of the text in order to position it
157
- labelFont.measureText (inputLabel.c_str (), inputLabel.size (),
158
- SkTextEncoding::kUTF8 , &inputLabelBounds);
159
- canvas->drawString (inputLabel, renderRect.fRight + kPad , -inputLabelBounds.fTop ,
160
- labelFont, labelPaint);
161
- // update the bounds to reflect the offset we used to draw it.
162
- inputLabelBounds.offset (renderRect.fRight + kPad , -inputLabelBounds.fTop );
163
-
164
- SkRect procLabelBounds;
165
- labelFont.measureText (procLabel.c_str (), procLabel.size (),
166
- SkTextEncoding::kUTF8 , &procLabelBounds);
167
- canvas->drawString (procLabel, renderRect.fRight + kPad ,
168
- inputLabelBounds.fBottom + 2 .f - procLabelBounds.fTop ,
169
- labelFont, labelPaint);
170
- procLabelBounds.offset (renderRect.fRight + kPad ,
171
- inputLabelBounds.fBottom + 2 .f - procLabelBounds.fTop );
172
-
173
- labelPaint.setStrokeWidth (0 );
174
- labelPaint.setStyle (SkPaint::kStroke_Style );
175
- canvas->drawRect (renderRect, labelPaint);
176
-
177
- canvas->restore ();
178
-
179
- // update x and y for the next test case.
180
- SkScalar height = renderRect.height ();
181
- SkScalar width = std::max (inputLabelBounds.fRight , procLabelBounds.fRight );
182
- maxW = std::max (maxW, width);
183
- y += height + kPad ;
184
- if (y + height > kHeight ) {
185
- y = kPad ;
186
- x += maxW + kPad ;
187
- maxW = 0 ;
188
- }
107
+ // translate by x,y for the canvas draws and the test target draws.
108
+ canvas->save ();
109
+ canvas->translate (x, y);
110
+
111
+ // rect to draw
112
+ SkRect renderRect = SkRect::MakeXYWH (0 , 0 , kRectSize , kRectSize );
113
+
114
+ // Create a base-layer FP for the const color processor to draw on top of.
115
+ std::unique_ptr<GrFragmentProcessor> baseFP;
116
+ if (paintType >= SK_ARRAY_COUNT (kPaintColors )) {
117
+ GrColorInfo colorInfo;
118
+ GrFPArgs args (context, SkSimpleMatrixProvider (SkMatrix::I ()),
119
+ kHigh_SkFilterQuality , &colorInfo);
120
+ baseFP = as_SB (fShader )->asFragmentProcessor (args);
121
+ } else {
122
+ baseFP = GrConstColorProcessor::Make (
123
+ SkPMColor4f::FromBytes_RGBA (kPaintColors [paintType]));
124
+ }
125
+
126
+ // Layer a color/modulation FP on top of the base layer, using various colors.
127
+ std::unique_ptr<GrFragmentProcessor> colorFP;
128
+ switch (fMode ) {
129
+ case TestMode::kConstColor :
130
+ colorFP = GrConstColorProcessor::Make (
131
+ SkPMColor4f::FromBytes_RGBA (kColors [procColor]));
132
+ break ;
133
+
134
+ case TestMode::kModulateRGBA :
135
+ colorFP = GrModulateRGBAEffect::Make (
136
+ std::move (baseFP),
137
+ SkPMColor4f::FromBytes_RGBA (kColors [procColor]));
138
+ break ;
139
+
140
+ case TestMode::kModulateAlpha :
141
+ colorFP = GrModulateAlphaEffect::Make (
142
+ std::move (baseFP),
143
+ SkPMColor4f::FromBytes_RGBA (kColors [procColor]));
144
+ break ;
145
+ }
146
+
147
+ // Render the FP tree.
148
+ if (auto op = sk_gpu_test::test_ops::MakeRect (context,
149
+ std::move (colorFP),
150
+ renderRect.makeOffset (x, y),
151
+ renderRect,
152
+ SkMatrix::I ())) {
153
+ renderTargetContext->priv ().testingOnly_addDrawOp (std::move (op));
154
+ }
155
+
156
+ // Draw labels for the input to the processor and the processor to the right of
157
+ // the test rect. The input label appears above the processor label.
158
+ SkFont labelFont;
159
+ labelFont.setTypeface (ToolUtils::create_portable_typeface ());
160
+ labelFont.setEdging (SkFont::Edging::kAntiAlias );
161
+ labelFont.setSize (10 .f );
162
+ SkPaint labelPaint;
163
+ labelPaint.setAntiAlias (true );
164
+ SkString inputLabel (" Input: " );
165
+ if (paintType >= SK_ARRAY_COUNT (kPaintColors )) {
166
+ inputLabel.append (" gradient" );
167
+ } else {
168
+ inputLabel.appendf (" 0x%08x" , kPaintColors [paintType]);
169
+ }
170
+ SkString procLabel;
171
+ procLabel.printf (" Proc: [0x%08x]" , kColors [procColor]);
172
+
173
+ SkRect inputLabelBounds;
174
+ // get the bounds of the text in order to position it
175
+ labelFont.measureText (inputLabel.c_str (), inputLabel.size (),
176
+ SkTextEncoding::kUTF8 , &inputLabelBounds);
177
+ canvas->drawString (inputLabel, renderRect.fRight + kPad , -inputLabelBounds.fTop ,
178
+ labelFont, labelPaint);
179
+ // update the bounds to reflect the offset we used to draw it.
180
+ inputLabelBounds.offset (renderRect.fRight + kPad , -inputLabelBounds.fTop );
181
+
182
+ SkRect procLabelBounds;
183
+ labelFont.measureText (procLabel.c_str (), procLabel.size (),
184
+ SkTextEncoding::kUTF8 , &procLabelBounds);
185
+ canvas->drawString (procLabel, renderRect.fRight + kPad ,
186
+ inputLabelBounds.fBottom + 2 .f - procLabelBounds.fTop ,
187
+ labelFont, labelPaint);
188
+ procLabelBounds.offset (renderRect.fRight + kPad ,
189
+ inputLabelBounds.fBottom + 2 .f - procLabelBounds.fTop );
190
+
191
+ labelPaint.setStrokeWidth (0 );
192
+ labelPaint.setStyle (SkPaint::kStroke_Style );
193
+ canvas->drawRect (renderRect, labelPaint);
194
+
195
+ canvas->restore ();
196
+
197
+ // update x and y for the next test case.
198
+ SkScalar height = renderRect.height ();
199
+ SkScalar width = std::max (inputLabelBounds.fRight , procLabelBounds.fRight );
200
+ maxW = std::max (maxW, width);
201
+ y += height + kPad ;
202
+ if (y + height > kHeight ) {
203
+ y = kPad ;
204
+ x += maxW + kPad ;
205
+ maxW = 0 ;
189
206
}
190
207
}
191
208
}
@@ -194,6 +211,7 @@ class ConstColorProcessor : public GpuGM {
194
211
private:
195
212
// Use this as a way of generating an input FP
196
213
sk_sp<SkShader> fShader ;
214
+ TestMode fMode ;
197
215
198
216
static constexpr SkScalar kPad = 10 .f;
199
217
static constexpr SkScalar kRectSize = 20 .f;
@@ -203,5 +221,8 @@ class ConstColorProcessor : public GpuGM {
203
221
typedef GM INHERITED;
204
222
};
205
223
206
- DEF_GM (return new ConstColorProcessor;)
224
+ DEF_GM (return new ColorProcessor{ColorProcessor::TestMode::kConstColor };)
225
+ DEF_GM (return new ColorProcessor{ColorProcessor::TestMode::kModulateRGBA };)
226
+ DEF_GM (return new ColorProcessor{ColorProcessor::TestMode::kModulateAlpha };)
227
+
207
228
}
0 commit comments