• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"; }
matrix()23     const SkMatrix& matrix() const { return fMatrix; }
24 
25 private:
26     GrMatrixEffect(const GrMatrixEffect& src);
27 
GrMatrixEffect(SkMatrix matrix,std::unique_ptr<GrFragmentProcessor> child)28     GrMatrixEffect(SkMatrix matrix, std::unique_ptr<GrFragmentProcessor> child)
29             : INHERITED(kGrMatrixEffect_ClassID, ProcessorOptimizationFlags(child.get()))
30             , fMatrix(matrix) {
31         SkASSERT(child);
32         this->registerChild(std::move(child),
33                             SkSL::SampleUsage::UniformMatrix("matrix", matrix.hasPerspective()));
34     }
35 
36     std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
37     void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
38     bool onIsEqual(const GrFragmentProcessor&) const override;
constantOutputForConstantInput(const SkPMColor4f & inputColor)39     SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inputColor) const override {
40         return ConstantOutputForConstantInput(this->childProcessor(0), inputColor);
41     }
42 
43     SkMatrix fMatrix;
44 
45     GR_DECLARE_FRAGMENT_PROCESSOR_TEST
46     using INHERITED = GrFragmentProcessor;
47 };
48 #endif
49