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 #include "include/core/SkTypes.h" 14 15 #include "src/gpu/GrCoordTransform.h" 16 #include "src/gpu/GrFragmentProcessor.h" 17 class GrColorMatrixFragmentProcessor : public GrFragmentProcessor { 18 public: constantOutputForConstantInput(const SkPMColor4f & input)19 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { 20 SkColor4f color; 21 if (unpremulInput) { 22 color = input.unpremul(); 23 } else { 24 color.fR = input.fR; 25 color.fG = input.fG; 26 color.fB = input.fB; 27 color.fA = input.fA; 28 } 29 m.mapScalars(color.vec()); 30 color.fR += v.fData[0]; 31 color.fG += v.fData[1]; 32 color.fB += v.fData[2]; 33 color.fA += v.fData[3]; 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(const float matrix[20],bool unpremulInput,bool clampRGBOutput,bool premulOutput)47 static std::unique_ptr<GrFragmentProcessor> Make(const float matrix[20], bool unpremulInput, 48 bool clampRGBOutput, bool premulOutput) { 49 SkMatrix44 m44; 50 m44.set4x4(matrix[0], matrix[5], matrix[10], matrix[15], matrix[1], matrix[6], matrix[11], 51 matrix[16], matrix[2], matrix[7], matrix[12], matrix[17], matrix[3], matrix[8], 52 matrix[13], matrix[18]); 53 auto v4 = SkVector4(matrix[4], matrix[9], matrix[14], matrix[19]); 54 return std::unique_ptr<GrFragmentProcessor>(new GrColorMatrixFragmentProcessor( 55 m44, v4, unpremulInput, clampRGBOutput, premulOutput)); 56 } 57 GrColorMatrixFragmentProcessor(const GrColorMatrixFragmentProcessor& src); 58 std::unique_ptr<GrFragmentProcessor> clone() const override; name()59 const char* name() const override { return "ColorMatrixFragmentProcessor"; } 60 SkMatrix44 m; 61 SkVector4 v; 62 bool unpremulInput; 63 bool clampRGBOutput; 64 bool premulOutput; 65 66 private: GrColorMatrixFragmentProcessor(SkMatrix44 m,SkVector4 v,bool unpremulInput,bool clampRGBOutput,bool premulOutput)67 GrColorMatrixFragmentProcessor(SkMatrix44 m, SkVector4 v, bool unpremulInput, 68 bool clampRGBOutput, bool premulOutput) 69 : INHERITED(kGrColorMatrixFragmentProcessor_ClassID, 70 (OptimizationFlags)kConstantOutputForConstantInput_OptimizationFlag) 71 , m(m) 72 , v(v) 73 , unpremulInput(unpremulInput) 74 , clampRGBOutput(clampRGBOutput) 75 , premulOutput(premulOutput) {} 76 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 77 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 78 bool onIsEqual(const GrFragmentProcessor&) const override; 79 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 80 typedef GrFragmentProcessor INHERITED; 81 }; 82 #endif 83