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

Unified Diff: tests/PictureTest.cpp

Issue 516593002: Add test that confirms Pictures don't leak pixel refs. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698