| 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 |
| 11 // The platform-specific device will include the necessary platform headers | 11 // The platform-specific device will include the necessary platform headers |
| 12 // to get the surface type. | 12 // to get the surface type. |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "skia/ext/platform_surface.h" | 14 #include "skia/ext/platform_surface.h" |
| 15 #include "skia/ext/refptr.h" | 15 #include "skia/ext/refptr.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkPixelRef.h" | 18 #include "third_party/skia/include/core/SkPixelRef.h" |
| 19 #include "third_party/skia/include/core/SkPixmap.h" | 19 #include "third_party/skia/include/core/SkPixmap.h" |
| 20 | 20 |
| 21 class SkBaseDevice; | 21 class SkBaseDevice; |
| 22 | 22 |
| 23 // A PlatformCanvas is a software-rasterized SkCanvas which is *also* |
| 24 // addressable by the platform-specific drawing API (GDI, Core Graphics, |
| 25 // Cairo...). |
| 26 |
| 23 namespace skia { | 27 namespace skia { |
| 24 | 28 |
| 25 typedef SkCanvas PlatformCanvas; | |
| 26 | |
| 27 // | 29 // |
| 28 // Note about error handling. | 30 // Note about error handling. |
| 29 // | 31 // |
| 30 // Creating a canvas can fail at times, most often because we fail to allocate | 32 // Creating a canvas can fail at times, most often because we fail to allocate |
| 31 // the backing-store (pixels). This can be from out-of-memory, or something | 33 // the backing-store (pixels). This can be from out-of-memory, or something |
| 32 // more opaque, like GDI or cairo reported a failure. | 34 // more opaque, like GDI or cairo reported a failure. |
| 33 // | 35 // |
| 34 // To allow the caller to handle the failure, every Create... factory takes an | 36 // To allow the caller to handle the failure, every Create... factory takes an |
| 35 // enum as its last parameter. The default value is kCrashOnFailure. If the | 37 // enum as its last parameter. The default value is kCrashOnFailure. If the |
| 36 // caller passes kReturnNullOnFailure, then the caller is responsible to check | 38 // caller passes kReturnNullOnFailure, then the caller is responsible to check |
| 37 // the return result. | 39 // the return result. |
| 38 // | 40 // |
| 39 enum OnFailureType { | 41 enum OnFailureType { |
| 40 CRASH_ON_FAILURE, | 42 CRASH_ON_FAILURE, |
| 41 RETURN_NULL_ON_FAILURE | 43 RETURN_NULL_ON_FAILURE |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 #if defined(WIN32) | 46 #if defined(WIN32) |
| 45 // The shared_section parameter is passed to gfx::PlatformDevice::create. | 47 // The shared_section parameter is passed to gfx::PlatformDevice::create. |
| 46 // See it for details. | 48 // See it for details. |
| 47 SK_API SkCanvas* CreatePlatformCanvas(int width, | 49 SK_API SkCanvas* CreatePlatformCanvas(int width, |
| 48 int height, | 50 int height, |
| 49 bool is_opaque, | 51 bool is_opaque, |
| 50 HANDLE shared_section, | 52 HANDLE shared_section, |
| 51 OnFailureType failure_type); | 53 OnFailureType failure_type); |
| 52 | 54 |
| 53 // 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 |
| 54 // with a PlatformCanvas with a BitmapPlatformDevice. | 56 // with a SkCanvas with a BitmapPlatformDevice. |
| 55 SK_API void DrawToNativeContext(SkCanvas* canvas, | 57 SK_API void DrawToNativeContext(SkCanvas* canvas, |
| 56 HDC hdc, | 58 HDC hdc, |
| 57 int x, | 59 int x, |
| 58 int y, | 60 int y, |
| 59 const RECT* src_rect); | 61 const RECT* src_rect); |
| 60 #elif defined(__APPLE__) | 62 #elif defined(__APPLE__) |
| 61 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context, | 63 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context, |
| 62 int width, | 64 int width, |
| 63 int height, | 65 int height, |
| 64 bool is_opaque, | 66 bool is_opaque, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); | 187 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); |
| 186 | 188 |
| 187 // Returns the CGContext that backing the SkCanvas. | 189 // Returns the CGContext that backing the SkCanvas. |
| 188 // Returns NULL if none is bound. | 190 // Returns NULL if none is bound. |
| 189 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); | 191 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); |
| 190 #endif | 192 #endif |
| 191 | 193 |
| 192 } // namespace skia | 194 } // namespace skia |
| 193 | 195 |
| 194 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ | 196 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ |
| OLD | NEW |