Flutter Engine
The Flutter Engine
GrMatrixEffect.cpp
Go to the documentation of this file.
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
9
17
18namespace skgpu { class KeyBuilder; }
19struct GrShaderCaps;
20
21std::unique_ptr<GrFragmentProcessor> GrMatrixEffect::Make(
22 const SkMatrix& matrix, std::unique_ptr<GrFragmentProcessor> child) {
23 if (child->classID() == kGrMatrixEffect_ClassID) {
24 auto me = static_cast<GrMatrixEffect*>(child.get());
25 // registerChild's sample usage records whether the matrix used has perspective or not,
26 // so we can't add perspective to 'me' if it doesn't already have it.
27 if (me->fMatrix.hasPerspective() || !matrix.hasPerspective()) {
28 me->fMatrix.preConcat(matrix);
29 return child;
30 }
31 }
32 return std::unique_ptr<GrFragmentProcessor>(new GrMatrixEffect(matrix, std::move(child)));
33}
34
35std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrMatrixEffect::onMakeProgramImpl() const {
36 class Impl : public ProgramImpl {
37 public:
38 void emitCode(EmitArgs& args) override {
39 fMatrixVar = args.fUniformHandler->addUniform(&args.fFp,
43 args.fFragBuilder->codeAppendf("return %s;\n",
44 this->invokeChildWithMatrix(0, args).c_str());
45 }
46
47 private:
48 void onSetData(const GrGLSLProgramDataManager& pdman,
49 const GrFragmentProcessor& proc) override {
50 const GrMatrixEffect& mtx = proc.cast<GrMatrixEffect>();
51 if (auto te = mtx.childProcessor(0)->asTextureEffect()) {
52 SkMatrix m = te->coordAdjustmentMatrix();
53 m.preConcat(mtx.fMatrix);
54 pdman.setSkMatrix(fMatrixVar, m);
55 } else {
56 pdman.setSkMatrix(fMatrixVar, mtx.fMatrix);
57 }
58 }
59
60 UniformHandle fMatrixVar;
61 };
62
63 return std::make_unique<Impl>();
64}
65
66void GrMatrixEffect::onAddToKey(const GrShaderCaps& caps, skgpu::KeyBuilder* b) const {}
67
68bool GrMatrixEffect::onIsEqual(const GrFragmentProcessor& other) const {
69 const GrMatrixEffect& that = other.cast<GrMatrixEffect>();
70 if (fMatrix != that.fMatrix) return false;
71 return true;
72}
73
74GrMatrixEffect::GrMatrixEffect(const GrMatrixEffect& src)
75 : INHERITED(src)
76 , fMatrix(src.fMatrix) {}
77
78std::unique_ptr<GrFragmentProcessor> GrMatrixEffect::clone() const {
79 return std::unique_ptr<GrFragmentProcessor>(new GrMatrixEffect(*this));
80}
SkMatrix fMatrix
Definition: FillRRectOp.cpp:74
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
GrTextureEffect * asTextureEffect()
GrFragmentProcessor * childProcessor(int index)
void setSkMatrix(UniformHandle, const SkMatrix &) const
std::unique_ptr< GrFragmentProcessor > clone() const override
static std::unique_ptr< GrFragmentProcessor > Make(const SkMatrix &matrix, std::unique_ptr< GrFragmentProcessor > child)
const T & cast() const
Definition: GrProcessor.h:127
@ kGrMatrixEffect_ClassID
Definition: GrProcessor.h:62
SkMatrix & preConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:674
static const char * MatrixUniformName()
static bool b
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Definition: GpuTools.h:21