When cloning picture, use a bitmap heap to avoid flattening bitmaps.
When cloning a picture, the paints are reflattened. Use a bitmap
heap so the bitmaps do not get unnecessarily get flattened as well.
For br.337, this speeds up bench_pictures timing the clone
operation (not yet checked in, but currently timing making five
clones) from around 180 ms to around 24ms.
Review URL: https://codereview.appspot.com/6903063
git-svn-id: http://skia.googlecode.com/svn/trunk@6740 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 3024c22..9a8f133 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -194,6 +194,20 @@
*/
deepCopyInfo->paintData.setCount(src.fPaints->count());
+ /* Use an SkBitmapHeap to avoid flattening bitmaps in shaders. If there already is one,
+ * use it. If this SkPicturePlayback was created from a stream, fBitmapHeap will be
+ * NULL, so create a new one.
+ */
+ if (fBitmapHeap.get() == NULL) {
+ // FIXME: Put this on the stack inside SkPicture::clone. Further, is it possible to
+ // do the rest of this initialization in SkPicture::clone as well?
+ SkBitmapHeap* heap = SkNEW(SkBitmapHeap);
+ deepCopyInfo->controller.setBitmapStorage(heap);
+ heap->unref();
+ } else {
+ deepCopyInfo->controller.setBitmapStorage(fBitmapHeap);
+ }
+
SkDEBUGCODE(int heapSize = SafeCount(fBitmapHeap.get());)
for (int i = 0; i < src.fPaints->count(); i++) {
if (needs_deep_copy(src.fPaints->at(i))) {