gfx/thebes/gfxWindowsNativeDrawing.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial