| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // The platform-specific device will include the necessary platform headers | 9 // The platform-specific device will include the necessary platform headers |
| 10 // to get the surface type. | 10 // to get the surface type. |
| 11 #include "skia/ext/platform_device.h" | 11 #include "skia/ext/platform_device.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 | 13 |
| 14 namespace skia { | 14 namespace skia { |
| 15 | 15 |
| 16 // This class is a specialization of the regular SkCanvas that is designed to | 16 // This class is a specialization of the regular SkCanvas that is designed to |
| 17 // work with a PlatformDevice to manage platform-specific drawing. It allows | 17 // work with a PlatformDevice to manage platform-specific drawing. It allows |
| 18 // using both Skia operations and platform-specific operations. | 18 // using both Skia operations and platform-specific operations. |
| 19 class SK_API PlatformCanvas : public SkCanvas { | 19 class SK_API PlatformCanvas : public SkCanvas { |
| 20 public: | 20 public: |
| 21 // If you use the version with no arguments, you MUST call initialize() | 21 // If you use the version with no arguments, you MUST call initialize() |
| 22 PlatformCanvas(); | 22 PlatformCanvas(); |
| 23 // Set is_opaque if you are going to erase the bitmap and not use | 23 // Set flags to FLAGS_OPAQUE if you are going to erase the bitmap and not use |
| 24 // transparency: this will enable some optimizations. | 24 // transparency: this will enable some optimizations. |
| 25 PlatformCanvas(int width, int height, bool is_opaque); | 25 // Set flags to FLAGS_INITIALIZED if the canvas should be initialized to 0. |
| 26 PlatformCanvas(int width, int height, int flags); |
| 26 | 27 |
| 27 #if defined(WIN32) | 28 #if defined(WIN32) |
| 28 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 29 // The shared_section parameter is passed to gfx::PlatformDevice::create. |
| 29 // See it for details. | 30 // See it for details. |
| 30 PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section); | 31 PlatformCanvas(int width, int height, int flags, HANDLE shared_section); |
| 31 #elif defined(__APPLE__) | 32 #elif defined(__APPLE__) |
| 32 PlatformCanvas(int width, int height, bool is_opaque, | 33 PlatformCanvas(int width, int height, int flags, CGContextRef context); |
| 33 CGContextRef context); | 34 PlatformCanvas(int width, int height, int flags, uint8_t* context); |
| 34 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context); | |
| 35 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | 35 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 36 defined(__sun) || defined(ANDROID) | 36 defined(__sun) || defined(ANDROID) |
| 37 // Linux --------------------------------------------------------------------- | 37 // Linux --------------------------------------------------------------------- |
| 38 | 38 |
| 39 // Construct a canvas from the given memory region. The memory is not cleared | 39 // Construct a canvas from the given memory region. The memory is not cleared |
| 40 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. | 40 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. |
| 41 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data); | 41 PlatformCanvas(int width, int height, int flags, uint8_t* data); |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 virtual ~PlatformCanvas(); | 44 virtual ~PlatformCanvas(); |
| 45 | 45 |
| 46 #if defined(WIN32) | 46 #if defined(WIN32) |
| 47 // For two-part init, call if you use the no-argument constructor above. Note | 47 // For two-part init, call if you use the no-argument constructor above. Note |
| 48 // that we want this to optionally match the Linux initialize if you only | 48 // that we want this to optionally match the Linux initialize if you only |
| 49 // pass 3 arguments, hence the evil default argument. | 49 // pass 3 arguments, hence the evil default argument. |
| 50 bool initialize(int width, int height, bool is_opaque, | 50 bool initialize(int width, int height, int flags, |
| 51 HANDLE shared_section = NULL); | 51 HANDLE shared_section = NULL); |
| 52 #elif defined(__APPLE__) | 52 #elif defined(__APPLE__) |
| 53 // For two-part init, call if you use the no-argument constructor above | 53 // For two-part init, call if you use the no-argument constructor above |
| 54 bool initialize(CGContextRef context, int width, int height, bool is_opaque); | 54 bool initialize(CGContextRef context, int width, int height, int flags); |
| 55 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); | 55 bool initialize(int width, int height, int flags, uint8_t* data = NULL); |
| 56 | 56 |
| 57 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | 57 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 58 defined(__sun) || defined(ANDROID) | 58 defined(__sun) || defined(ANDROID) |
| 59 // For two-part init, call if you use the no-argument constructor above | 59 // For two-part init, call if you use the no-argument constructor above |
| 60 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); | 60 bool initialize(int width, int height, int flags, uint8_t* data = NULL); |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 // Shared -------------------------------------------------------------------- | 63 // Shared -------------------------------------------------------------------- |
| 64 | 64 |
| 65 // Return the stride (length of a line in bytes) for the given width. Because | 65 // Return the stride (length of a line in bytes) for the given width. Because |
| 66 // we use 32-bits per pixel, this will be roughly 4*width. However, for | 66 // we use 32-bits per pixel, this will be roughly 4*width. However, for |
| 67 // alignment reasons we may wish to increase that. | 67 // alignment reasons we may wish to increase that. |
| 68 static size_t StrideForWidth(unsigned width); | 68 static size_t StrideForWidth(unsigned width); |
| 69 | 69 |
| 70 // Allow callers to see the non-virtual function even though we have an | 70 // Allow callers to see the non-virtual function even though we have an |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // | 102 // |
| 103 // Danger: the resulting device should not be saved. It will be invalidated | 103 // Danger: the resulting device should not be saved. It will be invalidated |
| 104 // by the next call to save() or restore(). | 104 // by the next call to save() or restore(). |
| 105 SK_API SkDevice* GetTopDevice(const SkCanvas& canvas); | 105 SK_API SkDevice* GetTopDevice(const SkCanvas& canvas); |
| 106 | 106 |
| 107 // Creates a canvas with raster bitmap backing. | 107 // Creates a canvas with raster bitmap backing. |
| 108 // Set is_opaque if you are going to erase the bitmap and not use | 108 // Set is_opaque if you are going to erase the bitmap and not use |
| 109 // transparency: this will enable some optimizations. | 109 // transparency: this will enable some optimizations. |
| 110 SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque); | 110 SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque); |
| 111 | 111 |
| 112 // Creates a canvas with raster bitmap backing. |
| 113 // Set flags to FLAGS_OPAQUE if you are going to erase the bitmap and not use |
| 114 // transparency: this will enable some optimizations. |
| 115 // Set flags to FLAGS_INITIALIZED if the canvas should be initialized to 0. |
| 116 SK_API SkCanvas* CreateBitmapCanvas(int width, int height, int flags); |
| 117 |
| 112 // Non-crashing version of CreateBitmapCanvas | 118 // Non-crashing version of CreateBitmapCanvas |
| 113 // returns NULL if allocation fails for any reason. | 119 // returns NULL if allocation fails for any reason. |
| 114 // Use this instead of CreateBitmapCanvas in places that are likely to | 120 // Use this instead of CreateBitmapCanvas in places that are likely to |
| 115 // attempt to allocate very large canvases (therefore likely to fail), | 121 // attempt to allocate very large canvases (therefore likely to fail), |
| 116 // and where it is possible to recover gracefully from the failed allocation. | 122 // and where it is possible to recover gracefully from the failed allocation. |
| 117 SK_API SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque); | 123 SK_API SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque); |
| 124 SK_API SkCanvas* TryCreateBitmapCanvas(int width, int height, int flags); |
| 118 | 125 |
| 119 // Returns true if native platform routines can be used to draw on the | 126 // Returns true if native platform routines can be used to draw on the |
| 120 // given canvas. If this function returns false, BeginPlatformPaint will | 127 // given canvas. If this function returns false, BeginPlatformPaint will |
| 121 // return NULL PlatformSurface. | 128 // return NULL PlatformSurface. |
| 122 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); | 129 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); |
| 123 | 130 |
| 124 // Draws into the a native platform surface, |context|. Forwards to | 131 // Draws into the a native platform surface, |context|. Forwards to |
| 125 // DrawToNativeContext on a PlatformDevice instance bound to the top device. | 132 // DrawToNativeContext on a PlatformDevice instance bound to the top device. |
| 126 // If no PlatformDevice instance is bound, is a no-operation. | 133 // If no PlatformDevice instance is bound, is a no-operation. |
| 127 SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, | 134 SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 156 PlatformSurface platform_surface_; | 163 PlatformSurface platform_surface_; |
| 157 | 164 |
| 158 // Disallow copy and assign | 165 // Disallow copy and assign |
| 159 ScopedPlatformPaint(const ScopedPlatformPaint&); | 166 ScopedPlatformPaint(const ScopedPlatformPaint&); |
| 160 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); | 167 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); |
| 161 }; | 168 }; |
| 162 | 169 |
| 163 } // namespace skia | 170 } // namespace skia |
| 164 | 171 |
| 165 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 172 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
| OLD | NEW |