1 /* 2 * Copyright 2018 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 /************************************************************************************************** 9 *** This file was autogenerated from GrConstColorProcessor.fp; do not modify. 10 **************************************************************************************************/ 11 #ifndef GrConstColorProcessor_DEFINED 12 #define GrConstColorProcessor_DEFINED 13 #include "SkTypes.h" 14 #include "GrFragmentProcessor.h" 15 #include "GrCoordTransform.h" 16 class GrConstColorProcessor : public GrFragmentProcessor { 17 public: 18 enum class InputMode { kIgnore = 0, kLast = 2, kModulateA = 2, kModulateRGBA = 1 }; 19 20 static const int kInputModeCnt = (int)InputMode::kLast + 1; 21 OptFlags(const SkPMColor4f & color,InputMode mode)22 static OptimizationFlags OptFlags(const SkPMColor4f& color, InputMode mode) { 23 OptimizationFlags flags = kConstantOutputForConstantInput_OptimizationFlag; 24 if (mode != InputMode::kIgnore) { 25 flags |= kCompatibleWithCoverageAsAlpha_OptimizationFlag; 26 } 27 if (color.isOpaque()) { 28 flags |= kPreservesOpaqueInput_OptimizationFlag; 29 } 30 return flags; 31 } 32 constantOutputForConstantInput(const SkPMColor4f & input)33 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { 34 switch (fMode) { 35 case InputMode::kIgnore: 36 return fColor; 37 case InputMode::kModulateA: 38 return fColor * input.fA; 39 case InputMode::kModulateRGBA: 40 return fColor * input; 41 } 42 SK_ABORT("Unexpected mode"); 43 return SK_PMColor4fTRANSPARENT; 44 } color()45 const SkPMColor4f& color() const { return fColor; } mode()46 const InputMode& mode() const { return fMode; } Make(SkPMColor4f color,InputMode mode)47 static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f 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; name()52 const char* name() const override { return "ConstColorProcessor"; } 53 54 private: GrConstColorProcessor(SkPMColor4f color,InputMode mode)55 GrConstColorProcessor(SkPMColor4f color, InputMode mode) 56 : INHERITED(kGrConstColorProcessor_ClassID, (OptimizationFlags)OptFlags(color, mode)) 57 , fColor(color) 58 , fMode(mode) {} 59 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 60 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 61 bool onIsEqual(const GrFragmentProcessor&) const override; 62 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 63 SkPMColor4f fColor; 64 InputMode fMode; 65 typedef GrFragmentProcessor INHERITED; 66 }; 67 #endif 68