| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // the return result. | 38 // the return result. |
| 39 // | 39 // |
| 40 enum OnFailureType { | 40 enum OnFailureType { |
| 41 CRASH_ON_FAILURE, | 41 CRASH_ON_FAILURE, |
| 42 RETURN_NULL_ON_FAILURE | 42 RETURN_NULL_ON_FAILURE |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 #if defined(WIN32) | 45 #if defined(WIN32) |
| 46 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 46 // The shared_section parameter is passed to gfx::PlatformDevice::create. |
| 47 // See it for details. | 47 // See it for details. |
| 48 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( | 48 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvasWithSharedSection( |
| 49 int width, | 49 int width, |
| 50 int height, | 50 int height, |
| 51 bool is_opaque, | 51 bool is_opaque, |
| 52 HANDLE shared_section, | 52 HANDLE shared_section, |
| 53 OnFailureType failure_type); | 53 OnFailureType failure_type); |
| 54 | 54 |
| 55 // Draws the top layer of the canvas into the specified HDC. Only works | 55 // Draws the top layer of the canvas into the specified HDC. Only works |
| 56 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary | 56 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary |
| 57 // HDC to back the canvas if one doesn't already exist, tearing it down | 57 // HDC to back the canvas if one doesn't already exist, tearing it down |
| 58 // before returning. If |src_rect| is null, copies the entire canvas. | 58 // before returning. If |src_rect| is null, copies the entire canvas. |
| 59 SK_API void DrawToNativeContext(SkCanvas* canvas, | 59 SK_API void DrawToNativeContext(SkCanvas* canvas, |
| 60 HDC hdc, | 60 HDC hdc, |
| 61 int x, | 61 int x, |
| 62 int y, | 62 int y, |
| 63 const RECT* src_rect); | 63 const RECT* src_rect); |
| 64 #elif defined(__APPLE__) | 64 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 65 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( | 65 defined(__sun) || defined(ANDROID) || defined(__APPLE__) |
| 66 CGContextRef context, | 66 // Construct a canvas from the given memory region. The memory is not cleared |
| 67 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. |
| 68 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( |
| 67 int width, | 69 int width, |
| 68 int height, | 70 int height, |
| 69 bool is_opaque, | 71 bool is_opaque, |
| 70 OnFailureType failure_type); | |
| 71 | |
| 72 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( | |
| 73 int width, | |
| 74 int height, | |
| 75 bool is_opaque, | |
| 76 uint8_t* context, | |
| 77 OnFailureType failure_type); | |
| 78 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
| 79 defined(__sun) || defined(ANDROID) | |
| 80 // Linux --------------------------------------------------------------------- | |
| 81 | |
| 82 // Construct a canvas from the given memory region. The memory is not cleared | |
| 83 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. | |
| 84 SK_API std::unique_ptr<SkCanvas> CreatePlatformCanvas( | |
| 85 int width, | |
| 86 int height, | |
| 87 bool is_opaque, | |
| 88 uint8_t* data, | 72 uint8_t* data, |
| 89 OnFailureType failure_type); | 73 OnFailureType failure_type); |
| 90 #endif | 74 #endif |
| 91 | 75 |
| 92 static inline std::unique_ptr<SkCanvas> CreatePlatformCanvas(int width, | 76 static inline std::unique_ptr<SkCanvas> CreatePlatformCanvas(int width, |
| 93 int height, | 77 int height, |
| 94 bool is_opaque) { | 78 bool is_opaque) { |
| 95 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); | 79 #if defined(WIN32) |
| 80 return CreatePlatformCanvasWithSharedSection(width, height, is_opaque, 0, |
| 81 CRASH_ON_FAILURE); |
| 82 #else |
| 83 return CreatePlatformCanvasWithPixels(width, height, is_opaque, 0, |
| 84 CRASH_ON_FAILURE); |
| 85 #endif |
| 96 } | 86 } |
| 97 | 87 |
| 98 SK_API std::unique_ptr<SkCanvas> CreateCanvas(const sk_sp<SkBaseDevice>& device, | 88 SK_API std::unique_ptr<SkCanvas> CreateCanvas(const sk_sp<SkBaseDevice>& device, |
| 99 OnFailureType failure_type); | 89 OnFailureType failure_type); |
| 100 | 90 |
| 101 static inline std::unique_ptr<SkCanvas> CreateBitmapCanvas(int width, | |
| 102 int height, | |
| 103 bool is_opaque) { | |
| 104 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); | |
| 105 } | |
| 106 | |
| 107 static inline std::unique_ptr<SkCanvas> TryCreateBitmapCanvas(int width, | 91 static inline std::unique_ptr<SkCanvas> TryCreateBitmapCanvas(int width, |
| 108 int height, | 92 int height, |
| 109 bool is_opaque) { | 93 bool is_opaque) { |
| 110 return CreatePlatformCanvas(width, height, is_opaque, 0, | 94 #if defined(WIN32) |
| 111 RETURN_NULL_ON_FAILURE); | 95 return CreatePlatformCanvasWithSharedSection(width, height, is_opaque, 0, |
| 96 RETURN_NULL_ON_FAILURE); |
| 97 #else |
| 98 return CreatePlatformCanvasWithPixels(width, height, is_opaque, 0, |
| 99 RETURN_NULL_ON_FAILURE); |
| 100 #endif |
| 112 } | 101 } |
| 113 | 102 |
| 114 // Return the stride (length of a line in bytes) for the given width. Because | 103 // Return the stride (length of a line in bytes) for the given width. Because |
| 115 // we use 32-bits per pixel, this will be roughly 4*width. However, for | 104 // we use 32-bits per pixel, this will be roughly 4*width. However, for |
| 116 // alignment reasons we may wish to increase that. | 105 // alignment reasons we may wish to increase that. |
| 117 SK_API size_t PlatformCanvasStrideForWidth(unsigned width); | 106 SK_API size_t PlatformCanvasStrideForWidth(unsigned width); |
| 118 | 107 |
| 119 // Copies pixels from the SkCanvas into an SkBitmap, fetching pixels from | 108 // Copies pixels from the SkCanvas into an SkBitmap, fetching pixels from |
| 120 // GPU memory if necessary. | 109 // GPU memory if necessary. |
| 121 // | 110 // |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); | 156 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); |
| 168 | 157 |
| 169 // Returns the CGContext that backing the SkCanvas. | 158 // Returns the CGContext that backing the SkCanvas. |
| 170 // Returns NULL if none is bound. | 159 // Returns NULL if none is bound. |
| 171 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); | 160 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); |
| 172 #endif | 161 #endif |
| 173 | 162 |
| 174 } // namespace skia | 163 } // namespace skia |
| 175 | 164 |
| 176 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 165 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
| OLD | NEW |