diff options
Diffstat (limited to 'experimental/sksg/effects/SkSGTransform.cpp')
-rw-r--r-- | experimental/sksg/effects/SkSGTransform.cpp | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/experimental/sksg/effects/SkSGTransform.cpp b/experimental/sksg/effects/SkSGTransform.cpp index dc31623db2..1ea1e619a8 100644 --- a/experimental/sksg/effects/SkSGTransform.cpp +++ b/experimental/sksg/effects/SkSGTransform.cpp @@ -11,21 +11,60 @@ namespace sksg { -Transform::Transform(sk_sp<RenderNode> child, const SkMatrix& matrix) +Matrix::Matrix(const SkMatrix& m, sk_sp<Matrix> parent) + : fParent(std::move(parent)) + , fLocalMatrix(m) { + if (fParent) { + fParent->addInvalReceiver(this); + } +} + +Matrix::~Matrix() { + if (fParent) { + fParent->removeInvalReceiver(this); + } +} + +Node::RevalidationResult Matrix::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { + fTotalMatrix = fLocalMatrix; + + if (fParent) { + fParent->revalidate(ic, ctm); + fTotalMatrix.postConcat(fParent->getTotalMatrix()); + } + + // A free-floating matrix contributes no damage. + return { SkRect::MakeEmpty(), Damage::kBlockSelf }; +} + +Transform::Transform(sk_sp<RenderNode> child, sk_sp<Matrix> matrix) : INHERITED(std::move(child)) - , fMatrix(matrix) {} + , fMatrix(std::move(matrix)) { + fMatrix->addInvalReceiver(this); +} + +Transform::~Transform() { + fMatrix->removeInvalReceiver(this); +} void Transform::onRender(SkCanvas* canvas) const { - SkAutoCanvasRestore acr(canvas, !fMatrix.isIdentity()); - canvas->concat(fMatrix); + const auto& m = fMatrix->getTotalMatrix(); + SkAutoCanvasRestore acr(canvas, !m.isIdentity()); + canvas->concat(m); this->INHERITED::onRender(canvas); } Node::RevalidationResult Transform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { SkASSERT(this->hasInval()); - auto result = this->INHERITED::onRevalidate(ic, SkMatrix::Concat(ctm, fMatrix)); - fMatrix.mapRect(&result.fBounds); + // We don't care about matrix reval results, but we do care whether it was invalidated. + const auto localDamage = fMatrix->hasInval() ? Damage::kForceSelf : Damage::kDefault; + fMatrix->revalidate(ic, ctm); + + const auto& m = fMatrix->getTotalMatrix(); + auto result = this->INHERITED::onRevalidate(ic, SkMatrix::Concat(ctm, m)); + m.mapRect(&result.fBounds); + result.fDamage = localDamage; return result; } |