1 /* 2 * Copyright 2019 Google LLC 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 GrColorMatrixFragmentProcessor.fp; do not modify. 10 **************************************************************************************************/ 11 #ifndef GrColorMatrixFragmentProcessor_DEFINED 12 #define GrColorMatrixFragmentProcessor_DEFINED 13 14 #include "include/core/SkM44.h" 15 #include "include/core/SkTypes.h" 16 17 #include "src/gpu/GrFragmentProcessor.h" 18 19 class GrColorMatrixFragmentProcessor : public GrFragmentProcessor { 20 public: constantOutputForConstantInput(const SkPMColor4f & inColor)21 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override { 22 SkPMColor4f input = ConstantOutputForConstantInput(this->childProcessor(0), inColor); 23 SkColor4f color; 24 if (unpremulInput) { 25 color = input.unpremul(); 26 } else { 27 color.fR = input.fR; 28 color.fG = input.fG; 29 color.fB = input.fB; 30 color.fA = input.fA; 31 } 32 auto v4 = m.map(color.fR, color.fG, color.fB, color.fA) + v; 33 color = {v4.x, v4.y, v4.z, v4.w}; 34 color.fA = SkTPin(color.fA, 0.f, 1.f); 35 if (clampRGBOutput) { 36 color.fR = SkTPin(color.fR, 0.f, 1.f); 37 color.fG = SkTPin(color.fG, 0.f, 1.f); 38 color.fB = SkTPin(color.fB, 0.f, 1.f); 39 } 40 if (premulOutput) { 41 return color.premul(); 42 } else { 43 return {color.fR, color.fG, color.fB, color.fA}; 44 } 45 } 46 Make(std::unique_ptr<GrFragmentProcessor> inputFP,const float matrix[20],bool unpremulInput,bool clampRGBOutput,bool premulOutput)47 static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP, 48 const float matrix[20], 49 bool unpremulInput, 50 bool clampRGBOutput, 51 bool premulOutput) { 52 SkM44 m44(matrix[0], 53 matrix[1], 54 matrix[2], 55 matrix[3], 56 matrix[5], 57 matrix[6], 58 matrix[7], 59 matrix[8], 60 matrix[10], 61 matrix[11], 62 matrix[12], 63 matrix[13], 64 matrix[15], 65 matrix[16], 66 matrix[17], 67 matrix[18]); 68 SkV4 v4 = {matrix[4], matrix[9], matrix[14], matrix[19]}; 69 return std::unique_ptr<GrFragmentProcessor>(new GrColorMatrixFragmentProcessor( 70 std::move(inputFP), m44, v4, unpremulInput, clampRGBOutput, premulOutput)); 71 } 72 GrColorMatrixFragmentProcessor(const GrColorMatrixFragmentProcessor& src); 73 std::unique_ptr<GrFragmentProcessor> clone() const override; name()74 const char* name() const override { return "ColorMatrixFragmentProcessor"; } 75 SkM44 m; 76 SkV4 v; 77 bool unpremulInput; 78 bool clampRGBOutput; 79 bool premulOutput; 80 81 private: GrColorMatrixFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,SkM44 m,SkV4 v,bool unpremulInput,bool clampRGBOutput,bool premulOutput)82 GrColorMatrixFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP, 83 SkM44 m, 84 SkV4 v, 85 bool unpremulInput, 86 bool clampRGBOutput, 87 bool premulOutput) 88 : INHERITED(kGrColorMatrixFragmentProcessor_ClassID, 89 (OptimizationFlags)ProcessorOptimizationFlags(inputFP.get()) & 90 kConstantOutputForConstantInput_OptimizationFlag) 91 , m(m) 92 , v(v) 93 , unpremulInput(unpremulInput) 94 , clampRGBOutput(clampRGBOutput) 95 , premulOutput(premulOutput) { 96 this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough()); 97 } 98 std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override; 99 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 100 bool onIsEqual(const GrFragmentProcessor&) const override; 101 #if GR_TEST_UTILS 102 SkString onDumpInfo() const override; 103 #endif 104 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 105 using INHERITED = GrFragmentProcessor; 106 }; 107 #endif 108