OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 PlatformDeviceWin_h | |
6 #define PlatformDeviceWin_h | |
7 | |
8 #include <windows.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "SkDevice.h" | |
13 | |
14 class SkMatrix; | |
15 class SkPath; | |
16 class SkRegion; | |
17 | |
18 namespace gfx { | |
19 | |
20 // A device is basically a wrapper around SkBitmap that provides a surface for | |
21 // SkCanvas to draw into. Our device provides a surface Windows can also write | |
22 // to. It also provides functionality to play well with GDI drawing functions. | |
23 // This class is abstract and must be subclassed. It provides the basic | |
24 // interface to implement it either with or without a bitmap backend. | |
25 class PlatformDeviceWin : public SkDevice { | |
26 public: | |
27 // The DC that corresponds to the bitmap, used for GDI operations drawing | |
28 // into the bitmap. This is possibly heavyweight, so it should be existant | |
29 // only during one pass of rendering. | |
30 virtual HDC getBitmapDC() = 0; | |
31 | |
32 // Draws to the given screen DC, if the bitmap DC doesn't exist, this will | |
33 // temporarily create it. However, if you have created the bitmap DC, it will | |
34 // be more efficient if you don't free it until after this call so it doesn't | |
35 // have to be created twice. If src_rect is null, then the entirety of the | |
36 // source device will be copied. | |
37 virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect) = 0; | |
38 | |
39 // Invoke before using GDI functions. See description in platform_device.cc | |
40 // for specifics. | |
41 // NOTE: x,y,width and height are relative to the current transform. | |
42 virtual void prepareForGDI(int x, int y, int width, int height) { } | |
43 | |
44 // Invoke after using GDI functions. See description in platform_device.cc | |
45 // for specifics. | |
46 // NOTE: x,y,width and height are relative to the current transform. | |
47 virtual void postProcessGDI(int x, int y, int width, int height) { } | |
48 | |
49 // Sets the opacity of each pixel in the specified region to be opaque. | |
50 virtual void makeOpaque(int x, int y, int width, int height) { } | |
51 | |
52 // Call this function to fix the alpha channels before compositing this layer | |
53 // onto another. Internally, the device uses a special alpha method to work | |
54 // around problems with Windows. This call will put the values into what | |
55 // Skia expects, so it can be composited onto other layers. | |
56 // | |
57 // After this call, no more drawing can be done because the | |
58 // alpha channels will be "correct", which, if this function is called again | |
59 // will make them wrong. See the implementation for more discussion. | |
60 virtual void fixupAlphaBeforeCompositing() { } | |
61 | |
62 // Returns if the preferred rendering engine is vectorial or bitmap based. | |
63 virtual bool IsVectorial() = 0; | |
64 | |
65 // Initializes the default settings and colors in a device context. | |
66 static void InitializeDC(HDC context); | |
67 | |
68 // Loads a SkPath into the GDI context. The path can there after be used for | |
69 // clipping or as a stroke. | |
70 static void LoadPathToDC(HDC context, const SkPath& path); | |
71 | |
72 // Loads a SkRegion into the GDI context. | |
73 static void LoadClippingRegionToDC(HDC context, const SkRegion& region, | |
74 const SkMatrix& transformation); | |
75 | |
76 protected: | |
77 // Arrays must be inside structures. | |
78 struct CubicPoints { | |
79 SkPoint p[4]; | |
80 }; | |
81 typedef std::vector<CubicPoints> CubicPath; | |
82 typedef std::vector<CubicPath> CubicPaths; | |
83 | |
84 // Forwards |bitmap| to SkDevice's constructor. | |
85 PlatformDeviceWin(const SkBitmap& bitmap); | |
86 | |
87 // Loads the specified Skia transform into the device context, excluding | |
88 // perspective (which GDI doesn't support). | |
89 static void LoadTransformToDC(HDC dc, const SkMatrix& matrix); | |
90 | |
91 // Transforms SkPath's paths into a series of cubic path. | |
92 static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath); | |
93 }; | |
94 | |
95 } // namespace gfx | |
96 | |
97 #endif // PlatformDeviceWin_h | |
98 | |
OLD | NEW |