Skip to content

Commit e3a39f7

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Update ConstColor FP to support an input FP.
In the "ignore input" mode, the input FP contributes nothing and is never sampled. In the "modulate input" cases, the input FP is sampled as one would expect. Change-Id: I96717d63d8e3d7ef6aa4eaaf88154c6e5ce47e55 Bug: skia:10217 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296299 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
1 parent a4a132c commit e3a39f7

15 files changed

+144
-89
lines changed

gm/constcolorprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ConstColorProcessor : public GpuGM {
119119

120120
GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m;
121121
SkPMColor4f color = SkPMColor4f::FromBytes_RGBA(kColors[procColor]);
122-
auto fp = GrConstColorProcessor::Make(color, mode);
122+
auto fp = GrConstColorProcessor::Make(/*inputFP=*/nullptr, color, mode);
123123

124124
grPaint.addColorFragmentProcessor(std::move(fp));
125125
renderTargetContext->priv().testingOnly_addDrawOp(

src/core/SkModeColorFilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ std::unique_ptr<GrFragmentProcessor> SkModeColorFilter::asFragmentProcessor(
9494
return nullptr;
9595
}
9696

97-
auto constFP = GrConstColorProcessor::Make(SkColorToPMColor4f(fColor, dstColorInfo),
97+
auto constFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr,
98+
SkColorToPMColor4f(fColor, dstColorInfo),
9899
GrConstColorProcessor::InputMode::kIgnore);
99100
auto fp = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std::move(constFP), fMode);
100101
if (!fp) {

src/effects/imagefilters/SkArithmeticImageFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
362362
background->alphaType(),
363363
ctx.colorSpace());
364364
} else {
365-
bgFP = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
365+
bgFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
366366
GrConstColorProcessor::InputMode::kIgnore);
367367
}
368368

src/effects/imagefilters/SkXfermodeImageFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilterImpl::filterImageGPU(
272272
background->alphaType(),
273273
ctx.colorSpace());
274274
} else {
275-
bgFP = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
275+
bgFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
276276
GrConstColorProcessor::InputMode::kIgnore);
277277
}
278278

src/gpu/GrFragmentProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
420420
SkPMColor4f knownColor;
421421
int leadingFPsToEliminate = info.initialProcessorsToEliminate(&knownColor);
422422
if (leadingFPsToEliminate) {
423-
std::unique_ptr<GrFragmentProcessor> colorFP(
424-
GrConstColorProcessor::Make(knownColor, GrConstColorProcessor::InputMode::kIgnore));
423+
std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make(
424+
/*inputFP=*/nullptr, knownColor, GrConstColorProcessor::InputMode::kIgnore);
425425
if (leadingFPsToEliminate == cnt) {
426426
return colorFP;
427427
}

src/gpu/SkGr.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,19 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
293293
shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std::move(shaderFP),
294294
*primColorMode);
295295

296-
// The above may return null if compose results in a pass through of the prim color.
297-
if (shaderFP) {
298-
grPaint->addColorFragmentProcessor(std::move(shaderFP));
299-
}
300-
301296
// We can ignore origColor here - alpha is unchanged by gamma
302297
float paintAlpha = skPaint.getColor4f().fA;
303298
if (1.0f != paintAlpha) {
304299
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
305300
// color channels. It's value should be treated as the same in ANY color space.
306-
grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
307-
{ paintAlpha, paintAlpha, paintAlpha, paintAlpha },
308-
GrConstColorProcessor::InputMode::kModulateRGBA));
301+
shaderFP = GrConstColorProcessor::Make(
302+
std::move(shaderFP), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
303+
GrConstColorProcessor::InputMode::kModulateRGBA);
304+
}
305+
306+
// The above may return null if compose results in a pass through of the prim color.
307+
if (shaderFP) {
308+
grPaint->addColorFragmentProcessor(std::move(shaderFP));
309309
}
310310
} else {
311311
// The shader's FP sees the paint *unpremul* color
@@ -318,24 +318,24 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
318318
// There is a blend between the primitive color and the paint color. The blend considers
319319
// the opaque paint color. The paint's alpha is applied to the post-blended color.
320320
SkPMColor4f opaqueColor = origColor.makeOpaque().premul();
321-
auto processor = GrConstColorProcessor::Make(opaqueColor,
321+
auto processor = GrConstColorProcessor::Make(/*inputFP=*/nullptr, opaqueColor,
322322
GrConstColorProcessor::InputMode::kIgnore);
323323
processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std::move(processor),
324324
*primColorMode);
325-
if (processor) {
326-
grPaint->addColorFragmentProcessor(std::move(processor));
327-
}
328-
329325
grPaint->setColor4f(opaqueColor);
330326

331327
// We can ignore origColor here - alpha is unchanged by gamma
332328
float paintAlpha = skPaint.getColor4f().fA;
333329
if (1.0f != paintAlpha) {
334330
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
335331
// color channels. It's value should be treated as the same in ANY color space.
336-
grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
337-
{ paintAlpha, paintAlpha, paintAlpha, paintAlpha },
338-
GrConstColorProcessor::InputMode::kModulateRGBA));
332+
processor = GrConstColorProcessor::Make(
333+
std::move(processor), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
334+
GrConstColorProcessor::InputMode::kModulateRGBA);
335+
}
336+
337+
if (processor) {
338+
grPaint->addColorFragmentProcessor(std::move(processor));
339339
}
340340
} else {
341341
// No shader, no primitive color.

src/gpu/effects/GrConstColorProcessor.fp

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,60 @@ enum class InputMode {
1313
kLast = kModulateA
1414
};
1515

16+
in fragmentProcessor? inputFP;
1617
layout(ctype=SkPMColor4f, tracked) in uniform half4 color;
1718
layout(key) in InputMode mode;
1819

1920
@optimizationFlags {
20-
OptFlags(color, mode)
21+
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
22+
(kConstantOutputForConstantInput_OptimizationFlag |
23+
((mode != InputMode::kIgnore) ? kCompatibleWithCoverageAsAlpha_OptimizationFlag
24+
: kNone_OptimizationFlags) |
25+
((color.isOpaque()) ? kPreservesOpaqueInput_OptimizationFlag
26+
: kNone_OptimizationFlags))
2127
}
2228

2329
void main() {
2430
@switch (mode) {
25-
case InputMode::kIgnore:
31+
case InputMode::kIgnore: {
2632
sk_OutColor = color;
2733
break;
28-
case InputMode::kModulateRGBA:
29-
sk_OutColor = sk_InColor * color;
34+
}
35+
case InputMode::kModulateRGBA: {
36+
half4 inputColor = sample(inputFP, sk_InColor);
37+
sk_OutColor = inputColor * color;
3038
break;
31-
case InputMode::kModulateA:
32-
sk_OutColor = sk_InColor.a * color;
39+
}
40+
case InputMode::kModulateA: {
41+
half inputAlpha = sample(inputFP, sk_InColor).a;
42+
sk_OutColor = inputAlpha * color;
3343
break;
44+
}
3445
}
3546
}
3647

3748
@class {
3849
static const int kInputModeCnt = (int) InputMode::kLast + 1;
3950

40-
static OptimizationFlags OptFlags(const SkPMColor4f& color, InputMode mode) {
41-
OptimizationFlags flags = kConstantOutputForConstantInput_OptimizationFlag;
42-
if (mode != InputMode::kIgnore) {
43-
flags |= kCompatibleWithCoverageAsAlpha_OptimizationFlag;
44-
}
45-
if (color.isOpaque()) {
46-
flags |= kPreservesOpaqueInput_OptimizationFlag;
47-
}
48-
return flags;
49-
}
50-
51-
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
51+
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
5252
switch (mode) {
53-
case InputMode::kIgnore:
53+
case InputMode::kIgnore: {
5454
return color;
55-
case InputMode::kModulateA:
55+
}
56+
case InputMode::kModulateA: {
57+
SkPMColor4f input = this->numChildProcessors()
58+
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
59+
: inColor;
5660
return color * input.fA;
57-
case InputMode::kModulateRGBA:
61+
}
62+
case InputMode::kModulateRGBA: {
63+
SkPMColor4f input = this->numChildProcessors()
64+
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
65+
: inColor;
5866
return color * input;
67+
}
5968
}
60-
SK_ABORT("Unexpected mode");
69+
SkUNREACHABLE;
6170
}
6271
}
6372

@@ -82,5 +91,5 @@ void main() {
8291
break;
8392
}
8493
InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt));
85-
return GrConstColorProcessor::Make(color, mode);
94+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, color, mode);
8695
}

src/gpu/effects/GrConvexPolyEffect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::Make(GrClipEdgeType typ
105105
// skip the draw or omit the clip element.
106106
if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) {
107107
if (GrProcessorEdgeTypeIsInverseFill(type)) {
108-
return GrConstColorProcessor::Make(SK_PMColor4fWHITE,
108+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fWHITE,
109109
GrConstColorProcessor::InputMode::kModulateRGBA);
110110
}
111111
// This could use kIgnore instead of kModulateRGBA but it would trigger a debug print
112112
// about a coverage processor not being compatible with the alpha-as-coverage optimization.
113113
// We don't really care about this unlikely case so we just use kModulateRGBA to suppress
114114
// the print.
115-
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
115+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
116116
GrConstColorProcessor::InputMode::kModulateRGBA);
117117
}
118118

src/gpu/effects/GrSkSLFP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ std::unique_ptr<GrFragmentProcessor> GrSkSLFP::TestCreate(GrProcessorTestData* d
284284
auto result = GrSkSLFP::Make(d->context(), effect, "Arithmetic",
285285
SkData::MakeWithCopy(&inputs, sizeof(inputs)));
286286
result->addChild(GrConstColorProcessor::Make(
287-
SK_PMColor4fWHITE, GrConstColorProcessor::InputMode::kIgnore));
287+
/*inputFP=*/nullptr, SK_PMColor4fWHITE, GrConstColorProcessor::InputMode::kIgnore));
288288
return std::unique_ptr<GrFragmentProcessor>(result.release());
289289
}
290290
case 2: {

src/gpu/effects/GrXfermodeFragmentProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ std::unique_ptr<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromTwoPro
245245
SkBlendMode mode) {
246246
switch (mode) {
247247
case SkBlendMode::kClear:
248-
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
248+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
249249
GrConstColorProcessor::InputMode::kIgnore);
250250
case SkBlendMode::kSrc:
251251
return src;
@@ -496,7 +496,7 @@ std::unique_ptr<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromDstPro
496496
std::unique_ptr<GrFragmentProcessor> dst, SkBlendMode mode) {
497497
switch (mode) {
498498
case SkBlendMode::kClear:
499-
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
499+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
500500
GrConstColorProcessor::InputMode::kIgnore);
501501
case SkBlendMode::kSrc:
502502
return nullptr;
@@ -510,7 +510,7 @@ std::unique_ptr<GrFragmentProcessor> GrXfermodeFragmentProcessor::MakeFromSrcPro
510510
std::unique_ptr<GrFragmentProcessor> src, SkBlendMode mode) {
511511
switch (mode) {
512512
case SkBlendMode::kClear:
513-
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT,
513+
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
514514
GrConstColorProcessor::InputMode::kIgnore);
515515
case SkBlendMode::kDst:
516516
return nullptr;

0 commit comments

Comments
 (0)