OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 PlatformCanvas : public SkCanvas { | 19 class PlatformCanvas : public SkCanvas { |
20 public: | 20 public: |
| 21 // If you use the version with no arguments, you MUST call initialize() |
| 22 PlatformCanvas(); |
| 23 explicit PlatformCanvas(SkDeviceFactory* factory); |
21 // Set is_opaque if you are going to erase the bitmap and not use | 24 // Set is_opaque if you are going to erase the bitmap and not use |
22 // transparency: this will enable some optimizations. | 25 // transparency: this will enable some optimizations. |
23 // If you use the version with no arguments, you MUST call initialize() | |
24 PlatformCanvas(); | |
25 PlatformCanvas(int width, int height, bool is_opaque); | 26 PlatformCanvas(int width, int height, bool is_opaque); |
26 virtual ~PlatformCanvas(); | 27 virtual ~PlatformCanvas(); |
27 | 28 |
28 #if defined(WIN32) | 29 #if defined(WIN32) |
29 // Windows ------------------------------------------------------------------ | 30 // Windows ------------------------------------------------------------------ |
30 | 31 |
31 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 32 // The shared_section parameter is passed to gfx::PlatformDevice::create. |
32 // See it for details. | 33 // See it for details. |
33 PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section); | 34 PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section); |
34 | 35 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // Return the stride (length of a line in bytes) for the given width. Because | 90 // Return the stride (length of a line in bytes) for the given width. Because |
90 // we use 32-bits per pixel, this will be roughly 4*width. However, for | 91 // we use 32-bits per pixel, this will be roughly 4*width. However, for |
91 // alignment reasons we may wish to increase that. | 92 // alignment reasons we may wish to increase that. |
92 static size_t StrideForWidth(unsigned width); | 93 static size_t StrideForWidth(unsigned width); |
93 | 94 |
94 // Allow callers to see the non-virtual function even though we have an | 95 // Allow callers to see the non-virtual function even though we have an |
95 // override of a virtual one. | 96 // override of a virtual one. |
96 // FIXME(brettw) is this necessary? | 97 // FIXME(brettw) is this necessary? |
97 using SkCanvas::clipRect; | 98 using SkCanvas::clipRect; |
98 | 99 |
99 protected: | |
100 // Creates a device store for use by the canvas. We override this so that | |
101 // the device is always our own so we know that we can use platform | |
102 // operations on it. | |
103 virtual SkDevice* createDevice(SkBitmap::Config, | |
104 int width, | |
105 int height, | |
106 bool is_opaque, | |
107 bool isForLayer); | |
108 | |
109 private: | 100 private: |
110 // Unimplemented. This is to try to prevent people from calling this function | 101 // Unimplemented. This is to try to prevent people from calling this function |
111 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this | 102 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this |
112 // 100%, but hopefully this will make people notice and not use the function. | 103 // 100%, but hopefully this will make people notice and not use the function. |
113 // Calling SkCanvas' version will create a new device which is not compatible | 104 // Calling SkCanvas' version will create a new device which is not compatible |
114 // with us and we will crash if somebody tries to draw into it with | 105 // with us and we will crash if somebody tries to draw into it with |
115 // CoreGraphics. | 106 // CoreGraphics. |
116 virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); | 107 virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap); |
117 | 108 |
118 // Disallow copy and assign. | 109 // Disallow copy and assign. |
119 PlatformCanvas(const PlatformCanvas&); | 110 PlatformCanvas(const PlatformCanvas&); |
120 PlatformCanvas& operator=(const PlatformCanvas&); | 111 PlatformCanvas& operator=(const PlatformCanvas&); |
121 }; | 112 }; |
122 | 113 |
123 } // namespace skia | 114 } // namespace skia |
124 | 115 |
125 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 116 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
OLD | NEW |