aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRefCnt.h
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 19:38:19 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-01 19:38:19 +0000
commite70f798ebca1a66f0b568fa46065ebbad9a13b2f (patch)
treec251586a80f9dbd07fc7cef0d16dce670ebd549e /include/core/SkRefCnt.h
parentc3b80ba50a494efdf6505585dc32dbe7422d5555 (diff)
Serialize support for GDI.
Diffstat (limited to 'include/core/SkRefCnt.h')
-rw-r--r--include/core/SkRefCnt.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 384b3be2eb..d6277fdd83 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -141,7 +141,25 @@ public:
return obj;
}
- T* operator->() { return fObj; }
+ /**
+ * BlockRef<T> is a type which inherits from T, cannot be created,
+ * and makes ref and unref private.
+ */
+ template<typename T> class BlockRef : public T {
+ private:
+ BlockRef();
+ void ref() const;
+ void unref() const;
+ };
+ /**
+ * SkAutoTUnref assumes ownership of the ref. As a result, it is an error
+ * for the user to ref or unref through SkAutoTUnref. Therefore
+ * SkAutoTUnref::operator-> returns BlockRef<T>*. This prevents use of
+ * skAutoTUnrefInstance->ref() and skAutoTUnrefInstance->unref().
+ */
+ BlockRef<T> *operator->() const {
+ return static_cast<BlockRef<T>*>(fObj);
+ }
operator T*() { return fObj; }
private: