Chromium Code Reviews| 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); | 154 ~ScopedPlatformPaint(); |
|
f(malita)
2016/03/29 17:31:08
Nit: dtor no longer needed?
tomhudson
2016/03/29 17:47:32
Done.
| |
| 164 } | |
| 165 ~ScopedPlatformPaint() { EndPlatformPaint(canvas_); } | |
| 166 | 155 |
| 167 // Returns the PlatformSurface to use for native platform drawing calls. | 156 // Returns the PlatformSurface to use for native platform drawing calls. |
| 168 PlatformSurface GetPlatformSurface() { return platform_surface_; } | 157 PlatformSurface GetPlatformSurface(); |
|
f(malita)
2016/03/29 17:31:08
Nit: this is trivial enough to keep inline.
tomhudson
2016/03/29 17:47:32
I expect to change this soon enough that I wanted
| |
| 158 | |
| 169 private: | 159 private: |
| 170 SkCanvas* canvas_; | 160 SkCanvas* canvas_; |
| 171 PlatformSurface platform_surface_; | 161 PlatformSurface platform_surface_; |
| 172 | 162 |
| 173 // Disallow copy and assign | 163 // Disallow copy and assign |
| 174 ScopedPlatformPaint(const ScopedPlatformPaint&); | 164 ScopedPlatformPaint(const ScopedPlatformPaint&); |
| 175 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); | 165 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); |
| 176 }; | 166 }; |
| 177 | 167 |
| 178 // Following routines are used in print preview workflow to mark the | 168 // Following routines are used in print preview workflow to mark the |
| 179 // preview metafile. | 169 // preview metafile. |
| 180 SK_API SkMetaData& GetMetaData(const SkCanvas& canvas); | 170 SK_API SkMetaData& GetMetaData(const SkCanvas& canvas); |
| 181 | 171 |
| 182 #if defined(OS_MACOSX) | 172 #if defined(OS_MACOSX) |
| 183 SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); | 173 SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); |
| 184 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); | 174 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); |
| 185 | 175 |
| 186 // Returns the CGContext that backing the SkCanvas. | 176 // Returns the CGContext that backing the SkCanvas. |
| 187 // Returns NULL if none is bound. | 177 // Returns NULL if none is bound. |
| 188 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); | 178 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); |
| 189 #endif | 179 #endif |
| 190 | 180 |
| 191 } // namespace skia | 181 } // namespace skia |
| 192 | 182 |
| 193 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 183 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
| OLD | NEW |