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

Side by Side Diff: skia/ext/platform_canvas.h

Issue 2509983004: Revert "Change call-sites now that SkCanvas is not ref-counted" (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« 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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 27 matching lines...) Expand all
38 // the return result. 38 // the return result.
39 // 39 //
40 enum OnFailureType { 40 enum OnFailureType {
41 CRASH_ON_FAILURE, 41 CRASH_ON_FAILURE,
42 RETURN_NULL_ON_FAILURE 42 RETURN_NULL_ON_FAILURE
43 }; 43 };
44 44
45 #if defined(WIN32) 45 #if defined(WIN32)
46 // The shared_section parameter is passed to gfx::PlatformDevice::create. 46 // The shared_section parameter is passed to gfx::PlatformDevice::create.
47 // See it for details. 47 // See it for details.
48 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( 48 SK_API SkCanvas* CreatePlatformCanvas(int width,
49 int width, 49 int height,
50 int height, 50 bool is_opaque,
51 bool is_opaque, 51 HANDLE shared_section,
52 HANDLE shared_section, 52 OnFailureType failure_type);
53 OnFailureType failure_type);
54 53
55 // Draws the top layer of the canvas into the specified HDC. Only works 54 // Draws the top layer of the canvas into the specified HDC. Only works
56 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary 55 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary
57 // HDC to back the canvas if one doesn't already exist, tearing it down 56 // HDC to back the canvas if one doesn't already exist, tearing it down
58 // before returning. If |src_rect| is null, copies the entire canvas. 57 // before returning. If |src_rect| is null, copies the entire canvas.
59 SK_API void DrawToNativeContext(SkCanvas* canvas, 58 SK_API void DrawToNativeContext(SkCanvas* canvas,
60 HDC hdc, 59 HDC hdc,
61 int x, 60 int x,
62 int y, 61 int y,
63 const RECT* src_rect); 62 const RECT* src_rect);
64 #elif defined(__APPLE__) 63 #elif defined(__APPLE__)
65 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( 64 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context,
66 CGContextRef context, 65 int width,
67 int width, 66 int height,
68 int height, 67 bool is_opaque,
69 bool is_opaque, 68 OnFailureType failure_type);
70 OnFailureType failure_type);
71 69
72 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( 70 SK_API SkCanvas* CreatePlatformCanvas(int width,
73 int width, 71 int height,
74 int height, 72 bool is_opaque,
75 bool is_opaque, 73 uint8_t* context,
76 uint8_t* context, 74 OnFailureType failure_type);
77 OnFailureType failure_type);
78 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 75 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
79 defined(__sun) || defined(ANDROID) 76 defined(__sun) || defined(ANDROID)
80 // Linux --------------------------------------------------------------------- 77 // Linux ---------------------------------------------------------------------
81 78
82 // Construct a canvas from the given memory region. The memory is not cleared 79 // Construct a canvas from the given memory region. The memory is not cleared
83 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. 80 // first. @data must be, at least, @height * StrideForWidth(@width) bytes.
84 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( 81 SK_API SkCanvas* CreatePlatformCanvas(int width,
85 int width, 82 int height,
86 int height, 83 bool is_opaque,
87 bool is_opaque, 84 uint8_t* data,
88 uint8_t* data, 85 OnFailureType failure_type);
89 OnFailureType failure_type);
90 #endif 86 #endif
91 87
92 static inline std::unique_ptr<SkCanvas> CreatePlatformCanvas(int width, 88 static inline SkCanvas* CreatePlatformCanvas(int width,
93 int height, 89 int height,
94 bool is_opaque) { 90 bool is_opaque) {
95 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 91 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
96 } 92 }
97 93
98 SK_API std::unique_ptr<SkCanvas> CreateCanvas(const sk_sp<SkBaseDevice>& device, 94 SK_API SkCanvas* CreateCanvas(const sk_sp<SkBaseDevice>& device,
99 OnFailureType failure_type); 95 OnFailureType failure_type);
100 96
101 static inline std::unique_ptr<SkCanvas> CreateBitmapCanvas(int width, 97 static inline SkCanvas* CreateBitmapCanvas(int width,
102 int height, 98 int height,
103 bool is_opaque) { 99 bool is_opaque) {
104 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 100 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
105 } 101 }
106 102
107 static inline std::unique_ptr<SkCanvas> TryCreateBitmapCanvas(int width, 103 static inline SkCanvas* TryCreateBitmapCanvas(int width,
108 int height, 104 int height,
109 bool is_opaque) { 105 bool is_opaque) {
110 return CreatePlatformCanvas(width, height, is_opaque, 0, 106 return CreatePlatformCanvas(width, height, is_opaque, 0,
111 RETURN_NULL_ON_FAILURE); 107 RETURN_NULL_ON_FAILURE);
112 } 108 }
113 109
114 // Return the stride (length of a line in bytes) for the given width. Because 110 // Return the stride (length of a line in bytes) for the given width. Because
115 // we use 32-bits per pixel, this will be roughly 4*width. However, for 111 // we use 32-bits per pixel, this will be roughly 4*width. However, for
116 // alignment reasons we may wish to increase that. 112 // alignment reasons we may wish to increase that.
117 SK_API size_t PlatformCanvasStrideForWidth(unsigned width); 113 SK_API size_t PlatformCanvasStrideForWidth(unsigned width);
118 114
119 // Copies pixels from the SkCanvas into an SkBitmap, fetching pixels from 115 // Copies pixels from the SkCanvas into an SkBitmap, fetching pixels from
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); 163 SK_API bool IsPreviewMetafile(const SkCanvas& canvas);
168 164
169 // Returns the CGContext that backing the SkCanvas. 165 // Returns the CGContext that backing the SkCanvas.
170 // Returns NULL if none is bound. 166 // Returns NULL if none is bound.
171 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); 167 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas);
172 #endif 168 #endif
173 169
174 } // namespace skia 170 } // namespace skia
175 171
176 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ 172 #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