diff options
author | 2017-11-20 12:12:24 -0500 | |
---|---|---|
committer | 2017-11-20 20:34:38 +0000 | |
commit | e9d172af84fff5d76e19180a0c2b7b3cc51e90a2 (patch) | |
tree | 115bce6c41c0e7fada2f45de6e7b5e90b464e00a /src/gpu/effects/GrConstColorProcessor.fp | |
parent | 53d863c18cd3b53d8b4c4dcb8505f2c52f1e5c59 (diff) |
converted ConstColorProcessor to SkSL
Bug: skia:
Change-Id: Ic3b18f82c1ab940637fb26dec1cf376dd859b35d
Reviewed-on: https://skia-review.googlesource.com/73720
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/gpu/effects/GrConstColorProcessor.fp')
-rw-r--r-- | src/gpu/effects/GrConstColorProcessor.fp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/gpu/effects/GrConstColorProcessor.fp b/src/gpu/effects/GrConstColorProcessor.fp new file mode 100644 index 0000000000..d7db4f047c --- /dev/null +++ b/src/gpu/effects/GrConstColorProcessor.fp @@ -0,0 +1,91 @@ +enum class InputMode { + kIgnore, + kModulateRGBA, + kModulateA, + + kLast = kModulateA +}; + +layout(ctype=GrColor4f) in half4 color; +uniform half4 colorUniform; +layout(ctype=GrColor4f) half4 prevColor; +layout(key) in InputMode mode; + +@optimizationFlags { + OptFlags(color, mode) +} + +void main() { + @switch (mode) { + case InputMode::kIgnore: + sk_OutColor = colorUniform; + break; + case InputMode::kModulateRGBA: + sk_OutColor = sk_InColor * colorUniform; + break; + case InputMode::kModulateA: + sk_OutColor = sk_InColor.a * colorUniform; + break; + } +} + +@setData(pdman) { + // We use the "illegal" color value as an uninit sentinel. With GrColor4f, the "illegal" + // color is *really* illegal (not just unpremultiplied), so this check is simple. + if (prevColor != color) { + pdman.set4fv(colorUniform, 1, color.fRGBA); + prevColor = color; + } +} + +@class { + static const int kInputModeCnt = (int) InputMode::kLast + 1; + + static OptimizationFlags OptFlags(GrColor4f color, InputMode mode) { + OptimizationFlags flags = kConstantOutputForConstantInput_OptimizationFlag; + if (mode != InputMode::kIgnore) { + flags |= kCompatibleWithCoverageAsAlpha_OptimizationFlag; + } + if (color.isOpaque()) { + flags |= kPreservesOpaqueInput_OptimizationFlag; + } + return flags; + } + + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + switch (fMode) { + case InputMode::kIgnore: + return fColor; + case InputMode::kModulateA: + return fColor.mulByScalar(input.fRGBA[3]); + case InputMode::kModulateRGBA: + return fColor.modulate(input); + } + SK_ABORT("Unexpected mode"); + return GrColor4f::TransparentBlack(); + } +} + +@test(d) { + GrColor4f color; + int colorPicker = d->fRandom->nextULessThan(3); + switch (colorPicker) { + case 0: { + uint32_t a = d->fRandom->nextULessThan(0x100); + uint32_t r = d->fRandom->nextULessThan(a+1); + uint32_t g = d->fRandom->nextULessThan(a+1); + uint32_t b = d->fRandom->nextULessThan(a+1); + color = GrColor4f::FromGrColor(GrColorPackRGBA(r, g, b, a)); + break; + } + case 1: + color = GrColor4f::TransparentBlack(); + break; + case 2: + uint32_t c = d->fRandom->nextULessThan(0x100); + color = GrColor4f::FromGrColor(c | (c << 8) | (c << 16) | (c << 24)); + break; + } + InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt)); + return GrConstColorProcessor::Make(color, mode); +}
\ No newline at end of file |