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 // The platform-specific device will include the necessary platform headers | 8 // The platform-specific device will include the necessary platform headers |
9 // to get the surface type. | 9 // to get the surface type. |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "skia/ext/platform_device.h" | 11 #include "skia/ext/platform_device.h" |
12 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
15 #include "third_party/skia/include/core/SkPixelRef.h" | 15 #include "third_party/skia/include/core/SkPixelRef.h" |
| 16 #include "third_party/skia/include/core/SkPreConfig.h" |
16 | 17 |
17 namespace skia { | 18 namespace skia { |
18 | 19 |
19 typedef SkCanvas PlatformCanvas; | 20 typedef SkCanvas PlatformCanvas; |
20 | 21 |
21 // | 22 // |
22 // Note about error handling. | 23 // Note about error handling. |
23 // | 24 // |
24 // Creating a canvas can fail at times, most often because we fail to allocate | 25 // Creating a canvas can fail at times, most often because we fail to allocate |
25 // the backing-store (pixels). This can be from out-of-memory, or something | 26 // the backing-store (pixels). This can be from out-of-memory, or something |
26 // more opaque, like GDI or cairo reported a failure. | 27 // more opaque, like GDI or cairo reported a failure. |
27 // | 28 // |
28 // To allow the caller to handle the failure, every Create... factory takes an | 29 // To allow the caller to handle the failure, every Create... factory takes an |
29 // enum as its last parameter. The default value is kCrashOnFailure. If the | 30 // enum as its last parameter. The default value is kCrashOnFailure. If the |
30 // caller passes kReturnNullOnFailure, then the caller is responsible to check | 31 // caller passes kReturnNullOnFailure, then the caller is responsible to check |
31 // the return result. | 32 // the return result. |
32 // | 33 // |
33 enum OnFailureType { | 34 enum OnFailureType { |
34 CRASH_ON_FAILURE, | 35 CRASH_ON_FAILURE, |
35 RETURN_NULL_ON_FAILURE | 36 RETURN_NULL_ON_FAILURE |
36 }; | 37 }; |
37 | 38 |
38 #if defined(WIN32) | 39 #if defined(SK_BUILD_FOR_WIN32) |
39 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 40 // The shared_section parameter is passed to gfx::PlatformDevice::create. |
40 // See it for details. | 41 // See it for details. |
41 SK_API SkCanvas* CreatePlatformCanvas(int width, | 42 SK_API SkCanvas* CreatePlatformCanvas(int width, |
42 int height, | 43 int height, |
43 bool is_opaque, | 44 bool is_opaque, |
44 HANDLE shared_section, | 45 HANDLE shared_section, |
45 OnFailureType failure_type); | 46 OnFailureType failure_type); |
46 | 47 |
47 // Draws the top layer of the canvas into the specified HDC. Only works | 48 // Draws the top layer of the canvas into the specified HDC. Only works |
48 // with a PlatformCanvas with a BitmapPlatformDevice. | 49 // with a PlatformCanvas with a BitmapPlatformDevice. |
49 SK_API void DrawToNativeContext(SkCanvas* canvas, | 50 SK_API void DrawToNativeContext(SkCanvas* canvas, |
50 HDC hdc, | 51 HDC hdc, |
51 int x, | 52 int x, |
52 int y, | 53 int y, |
53 const RECT* src_rect); | 54 const RECT* src_rect); |
54 #elif defined(__APPLE__) | 55 #elif defined(SK_BUILD_FOR_MAC) |
55 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context, | 56 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context, |
56 int width, | 57 int width, |
57 int height, | 58 int height, |
58 bool is_opaque, | 59 bool is_opaque, |
59 OnFailureType failure_type); | 60 OnFailureType failure_type); |
60 | 61 |
61 SK_API SkCanvas* CreatePlatformCanvas(int width, | 62 SK_API SkCanvas* CreatePlatformCanvas(int width, |
62 int height, | 63 int height, |
63 bool is_opaque, | 64 bool is_opaque, |
64 uint8_t* context, | 65 uint8_t* context, |
65 OnFailureType failure_type); | 66 OnFailureType failure_type); |
66 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | 67 #elif defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) |
67 defined(__sun) || defined(ANDROID) | |
68 // Linux --------------------------------------------------------------------- | 68 // Linux --------------------------------------------------------------------- |
69 | 69 |
70 // Construct a canvas from the given memory region. The memory is not cleared | 70 // Construct a canvas from the given memory region. The memory is not cleared |
71 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. | 71 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. |
72 SK_API SkCanvas* CreatePlatformCanvas(int width, | 72 SK_API SkCanvas* CreatePlatformCanvas(int width, |
73 int height, | 73 int height, |
74 bool is_opaque, | 74 bool is_opaque, |
75 uint8_t* data, | 75 uint8_t* data, |
76 OnFailureType failure_type); | 76 OnFailureType failure_type); |
77 #endif | 77 #endif |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 SkBitmap bitmap_; | 178 SkBitmap bitmap_; |
179 PlatformSurface surface_; // initialized to 0 | 179 PlatformSurface surface_; // initialized to 0 |
180 intptr_t platform_extra_; // platform specific, initialized to 0 | 180 intptr_t platform_extra_; // platform specific, initialized to 0 |
181 | 181 |
182 DISALLOW_COPY_AND_ASSIGN(PlatformBitmap); | 182 DISALLOW_COPY_AND_ASSIGN(PlatformBitmap); |
183 }; | 183 }; |
184 | 184 |
185 } // namespace skia | 185 } // namespace skia |
186 | 186 |
187 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 187 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
OLD | NEW |