| 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. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); | 56 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); |
| 57 | 57 |
| 58 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | 58 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 59 defined(__Solaris__) | 59 defined(__Solaris__) |
| 60 // For two-part init, call if you use the no-argument constructor above | 60 // For two-part init, call if you use the no-argument constructor above |
| 61 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); | 61 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 // Shared -------------------------------------------------------------------- | 64 // Shared -------------------------------------------------------------------- |
| 65 | 65 |
| 66 // These calls should surround calls to platform drawing routines, the | |
| 67 // surface returned here can be used with the native platform routines | |
| 68 // | |
| 69 // Call endPlatformPaint when you are done and want to use Skia operations | |
| 70 // after calling the platform-specific beginPlatformPaint; this will | |
| 71 // synchronize the bitmap to OS if necessary. | |
| 72 PlatformDevice::PlatformSurface beginPlatformPaint() const; | |
| 73 void endPlatformPaint() const; | |
| 74 | |
| 75 // Returns the platform device pointer of the topmost rect with a non-empty | |
| 76 // clip. In practice, this is usually either the top layer or nothing, since | |
| 77 // we usually set the clip to new layers when we make them. | |
| 78 // | |
| 79 // If there is no layer that is not all clipped out, this will return a | |
| 80 // dummy device so callers do not have to check. If you are concerned about | |
| 81 // performance, check the clip before doing any painting. | |
| 82 // | |
| 83 // This is different than SkCanvas' getDevice, because that returns the | |
| 84 // bottommost device. | |
| 85 // | |
| 86 // Danger: the resulting device should not be saved. It will be invalidated | |
| 87 // by the next call to save() or restore(). | |
| 88 PlatformDevice& getTopPlatformDevice() const; | |
| 89 | |
| 90 // Return the stride (length of a line in bytes) for the given width. Because | 66 // Return the stride (length of a line in bytes) for the given width. Because |
| 91 // we use 32-bits per pixel, this will be roughly 4*width. However, for | 67 // we use 32-bits per pixel, this will be roughly 4*width. However, for |
| 92 // alignment reasons we may wish to increase that. | 68 // alignment reasons we may wish to increase that. |
| 93 static size_t StrideForWidth(unsigned width); | 69 static size_t StrideForWidth(unsigned width); |
| 94 | 70 |
| 95 // Allow callers to see the non-virtual function even though we have an | 71 // Allow callers to see the non-virtual function even though we have an |
| 96 // override of a virtual one. | 72 // override of a virtual one. |
| 97 // FIXME(brettw) is this necessary? | 73 // FIXME(brettw) is this necessary? |
| 98 using SkCanvas::clipRect; | 74 using SkCanvas::clipRect; |
| 99 | 75 |
| 100 private: | 76 private: |
| 101 // Helper method used internally by the initialize() methods. | 77 // Helper method used internally by the initialize() methods. |
| 102 bool initializeWithDevice(SkDevice* device); | 78 bool initializeWithDevice(SkDevice* device); |
| 103 | 79 |
| 104 // Unimplemented. This is to try to prevent people from calling this function | 80 // Unimplemented. This is to try to prevent people from calling this function |
| 105 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this | 81 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this |
| 106 // 100%, but hopefully this will make people notice and not use the function. | 82 // 100%, but hopefully this will make people notice and not use the function. |
| 107 // Calling SkCanvas' version will create a new device which is not compatible | 83 // Calling SkCanvas' version will create a new device which is not compatible |
| 108 // with us and we will crash if somebody tries to draw into it with | 84 // with us and we will crash if somebody tries to draw into it with |
| 109 // CoreGraphics. | 85 // CoreGraphics. |
| 110 virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); | 86 virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); |
| 111 | 87 |
| 112 // Disallow copy and assign. | 88 // Disallow copy and assign |
| 113 PlatformCanvas(const PlatformCanvas&); | 89 PlatformCanvas(const PlatformCanvas&); |
| 114 PlatformCanvas& operator=(const PlatformCanvas&); | 90 PlatformCanvas& operator=(const PlatformCanvas&); |
| 115 }; | 91 }; |
| 116 | 92 |
| 93 // Returns the SkDevice pointer of the topmost rect with a non-empty |
| 94 // clip. In practice, this is usually either the top layer or nothing, since |
| 95 // we usually set the clip to new layers when we make them. |
| 96 // |
| 97 // If there is no layer that is not all clipped out, this will return a |
| 98 // dummy device so callers do not have to check. If you are concerned about |
| 99 // performance, check the clip before doing any painting. |
| 100 // |
| 101 // This is different than SkCanvas' getDevice, because that returns the |
| 102 // bottommost device. |
| 103 // |
| 104 // Danger: the resulting device should not be saved. It will be invalidated |
| 105 // by the next call to save() or restore(). |
| 106 SK_API SkDevice* GetTopDevice(const SkCanvas& canvas); |
| 107 |
| 117 // Creates a canvas with raster bitmap backing. | 108 // Creates a canvas with raster bitmap backing. |
| 118 // Set is_opaque if you are going to erase the bitmap and not use | 109 // Set is_opaque if you are going to erase the bitmap and not use |
| 119 // transparency: this will enable some optimizations. | 110 // transparency: this will enable some optimizations. |
| 120 SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque); | 111 SK_API SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque); |
| 121 | 112 |
| 122 // Returns true if native platform routines can be used to draw on the | 113 // Returns true if native platform routines can be used to draw on the |
| 123 // given canvas. If this function returns false, BeginPlatformPaint will | 114 // given canvas. If this function returns false, BeginPlatformPaint will |
| 124 // return NULL PlatformSurface. | 115 // return NULL PlatformSurface. |
| 125 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); | 116 SK_API bool SupportsPlatformPaint(const SkCanvas* canvas); |
| 126 | 117 |
| 118 // Draws into the a native platform surface, |context|. Forwards to |
| 119 // DrawToNativeContext on a PlatformDevice instance bound to the top device. |
| 120 // If no PlatformDevice instance is bound, is a no-operation. |
| 121 SK_API void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, |
| 122 int x, int y, const PlatformRect* src_rect); |
| 123 |
| 124 // Sets the opacity of each pixel in the specified region to be opaque. |
| 125 SK_API void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height); |
| 126 |
| 127 // These calls should surround calls to platform drawing routines, the | 127 // These calls should surround calls to platform drawing routines, the |
| 128 // surface returned here can be used with the native platform routines. | 128 // surface returned here can be used with the native platform routines. |
| 129 // | 129 // |
| 130 // Call EndPlatformPaint when you are done and want to use skia operations | 130 // Call EndPlatformPaint when you are done and want to use skia operations |
| 131 // after calling the platform-specific BeginPlatformPaint; this will | 131 // after calling the platform-specific BeginPlatformPaint; this will |
| 132 // synchronize the bitmap to OS if necessary. | 132 // synchronize the bitmap to OS if necessary. |
| 133 // | 133 SK_API PlatformSurface BeginPlatformPaint(SkCanvas* canvas); |
| 134 // Note: These functions will eventually replace | |
| 135 // PlatformCanvas::beginPlatformPaint and PlatformCanvas::endPlatformPaint. | |
| 136 SK_API PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas); | |
| 137 SK_API void EndPlatformPaint(SkCanvas* canvas); | 134 SK_API void EndPlatformPaint(SkCanvas* canvas); |
| 138 | 135 |
| 136 // Helper class for pairing calls to BeginPlatformPaint and EndPlatformPaint. |
| 137 // Upon construction invokes BeginPlatformPaint, and upon destruction invokes |
| 138 // EndPlatformPaint. |
| 139 class SK_API ScopedPlatformPaint { |
| 140 public: |
| 141 explicit ScopedPlatformPaint(SkCanvas* canvas) : canvas_(canvas) { |
| 142 platform_surface_ = BeginPlatformPaint(canvas); |
| 143 } |
| 144 ~ScopedPlatformPaint() { EndPlatformPaint(canvas_); } |
| 145 |
| 146 // Returns the PlatformSurface to use for native platform drawing calls. |
| 147 PlatformSurface GetPlatformSurface() { return platform_surface_; } |
| 148 private: |
| 149 SkCanvas* canvas_; |
| 150 PlatformSurface platform_surface_; |
| 151 |
| 152 // Disallow copy and assign |
| 153 ScopedPlatformPaint(const ScopedPlatformPaint&); |
| 154 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); |
| 155 }; |
| 156 |
| 139 } // namespace skia | 157 } // namespace skia |
| 140 | 158 |
| 141 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 159 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
| OLD | NEW |