Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: src/effects/SkLayerRasterizer.cpp

Issue 233673002: Create SkLayerRasterizer w/o destroying Builder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Better comments. New function is now const, and has a better name. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkLayerRasterizer.cpp
diff --git a/src/effects/SkLayerRasterizer.cpp b/src/effects/SkLayerRasterizer.cpp
index e35c5e828fb253d5447e36cf281f21172bf4a8ac..7143a3b40e915839406efb9fa401cd59d7a50ae2 100644
--- a/src/effects/SkLayerRasterizer.cpp
+++ b/src/effects/SkLayerRasterizer.cpp
@@ -34,15 +34,20 @@ SkLayerRasterizer::SkLayerRasterizer(SkDeque* layers) : fLayers(layers)
{
}
-SkLayerRasterizer::~SkLayerRasterizer() {
- SkASSERT(fLayers);
- SkDeque::F2BIter iter(*fLayers);
+// Helper function to call destructors on SkPaints held by layers and delete layers.
+static void clean_up_layers(SkDeque* layers) {
+ SkDeque::F2BIter iter(*layers);
SkLayerRasterizer_Rec* rec;
while ((rec = (SkLayerRasterizer_Rec*)iter.next()) != NULL)
rec->fPaint.~SkPaint();
- SkDELETE(fLayers);
+ SkDELETE(layers);
+}
+
+SkLayerRasterizer::~SkLayerRasterizer() {
+ SkASSERT(fLayers);
+ clean_up_layers(const_cast<SkDeque*>(fLayers));
}
#ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API
@@ -194,7 +199,9 @@ SkLayerRasterizer::Builder::Builder()
SkLayerRasterizer::Builder::~Builder()
{
- SkDELETE(fLayers);
+ if (fLayers != NULL) {
+ clean_up_layers(fLayers);
+ }
}
void SkLayerRasterizer::Builder::addLayer(const SkPaint& paint, SkScalar dx,
@@ -211,3 +218,20 @@ SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() {
fLayers = NULL;
return rasterizer;
}
+
+SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const {
+ SkDeque* layers = SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec), fLayers->count()));
+ SkDeque::F2BIter iter(*fLayers);
+ const SkLayerRasterizer_Rec* recOrig;
+ SkDEBUGCODE(int count = 0;)
+ while ((recOrig = static_cast<SkLayerRasterizer_Rec*>(iter.next())) != NULL) {
+ SkDEBUGCODE(count++);
+ SkLayerRasterizer_Rec* recCopy = static_cast<SkLayerRasterizer_Rec*>(layers->push_back());
+ SkNEW_PLACEMENT_ARGS(&recCopy->fPaint, SkPaint, (recOrig->fPaint));
+ recCopy->fOffset = recOrig->fOffset;
+ }
+ SkASSERT(fLayers->count() == count);
+ SkASSERT(layers->count() == count);
+ SkLayerRasterizer* rasterizer = SkNEW_ARGS(SkLayerRasterizer, (layers));
+ return rasterizer;
+}

Powered by Google App Engine
This is Rietveld 408576698