xref: /aosp_15_r20/external/skia/src/gpu/ganesh/effects/GrMatrixEffect.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/SkMatrix.h"
12 #include "include/core/SkTypes.h"
13 #include "include/private/SkColorData.h"
14 #include "include/private/SkSLSampleUsage.h"
15 #include "src/gpu/ganesh/GrFragmentProcessor.h"
16 #include "src/gpu/ganesh/GrProcessorUnitTest.h"
17 
18 #include <memory>
19 #include <utility>
20 
21 namespace skgpu { class KeyBuilder; }
22 struct GrShaderCaps;
23 
24 class GrMatrixEffect : public GrFragmentProcessor {
25 public:
26     static std::unique_ptr<GrFragmentProcessor> Make(const SkMatrix& matrix,
27                                                      std::unique_ptr<GrFragmentProcessor> child);
28 
29     std::unique_ptr<GrFragmentProcessor> clone() const override;
name()30     const char* name() const override { return "MatrixEffect"; }
31 
32 private:
33     GrMatrixEffect(const GrMatrixEffect& src);
34 
GrMatrixEffect(SkMatrix matrix,std::unique_ptr<GrFragmentProcessor> child)35     GrMatrixEffect(SkMatrix matrix, std::unique_ptr<GrFragmentProcessor> child)
36             : INHERITED(kGrMatrixEffect_ClassID, ProcessorOptimizationFlags(child.get()))
37             , fMatrix(matrix) {
38         SkASSERT(child);
39         this->registerChild(std::move(child),
40                             SkSL::SampleUsage::UniformMatrix(matrix.hasPerspective()));
41     }
42 
43     std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
44     void onAddToKey(const GrShaderCaps&, skgpu::KeyBuilder*) const override;
45     bool onIsEqual(const GrFragmentProcessor&) const override;
constantOutputForConstantInput(const SkPMColor4f & inputColor)46     SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inputColor) const override {
47         return ConstantOutputForConstantInput(this->childProcessor(0), inputColor);
48     }
49 
50     SkMatrix fMatrix;
51 
52     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
53     using INHERITED = GrFragmentProcessor;
54 };
55 #endif
56