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_DEVICE_H_ | 5 #ifndef SKIA_EXT_PLATFORM_DEVICE_H_ |
6 #define SKIA_EXT_PLATFORM_DEVICE_H_ | 6 #define SKIA_EXT_PLATFORM_DEVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // This file provides an easy way to include the appropriate PlatformDevice | 9 #include "build/build_config.h" |
10 // header file for your platform. | |
11 | 10 |
12 #if defined(WIN32) | 11 #if defined(OS_WIN) |
13 #include <windows.h> | 12 #include <windows.h> |
13 #include <vector> | |
14 #endif | 14 #endif |
15 | 15 |
16 #include "third_party/skia/include/core/SkPreConfig.h" | 16 #include "third_party/skia/include/core/SkPreConfig.h" |
17 #include "third_party/skia/include/core/SkDevice.h" | |
17 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
18 | 19 |
20 class SkMatrix; | |
21 class SkPath; | |
22 class SkRegion; | |
19 | 23 |
20 class SkDevice; | |
21 struct SkIRect; | 24 struct SkIRect; |
22 | 25 |
23 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || define d(__sun) | 26 #if defined(OS_LINUX) |
24 typedef struct _cairo cairo_t; | 27 typedef struct _cairo cairo_t; |
25 typedef struct _cairo_rectangle cairo_rectangle_t; | 28 typedef struct _cairo_rectangle cairo_rectangle_t; |
26 #elif defined(__APPLE__) | 29 #elif defined(OS_MACOSX) |
27 typedef struct CGContext* CGContextRef; | 30 typedef struct CGContext* CGContextRef; |
28 typedef struct CGRect CGRect; | 31 typedef struct CGRect CGRect; |
29 #endif | 32 #endif |
30 | 33 |
31 namespace skia { | 34 namespace skia { |
32 | 35 |
33 class PlatformDevice; | 36 class PlatformDevice; |
34 | 37 |
35 #if defined(WIN32) | 38 #if defined(OS_WIN) |
36 typedef HDC PlatformSurface; | 39 typedef HDC PlatformSurface; |
37 typedef RECT PlatformRect; | 40 typedef RECT PlatformRect; |
38 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defi ned(__sun) | 41 #elif defined(OS_LINUX) |
39 typedef cairo_t* PlatformSurface; | 42 typedef cairo_t* PlatformSurface; |
40 typedef cairo_rectangle_t PlatformRect; | 43 typedef cairo_rectangle_t PlatformRect; |
41 #elif defined(__APPLE__) | 44 #elif defined(OS_MACOSX) |
42 typedef CGContextRef PlatformSurface; | 45 typedef CGContextRef PlatformSurface; |
43 typedef CGRect PlatformRect; | 46 typedef CGRect PlatformRect; |
44 #endif | 47 #endif |
45 | 48 |
46 // The following routines provide accessor points for the functionality | 49 // The following routines provide accessor points for the functionality |
47 // exported by the various PlatformDevice ports. The PlatformDevice, and | 50 // exported by the various PlatformDevice ports. The PlatformDevice, and |
48 // BitmapPlatformDevice classes inherit directly from SkDevice, which is no | 51 // BitmapPlatformDevice classes inherit directly from SkDevice, which is no |
49 // longer a supported usage-pattern for skia. In preparation of the removal of | 52 // longer a supported usage-pattern for skia. In preparation of the removal of |
50 // these classes, all calls to PlatformDevice::* should be routed through these | 53 // these classes, all calls to PlatformDevice::* should be routed through these |
51 // helper functions. | 54 // helper functions. |
52 | 55 |
53 // Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent | 56 // Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent |
54 // calls to the functions exported below will forward the request to the | 57 // calls to the functions exported below will forward the request to the |
55 // corresponding method on the bound PlatformDevice instance. If no | 58 // corresponding method on the bound PlatformDevice instance. If no |
56 // PlatformDevice has been bound to the SkDevice passed, then the routines are | 59 // PlatformDevice has been bound to the SkDevice passed, then the routines are |
57 // NOPS. | 60 // NOPS. |
58 SK_API void SetPlatformDevice(SkDevice* device, | 61 SK_API void SetPlatformDevice(SkDevice* device, |
59 PlatformDevice* platform_device); | 62 PlatformDevice* platform_device); |
60 SK_API PlatformDevice* GetPlatformDevice(SkDevice* device); | 63 SK_API PlatformDevice* GetPlatformDevice(SkDevice* device); |
61 | 64 |
65 | |
66 #if defined(OS_WIN) | |
67 // Initializes the default settings and colors in a device context. | |
68 SK_API void InitializeDC(HDC context); | |
69 #elif defined (OS_MACOSX) | |
70 // Returns the CGContext that backing the SkDevice. Forwards to the bound | |
71 // PlatformDevice. Returns NULL if no PlatformDevice is bound. | |
72 SK_API CGContextRef GetBitmapContext(SkDevice* device); | |
73 #endif | |
74 | |
75 // A SkDevice is basically a wrapper around SkBitmap that provides a surface for | |
76 // SkCanvas to draw into. PlatformDevice provides a surface Windows can also | |
77 // write to. It also provides functionality to play well with GDI drawing | |
78 // functions. This class is abstract and must be subclassed. It provides the | |
79 // basic interface to implement it either with or without a bitmap backend. | |
80 // | |
81 // PlatformDevice provides an interface which sub-classes of SkDevice can also | |
82 // provide to allow for drawing by the native platform into the device. | |
83 class SK_API PlatformDevice { | |
alokp
2011/08/24 17:03:02
This is OK for now. Medium term I would like to ge
Jeff Timanus
2011/08/24 22:09:58
This change is a good step in that direction.
I'm
| |
84 public: | |
85 #if defined(OS_WIN) | |
86 typedef HDC PlatformSurface; | |
alokp
2011/08/24 17:03:02
definition of PlatformSurface is duplicated here.
Jeff Timanus
2011/08/24 22:09:58
Done.
| |
87 #elif defined(OS_MACOSX) | |
88 typedef CGContextRef PlatformSurface; | |
89 #elif defined(OS_LINUX) | |
vandebo (ex-Chrome)
2011/08/23 21:16:43
There are OS_ defines for the BSD's and Sun, if yo
Jeff Timanus
2011/08/24 22:09:58
Done.
| |
90 typedef cairo_t* PlatformSurface; | |
91 #endif | |
92 | |
93 virtual ~PlatformDevice() {} | |
94 | |
95 #if defined(OS_MACOSX) | |
96 // The CGContext that corresponds to the bitmap, used for CoreGraphics | |
97 // operations drawing into the bitmap. This is possibly heavyweight, so it | |
98 // should exist only during one pass of rendering. | |
99 virtual CGContextRef GetBitmapContext() = 0; | |
100 #endif | |
101 | |
102 // The DC that corresponds to the bitmap, used for GDI operations drawing | |
103 // into the bitmap. This is possibly heavyweight, so it should be existant | |
104 // only during one pass of rendering. | |
105 virtual PlatformSurface BeginPlatformPaint(); | |
106 | |
107 // Finish a previous call to beginPlatformPaint. | |
108 virtual void EndPlatformPaint(); | |
109 | |
110 // Draws to the given screen DC, if the bitmap DC doesn't exist, this will | |
111 // temporarily create it. However, if you have created the bitmap DC, it will | |
112 // be more efficient if you don't free it until after this call so it doesn't | |
113 // have to be created twice. If src_rect is null, then the entirety of the | |
114 // source device will be copied. | |
115 virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, | |
116 const PlatformRect* src_rect) = 0; | |
117 | |
118 // Sets the opacity of each pixel in the specified region to be opaque. | |
119 virtual void MakeOpaque(int x, int y, int width, int height) { } | |
120 | |
121 // Returns if GDI is allowed to render text to this device. | |
122 virtual bool IsNativeFontRenderingAllowed(); | |
123 | |
124 // True if AlphaBlend() was called during a | |
125 // BeginPlatformPaint()/EndPlatformPaint() pair. | |
126 // Used by the printing subclasses. See |VectorPlatformDeviceEmf|. | |
127 virtual bool AlphaBlendUsed() const; | |
128 | |
129 #if defined(OS_WIN) | |
130 // Loads a SkPath into the GDI context. The path can there after be used for | |
131 // clipping or as a stroke. Returns false if the path failed to be loaded. | |
132 static bool LoadPathToDC(HDC context, const SkPath& path); | |
133 | |
134 // Loads a SkRegion into the GDI context. | |
135 static void LoadClippingRegionToDC(HDC context, const SkRegion& region, | |
136 const SkMatrix& transformation); | |
137 #elif defined(OS_MACOSX) | |
138 // Loads a SkPath into the CG context. The path can there after be used for | |
139 // clipping or as a stroke. | |
140 static void LoadPathToCGContext(CGContextRef context, const SkPath& path); | |
141 | |
142 // Initializes the default settings and colors in a device context. | |
143 static void InitializeCGContext(CGContextRef context); | |
144 | |
145 // Loads a SkRegion into the CG context. | |
146 static void LoadClippingRegionToCGContext(CGContextRef context, | |
147 const SkRegion& region, | |
148 const SkMatrix& transformation); | |
149 #endif | |
150 | |
151 protected: | |
152 #if defined(OS_WIN) | |
153 // Arrays must be inside structures. | |
154 struct CubicPoints { | |
155 SkPoint p[4]; | |
156 }; | |
157 typedef std::vector<CubicPoints> CubicPath; | |
158 typedef std::vector<CubicPath> CubicPaths; | |
159 | |
160 // Loads the specified Skia transform into the device context, excluding | |
161 // perspective (which GDI doesn't support). | |
162 static void LoadTransformToDC(HDC dc, const SkMatrix& matrix); | |
163 | |
164 // Transforms SkPath's paths into a series of cubic path. | |
165 static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); | |
166 #elif defined(OS_MACOSX) | |
167 // Loads the specified Skia transform into the device context | |
168 static void LoadTransformToCGContext(CGContextRef context, | |
169 const SkMatrix& matrix); | |
170 #endif | |
171 }; | |
172 | |
62 } // namespace skia | 173 } // namespace skia |
63 | 174 |
64 #if defined(WIN32) | |
65 #include "skia/ext/platform_device_win.h" | |
66 #elif defined(__APPLE__) | |
67 #include "skia/ext/platform_device_mac.h" | |
68 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
69 defined(__sun) | |
70 #include "skia/ext/platform_device_linux.h" | |
71 #endif | 175 #endif |
72 | |
73 #endif | |
OLD | NEW |