diff options
author | Florin Malita <fmalita@chromium.org> | 2017-12-28 19:24:07 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-29 00:41:00 +0000 |
commit | 2a2dfcbb4267e1c7e4aac39e0d78bc41695a2259 (patch) | |
tree | decc8655a4ff7d570da3427fd1971daab2994c1d /experimental | |
parent | 10f7090e6ecc7ca3345501d6f08fea0a01f7dd7a (diff) |
[sksg] Fix paint inval
Paint nodes contribute to invalidation. Hoist the inval logic from
geometry nodes to draw nodes.
TBR=
Change-Id: Iab33086c377ef4940a84dae3cdccb2c9bdbee99c
Reviewed-on: https://skia-review.googlesource.com/89901
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/sksg/SkSGDraw.cpp | 9 | ||||
-rw-r--r-- | experimental/sksg/SkSGGeometryNode.cpp | 24 | ||||
-rw-r--r-- | experimental/sksg/SkSGGeometryNode.h | 2 | ||||
-rw-r--r-- | experimental/sksg/SkSGInvalidationController.cpp | 11 | ||||
-rw-r--r-- | experimental/sksg/SkSGInvalidationController.h | 3 |
5 files changed, 23 insertions, 26 deletions
diff --git a/experimental/sksg/SkSGDraw.cpp b/experimental/sksg/SkSGDraw.cpp index 7319c635fe..fe6d42a152 100644 --- a/experimental/sksg/SkSGDraw.cpp +++ b/experimental/sksg/SkSGDraw.cpp @@ -8,6 +8,7 @@ #include "SkSGDraw.h" #include "SkSGGeometryNode.h" +#include "SkSGInvalidationController.h" #include "SkSGPaintNode.h" namespace sksg { @@ -31,8 +32,16 @@ void Draw::onRender(SkCanvas* canvas) const { void Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { SkASSERT(this->isInvalidated()); + // TODO: paint bounds extents + const auto oldBounds = fGeometry->fBounds; + fGeometry->revalidate(ic, ctm); fPaint->revalidate(ic, ctm); + + ic->inval(oldBounds, ctm); + if (fGeometry->fBounds != oldBounds) { + ic->inval(fGeometry->fBounds, ctm); + } } } // namespace sksg diff --git a/experimental/sksg/SkSGGeometryNode.cpp b/experimental/sksg/SkSGGeometryNode.cpp index ea14ec0255..ffd5db4d1c 100644 --- a/experimental/sksg/SkSGGeometryNode.cpp +++ b/experimental/sksg/SkSGGeometryNode.cpp @@ -7,9 +7,6 @@ #include "SkSGGeometryNode.h" -#include "SkMatrix.h" -#include "SkSGInvalidationController.h" - namespace sksg { GeometryNode::GeometryNode() @@ -20,29 +17,10 @@ void GeometryNode::draw(SkCanvas* canvas, const SkPaint& paint) const { this->onDraw(canvas, paint); } -static void inval_rect(const SkRect& r, const SkMatrix& ctm, InvalidationController* ic) { - if (ctm.isIdentity()) { - ic->inval(r); - return; - } - - SkRect mappedRect; - if (!ctm.mapRect(&mappedRect, r)) { - mappedRect = SkRect::MakeLTRB(SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax); - } - ic->inval(mappedRect); -} - -void GeometryNode::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { +void GeometryNode::onRevalidate(InvalidationController*, const SkMatrix&) { SkASSERT(this->isInvalidated()); - const auto oldBounds = fBounds; fBounds = this->onComputeBounds(); - - inval_rect(oldBounds, ctm, ic); - if (fBounds != oldBounds) { - inval_rect(fBounds, ctm, ic); - } } } // namespace sksg diff --git a/experimental/sksg/SkSGGeometryNode.h b/experimental/sksg/SkSGGeometryNode.h index 52b2df0367..a687b19aea 100644 --- a/experimental/sksg/SkSGGeometryNode.h +++ b/experimental/sksg/SkSGGeometryNode.h @@ -41,6 +41,8 @@ protected: void onRevalidate(InvalidationController*, const SkMatrix&) override; private: + friend class Draw; // wants to know the cached bounds. + SkRect fBounds; typedef Node INHERITED; diff --git a/experimental/sksg/SkSGInvalidationController.cpp b/experimental/sksg/SkSGInvalidationController.cpp index 9693f1e754..114d724d1c 100644 --- a/experimental/sksg/SkSGInvalidationController.cpp +++ b/experimental/sksg/SkSGInvalidationController.cpp @@ -8,13 +8,20 @@ #include "SkSGInvalidationController.h" #include "SkRect.h" +#include "SkTLazy.h" namespace sksg { InvalidationController::InvalidationController() {} -void InvalidationController::inval(const SkRect& r) { - fRects.push(r); +void InvalidationController::inval(const SkRect& r, const SkMatrix& ctm) { + SkTCopyOnFirstWrite<SkRect> rect(r); + + if (!ctm.isIdentity() && !ctm.mapRect(rect.writable())) { + *rect.writable() = SkRect::MakeLTRB(SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax); + } + + fRects.push(*rect); } } // namespace sksg diff --git a/experimental/sksg/SkSGInvalidationController.h b/experimental/sksg/SkSGInvalidationController.h index e00ece52fc..4354d43129 100644 --- a/experimental/sksg/SkSGInvalidationController.h +++ b/experimental/sksg/SkSGInvalidationController.h @@ -8,6 +8,7 @@ #ifndef SkSGInvalidationController_DEFINED #define SkSGInvalidationController_DEFINED +#include "SkMatrix.h" #include "SkTDArray.h" #include "SkTypes.h" @@ -24,7 +25,7 @@ class InvalidationController : public SkNoncopyable { public: InvalidationController(); - void inval(const SkRect&); + void inval(const SkRect&, const SkMatrix& ctm = SkMatrix::I()); const SkRect* begin() const { return fRects.begin(); } const SkRect* end() const { return fRects.end(); } |