Bumping manifests a=b2g-bump
[gecko.git] / gfx / thebes / gfxWindowsNativeDrawing.h
blob4be044b98c00857ba6958f71f981ce0c590fe16c
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/. */
6 #ifndef _GFXWINDOWSNATIVEDRAWING_H_
7 #define _GFXWINDOWSNATIVEDRAWING_H_
9 #include <windows.h>
11 #include "gfxContext.h"
12 #include "gfxWindowsSurface.h"
14 class gfxWindowsNativeDrawing {
15 public:
17 /* Flags for notifying this class what kind of operations the native
18 * drawing supports
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,
26 /* Whether the native drawing can be scaled using SetWorldTransform */
27 CAN_AXIS_ALIGNED_SCALE = 1 << 1,
28 CANNOT_AXIS_ALIGNED_SCALE = 0 << 1,
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,
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
39 /* Create native win32 drawing for a rectangle bounded by
40 * nativeRect.
42 * Typical usage looks like:
44 * gfxWindowsNativeDrawing nativeDraw(ctx, destGfxRect, capabilities);
45 * do {
46 * HDC dc = nativeDraw.BeginNativeDrawing();
47 * if (!dc)
48 * return NS_ERROR_FAILURE;
50 * RECT winRect;
51 * nativeDraw.TransformToNativeRect(rect, winRect);
53 * ... call win32 operations on HDC to draw to winRect ...
55 * nativeDraw.EndNativeDrawing();
56 * } while (nativeDraw.ShouldRenderAgain());
57 * nativeDraw.PaintToContext();
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);
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();
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);
76 /* Marks the end of native drawing */
77 void EndNativeDrawing();
79 /* Returns true if the native drawing should be executed again */
80 bool ShouldRenderAgain();
82 /* Returns true if double pass alpha extraction is taking place. */
83 bool IsDoublePass();
85 /* Places the result to the context, if necessary */
86 void PaintToContext();
88 private:
90 nsRefPtr<gfxContext> mContext;
91 gfxRect mNativeRect;
92 uint32_t mNativeDrawFlags;
94 // what state the rendering is in
95 uint8_t mRenderState;
97 gfxPoint mDeviceOffset;
98 nsRefPtr<gfxPattern> mBlackPattern, mWhitePattern;
100 enum TransformType {
101 TRANSLATION_ONLY,
102 AXIS_ALIGNED_SCALE,
103 COMPLEX
106 TransformType mTransformType;
107 gfxPoint mTranslation;
108 gfxSize mScale;
109 XFORM mWorldTransform;
111 // saved state
112 nsRefPtr<gfxWindowsSurface> mWinSurface, mBlackSurface, mWhiteSurface;
113 HDC mDC;
114 XFORM mOldWorldTransform;
115 POINT mOrigViewportOrigin;
116 gfxIntSize mTempSurfaceSize;
119 #endif