Index: cc/skia_refptr.h |
diff --git a/cc/skia_refptr.h b/cc/skia_refptr.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..95a6a1b1594ba68da23d5eb58ff1246abe499e3c |
--- /dev/null |
+++ b/cc/skia_refptr.h |
@@ -0,0 +1,64 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CC_SKIA_REFPTR_H_ |
+#define CC_SKIA_REFPTR_H_ |
+ |
+#include "third_party/skia/include/core/SkRefCnt.h" |
+ |
+namespace cc { |
+ |
+template<typename T> |
+class SkiaRefPtr { |
jamesr
2012/11/28 22:20:54
This doesn't belong in cc/
|
+ public: |
+ SkiaRefPtr() |
+ : ptr_(NULL) { |
+ } |
+ |
+ SkiaRefPtr(const SkiaRefPtr& other) |
+ : ptr_(other.ptr_) { |
+ SkSafeRef(ptr_); |
+ } |
+ |
+ ~SkiaRefPtr() { |
+ clear(); |
+ } |
+ |
+ SkiaRefPtr& operator=(const SkiaRefPtr& other) { |
+ SkRefCnt_SafeAssign(ptr_, other.ptr_); |
+ return *this; |
+ } |
+ |
+ T* get() const { return ptr_; } |
+ T& operator*() const { return *ptr_; } |
+ T* operator->() const { return ptr_; } |
+ |
+ void clear() { |
+ T* to_unref = ptr_; |
+ ptr_ = NULL; |
+ SkSafeUnref(to_unref); |
+ } |
+ |
+ typedef T* SkiaRefPtr::*unspecified_bool_type; |
+ operator unspecified_bool_type() const { |
+ return ptr_ ? &SkiaRefPtr::ptr_ : NULL; |
+ } |
+ |
+ // Skia objects come with a reference of 1, steal that reference here to |
+ // take ownership. |
+ static SkiaRefPtr<T> Adopt(T* ptr) { |
+ return SkiaRefPtr<T>(ptr); |
+ } |
+ |
+ private: |
+ T* ptr_; |
+ |
+ // Only let Adopt() create this class from a raw Skia ref-counted |
+ // pointer. |
+ explicit SkiaRefPtr(T* ptr) : ptr_(ptr) {} |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_SKIA_REFPTR_H_ |