Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | // Ignores its own input color and invokes 'fp' with a constant color |
| 9 | // The constant color can either be specified as a literal or as a |
| 10 | // uniform, controlled by useUniform. |
| 11 | |
| 12 | in fragmentProcessor fp; |
| 13 | layout(key) in bool useUniform; |
| 14 | layout(when=useUniform, ctype=SkPMColor4f) in uniform half4 uniformColor; |
| 15 | layout(when=!useUniform, key, ctype=SkPMColor4f) in half4 literalColor; |
| 16 | |
| 17 | @make { |
| 18 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp, |
| 19 | const SkPMColor4f& color, |
| 20 | bool useUniform = true) { |
| 21 | return std::unique_ptr<GrFragmentProcessor>( |
| 22 | new GrOverrideInputFragmentProcessor(std::move(fp), useUniform, color, color)); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | @class { |
| 27 | static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp, |
| 28 | const SkPMColor4f& color) { |
| 29 | auto childFlags = ProcessorOptimizationFlags(fp.get()); |
| 30 | auto flags = kNone_OptimizationFlags; |
| 31 | if (childFlags & kConstantOutputForConstantInput_OptimizationFlag) { |
| 32 | flags |= kConstantOutputForConstantInput_OptimizationFlag; |
| 33 | } |
| 34 | if ((childFlags & kPreservesOpaqueInput_OptimizationFlag) && color.isOpaque()) { |
| 35 | flags |= kPreservesOpaqueInput_OptimizationFlag; |
| 36 | } |
| 37 | return flags; |
| 38 | } |
| 39 | |
| 40 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
| 41 | return ConstantOutputForConstantInput(this->childProcessor(0), uniformColor); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | @optimizationFlags { OptFlags(fp, useUniform ? uniformColor : literalColor) } |
| 46 | |
| 47 | void main() { |
| 48 | half4 constColor; |
| 49 | @if(useUniform) { |
| 50 | constColor = uniformColor; |
| 51 | } else { |
| 52 | constColor = literalColor; |
| 53 | } |
| 54 | sk_OutColor = process(fp, constColor); |
| 55 | } |