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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/render_surface_impl.cc ('k') | cc/software_renderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_SKIA_REFPTR_H_
6 #define CC_SKIA_REFPTR_H_
7
8 #include "third_party/skia/include/core/SkRefCnt.h"
9
10 namespace cc {
11
12 template<typename T>
13 class SkiaRefPtr {
jamesr 2012/11/28 22:20:54 This doesn't belong in cc/
14 public:
15 SkiaRefPtr()
16 : ptr_(NULL) {
17 }
18
19 SkiaRefPtr(const SkiaRefPtr& other)
20 : ptr_(other.ptr_) {
21 SkSafeRef(ptr_);
22 }
23
24 ~SkiaRefPtr() {
25 clear();
26 }
27
28 SkiaRefPtr& operator=(const SkiaRefPtr& other) {
29 SkRefCnt_SafeAssign(ptr_, other.ptr_);
30 return *this;
31 }
32
33 T* get() const { return ptr_; }
34 T& operator*() const { return *ptr_; }
35 T* operator->() const { return ptr_; }
36
37 void clear() {
38 T* to_unref = ptr_;
39 ptr_ = NULL;
40 SkSafeUnref(to_unref);
41 }
42
43 typedef T* SkiaRefPtr::*unspecified_bool_type;
44 operator unspecified_bool_type() const {
45 return ptr_ ? &SkiaRefPtr::ptr_ : NULL;
46 }
47
48 // Skia objects come with a reference of 1, steal that reference here to
49 // take ownership.
50 static SkiaRefPtr<T> Adopt(T* ptr) {
51 return SkiaRefPtr<T>(ptr);
52 }
53
54 private:
55 T* ptr_;
56
57 // Only let Adopt() create this class from a raw Skia ref-counted
58 // pointer.
59 explicit SkiaRefPtr(T* ptr) : ptr_(ptr) {}
60 };
61
62 } // namespace cc
63
64 #endif // CC_SKIA_REFPTR_H_
OLDNEW
« 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