gfx/thebes/gfxWindowsNativeDrawing.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:47bdbf24f221
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef _GFXWINDOWSNATIVEDRAWING_H_
7 #define _GFXWINDOWSNATIVEDRAWING_H_
8
9 #include <windows.h>
10
11 #include "gfxContext.h"
12 #include "gfxWindowsSurface.h"
13
14 class gfxWindowsNativeDrawing {
15 public:
16
17 /* Flags for notifying this class what kind of operations the native
18 * drawing supports
19 */
20
21 enum {
22 /* Whether the native drawing can draw to a surface of content COLOR_ALPHA */
23 CAN_DRAW_TO_COLOR_ALPHA = 1 << 0,
24 CANNOT_DRAW_TO_COLOR_ALPHA = 0 << 0,
25
26 /* Whether the native drawing can be scaled using SetWorldTransform */
27 CAN_AXIS_ALIGNED_SCALE = 1 << 1,
28 CANNOT_AXIS_ALIGNED_SCALE = 0 << 1,
29
30 /* Whether the native drawing can be both scaled and rotated arbitrarily using SetWorldTransform */
31 CAN_COMPLEX_TRANSFORM = 1 << 2,
32 CANNOT_COMPLEX_TRANSFORM = 0 << 2,
33
34 /* If we have to do transforms with cairo, should we use nearest-neighbour filtering? */
35 DO_NEAREST_NEIGHBOR_FILTERING = 1 << 3,
36 DO_BILINEAR_FILTERING = 0 << 3
37 };
38
39 /* Create native win32 drawing for a rectangle bounded by
40 * nativeRect.
41 *
42 * Typical usage looks like:
43 *
44 * gfxWindowsNativeDrawing nativeDraw(ctx, destGfxRect, capabilities);
45 * do {
46 * HDC dc = nativeDraw.BeginNativeDrawing();
47 * if (!dc)
48 * return NS_ERROR_FAILURE;
49 *
50 * RECT winRect;
51 * nativeDraw.TransformToNativeRect(rect, winRect);
52 *
53 * ... call win32 operations on HDC to draw to winRect ...
54 *
55 * nativeDraw.EndNativeDrawing();
56 * } while (nativeDraw.ShouldRenderAgain());
57 * nativeDraw.PaintToContext();
58 */
59 gfxWindowsNativeDrawing(gfxContext *ctx,
60 const gfxRect& nativeRect,
61 uint32_t nativeDrawFlags = CANNOT_DRAW_TO_COLOR_ALPHA |
62 CANNOT_AXIS_ALIGNED_SCALE |
63 CANNOT_COMPLEX_TRANSFORM |
64 DO_BILINEAR_FILTERING);
65
66 /* Returns a HDC which may be used for native drawing. This HDC is valid
67 * until EndNativeDrawing is called; if it is used for drawing after that time,
68 * the result is undefined. */
69 HDC BeginNativeDrawing();
70
71 /* Transform the native rect into something valid for rendering
72 * to the HDC. This may or may not change RECT, depending on
73 * whether SetWorldTransform is used or not. */
74 void TransformToNativeRect(const gfxRect& r, RECT& rout);
75
76 /* Marks the end of native drawing */
77 void EndNativeDrawing();
78
79 /* Returns true if the native drawing should be executed again */
80 bool ShouldRenderAgain();
81
82 /* Returns true if double pass alpha extraction is taking place. */
83 bool IsDoublePass();
84
85 /* Places the result to the context, if necessary */
86 void PaintToContext();
87
88 private:
89
90 nsRefPtr<gfxContext> mContext;
91 gfxRect mNativeRect;
92 uint32_t mNativeDrawFlags;
93
94 // what state the rendering is in
95 uint8_t mRenderState;
96
97 gfxPoint mDeviceOffset;
98 nsRefPtr<gfxPattern> mBlackPattern, mWhitePattern;
99
100 enum TransformType {
101 TRANSLATION_ONLY,
102 AXIS_ALIGNED_SCALE,
103 COMPLEX
104 };
105
106 TransformType mTransformType;
107 gfxPoint mTranslation;
108 gfxSize mScale;
109 XFORM mWorldTransform;
110
111 // saved state
112 nsRefPtr<gfxWindowsSurface> mWinSurface, mBlackSurface, mWhiteSurface;
113 HDC mDC;
114 XFORM mOldWorldTransform;
115 POINT mOrigViewportOrigin;
116 gfxIntSize mTempSurfaceSize;
117 };
118
119 #endif

mercurial