Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
67
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}
@ kFragment_GrShaderFlag
#define INHERITED(method,...)
GrTextureEffect * asTextureEffect()
GrFragmentProcessor * childProcessor(int index)
void setSkMatrix(UniformHandle, const SkMatrix &) const
void onAddToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const override
std::unique_ptr< GrFragmentProcessor > clone() const override
std::unique_ptr< ProgramImpl > onMakeProgramImpl() const override
bool onIsEqual(const GrFragmentProcessor &) const override
static std::unique_ptr< GrFragmentProcessor > Make(const SkMatrix &matrix, std::unique_ptr< GrFragmentProcessor > child)
const T & cast() const
@ 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