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

Unified Diff: src/core/SkPicture.cpp

Issue 388833003: Remove Skia's use of the default SkPicture constructor and multi-clone (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix test Created 6 years, 5 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
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPictureData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index b96caf908c95dca0503dab5c5ea34df15ff7e15a..d57de97d78c5f67a3c3da1c9a0087b9497e7a052 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -111,6 +111,7 @@ const char* DrawTypeToString(DrawType drawType) {
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_DEFAULT_PICTURE_CTOR
// fRecord OK
SkPicture::SkPicture()
: fWidth(0)
@@ -118,6 +119,7 @@ SkPicture::SkPicture()
, fRecordWillPlayBackBitmaps(false) {
this->needsNewGenID();
}
+#endif
// fRecord OK
SkPicture::SkPicture(int width, int height,
@@ -147,75 +149,59 @@ SkPicture::~SkPicture() {}
#ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
// fRecord TODO, fix by deleting this method
SkPicture* SkPicture::clone() const {
- SkPicture* clonedPicture = SkNEW(SkPicture);
- this->clone(clonedPicture, 1);
- return clonedPicture;
-}
-// fRecord TODO, fix by deleting this method
-void SkPicture::clone(SkPicture* pictures, int count) const {
- SkPictCopyInfo copyInfo;
+ SkAutoTDelete<SkPictureData> newData;
- for (int i = 0; i < count; i++) {
- SkPicture* clone = &pictures[i];
+ if (fData.get()) {
+ SkPictCopyInfo copyInfo;
- clone->needsNewGenID();
- clone->fWidth = fWidth;
- clone->fHeight = fHeight;
- clone->fData.reset(NULL);
- clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps;
+ int paintCount = SafeCount(fData->fPaints);
- /* We want to copy the src's playback. However, if that hasn't been built
- yet, we need to fake a call to endRecording() without actually calling
- it (since it is destructive, and we don't want to change src).
+ /* The alternative to doing this is to have a clone method on the paint and have it
+ * make the deep copy of its internal structures as needed. The holdup to doing
+ * that is at this point we would need to pass the SkBitmapHeap so that we don't
+ * unnecessarily flatten the pixels in a bitmap shader.
*/
- if (fData.get()) {
- if (!copyInfo.initialized) {
- int paintCount = SafeCount(fData->fPaints);
-
- /* The alternative to doing this is to have a clone method on the paint and have it
- * make the deep copy of its internal structures as needed. The holdup to doing
- * that is at this point we would need to pass the SkBitmapHeap so that we don't
- * unnecessarily flatten the pixels in a bitmap shader.
- */
- copyInfo.paintData.setCount(paintCount);
-
- /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. If there already is
- * one, use it. If this SkPictureData was created from a stream, fBitmapHeap
- * will be NULL, so create a new one.
- */
- if (fData->fBitmapHeap.get() == NULL) {
- // FIXME: Put this on the stack inside SkPicture::clone.
- SkBitmapHeap* heap = SkNEW(SkBitmapHeap);
- copyInfo.controller.setBitmapStorage(heap);
- heap->unref();
- } else {
- copyInfo.controller.setBitmapStorage(fData->fBitmapHeap);
- }
-
- SkDEBUGCODE(int heapSize = SafeCount(fData->fBitmapHeap.get());)
- for (int i = 0; i < paintCount; i++) {
- if (NeedsDeepCopy(fData->fPaints->at(i))) {
- copyInfo.paintData[i] =
- SkFlatData::Create<SkPaint::FlatteningTraits>(&copyInfo.controller,
- fData->fPaints->at(i), 0);
-
- } else {
- // this is our sentinel, which we use in the unflatten loop
- copyInfo.paintData[i] = NULL;
- }
- }
- SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize);
-
- // needed to create typeface playback
- copyInfo.controller.setupPlaybacks();
- copyInfo.initialized = true;
- }
+ copyInfo.paintData.setCount(paintCount);
- clone->fData.reset(SkNEW_ARGS(SkPictureData, (*fData, &copyInfo)));
- clone->fUniqueID = this->uniqueID(); // need to call method to ensure != 0
+ /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. If there already is
+ * one, use it. If this SkPictureData was created from a stream, fBitmapHeap
+ * will be NULL, so create a new one.
+ */
+ if (fData->fBitmapHeap.get() == NULL) {
+ // FIXME: Put this on the stack inside SkPicture::clone.
+ SkBitmapHeap* heap = SkNEW(SkBitmapHeap);
+ copyInfo.controller.setBitmapStorage(heap);
+ heap->unref();
+ } else {
+ copyInfo.controller.setBitmapStorage(fData->fBitmapHeap);
}
+
+ SkDEBUGCODE(int heapSize = SafeCount(fData->fBitmapHeap.get());)
+ for (int i = 0; i < paintCount; i++) {
+ if (NeedsDeepCopy(fData->fPaints->at(i))) {
+ copyInfo.paintData[i] =
+ SkFlatData::Create<SkPaint::FlatteningTraits>(&copyInfo.controller,
+ fData->fPaints->at(i), 0);
+
+ } else {
+ // this is our sentinel, which we use in the unflatten loop
+ copyInfo.paintData[i] = NULL;
+ }
+ }
+ SkASSERT(SafeCount(fData->fBitmapHeap.get()) == heapSize);
+
+ // needed to create typeface playback
+ copyInfo.controller.setupPlaybacks();
+
+ newData.reset(SkNEW_ARGS(SkPictureData, (*fData, &copyInfo)));
}
+
+ SkPicture* clone = SkNEW_ARGS(SkPicture, (newData.detach(), fWidth, fHeight));
+ clone->fRecordWillPlayBackBitmaps = fRecordWillPlayBackBitmaps;
+ clone->fUniqueID = this->uniqueID(); // need to call method to ensure != 0
+
+ return clone;
}
#endif//SK_SUPPORT_LEGACY_PICTURE_CLONE
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPictureData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698