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

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

Issue 7633040: CL removing inheritance of SkDevice from PlatformDevice. Flavours of PlatformDevice classes now ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 // 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) || defined(OS_OPENBSD) || defined(OS_FREEBSD) \
27 || defined(OS_SUN)
24 typedef struct _cairo cairo_t; 28 typedef struct _cairo cairo_t;
25 typedef struct _cairo_rectangle cairo_rectangle_t; 29 typedef struct _cairo_rectangle cairo_rectangle_t;
26 #elif defined(__APPLE__) 30 #elif defined(OS_MACOSX)
27 typedef struct CGContext* CGContextRef; 31 typedef struct CGContext* CGContextRef;
28 typedef struct CGRect CGRect; 32 typedef struct CGRect CGRect;
29 #endif 33 #endif
30 34
31 namespace skia { 35 namespace skia {
32 36
33 class PlatformDevice; 37 class PlatformDevice;
34 38
35 #if defined(WIN32) 39 #if defined(OS_WIN)
36 typedef HDC PlatformSurface; 40 typedef HDC PlatformSurface;
37 typedef RECT PlatformRect; 41 typedef RECT PlatformRect;
38 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defi ned(__sun) 42 #elif defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_FREEBSD) \
43 || defined(OS_SUN)
39 typedef cairo_t* PlatformSurface; 44 typedef cairo_t* PlatformSurface;
40 typedef cairo_rectangle_t PlatformRect; 45 typedef cairo_rectangle_t PlatformRect;
41 #elif defined(__APPLE__) 46 #elif defined(OS_MACOSX)
42 typedef CGContextRef PlatformSurface; 47 typedef CGContextRef PlatformSurface;
43 typedef CGRect PlatformRect; 48 typedef CGRect PlatformRect;
44 #endif 49 #endif
45 50
46 // The following routines provide accessor points for the functionality 51 // The following routines provide accessor points for the functionality
47 // exported by the various PlatformDevice ports. The PlatformDevice, and 52 // exported by the various PlatformDevice ports. The PlatformDevice, and
48 // BitmapPlatformDevice classes inherit directly from SkDevice, which is no 53 // BitmapPlatformDevice classes inherit directly from SkDevice, which is no
49 // longer a supported usage-pattern for skia. In preparation of the removal of 54 // 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 55 // these classes, all calls to PlatformDevice::* should be routed through these
51 // helper functions. 56 // helper functions.
52 57
53 // Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent 58 // Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent
54 // calls to the functions exported below will forward the request to the 59 // calls to the functions exported below will forward the request to the
55 // corresponding method on the bound PlatformDevice instance. If no 60 // corresponding method on the bound PlatformDevice instance. If no
56 // PlatformDevice has been bound to the SkDevice passed, then the routines are 61 // PlatformDevice has been bound to the SkDevice passed, then the routines are
57 // NOPS. 62 // NOPS.
58 SK_API void SetPlatformDevice(SkDevice* device, 63 SK_API void SetPlatformDevice(SkDevice* device,
59 PlatformDevice* platform_device); 64 PlatformDevice* platform_device);
60 SK_API PlatformDevice* GetPlatformDevice(SkDevice* device); 65 SK_API PlatformDevice* GetPlatformDevice(SkDevice* device);
61 66
67
68 #if defined(OS_WIN)
69 // Initializes the default settings and colors in a device context.
70 SK_API void InitializeDC(HDC context);
71 #elif defined (OS_MACOSX)
72 // Returns the CGContext that backing the SkDevice. Forwards to the bound
73 // PlatformDevice. Returns NULL if no PlatformDevice is bound.
74 SK_API CGContextRef GetBitmapContext(SkDevice* device);
75 #endif
76
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
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
62 } // namespace skia 167 } // namespace skia
63 168
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 169 #endif
72
73 #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