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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Returns false on failure: if either argument is nullptr, or if the | 138 // Returns false on failure: if either argument is nullptr, or if the |
139 // pixels can not be retrieved from the canvas. In the latter case resets | 139 // pixels can not be retrieved from the canvas. In the latter case resets |
140 // the pixmap to empty. | 140 // the pixmap to empty. |
141 SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap); | 141 SK_API bool GetWritablePixels(SkCanvas* canvas, SkPixmap* pixmap); |
142 | 142 |
143 // Returns true if native platform routines can be used to draw on the | 143 // Returns true if native platform routines can be used to draw on the |
144 // given canvas. If this function returns false, BeginPlatformPaint will | 144 // given canvas. If this function returns false, BeginPlatformPaint will |
145 // return NULL PlatformSurface. | 145 // return NULL PlatformSurface. |
146 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); | 146 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); |
147 | 147 |
148 // These calls should surround calls to platform drawing routines, the | 148 // This object guards calls to platform drawing routines. The surface |
149 // surface returned here can be used with the native platform routines. | 149 // returned from GetPlatformSurface() can be used with the native platform |
150 // | 150 // routines. |
151 // Call EndPlatformPaint when you are done and want to use skia operations | |
152 // after calling the platform-specific BeginPlatformPaint; this will | |
153 // synchronize the bitmap to OS if necessary. | |
154 SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas); | |
155 SK_API void EndPlatformPaint(SkCanvas* canvas); | |
156 | |
157 // Helper class for pairing calls to BeginPlatformPaint and EndPlatformPaint. | |
158 // Upon construction invokes BeginPlatformPaint, and upon destruction invokes | |
159 // EndPlatformPaint. | |
160 class SK_API ScopedPlatformPaint { | 151 class SK_API ScopedPlatformPaint { |
161 public: | 152 public: |
162 explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) { | 153 explicit ScopedPlatformPaint(SkCanvas* canvas); |
163 platform_surface_ = BeginPlatformPaint(canvas); | |
164 } | |
165 ~ScopedPlatformPaint() { EndPlatformPaint(canvas_); } | |
166 | 154 |
167 // Returns the PlatformSurface to use for native platform drawing calls. | 155 // Returns the PlatformSurface to use for native platform drawing calls. |
168 PlatformSurface GetPlatformSurface() { return platform_surface_; } | 156 PlatformSurface GetPlatformSurface() { return platform_surface_; } |
| 157 |
169 private: | 158 private: |
170 SkCanvas* canvas_; | 159 SkCanvas* canvas_; |
171 PlatformSurface platform_surface_; | 160 PlatformSurface platform_surface_; |
172 | 161 |
173 // Disallow copy and assign | 162 // Disallow copy and assign |
174 ScopedPlatformPaint(const ScopedPlatformPaint&); | 163 ScopedPlatformPaint(const ScopedPlatformPaint&); |
175 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); | 164 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); |
176 }; | 165 }; |
177 | 166 |
178 // Following routines are used in print preview workflow to mark the | 167 // Following routines are used in print preview workflow to mark the |
179 // preview metafile. | 168 // preview metafile. |
180 SK_API SkMetaData& GetMetaData(const SkCanvas& canvas); | 169 SK_API SkMetaData& GetMetaData(const SkCanvas& canvas); |
181 | 170 |
182 #if defined(OS_MACOSX) | 171 #if defined(OS_MACOSX) |
183 SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); | 172 SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); |
184 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); | 173 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); |
185 | 174 |
186 // Returns the CGContext that backing the SkCanvas. | 175 // Returns the CGContext that backing the SkCanvas. |
187 // Returns NULL if none is bound. | 176 // Returns NULL if none is bound. |
188 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); | 177 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); |
189 #endif | 178 #endif |
190 | 179 |
191 } // namespace skia | 180 } // namespace skia |
192 | 181 |
193 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 182 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
OLD | NEW |