blob: 42e3bb43ca4c54884e2e7693e0af1363765d62eb [file] [log] [blame]
/*
* 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<GrFragmentProcessor> Make(const SkMatrix& matrix,
std::unique_ptr<GrFragmentProcessor> child) {
if (matrix.isIdentity()) {
return child;
}
return std::unique_ptr<GrFragmentProcessor>(new GrMatrixEffect(matrix, std::move(child)));
}
std::unique_ptr<GrFragmentProcessor> 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<GrFragmentProcessor> 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