bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrConstColorProcessor.fp; do not modify. |
| 10 | **************************************************************************************************/ |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 11 | #ifndef GrConstColorProcessor_DEFINED |
| 12 | #define GrConstColorProcessor_DEFINED |
| 13 | #include "SkTypes.h" |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 14 | #include "GrFragmentProcessor.h" |
| 15 | #include "GrCoordTransform.h" |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 16 | class GrConstColorProcessor : public GrFragmentProcessor { |
| 17 | public: |
Ethan Nicholas | 2c33e3e | 2018-01-08 15:36:28 -0500 | [diff] [blame] | 18 | enum class InputMode { kIgnore = 0, kLast = 2, kModulateA = 2, kModulateRGBA = 1 }; |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 19 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 20 | static const int kInputModeCnt = (int)InputMode::kLast + 1; |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 21 | |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 22 | static OptimizationFlags OptFlags(GrColor4f color, InputMode mode) { |
| 23 | OptimizationFlags flags = kConstantOutputForConstantInput_OptimizationFlag; |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 24 | if (mode != InputMode::kIgnore) { |
Brian Salomon | f3b995b | 2017-02-15 10:22:23 -0500 | [diff] [blame] | 25 | flags |= kCompatibleWithCoverageAsAlpha_OptimizationFlag; |
Brian Salomon | 587e08f | 2017-01-27 10:59:27 -0500 | [diff] [blame] | 26 | } |
| 27 | if (color.isOpaque()) { |
| 28 | flags |= kPreservesOpaqueInput_OptimizationFlag; |
| 29 | } |
| 30 | return flags; |
| 31 | } |
| 32 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 33 | GrColor4f constantOutputForConstantInput(GrColor4f input) const override { |
| 34 | switch (fMode) { |
| 35 | case InputMode::kIgnore: |
| 36 | return fColor; |
| 37 | case InputMode::kModulateA: |
| 38 | return fColor.mulByScalar(input.fRGBA[3]); |
| 39 | case InputMode::kModulateRGBA: |
| 40 | return fColor.modulate(input); |
| 41 | } |
| 42 | SK_ABORT("Unexpected mode"); |
| 43 | return GrColor4f::TransparentBlack(); |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 44 | } |
Michael Ludwig | a427559 | 2018-08-31 10:52:47 -0400 | [diff] [blame^] | 45 | const GrColor4f& color() const { return fColor; } |
| 46 | const InputMode& mode() const { return fMode; } |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 47 | static std::unique_ptr<GrFragmentProcessor> Make(GrColor4f color, InputMode mode) { |
| 48 | return std::unique_ptr<GrFragmentProcessor>(new GrConstColorProcessor(color, mode)); |
| 49 | } |
| 50 | GrConstColorProcessor(const GrConstColorProcessor& src); |
| 51 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 52 | const char* name() const override { return "ConstColorProcessor"; } |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 53 | |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 54 | private: |
| 55 | GrConstColorProcessor(GrColor4f color, InputMode mode) |
| 56 | : INHERITED(kGrConstColorProcessor_ClassID, (OptimizationFlags)OptFlags(color, mode)) |
| 57 | , fColor(color) |
| 58 | , fMode(mode) {} |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 59 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 60 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 61 | bool onIsEqual(const GrFragmentProcessor&) const override; |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 62 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 63 | GrColor4f fColor; |
| 64 | InputMode fMode; |
bsalomon | c9c3e62 | 2015-04-02 11:12:09 -0700 | [diff] [blame] | 65 | typedef GrFragmentProcessor INHERITED; |
| 66 | }; |
Ethan Nicholas | e9d172a | 2017-11-20 12:12:24 -0500 | [diff] [blame] | 67 | #endif |