1 /* 2 * Copyright 2020 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 #ifndef GrMatrixEffect_DEFINED 9 #define GrMatrixEffect_DEFINED 10 11 #include "include/core/SkM44.h" 12 #include "include/core/SkTypes.h" 13 14 #include "src/gpu/GrFragmentProcessor.h" 15 16 class GrMatrixEffect : public GrFragmentProcessor { 17 public: 18 static std::unique_ptr<GrFragmentProcessor> Make(const SkMatrix& matrix, 19 std::unique_ptr<GrFragmentProcessor> child); 20 21 std::unique_ptr<GrFragmentProcessor> clone() const override; name()22 const char* name() const override { return "MatrixEffect"; } 23 24 private: 25 GrMatrixEffect(const GrMatrixEffect& src); 26 GrMatrixEffect(SkMatrix matrix,std::unique_ptr<GrFragmentProcessor> child)27 GrMatrixEffect(SkMatrix matrix, std::unique_ptr<GrFragmentProcessor> child) 28 : INHERITED(kGrMatrixEffect_ClassID, ProcessorOptimizationFlags(child.get())) 29 , fMatrix(matrix) { 30 SkASSERT(child); 31 this->registerChild(std::move(child), 32 SkSL::SampleUsage::UniformMatrix(matrix.hasPerspective())); 33 } 34 35 std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override; 36 void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 37 bool onIsEqual(const GrFragmentProcessor&) const override; constantOutputForConstantInput(const SkPMColor4f & inputColor)38 SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inputColor) const override { 39 return ConstantOutputForConstantInput(this->childProcessor(0), inputColor); 40 } 41 42 SkMatrix fMatrix; 43 44 GR_DECLARE_FRAGMENT_PROCESSOR_TEST 45 using INHERITED = GrFragmentProcessor; 46 }; 47 #endif 48