Chromium Code Reviews| 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 | |
| 10 // header file for your platform. | |
| 11 | |
| 12 #if defined(WIN32) | 9 #if defined(WIN32) |
| 13 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <vector> | |
| 14 #endif | 12 #endif |
| 15 | 13 |
| 16 #include "third_party/skia/include/core/SkPreConfig.h" | 14 #include "third_party/skia/include/core/SkPreConfig.h" |
| 15 #include "third_party/skia/include/core/SkDevice.h" | |
| 17 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 18 | 17 |
| 18 class SkMatrix; | |
| 19 class SkPath; | |
| 20 class SkRegion; | |
| 19 | 21 |
| 20 class SkDevice; | |
| 21 struct SkIRect; | 22 struct SkIRect; |
| 22 | 23 |
| 23 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || define d(__sun) | 24 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 25 defined(__sun) | |
| 24 typedef struct _cairo cairo_t; | 26 typedef struct _cairo cairo_t; |
| 25 typedef struct _cairo_rectangle cairo_rectangle_t; | 27 typedef struct _cairo_rectangle cairo_rectangle_t; |
| 26 #elif defined(__APPLE__) | 28 #elif defined(__APPLE__) |
| 27 typedef struct CGContext* CGContextRef; | 29 typedef struct CGContext* CGContextRef; |
| 28 typedef struct CGRect CGRect; | 30 typedef struct CGRect CGRect; |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 namespace skia { | 33 namespace skia { |
| 32 | 34 |
| 33 class PlatformDevice; | 35 class PlatformDevice; |
| 34 | 36 |
| 35 #if defined(WIN32) | 37 #if defined(WIN32) |
| 36 typedef HDC PlatformSurface; | 38 typedef HDC PlatformSurface; |
| 37 typedef RECT PlatformRect; | 39 typedef RECT PlatformRect; |
| 38 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defi ned(__sun) | 40 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
| 41 defined(__sun) | |
| 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(__APPLE__) |
| 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(WIN32) | |
|
vandebo (ex-Chrome)
2011/08/23 17:40:35
The standard os defines are OS_WIN, OS_MACOSX, OS_
Jeff Timanus
2011/08/23 21:13:02
Done.
| |
| 67 // Initializes the default settings and colors in a device context. | |
| 68 SK_API void InitializeDC(HDC context); | |
| 69 #elif defined (__APPLE__) | |
| 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 { | |
| 84 public: | |
| 85 #if defined(WIN32) | |
| 86 typedef HDC PlatformSurface; | |
| 87 #elif defined(__APPLE__) | |
| 88 typedef CGContextRef PlatformSurface; | |
| 89 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
| 90 defined(__sun) | |
| 91 typedef cairo_t* PlatformSurface; | |
| 92 #endif | |
| 93 | |
| 94 virtual ~PlatformDevice() {} | |
| 95 | |
| 96 #if defined(__APPLE__) | |
| 97 // The CGContext that corresponds to the bitmap, used for CoreGraphics | |
| 98 // operations drawing into the bitmap. This is possibly heavyweight, so it | |
| 99 // should exist only during one pass of rendering. | |
| 100 virtual CGContextRef GetBitmapContext() = 0; | |
| 101 #endif | |
| 102 | |
| 103 // The DC that corresponds to the bitmap, used for GDI operations drawing | |
| 104 // into the bitmap. This is possibly heavyweight, so it should be existant | |
| 105 // only during one pass of rendering. | |
| 106 virtual PlatformSurface BeginPlatformPaint(); | |
| 107 | |
| 108 // Finish a previous call to beginPlatformPaint. | |
| 109 virtual void EndPlatformPaint(); | |
| 110 | |
| 111 // Draws to the given screen DC, if the bitmap DC doesn't exist, this will | |
| 112 // temporarily create it. However, if you have created the bitmap DC, it will | |
| 113 // be more efficient if you don't free it until after this call so it doesn't | |
| 114 // have to be created twice. If src_rect is null, then the entirety of the | |
| 115 // source device will be copied. | |
| 116 virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, | |
|
vandebo (ex-Chrome)
2011/08/23 17:40:35
No platform has a meaningful implementation of thi
Jeff Timanus
2011/08/23 21:13:02
The routine was previously pure virtual on windows
| |
| 117 const PlatformRect* src_rect); | |
| 118 | |
| 119 // Sets the opacity of each pixel in the specified region to be opaque. | |
| 120 virtual void MakeOpaque(int x, int y, int width, int height) { } | |
| 121 | |
| 122 // Returns if GDI is allowed to render text to this device. | |
| 123 virtual bool IsNativeFontRenderingAllowed(); | |
| 124 | |
| 125 // True if AlphaBlend() was called during a | |
| 126 // BeginPlatformPaint()/EndPlatformPaint() pair. | |
| 127 // Used by the printing subclasses. See |VectorPlatformDeviceEmf|. | |
| 128 virtual bool AlphaBlendUsed() const; | |
| 129 | |
| 130 #if defined(WIN32) | |
| 131 // Loads a SkPath into the GDI context. The path can there after be used for | |
| 132 // clipping or as a stroke. Returns false if the path failed to be loaded. | |
| 133 static bool LoadPathToDC(HDC context, const SkPath& path); | |
| 134 | |
| 135 // Loads a SkRegion into the GDI context. | |
| 136 static void LoadClippingRegionToDC(HDC context, const SkRegion& region, | |
| 137 const SkMatrix& transformation); | |
| 138 #elif defined(__APPLE__) | |
| 139 // Loads a SkPath into the CG context. The path can there after be used for | |
| 140 // clipping or as a stroke. | |
| 141 static void LoadPathToCGContext(CGContextRef context, const SkPath& path); | |
| 142 | |
| 143 // Loads a SkRegion into the CG context. | |
| 144 static void LoadClippingRegionToCGContext(CGContextRef context, | |
| 145 const SkRegion& region, | |
| 146 const SkMatrix& transformation); | |
| 147 #endif | |
| 148 | |
| 149 protected: | |
| 150 #if defined(WIN32) | |
| 151 // Arrays must be inside structures. | |
| 152 struct CubicPoints { | |
| 153 SkPoint p[4]; | |
| 154 }; | |
| 155 typedef std::vector<CubicPoints> CubicPath; | |
| 156 typedef std::vector<CubicPath> CubicPaths; | |
| 157 | |
| 158 // Loads the specified Skia transform into the device context, excluding | |
| 159 // perspective (which GDI doesn't support). | |
| 160 static void LoadTransformToDC(HDC dc, const SkMatrix& matrix); | |
| 161 | |
| 162 // Transforms SkPath's paths into a series of cubic path. | |
| 163 static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); | |
| 164 #elif defined(__APPLE__) | |
| 165 // Loads the specified Skia transform into the device context | |
| 166 static void LoadTransformToCGContext(CGContextRef context, | |
| 167 const SkMatrix& matrix); | |
| 168 #endif | |
| 169 }; | |
| 170 | |
| 62 } // namespace skia | 171 } // namespace skia |
| 63 | 172 |
| 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 | 173 #endif |
| 72 | |
| 73 #endif | |
| OLD | NEW |