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

Unified Diff: cc/skia_refptr.h

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 8 years, 1 month 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
« no previous file with comments | « cc/render_surface_impl.cc ('k') | cc/software_renderer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « cc/render_surface_impl.cc ('k') | cc/software_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698