| 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( | 
| 19 | const SkMatrix& matrix, std::unique_ptr<GrFragmentProcessor> child) { | 
| 20 | if (matrix.isIdentity()) { | 
| 21 | return child; | 
| 22 | } | 
| 23 | return std::unique_ptr<GrFragmentProcessor>(new GrMatrixEffect(matrix, std::move(child))); | 
| 24 | } | 
| 25 | |
| 26 | std::unique_ptr<GrFragmentProcessor> clone() const override; | 
| 27 | const char* name() const override { return "MatrixEffect"; } | 
| 28 | const SkMatrix& matrix() const { return fMatrix; } | 
| 29 | |
| 30 | private: | 
| 31 | GrMatrixEffect(const GrMatrixEffect& src); | 
| 32 | |
| 33 | GrMatrixEffect(SkMatrix matrix, std::unique_ptr<GrFragmentProcessor> child) | 
| 34 | : INHERITED(kGrMatrixEffect_ClassID, ProcessorOptimizationFlags(child.get())) | 
| 35 | , fMatrix(matrix) { | 
| 36 | SkASSERT(child); | 
| 37 | this->registerChild(std::move(child), | 
| 38 | SkSL::SampleUsage::UniformMatrix( | 
| 39 | "matrix", matrix.hasPerspective())); | 
| 40 | } | 
| 41 | |
| 42 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 
| 43 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; | 
| 44 | bool onIsEqual(const GrFragmentProcessor&) const override; | 
| 45 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inputColor) const override { | 
| 46 | return ConstantOutputForConstantInput(this->childProcessor(0), inputColor); | 
| 47 | } | 
| 48 | |
| 49 | SkMatrix fMatrix; | 
| 50 | |
| 51 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST | 
| 52 | typedef GrFragmentProcessor INHERITED; | 
| 53 | }; | 
| 54 | #endif | 
| 55 |