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

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

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

Powered by Google App Engine
This is Rietveld 408576698