Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7c19677

Browse files
johnstiles-googleSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Split GrConstColorProcessor into three separate .fp effects.
ConstColorProcessor contained three separate InputModes with their own unique behaviors, but every (non-test) call site simply hardcoded one of the InputModes. This change also allows the actual const-color processor to remove the inputFP entirely; it is never sampled. The GM slide has been split into three separate slides as well. Change-Id: I2b77f4eab4d655f06e3704fb6fde8d4f8c70a075 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301987 Commit-Queue: John Stiles <[email protected]> Reviewed-by: Brian Salomon <[email protected]>
1 parent d9800f8 commit 7c19677

24 files changed

+598
-301
lines changed

gm/constcolorprocessor.cpp

Lines changed: 121 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "src/gpu/GrRenderTargetContextPriv.h"
3838
#include "src/gpu/SkGr.h"
3939
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
40+
#include "src/gpu/effects/generated/GrModulateAlphaEffect.h"
41+
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
4042
#include "src/gpu/ops/GrDrawOp.h"
4143
#include "src/gpu/ops/GrFillRectOp.h"
4244
#include "tools/ToolUtils.h"
@@ -46,17 +48,28 @@
4648

4749
namespace skiagm {
4850
/**
49-
* This GM directly exercises GrConstColorProcessor.
51+
* This GM directly exercises GrConstColorProcessor, GrModulateRGBAEffect and GrModulateAlphaEffect.
5052
*/
51-
class ConstColorProcessor : public GpuGM {
53+
class ColorProcessor : public GpuGM {
5254
public:
53-
ConstColorProcessor() {
55+
enum class TestMode {
56+
kConstColor,
57+
kModulateRGBA,
58+
kModulateAlpha
59+
};
60+
61+
ColorProcessor(TestMode mode) : fMode(mode) {
5462
this->setBGColor(0xFFDDDDDD);
5563
}
5664

5765
protected:
5866
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;
6073
}
6174

6275
SkISize onISize() override {
@@ -86,106 +99,110 @@ class ConstColorProcessor : public GpuGM {
8699
0x00000000,
87100
};
88101

89-
const char* kModeStrs[] {
90-
"kIgnore",
91-
"kModulateRGBA",
92-
"kModulateA",
93-
};
94-
static_assert(SK_ARRAY_COUNT(kModeStrs) == GrConstColorProcessor::kInputModeCnt);
95-
96102
SkScalar y = kPad;
97103
SkScalar x = kPad;
98104
SkScalar maxW = 0;
99105
for (size_t paintType = 0; paintType < SK_ARRAY_COUNT(kPaintColors) + 1; ++paintType) {
100106
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;
189206
}
190207
}
191208
}
@@ -194,6 +211,7 @@ class ConstColorProcessor : public GpuGM {
194211
private:
195212
// Use this as a way of generating an input FP
196213
sk_sp<SkShader> fShader;
214+
TestMode fMode;
197215

198216
static constexpr SkScalar kPad = 10.f;
199217
static constexpr SkScalar kRectSize = 20.f;
@@ -203,5 +221,8 @@ class ConstColorProcessor : public GpuGM {
203221
typedef GM INHERITED;
204222
};
205223

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+
207228
}

gn/gpu.gni

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ skia_gpu_sources = [
344344
"$_src/gpu/effects/generated/GrMagnifierEffect.h",
345345
"$_src/gpu/effects/generated/GrMixerEffect.cpp",
346346
"$_src/gpu/effects/generated/GrMixerEffect.h",
347+
"$_src/gpu/effects/generated/GrModulateAlphaEffect.cpp",
348+
"$_src/gpu/effects/generated/GrModulateAlphaEffect.h",
349+
"$_src/gpu/effects/generated/GrModulateRGBAEffect.cpp",
350+
"$_src/gpu/effects/generated/GrModulateRGBAEffect.h",
347351
"$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp",
348352
"$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h",
349353
"$_src/gpu/effects/generated/GrRGBToHSLFilterEffect.cpp",

gn/sksl.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ skia_gpu_processor_sources = [
9696
"$_src/gpu/effects/GrLumaColorFilterEffect.fp",
9797
"$_src/gpu/effects/GrMagnifierEffect.fp",
9898
"$_src/gpu/effects/GrMixerEffect.fp",
99+
"$_src/gpu/effects/GrModulateAlphaEffect.fp",
100+
"$_src/gpu/effects/GrModulateRGBAEffect.fp",
99101
"$_src/gpu/effects/GrOverrideInputFragmentProcessor.fp",
100102
"$_src/gpu/effects/GrRGBToHSLFilterEffect.fp",
101103
"$_src/gpu/effects/GrRRectBlurEffect.fp",

src/core/SkModeColorFilter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ GrFPResult SkModeColorFilter::asFragmentProcessor(std::unique_ptr<GrFragmentProc
9999

100100
SkDEBUGCODE(const bool fpHasConstIO = !inputFP || inputFP->hasConstantOutputForConstantInput();)
101101

102-
auto colorFP = GrConstColorProcessor::Make(
103-
/*inputFP=*/nullptr, SkColorToPMColor4f(fColor, dstColorInfo),
104-
GrConstColorProcessor::InputMode::kIgnore);
102+
auto colorFP = GrConstColorProcessor::Make(SkColorToPMColor4f(fColor, dstColorInfo));
105103
auto xferFP = GrXfermodeFragmentProcessor::Make(
106104
std::move(colorFP), std::move(inputFP), fMode,
107105
GrXfermodeFragmentProcessor::ComposeBehavior::kSkModeBehavior);

src/effects/imagefilters/SkArithmeticImageFilter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
348348
background->getColorSpace(), background->alphaType(),
349349
ctx.colorSpace(), kPremul_SkAlphaType);
350350
} else {
351-
bgFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
352-
GrConstColorProcessor::InputMode::kIgnore);
351+
bgFP = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
353352
}
354353

355354
if (foreground) {

src/effects/imagefilters/SkXfermodeImageFilter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilterImpl::filterImageGPU(
268268
background->alphaType(), ctx.colorSpace(),
269269
kPremul_SkAlphaType);
270270
} else {
271-
fp = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
272-
GrConstColorProcessor::InputMode::kIgnore);
271+
fp = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
273272
}
274273

275274
if (foregroundView.asTextureProxy()) {

src/gpu/GrFragmentProcessor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
431431
SkPMColor4f knownColor;
432432
int leadingFPsToEliminate = info.initialProcessorsToEliminate(&knownColor);
433433
if (leadingFPsToEliminate) {
434-
std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make(
435-
/*inputFP=*/nullptr, knownColor, GrConstColorProcessor::InputMode::kIgnore);
434+
std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make(knownColor);
436435
if (leadingFPsToEliminate == cnt) {
437436
return colorFP;
438437
}

src/gpu/GrProcessor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class GrProcessor {
121121
kGrMatrixConvolutionEffect_ClassID,
122122
kGrMatrixEffect_ClassID,
123123
kGrMeshTestProcessor_ClassID,
124+
kGrModulateAlphaEffect_ClassID,
125+
kGrModulateRGBAEffect_ClassID,
124126
kGrMorphologyEffect_ClassID,
125127
kGrMixerEffect_ClassID,
126128
kGrOverrideInputFragmentProcessor_ClassID,

src/gpu/GrProcessorUnitTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories()
8181
* we verify the count is as expected. If a new factory is added, then these numbers must be
8282
* manually adjusted.
8383
*/
84-
static const int kFPFactoryCount = 37;
84+
static const int kFPFactoryCount = 39;
8585
static const int kGPFactoryCount = 14;
8686
static const int kXPFactoryCount = 4;
8787

src/gpu/SkGr.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "src/gpu/effects/generated/GrClampFragmentProcessor.h"
4646
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
4747
#include "src/gpu/effects/generated/GrDitherEffect.h"
48+
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
4849
#include "src/image/SkImage_Base.h"
4950
#include "src/shaders/SkShaderBase.h"
5051

@@ -262,9 +263,8 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
262263
if (1.0f != paintAlpha) {
263264
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
264265
// color channels. It's value should be treated as the same in ANY color space.
265-
paintFP = GrConstColorProcessor::Make(
266-
std::move(paintFP), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
267-
GrConstColorProcessor::InputMode::kModulateRGBA);
266+
paintFP = GrModulateRGBAEffect::Make(
267+
std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha});
268268
}
269269
} else {
270270
// The shader's FP sees the paint *unpremul* color
@@ -276,8 +276,7 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
276276
// There is a blend between the primitive color and the paint color. The blend considers
277277
// the opaque paint color. The paint's alpha is applied to the post-blended color.
278278
SkPMColor4f opaqueColor = origColor.makeOpaque().premul();
279-
paintFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, opaqueColor,
280-
GrConstColorProcessor::InputMode::kIgnore);
279+
paintFP = GrConstColorProcessor::Make(opaqueColor);
281280
paintFP = GrXfermodeFragmentProcessor::Make(std::move(paintFP), /*dst=*/nullptr,
282281
*primColorMode);
283282
grPaint->setColor4f(opaqueColor);
@@ -287,9 +286,8 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
287286
if (1.0f != paintAlpha) {
288287
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
289288
// color channels. It's value should be treated as the same in ANY color space.
290-
paintFP = GrConstColorProcessor::Make(
291-
std::move(paintFP), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
292-
GrConstColorProcessor::InputMode::kModulateRGBA);
289+
paintFP = GrModulateRGBAEffect::Make(
290+
std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha});
293291
}
294292
} else {
295293
// No shader, no primitive color.

0 commit comments

Comments
 (0)