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

Side by Side Diff: skia/ext/platform_canvas.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+rebase 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 | « skia/ext/bitmap_platform_device_win.cc ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SKIA_EXT_PLATFORM_CANVAS_H_ 5 #ifndef SKIA_EXT_PLATFORM_CANVAS_H_
6 #define SKIA_EXT_PLATFORM_CANVAS_H_ 6 #define SKIA_EXT_PLATFORM_CANVAS_H_
7 7
8 // The platform-specific device will include the necessary platform headers 8 // The platform-specific device will include the necessary platform headers
9 // to get the surface type. 9 // to get the surface type.
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "skia/ext/platform_device.h" 11 #include "skia/ext/platform_device.h"
12 #include "skia/ext/refptr.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
13 14
14 namespace skia { 15 namespace skia {
15 16
16 typedef SkCanvas PlatformCanvas; 17 typedef SkCanvas PlatformCanvas;
17 18
18 // 19 //
19 // Note about error handling. 20 // Note about error handling.
20 // 21 //
21 // Creating a canvas can fail at times, most often because we fail to allocate 22 // Creating a canvas can fail at times, most often because we fail to allocate
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 uint8_t* data, 65 uint8_t* data,
65 OnFailureType failure_type); 66 OnFailureType failure_type);
66 #endif 67 #endif
67 68
68 static inline SkCanvas* CreatePlatformCanvas(int width, 69 static inline SkCanvas* CreatePlatformCanvas(int width,
69 int height, 70 int height,
70 bool is_opaque) { 71 bool is_opaque) {
71 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 72 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
72 } 73 }
73 74
74 // Takes ownership of the device, so the caller need not call unref(). 75 SK_API SkCanvas* CreateCanvas(const skia::RefPtr<SkDevice>& device,
75 SK_API SkCanvas* CreateCanvas(SkDevice* device, OnFailureType failure_type); 76 OnFailureType failure_type);
76 77
77 static inline SkCanvas* CreateBitmapCanvas(int width, 78 static inline SkCanvas* CreateBitmapCanvas(int width,
78 int height, 79 int height,
79 bool is_opaque) { 80 bool is_opaque) {
80 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 81 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
81 } 82 }
82 83
83 static inline SkCanvas* TryCreateBitmapCanvas(int width, 84 static inline SkCanvas* TryCreateBitmapCanvas(int width,
84 int height, 85 int height,
85 bool is_opaque) { 86 bool is_opaque) {
86 return CreatePlatformCanvas(width, height, is_opaque, 0, 87 return CreatePlatformCanvas(width, height, is_opaque, 0,
87 RETURN_NULL_ON_FAILURE); 88 RETURN_NULL_ON_FAILURE);
88 } 89 }
89 90
90 class SK_API ScopedPlatformCanvas : public SkAutoTUnref<SkCanvas> { 91 class SK_API ScopedPlatformCanvas : public RefPtr<SkCanvas> {
91 public: 92 public:
92 ScopedPlatformCanvas(int width, int height, bool is_opaque) 93 ScopedPlatformCanvas(int width, int height, bool is_opaque)
93 : SkAutoTUnref<SkCanvas>(CreatePlatformCanvas(width, height, is_opaque)){} 94 : RefPtr<SkCanvas>(AdoptRef(
95 CreatePlatformCanvas(width, height, is_opaque)))
96 {}
94 }; 97 };
95 98
96 // Return the stride (length of a line in bytes) for the given width. Because 99 // Return the stride (length of a line in bytes) for the given width. Because
97 // we use 32-bits per pixel, this will be roughly 4*width. However, for 100 // we use 32-bits per pixel, this will be roughly 4*width. However, for
98 // alignment reasons we may wish to increase that. 101 // alignment reasons we may wish to increase that.
99 SK_API size_t PlatformCanvasStrideForWidth(unsigned width); 102 SK_API size_t PlatformCanvasStrideForWidth(unsigned width);
100 103
101 // Returns the SkDevice pointer of the topmost rect with a non-empty 104 // Returns the SkDevice pointer of the topmost rect with a non-empty
102 // clip. In practice, this is usually either the top layer or nothing, since 105 // clip. In practice, this is usually either the top layer or nothing, since
103 // we usually set the clip to new layers when we make them. 106 // we usually set the clip to new layers when we make them.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 SkBitmap bitmap_; 182 SkBitmap bitmap_;
180 PlatformSurface surface_; // initialized to 0 183 PlatformSurface surface_; // initialized to 0
181 intptr_t platform_extra_; // initialized to 0, specific to each platform 184 intptr_t platform_extra_; // initialized to 0, specific to each platform
182 185
183 DISALLOW_COPY_AND_ASSIGN(PlatformBitmap); 186 DISALLOW_COPY_AND_ASSIGN(PlatformBitmap);
184 }; 187 };
185 188
186 } // namespace skia 189 } // namespace skia
187 190
188 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ 191 #endif // SKIA_EXT_PLATFORM_CANVAS_H_
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_win.cc ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698