aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-08-27 12:12:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-27 12:12:23 -0700
commitd72094d1c1062a9daa6fa92682ef29f02ba59335 (patch)
treed0377049cf8d508e4d72aedae09274c85b3da88a
parentd62833079fc36e28e65692f9a0c7dbdb124519c6 (diff)
Add test that confirms Pictures don't leak pixel refs.
Have been investigating memory leak failures that show SkRecords' ImmutableBitmap copy leaking. I think this test proves its not an obvious problem with ImmutableBitmap or SkRecord. http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%282%29/builds/2509/steps/interactive_ui_tests/logs/stdio BUG=skia: R=bungeman@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/516593002
-rw-r--r--tests/PictureTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index a189c1a4ae..627e96e20f 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"
@@ -1916,3 +1917,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());
+}