[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>
This commit is contained in:
parent
10f7090e6e
commit
2a2dfcbb42
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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(); }
|
||||
|
@ -62,6 +62,10 @@ protected:
|
||||
}
|
||||
|
||||
bool onAnimate(const SkAnimTimer& timer) override {
|
||||
if (!fRoot) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static constexpr SkScalar kSize = 50;
|
||||
static constexpr SkScalar kRate = 1.0f / 500;
|
||||
const auto t = timer.msec() * kRate;
|
||||
|
Loading…
Reference in New Issue
Block a user