skia2/experimental/sksg/effects/SkSGTransform.h
Florin Malita c14f144484 [sksg] More inval fixes
Backpedal on node/reval-time-determined damage: nodes cannot control
the invalidation order, and shared descendants may be revalidated before
a particular ancestor gets to query their state - thus making any
decisions based on that invalid.

Instead, apply damage suppression at invalidation time, based on node
type/traits.  Node types which don't generate direct damage are marked
as such, and the invalidation logic bubbles damage past them, until it
finds a valid damage receiver.

Nodes which currently suppress damage:

 - PaintNode    (and subclasses)
 - GeometryNode (and subclasses)
 - Matrix

TBR=
Change-Id: I843e683e64cb6253d8c26d8397c44d02a7d6026f
Reviewed-on: https://skia-review.googlesource.com/91421
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2018-01-05 18:08:31 +00:00

82 lines
1.9 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSGTransform_DEFINED
#define SkSGTransform_DEFINED
#include "SkSGEffectNode.h"
#include "SkMatrix.h"
namespace sksg {
/**
* Concrete node, wrapping an SkMatrix, with an optional parent Matrix (to allow chaining):
*
* M' = parent x M
*/
class Matrix : public Node {
public:
static sk_sp<Matrix> Make(const SkMatrix& m, sk_sp<Matrix> parent = nullptr) {
return sk_sp<Matrix>(new Matrix(m, std::move(parent)));
}
~Matrix() override;
SG_ATTRIBUTE(Matrix, SkMatrix, fLocalMatrix)
const SkMatrix& getTotalMatrix() const { return fTotalMatrix; }
protected:
Matrix(const SkMatrix&, sk_sp<Matrix>);
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
private:
sk_sp<Matrix> fParent;
SkMatrix fLocalMatrix,
fTotalMatrix; // cached during revalidation
typedef Node INHERITED;
};
/**
* Concrete Effect node, binding a Matrix to a RenderNode.
*/
class Transform : public EffectNode {
public:
static sk_sp<Transform> Make(sk_sp<RenderNode> child, sk_sp<Matrix> matrix) {
return child && matrix
? sk_sp<Transform>(new Transform(std::move(child), std::move(matrix)))
: nullptr;
}
static sk_sp<Transform> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
return Make(std::move(child), Matrix::Make(m));
}
~Transform() override;
const sk_sp<Matrix>& getMatrix() const { return fMatrix; }
protected:
Transform(sk_sp<RenderNode>, sk_sp<Matrix>);
void onRender(SkCanvas*) const override;
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
private:
sk_sp<Matrix> fMatrix;
typedef EffectNode INHERITED;
};
} // namespace sksg
#endif // SkSGTransform_DEFINED