[sksg] Stop caching full SkPaints in Paint nodes
Create on the fly, when needed.
TBR=
Bug: skia:8340
Change-Id: I4c319821a6d6e84e0ec37e8858c4a89ba1668626
Reviewed-on: https://skia-review.googlesource.com/153141
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/sksg/include/SkSGPaintNode.h b/modules/sksg/include/SkSGPaintNode.h
index 5c9563b..dc4af49 100644
--- a/modules/sksg/include/SkSGPaintNode.h
+++ b/modules/sksg/include/SkSGPaintNode.h
@@ -22,7 +22,7 @@
*/
class PaintNode : public Node {
public:
- const SkPaint& makePaint();
+ SkPaint makePaint() const;
SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
@@ -41,8 +41,6 @@
SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
private:
- SkPaint fPaint;
-
SkScalar fOpacity = 1,
fStrokeWidth = 1,
fStrokeMiter = 4;
diff --git a/modules/sksg/src/SkSGDraw.cpp b/modules/sksg/src/SkSGDraw.cpp
index a75886f..24b358e 100644
--- a/modules/sksg/src/SkSGDraw.cpp
+++ b/modules/sksg/src/SkSGDraw.cpp
@@ -27,16 +27,16 @@
}
void Draw::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
- SkTCopyOnFirstWrite<SkPaint> paint(fPaint->makePaint());
+ auto paint = fPaint->makePaint();
if (ctx) {
- ctx->modulatePaint(paint.writable());
+ ctx->modulatePaint(&paint);
}
- const auto skipDraw = paint->nothingToDraw() ||
- (paint->getStyle() == SkPaint::kStroke_Style && paint->getStrokeWidth() <= 0);
+ const auto skipDraw = paint.nothingToDraw() ||
+ (paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
if (!skipDraw) {
- fGeometry->draw(canvas, *paint);
+ fGeometry->draw(canvas, paint);
}
}
@@ -46,7 +46,7 @@
auto bounds = fGeometry->revalidate(ic, ctm);
fPaint->revalidate(ic, ctm);
- const auto& paint = fPaint->makePaint();
+ const auto paint = fPaint->makePaint();
SkASSERT(paint.canComputeFastBounds());
return paint.computeFastBounds(bounds, &bounds);
diff --git a/modules/sksg/src/SkSGPaintNode.cpp b/modules/sksg/src/SkSGPaintNode.cpp
index 9220b0f..c929fc6 100644
--- a/modules/sksg/src/SkSGPaintNode.cpp
+++ b/modules/sksg/src/SkSGPaintNode.cpp
@@ -12,29 +12,30 @@
// Paint nodes don't generate damage on their own, but via their aggregation ancestor Draw nodes.
PaintNode::PaintNode() : INHERITED(kBubbleDamage_Trait) {}
-const SkPaint& PaintNode::makePaint() {
+SkPaint PaintNode::makePaint() const {
SkASSERT(!this->hasInval());
- return fPaint;
+ SkPaint paint;
+
+ paint.setAntiAlias(fAntiAlias);
+ paint.setBlendMode(fBlendMode);
+ paint.setStyle(fStyle);
+ paint.setStrokeWidth(fStrokeWidth);
+ paint.setStrokeMiter(fStrokeMiter);
+ paint.setStrokeJoin(fStrokeJoin);
+ paint.setStrokeCap(fStrokeCap);
+
+ this->onApplyToPaint(&paint);
+
+ // Compose opacity on top of the subclass value.
+ paint.setAlpha(SkScalarRoundToInt(paint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
+
+ return paint;
}
SkRect PaintNode::onRevalidate(InvalidationController*, const SkMatrix&) {
SkASSERT(this->hasInval());
- fPaint.reset();
- fPaint.setAntiAlias(fAntiAlias);
- fPaint.setBlendMode(fBlendMode);
- fPaint.setStyle(fStyle);
- fPaint.setStrokeWidth(fStrokeWidth);
- fPaint.setStrokeMiter(fStrokeMiter);
- fPaint.setStrokeJoin(fStrokeJoin);
- fPaint.setStrokeCap(fStrokeCap);
-
- this->onApplyToPaint(&fPaint);
-
- // Compose opacity on top of the subclass value.
- fPaint.setAlpha(SkScalarRoundToInt(fPaint.getAlpha() * SkTPin<SkScalar>(fOpacity, 0, 1)));
-
return SkRect::MakeEmpty();
}