diff options
author | 2014-07-08 06:48:17 -0700 | |
---|---|---|
committer | 2014-07-08 06:48:17 -0700 | |
commit | 4ae94ffce5ecf1b71cb5e295b68bf4ec9e697443 (patch) | |
tree | 6c734cf27a2f033bfb5f512420860fd035d0bbfa /include/core | |
parent | 3afef1f75f710b8f183113cdc5188416f7d01f28 (diff) |
Remove ability for Release code to call getRefCnt() or getWeakRefCnt().
These getRefCnt() methods are not thread safe, so Skia code should not
be calling them. unique() is fine.
SkDEBUG code (SkASSERTs) can still call getRefCnt() / getWeakRefCnt().
This adds tools/RefCntIs.{h,cpp}, which lets tests make their assertions in
both debug and release modes.
BUG=skia:2726
R=senorblanco@chromium.org, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/378643003
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkImageFilter.h | 1 | ||||
-rw-r--r-- | include/core/SkRefCnt.h | 5 | ||||
-rw-r--r-- | include/core/SkWeakRefCnt.h | 7 |
3 files changed, 10 insertions, 3 deletions
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h index 9cdd27599a..15e9a2f0c9 100644 --- a/include/core/SkImageFilter.h +++ b/include/core/SkImageFilter.h @@ -51,6 +51,7 @@ public: class SK_API Cache : public SkRefCnt { public: // By default, we cache only image filters with 2 or more children. + // Values less than 2 mean always cache; values greater than 2 are not supported. static Cache* Create(int minChildren = 2); virtual ~Cache() {} virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* offset) = 0; diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 1724c77d8d..d3a26df4d5 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -42,8 +42,10 @@ public: #endif } +#ifdef SK_DEBUG /** Return the reference count. Use only for debugging. */ int32_t getRefCnt() const { return fRefCnt; } +#endif /** May return true if the caller is the only owner. * Ensures that all previous owner's actions are complete. @@ -118,6 +120,9 @@ private: mutable int32_t fRefCnt; + // Used by tests. + friend bool RefCntIs(const SkRefCntBase&, int32_t); + typedef SkNoncopyable INHERITED; }; diff --git a/include/core/SkWeakRefCnt.h b/include/core/SkWeakRefCnt.h index 210dcc9f1c..d9f0dc80d6 100644 --- a/include/core/SkWeakRefCnt.h +++ b/include/core/SkWeakRefCnt.h @@ -60,20 +60,18 @@ public: */ SkWeakRefCnt() : SkRefCnt(), fWeakCnt(1) {} +#ifdef SK_DEBUG /** Destruct, asserting that the weak reference count is 1. */ virtual ~SkWeakRefCnt() { -#ifdef SK_DEBUG SkASSERT(fWeakCnt == 1); fWeakCnt = 0; -#endif } /** Return the weak reference count. */ int32_t getWeakCnt() const { return fWeakCnt; } -#ifdef SK_DEBUG void validate() const { this->INHERITED::validate(); SkASSERT(fWeakCnt > 0); @@ -155,6 +153,9 @@ private: /* Invariant: fWeakCnt = #weak + (fRefCnt > 0 ? 1 : 0) */ mutable int32_t fWeakCnt; + // Used by tests. + friend bool WeakRefCntIs(const SkWeakRefCnt&, int32_t); + typedef SkRefCnt INHERITED; }; |