| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SKIA_EXT_PLATFORM_DEVICE_H_ | |
| 6 #define SKIA_EXT_PLATFORM_DEVICE_H_ | |
| 7 | |
| 8 #include "build/build_config.h" | |
| 9 | |
| 10 #if defined(OS_WIN) | |
| 11 #include <windows.h> | |
| 12 #include <vector> | |
| 13 #endif | |
| 14 | |
| 15 #include "third_party/skia/include/core/SkColor.h" | |
| 16 #include "third_party/skia/include/core/SkBitmapDevice.h" | |
| 17 #include "third_party/skia/include/core/SkPreConfig.h" | |
| 18 | |
| 19 class SkMatrix; | |
| 20 class SkMetaData; | |
| 21 class SkPath; | |
| 22 class SkRegion; | |
| 23 | |
| 24 #if defined(OS_MACOSX) | |
| 25 typedef struct CGContext* CGContextRef; | |
| 26 typedef struct CGRect CGRect; | |
| 27 #endif | |
| 28 | |
| 29 namespace skia { | |
| 30 | |
| 31 class PlatformDevice; | |
| 32 | |
| 33 #if defined(OS_WIN) | |
| 34 typedef HDC PlatformSurface; | |
| 35 typedef RECT PlatformRect; | |
| 36 #elif defined(OS_MACOSX) | |
| 37 typedef CGContextRef PlatformSurface; | |
| 38 typedef CGRect PlatformRect; | |
| 39 #else | |
| 40 typedef void* PlatformSurface; | |
| 41 typedef SkIRect* PlatformRect; | |
| 42 #endif | |
| 43 | |
| 44 // The following routines provide accessor points for the functionality | |
| 45 // exported by the various PlatformDevice ports. | |
| 46 // All calls to PlatformDevice::* should be routed through these | |
| 47 // helper functions. | |
| 48 | |
| 49 // Bind a PlatformDevice instance, |platform_device| to |device|. Subsequent | |
| 50 // calls to the functions exported below will forward the request to the | |
| 51 // corresponding method on the bound PlatformDevice instance. If no | |
| 52 // PlatformDevice has been bound to the SkBaseDevice passed, then the | |
| 53 // routines are NOPS. | |
| 54 SK_API void SetPlatformDevice(SkBaseDevice* device, | |
| 55 PlatformDevice* platform_device); | |
| 56 SK_API PlatformDevice* GetPlatformDevice(SkBaseDevice* device); | |
| 57 | |
| 58 | |
| 59 #if defined(OS_WIN) | |
| 60 // Initializes the default settings and colors in a device context. | |
| 61 SK_API void InitializeDC(HDC context); | |
| 62 #elif defined(OS_MACOSX) | |
| 63 // Returns the CGContext that backing the SkBaseDevice. Forwards to the bound | |
| 64 // PlatformDevice. Returns NULL if no PlatformDevice is bound. | |
| 65 SK_API CGContextRef GetBitmapContext(SkBaseDevice* device); | |
| 66 #endif | |
| 67 | |
| 68 // Following routines are used in print preview workflow to mark the draft mode | |
| 69 // metafile and preview metafile. | |
| 70 SK_API SkMetaData& getMetaData(const SkCanvas& canvas); | |
| 71 SK_API void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode); | |
| 72 SK_API bool IsDraftMode(const SkCanvas& canvas); | |
| 73 | |
| 74 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 75 SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); | |
| 76 SK_API bool IsPreviewMetafile(const SkCanvas& canvas); | |
| 77 #endif | |
| 78 | |
| 79 // A SkBitmapDevice is basically a wrapper around SkBitmap that provides a | |
| 80 // surface for SkCanvas to draw into. PlatformDevice provides a surface | |
| 81 // Windows can also write to. It also provides functionality to play well | |
| 82 // with GDI drawing functions. This class is abstract and must be subclassed. | |
| 83 // It provides the basic interface to implement it either with or without | |
| 84 // a bitmap backend. | |
| 85 // | |
| 86 // PlatformDevice provides an interface which sub-classes of SkBaseDevice can | |
| 87 // also provide to allow for drawing by the native platform into the device. | |
| 88 // TODO(robertphillips): Once the bitmap-specific entry points are removed | |
| 89 // from SkBaseDevice it might make sense for PlatformDevice to be derived | |
| 90 // from it. | |
| 91 class SK_API PlatformDevice { | |
| 92 public: | |
| 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 // Returns true if GDI operations can be used for drawing into the bitmap. | |
| 111 virtual bool SupportsPlatformPaint(); | |
| 112 | |
| 113 #if defined(OS_WIN) | |
| 114 // Loads a SkPath into the GDI context. The path can there after be used for | |
| 115 // clipping or as a stroke. Returns false if the path failed to be loaded. | |
| 116 static bool LoadPathToDC(HDC context, const SkPath& path); | |
| 117 | |
| 118 // Loads a SkRegion into the GDI context. | |
| 119 static void LoadClippingRegionToDC(HDC context, const SkRegion& region, | |
| 120 const SkMatrix& transformation); | |
| 121 | |
| 122 // Draws to the given screen DC, if the bitmap DC doesn't exist, this will | |
| 123 // temporarily create it. However, if you have created the bitmap DC, it will | |
| 124 // be more efficient if you don't free it until after this call so it doesn't | |
| 125 // have to be created twice. If src_rect is null, then the entirety of the | |
| 126 // source device will be copied. | |
| 127 virtual void DrawToHDC(HDC, int x, int y, const RECT* src_rect); | |
| 128 #endif | |
| 129 | |
| 130 protected: | |
| 131 #if defined(OS_WIN) | |
| 132 // Arrays must be inside structures. | |
| 133 struct CubicPoints { | |
| 134 SkPoint p[4]; | |
| 135 }; | |
| 136 typedef std::vector<CubicPoints> CubicPath; | |
| 137 typedef std::vector<CubicPath> CubicPaths; | |
| 138 | |
| 139 // Loads the specified Skia transform into the device context, excluding | |
| 140 // perspective (which GDI doesn't support). | |
| 141 static void LoadTransformToDC(HDC dc, const SkMatrix& matrix); | |
| 142 | |
| 143 // Transforms SkPath's paths into a series of cubic path. | |
| 144 static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); | |
| 145 #endif | |
| 146 }; | |
| 147 | |
| 148 } // namespace skia | |
| 149 | |
| 150 #endif // SKIA_EXT_PLATFORM_DEVICE_H_ | |
| OLD | NEW |