Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: skia/ext/platform_canvas.h

Issue 2304273002: WIP RasterCanvasLayerAllocator experiment 2
Patch Set: update to Skia patchset 13 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/ext/layer_allocator_win.cc ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkPixelRef.h" 17 #include "third_party/skia/include/core/SkPixelRef.h"
18 #include "third_party/skia/include/core/SkPixmap.h" 18 #include "third_party/skia/include/core/SkPixmap.h"
19 19
20 class SkBaseDevice; 20 class SkBaseDevice;
21 21
22 // A PlatformCanvas is a software-rasterized SkCanvas which is *also* 22 // A PlatformCanvas is a software-rasterized SkCanvas which is *also*
23 // addressable by the platform-specific drawing API (GDI, Core Graphics, 23 // addressable by the platform-specific drawing API (GDI, Core Graphics,
24 // Cairo...). 24 // Cairo...).
25 25
26 namespace skia { 26 namespace skia {
27 27
28 class LayerAllocator;
29
28 // 30 //
29 // Note about error handling. 31 // Note about error handling.
30 // 32 //
31 // Creating a canvas can fail at times, most often because we fail to allocate 33 // Creating a canvas can fail at times, most often because we fail to allocate
32 // the backing-store (pixels). This can be from out-of-memory, or something 34 // the backing-store (pixels). This can be from out-of-memory, or something
33 // more opaque, like GDI or cairo reported a failure. 35 // more opaque, like GDI or cairo reported a failure.
34 // 36 //
35 // To allow the caller to handle the failure, every Create... factory takes an 37 // To allow the caller to handle the failure, every Create... factory takes an
36 // enum as its last parameter. The default value is kCrashOnFailure. If the 38 // enum as its last parameter. The default value is kCrashOnFailure. If the
37 // caller passes kReturnNullOnFailure, then the caller is responsible to check 39 // caller passes kReturnNullOnFailure, then the caller is responsible to check
38 // the return result. 40 // the return result.
39 // 41 //
40 enum OnFailureType { 42 enum OnFailureType {
41 CRASH_ON_FAILURE, 43 CRASH_ON_FAILURE,
42 RETURN_NULL_ON_FAILURE 44 RETURN_NULL_ON_FAILURE
43 }; 45 };
44 46
45 #if defined(WIN32) 47 #if defined(WIN32)
46 // The shared_section parameter is passed to gfx::PlatformDevice::create. 48 // The shared_section parameter is passed to gfx::PlatformDevice::create.
47 // See it for details. 49 // See it for details.
50 // TODO: this should become sk_sp<SkCanvas>
48 SK_API SkCanvas* CreatePlatformCanvas(int width, 51 SK_API SkCanvas* CreatePlatformCanvas(int width,
49 int height, 52 int height,
50 bool is_opaque, 53 bool is_opaque,
51 HANDLE shared_section, 54 HANDLE shared_section,
52 OnFailureType failure_type); 55 OnFailureType failure_type);
53 56
54 // Draws the top layer of the canvas into the specified HDC. Only works 57 // Draws the top layer of the canvas into the specified HDC. Only works
55 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary 58 // with a SkCanvas with a BitmapPlatformDevice. Will create a temporary
56 // HDC to back the canvas if one doesn't already exist, tearing it down 59 // HDC to back the canvas if one doesn't already exist, tearing it down
57 // before returning. If |src_rect| is null, copies the entire canvas. 60 // before returning. If |src_rect| is null, copies the entire canvas.
58 SK_API void DrawToNativeContext(SkCanvas* canvas, 61 SK_API void DrawToNativeContext(SkCanvas* canvas,
59 HDC hdc, 62 HDC hdc,
60 int x, 63 int x,
61 int y, 64 int y,
62 const RECT* src_rect); 65 const RECT* src_rect);
63 #elif defined(__APPLE__) 66 #elif defined(__APPLE__)
67 // TODO: this should become sk_sp<SkCanvas>
64 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context, 68 SK_API SkCanvas* CreatePlatformCanvas(CGContextRef context,
65 int width, 69 int width,
66 int height, 70 int height,
67 bool is_opaque, 71 bool is_opaque,
68 OnFailureType failure_type); 72 OnFailureType failure_type);
69 73
74 // TODO: this should become sk_sp<SkCanvas>
70 SK_API SkCanvas* CreatePlatformCanvas(int width, 75 SK_API SkCanvas* CreatePlatformCanvas(int width,
71 int height, 76 int height,
72 bool is_opaque, 77 bool is_opaque,
73 uint8_t* context, 78 uint8_t* context,
74 OnFailureType failure_type); 79 OnFailureType failure_type);
75 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 80 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
76 defined(__sun) || defined(ANDROID) 81 defined(__sun) || defined(ANDROID)
77 // Linux --------------------------------------------------------------------- 82 // Linux ---------------------------------------------------------------------
78 83
79 // Construct a canvas from the given memory region. The memory is not cleared 84 // Construct a canvas from the given memory region. The memory is not cleared
80 // first. @data must be, at least, @height * StrideForWidth(@width) bytes. 85 // first. @data must be, at least, @height * StrideForWidth(@width) bytes.
86 // TODO: this should become sk_sp<SkCanvas>
81 SK_API SkCanvas* CreatePlatformCanvas(int width, 87 SK_API SkCanvas* CreatePlatformCanvas(int width,
82 int height, 88 int height,
83 bool is_opaque, 89 bool is_opaque,
84 uint8_t* data, 90 uint8_t* data,
85 OnFailureType failure_type); 91 OnFailureType failure_type);
86 #endif 92 #endif
87 93
88 static inline SkCanvas* CreatePlatformCanvas(int width, 94 static inline SkCanvas* CreatePlatformCanvas(int width,
89 int height, 95 int height,
90 bool is_opaque) { 96 bool is_opaque) {
91 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 97 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
92 } 98 }
93 99
94 SK_API SkCanvas* CreateCanvas(const sk_sp<SkBaseDevice>& device,
95 OnFailureType failure_type);
96
97 static inline SkCanvas* CreateBitmapCanvas(int width, 100 static inline SkCanvas* CreateBitmapCanvas(int width,
98 int height, 101 int height,
99 bool is_opaque) { 102 bool is_opaque) {
100 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE); 103 return CreatePlatformCanvas(width, height, is_opaque, 0, CRASH_ON_FAILURE);
101 } 104 }
102 105
103 static inline SkCanvas* TryCreateBitmapCanvas(int width, 106 static inline SkCanvas* TryCreateBitmapCanvas(int width,
104 int height, 107 int height,
105 bool is_opaque) { 108 bool is_opaque) {
106 return CreatePlatformCanvas(width, height, is_opaque, 0, 109 return CreatePlatformCanvas(width, height, is_opaque, 0,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); 164 SK_API bool IsPreviewMetafile(const SkCanvas& canvas);
162 165
163 // Returns the CGContext that backing the SkCanvas. 166 // Returns the CGContext that backing the SkCanvas.
164 // Returns NULL if none is bound. 167 // Returns NULL if none is bound.
165 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas); 168 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas);
166 #endif 169 #endif
167 170
168 } // namespace skia 171 } // namespace skia
169 172
170 #endif // SKIA_EXT_PLATFORM_CANVAS_H_ 173 #endif // SKIA_EXT_PLATFORM_CANVAS_H_
OLDNEW
« no previous file with comments | « skia/ext/layer_allocator_win.cc ('k') | skia/ext/platform_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698