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

Unified Diff: third_party/skia/include/core/SkRefCnt.h

Issue 40973002: Enable reference adoption checks for Blink+skia in Debug builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Patching on gpu bots is basically broken, use rietveld for arbitrary patches. Created 7 years, 2 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
Index: third_party/skia/include/core/SkRefCnt.h
===================================================================
--- third_party/skia/include/core/SkRefCnt.h (revision 11932)
+++ third_party/skia/include/core/SkRefCnt.h (working copy)
@@ -14,25 +14,9 @@
#include "SkInstCnt.h"
#include "SkTemplates.h"
-#ifdef SK_REF_CNT_BASE_INCLUDE
-#include SK_REF_CNT_BASE_INCLUDE
-#else
/** \class SkRefCntBase
- Default implementation of SkRefCntBase. The base class' contract is to
- provide an implementation of aboutToRef. Embedders of skia can specify
- an alternate implementation by setting SK_REF_CNT_BASE_INCLUDE. This is
- useful for adding debug run-time checks to enforce certain usage patterns.
-*/
-class SK_API SkRefCntBase {
-public:
- void aboutToRef() const {}
-};
-#endif
-
-/** \class SkRefCnt
-
- SkRefCnt is the base class for objects that may be shared by multiple
+ SkRefCntBase is the base class for objects that may be shared by multiple
objects. When an existing owner wants to share a reference, it calls ref().
When an owner wants to release its reference, it calls unref(). When the
shared object's reference count goes to zero as the result of an unref()
@@ -40,17 +24,17 @@
destructor to be called explicitly (or via the object going out of scope on
the stack or calling delete) if getRefCnt() > 1.
*/
-class SK_API SkRefCnt : public SkRefCntBase {
+class SK_API SkRefCntBase : public SkNoncopyable {
public:
- SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
+ SK_DECLARE_INST_COUNT_ROOT(SkRefCntBase)
/** Default construct, initializing the reference count to 1.
*/
- SkRefCnt() : fRefCnt(1) {}
+ SkRefCntBase() : fRefCnt(1) {}
/** Destruct, asserting that the reference count is 1.
*/
- virtual ~SkRefCnt() {
+ virtual ~SkRefCntBase() {
#ifdef SK_DEBUG
SkASSERT(fRefCnt == 1);
fRefCnt = 0; // illegal value, to catch us if we reuse after delete
@@ -66,7 +50,7 @@
bool unique() const {
bool const unique = (1 == fRefCnt);
if (unique) {
- // Aquire barrier (L/SL), if not provided by load of fRefCnt.
+ // Acquire barrier (L/SL), if not provided by load of fRefCnt.
// Prevents user's 'unique' code from happening before decrements.
//TODO: issue the barrier.
}
@@ -77,7 +61,6 @@
*/
void ref() const {
SkASSERT(fRefCnt > 0);
- this->INHERITED::aboutToRef();
sk_atomic_inc(&fRefCnt); // No barrier required.
}
@@ -89,9 +72,9 @@
SkASSERT(fRefCnt > 0);
// Release barrier (SL/S), if not provided below.
if (sk_atomic_dec(&fRefCnt) == 1) {
- // Aquire barrier (L/SL), if not provided above.
+ // Acquire barrier (L/SL), if not provided above.
// Prevents code in dispose from happening before the decrement.
- sk_membar_aquire__after_atomic_dec();
+ sk_membar_acquire__after_atomic_dec();
internal_dispose();
}
}
@@ -102,11 +85,6 @@
}
#endif
- /**
- * Alias for unref(), for compatibility with WTF::RefPtr.
- */
- void deref() { this->unref(); }
-
protected:
/**
* Allow subclasses to call this if they've overridden internal_dispose
@@ -123,12 +101,6 @@
private:
/**
- * Make SkRefCnt non-copyable.
- */
- SkRefCnt(const SkRefCnt&);
- SkRefCnt& operator=(const SkRefCnt&);
-
- /**
* Called when the ref count goes to 0.
*/
virtual void internal_dispose() const {
@@ -143,9 +115,17 @@
mutable int32_t fRefCnt;
- typedef SkRefCntBase INHERITED;
+ typedef SkNoncopyable INHERITED;
};
+#ifdef SK_REF_CNT_MIXIN_INCLUDE
+// It is the responsibility of the following include to define the type SkRefCnt.
+// This SkRefCnt should normally derive from SkRefCntBase.
+#include SK_REF_CNT_MIXIN_INCLUDE
+#else
+class SK_API SkRefCnt : public SkRefCntBase { };
+#endif
+
///////////////////////////////////////////////////////////////////////////////
/** Helper macro to safely assign one SkRefCnt[TS]* to another, checking for

Powered by Google App Engine
This is Rietveld 408576698