michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _GFXWINDOWSNATIVEDRAWING_H_ michael@0: #define _GFXWINDOWSNATIVEDRAWING_H_ michael@0: michael@0: #include michael@0: michael@0: #include "gfxContext.h" michael@0: #include "gfxWindowsSurface.h" michael@0: michael@0: class gfxWindowsNativeDrawing { michael@0: public: michael@0: michael@0: /* Flags for notifying this class what kind of operations the native michael@0: * drawing supports michael@0: */ michael@0: michael@0: enum { michael@0: /* Whether the native drawing can draw to a surface of content COLOR_ALPHA */ michael@0: CAN_DRAW_TO_COLOR_ALPHA = 1 << 0, michael@0: CANNOT_DRAW_TO_COLOR_ALPHA = 0 << 0, michael@0: michael@0: /* Whether the native drawing can be scaled using SetWorldTransform */ michael@0: CAN_AXIS_ALIGNED_SCALE = 1 << 1, michael@0: CANNOT_AXIS_ALIGNED_SCALE = 0 << 1, michael@0: michael@0: /* Whether the native drawing can be both scaled and rotated arbitrarily using SetWorldTransform */ michael@0: CAN_COMPLEX_TRANSFORM = 1 << 2, michael@0: CANNOT_COMPLEX_TRANSFORM = 0 << 2, michael@0: michael@0: /* If we have to do transforms with cairo, should we use nearest-neighbour filtering? */ michael@0: DO_NEAREST_NEIGHBOR_FILTERING = 1 << 3, michael@0: DO_BILINEAR_FILTERING = 0 << 3 michael@0: }; michael@0: michael@0: /* Create native win32 drawing for a rectangle bounded by michael@0: * nativeRect. michael@0: * michael@0: * Typical usage looks like: michael@0: * michael@0: * gfxWindowsNativeDrawing nativeDraw(ctx, destGfxRect, capabilities); michael@0: * do { michael@0: * HDC dc = nativeDraw.BeginNativeDrawing(); michael@0: * if (!dc) michael@0: * return NS_ERROR_FAILURE; michael@0: * michael@0: * RECT winRect; michael@0: * nativeDraw.TransformToNativeRect(rect, winRect); michael@0: * michael@0: * ... call win32 operations on HDC to draw to winRect ... michael@0: * michael@0: * nativeDraw.EndNativeDrawing(); michael@0: * } while (nativeDraw.ShouldRenderAgain()); michael@0: * nativeDraw.PaintToContext(); michael@0: */ michael@0: gfxWindowsNativeDrawing(gfxContext *ctx, michael@0: const gfxRect& nativeRect, michael@0: uint32_t nativeDrawFlags = CANNOT_DRAW_TO_COLOR_ALPHA | michael@0: CANNOT_AXIS_ALIGNED_SCALE | michael@0: CANNOT_COMPLEX_TRANSFORM | michael@0: DO_BILINEAR_FILTERING); michael@0: michael@0: /* Returns a HDC which may be used for native drawing. This HDC is valid michael@0: * until EndNativeDrawing is called; if it is used for drawing after that time, michael@0: * the result is undefined. */ michael@0: HDC BeginNativeDrawing(); michael@0: michael@0: /* Transform the native rect into something valid for rendering michael@0: * to the HDC. This may or may not change RECT, depending on michael@0: * whether SetWorldTransform is used or not. */ michael@0: void TransformToNativeRect(const gfxRect& r, RECT& rout); michael@0: michael@0: /* Marks the end of native drawing */ michael@0: void EndNativeDrawing(); michael@0: michael@0: /* Returns true if the native drawing should be executed again */ michael@0: bool ShouldRenderAgain(); michael@0: michael@0: /* Returns true if double pass alpha extraction is taking place. */ michael@0: bool IsDoublePass(); michael@0: michael@0: /* Places the result to the context, if necessary */ michael@0: void PaintToContext(); michael@0: michael@0: private: michael@0: michael@0: nsRefPtr mContext; michael@0: gfxRect mNativeRect; michael@0: uint32_t mNativeDrawFlags; michael@0: michael@0: // what state the rendering is in michael@0: uint8_t mRenderState; michael@0: michael@0: gfxPoint mDeviceOffset; michael@0: nsRefPtr mBlackPattern, mWhitePattern; michael@0: michael@0: enum TransformType { michael@0: TRANSLATION_ONLY, michael@0: AXIS_ALIGNED_SCALE, michael@0: COMPLEX michael@0: }; michael@0: michael@0: TransformType mTransformType; michael@0: gfxPoint mTranslation; michael@0: gfxSize mScale; michael@0: XFORM mWorldTransform; michael@0: michael@0: // saved state michael@0: nsRefPtr mWinSurface, mBlackSurface, mWhiteSurface; michael@0: HDC mDC; michael@0: XFORM mOldWorldTransform; michael@0: POINT mOrigViewportOrigin; michael@0: gfxIntSize mTempSurfaceSize; michael@0: }; michael@0: michael@0: #endif