/* * Copyright 2020 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrMatrixEffect_DEFINED #define GrMatrixEffect_DEFINED #include "include/core/SkM44.h" #include "include/core/SkTypes.h" #include "src/gpu/GrFragmentProcessor.h" class GrMatrixEffect : public GrFragmentProcessor { public: static std::unique_ptr Make(const SkMatrix& matrix, std::unique_ptr child) { if (matrix.isIdentity()) { return child; } return std::unique_ptr(new GrMatrixEffect(matrix, std::move(child))); } bool usesExplicitReturn() const override { return true; } std::unique_ptr clone() const override; const char* name() const override { return "MatrixEffect"; } const SkMatrix& matrix() const { return fMatrix; } private: GrMatrixEffect(const GrMatrixEffect& src); GrMatrixEffect(SkMatrix matrix, std::unique_ptr child) : INHERITED(kGrMatrixEffect_ClassID, ProcessorOptimizationFlags(child.get())) , fMatrix(matrix) { SkASSERT(child); this->registerChild(std::move(child), SkSL::SampleUsage::UniformMatrix("matrix", matrix.hasPerspective())); } GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; bool onIsEqual(const GrFragmentProcessor&) const override; SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inputColor) const override { return ConstantOutputForConstantInput(this->childProcessor(0), inputColor); } SkMatrix fMatrix; GR_DECLARE_FRAGMENT_PROCESSOR_TEST using INHERITED = GrFragmentProcessor; }; #endif