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