aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-05-21 06:29:05 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-21 06:29:05 -0700
commitab8657722c7a6676b67b0820210b288ba84a14d9 (patch)
tree90c44b53ccafaa659b373840d37bba7af039300b
parentb4a797f3aa8c10387f01cf51a65dd1a8aa5eec9d (diff)
add assert that the lock-count on pixelref is balanced
BUG=skia: TBR= Review URL: https://codereview.chromium.org/1147153004
-rw-r--r--gyp/skia_for_android_framework_defines.gypi1
-rw-r--r--src/core/SkPixelRef.cpp5
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp2
3 files changed, 8 insertions, 0 deletions
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi
index aba03844a3..46941547c5 100644
--- a/gyp/skia_for_android_framework_defines.gypi
+++ b/gyp/skia_for_android_framework_defines.gypi
@@ -15,6 +15,7 @@
'skia_for_android_framework_defines': [
'SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS',
'SK_SUPPORT_LEGACY_GETDEVICE',
+ 'SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT',
# Needed until we fix skbug.com/2440.
'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 3191b0333b..e7f5c8d947 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -10,6 +10,7 @@
#include "SkThread.h"
#include "SkTraceEvent.h"
+//#define SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT
//#define SK_TRACE_PIXELREF_LIFETIME
#ifdef SK_BUILD_FOR_WIN32
@@ -130,6 +131,10 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex)
}
SkPixelRef::~SkPixelRef() {
+#ifndef SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT
+ SkASSERT(SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount || 0 == fLockCount);
+#endif
+
#ifdef SK_TRACE_PIXELREF_LIFETIME
SkDebugf("~pixelref %d\n", sk_atomic_dec(&gInstCounter) - 1);
#endif
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 670d849436..66e5273625 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -262,11 +262,13 @@ static void check_pixelref(TestImageGenerator::TestType type,
// new/lock/delete is an odd pattern for a pixelref, but it needs to not assert
static void test_newlockdelete(skiatest::Reporter* reporter) {
+#ifdef SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT
SkBitmap bm;
SkImageGenerator* ig = new TestImageGenerator(
TestImageGenerator::kSucceedGetPixels_TestType, reporter);
SkInstallDiscardablePixelRef(ig, &bm);
bm.pixelRef()->lockPixels();
+#endif
}
/**