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 #if defined(WIN32) | |
17 typedef HANDLE PlatformData; | |
18 #else | |
Alexei Svitkine (slow)
2012/04/16 19:01:44
Shouldn't you have this:
#elif defined(__APPLE__)
| |
19 typedef uint8_t* PlatformData; | |
20 #endif | |
21 | |
16 // This class is a specialization of the regular SkCanvas that is designed to | 22 // 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 | 23 // work with a PlatformDevice to manage platform-specific drawing. It allows |
18 // using both Skia operations and platform-specific operations. | 24 // using both Skia operations and platform-specific operations. |
19 class SK_API PlatformCanvas : public SkCanvas { | 25 class SK_API PlatformCanvas : public SkCanvas { |
20 public: | 26 public: |
21 // If you use the version with no arguments, you MUST call initialize() | 27 // If you use the version with no arguments, you MUST call initialize() |
22 PlatformCanvas(); | 28 PlatformCanvas(); |
23 // Set is_opaque if you are going to erase the bitmap and not use | 29 // Set is_opaque if you are going to erase the bitmap and not use |
24 // transparency: this will enable some optimizations. | 30 // transparency: this will enable some optimizations. |
25 PlatformCanvas(int width, int height, bool is_opaque); | 31 PlatformCanvas(int width, int height, bool is_opaque); |
26 | 32 |
27 #if defined(WIN32) | 33 // Construct a canvas from the given platform specific data. The data is |
28 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 34 // not cleared first. @data must be, at least, |
29 // See it for details. | 35 // @height * StrideForWidth(@width) bytes. |
Alexei Svitkine (slow)
2012/04/16 19:01:44
Nit: Use pairs of |'s instead of @'s for param nam
| |
30 PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section); | 36 PlatformCanvas(int width, int height, bool is_opaque, PlatformData data); |
31 #elif defined(__APPLE__) | |
32 PlatformCanvas(int width, int height, bool is_opaque, | |
33 CGContextRef context); | |
34 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context); | |
35 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
36 defined(__sun) || defined(ANDROID) | |
37 // Linux --------------------------------------------------------------------- | |
38 | 37 |
39 // Construct a canvas from the given memory region. The memory is not cleared | 38 #if defined(__APPLE__) |
40 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. | 39 PlatformCanvas(int width, int height, bool is_opaque, CGContextRef context); |
41 PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data); | |
42 #endif | 40 #endif |
43 | 41 |
44 virtual ~PlatformCanvas(); | 42 virtual ~PlatformCanvas(); |
45 | 43 |
46 #if defined(WIN32) | 44 // For two-part init, call if you use the no-argument constructor above |
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 | |
49 // pass 3 arguments, hence the evil default argument. | |
50 bool initialize(int width, int height, bool is_opaque, | 45 bool initialize(int width, int height, bool is_opaque, |
51 HANDLE shared_section = NULL); | 46 PlatformData data = NULL); |
52 #elif defined(__APPLE__) | 47 |
48 #if defined(__APPLE__) | |
53 // For two-part init, call if you use the no-argument constructor above | 49 // 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); | 50 bool initialize(CGContextRef context, int width, int height, bool is_opaque); |
55 bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL); | |
56 | |
57 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
58 defined(__sun) || defined(ANDROID) | |
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); | |
61 #endif | 51 #endif |
62 | 52 |
63 // Shared -------------------------------------------------------------------- | 53 // Shared -------------------------------------------------------------------- |
64 | 54 |
65 // Return the stride (length of a line in bytes) for the given width. Because | 55 // 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 | 56 // we use 32-bits per pixel, this will be roughly 4*width. However, for |
67 // alignment reasons we may wish to increase that. | 57 // alignment reasons we may wish to increase that. |
68 static size_t StrideForWidth(unsigned width); | 58 static size_t StrideForWidth(unsigned width); |
69 | 59 |
70 // Allow callers to see the non-virtual function even though we have an | 60 // Allow callers to see the non-virtual function even though we have an |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 PlatformSurface platform_surface_; | 146 PlatformSurface platform_surface_; |
157 | 147 |
158 // Disallow copy and assign | 148 // Disallow copy and assign |
159 ScopedPlatformPaint(const ScopedPlatformPaint&); | 149 ScopedPlatformPaint(const ScopedPlatformPaint&); |
160 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); | 150 ScopedPlatformPaint& operator=(const ScopedPlatformPaint&); |
161 }; | 151 }; |
162 | 152 |
163 } // namespace skia | 153 } // namespace skia |
164 | 154 |
165 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 155 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
OLD | NEW |