Index: tests/PictureTest.cpp |
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp |
index 3535e8e3bfd9a33d93395266e668930a5225f7c9..c834a684ad080aac74ea35f04c2b1b61c524ec74 100644 |
--- a/tests/PictureTest.cpp |
+++ b/tests/PictureTest.cpp |
@@ -19,6 +19,7 @@ |
#include "SkPicture.h" |
#include "SkPictureRecorder.h" |
#include "SkPictureUtils.h" |
+#include "SkPixelRef.h" |
#include "SkRRect.h" |
#include "SkRandom.h" |
#include "SkShader.h" |
@@ -1848,3 +1849,31 @@ DEF_TEST(Picture_SkipBBH, r) { |
picture->draw(&small); |
REPORTER_ASSERT(r, bbh.searchCalls == 1); |
} |
+ |
+DEF_TEST(Picture_BitmapLeak, r) { |
+ SkBitmap mut, immut; |
+ mut.allocN32Pixels(300, 200); |
+ immut.allocN32Pixels(300, 200); |
+ immut.setImmutable(); |
+ SkASSERT(!mut.isImmutable()); |
+ SkASSERT(immut.isImmutable()); |
+ |
+ // No one can hold a ref on our pixels yet. |
+ REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
+ REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
+ |
+ SkPictureRecorder rec; |
+ SkCanvas* canvas = rec.beginRecording(1920, 1200); |
+ canvas->drawBitmap(mut, 0, 0); |
+ canvas->drawBitmap(immut, 800, 600); |
+ SkAutoTDelete<const SkPicture> pic(rec.endRecording()); |
+ |
+ // The picture shares the immutable pixels but copies the mutable ones. |
+ REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
+ REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
+ |
+ // When the picture goes away, it's just our bitmaps holding the refs. |
+ pic.reset(NULL); |
+ REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
+ REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
+} |