From d72094d1c1062a9daa6fa92682ef29f02ba59335 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 27 Aug 2014 12:12:23 -0700 Subject: 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 --- tests/PictureTest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 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()); +} -- cgit v1.2.3