From 4bbb29070c46798b97163d13f8cc87b4f83ca5ec Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 13 Apr 2021 10:04:20 -0400 Subject: [PATCH] Concatenate matrices when GrMatrixEffect wraps another GrMatrixEffect Bug: skia:11844 Change-Id: I13165fb17b06371854a4911c5d91bf2415d4df2a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396017 Reviewed-by: Brian Osman Reviewed-by: Michael Ludwig Commit-Queue: Brian Salomon --- src/gpu/effects/GrMatrixEffect.cpp | 17 +++++++++++++++++ src/gpu/effects/GrMatrixEffect.h | 7 +------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gpu/effects/GrMatrixEffect.cpp b/src/gpu/effects/GrMatrixEffect.cpp index 2ff4604213..172691e3b0 100644 --- a/src/gpu/effects/GrMatrixEffect.cpp +++ b/src/gpu/effects/GrMatrixEffect.cpp @@ -35,6 +35,23 @@ private: UniformHandle fMatrixVar; }; +std::unique_ptr GrMatrixEffect::Make( + const SkMatrix& matrix, std::unique_ptr child) { + if (matrix.isIdentity()) { + return child; + } + if (child->classID() == kGrMatrixEffect_ClassID) { + auto me = static_cast(child.get()); + // registerChild's sample usage records whether the matrix used has perspective or not, + // so we can't add perspective to 'me' if it doesn't already have it. + if (me->matrix().hasPerspective() || !matrix.hasPerspective()) { + me->fMatrix.preConcat(matrix); + return child; + } + } + return std::unique_ptr(new GrMatrixEffect(matrix, std::move(child))); +} + std::unique_ptr GrMatrixEffect::onMakeProgramImpl() const { return std::make_unique(); } diff --git a/src/gpu/effects/GrMatrixEffect.h b/src/gpu/effects/GrMatrixEffect.h index 5d82750f25..f939a93f7f 100644 --- a/src/gpu/effects/GrMatrixEffect.h +++ b/src/gpu/effects/GrMatrixEffect.h @@ -16,12 +16,7 @@ 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))); - } + std::unique_ptr child); std::unique_ptr clone() const override; const char* name() const override { return "MatrixEffect"; }