2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-03 03:18:34 +03:00
|
|
|
|
|
|
|
#ifndef _GFXWINDOWSNATIVEDRAWING_H_
|
|
|
|
#define _GFXWINDOWSNATIVEDRAWING_H_
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxWindowsNativeDrawing {
|
2007-03-03 03:18:34 +03:00
|
|
|
public:
|
|
|
|
/* Flags for notifying this class what kind of operations the native
|
|
|
|
* drawing supports
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2007-03-03 03:18:34 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
enum {
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Whether the native drawing can draw to a surface of content COLOR_ALPHA
|
|
|
|
*/
|
|
|
|
CAN_DRAW_TO_COLOR_ALPHA = 1 << 0,
|
|
|
|
CANNOT_DRAW_TO_COLOR_ALPHA = 0 << 0,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Whether the native drawing can be scaled using SetWorldTransform */
|
|
|
|
CAN_AXIS_ALIGNED_SCALE = 1 << 1,
|
|
|
|
CANNOT_AXIS_ALIGNED_SCALE = 0 << 1,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Whether the native drawing can be both scaled and rotated arbitrarily
|
|
|
|
using SetWorldTransform */
|
|
|
|
CAN_COMPLEX_TRANSFORM = 1 << 2,
|
|
|
|
CANNOT_COMPLEX_TRANSFORM = 0 << 2,
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Create native win32 drawing for a rectangle bounded by
|
|
|
|
* nativeRect.
|
|
|
|
*
|
|
|
|
* Typical usage looks like:
|
|
|
|
*
|
2008-11-05 01:01:21 +03:00
|
|
|
* gfxWindowsNativeDrawing nativeDraw(ctx, destGfxRect, capabilities);
|
2007-03-03 03:18:34 +03:00
|
|
|
* do {
|
|
|
|
* HDC dc = nativeDraw.BeginNativeDrawing();
|
2007-08-09 22:54:17 +04:00
|
|
|
* if (!dc)
|
|
|
|
* return NS_ERROR_FAILURE;
|
2007-03-03 03:18:34 +03:00
|
|
|
*
|
|
|
|
* RECT winRect;
|
|
|
|
* nativeDraw.TransformToNativeRect(rect, winRect);
|
|
|
|
*
|
|
|
|
* ... call win32 operations on HDC to draw to winRect ...
|
|
|
|
*
|
|
|
|
* nativeDraw.EndNativeDrawing();
|
|
|
|
* } while (nativeDraw.ShouldRenderAgain());
|
|
|
|
* nativeDraw.PaintToContext();
|
|
|
|
*/
|
|
|
|
gfxWindowsNativeDrawing(
|
|
|
|
gfxContext* ctx, const gfxRect& nativeRect,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nativeDrawFlags = CANNOT_DRAW_TO_COLOR_ALPHA |
|
2007-03-03 03:18:34 +03:00
|
|
|
CANNOT_AXIS_ALIGNED_SCALE |
|
2020-01-09 18:40:25 +03:00
|
|
|
CANNOT_COMPLEX_TRANSFORM);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Returns a HDC which may be used for native drawing. This HDC is valid
|
|
|
|
* until EndNativeDrawing is called; if it is used for drawing after that
|
|
|
|
* time, the result is undefined. */
|
|
|
|
HDC BeginNativeDrawing();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Transform the native rect into something valid for rendering
|
|
|
|
* to the HDC. This may or may not change RECT, depending on
|
|
|
|
* whether SetWorldTransform is used or not. */
|
|
|
|
void TransformToNativeRect(const gfxRect& r, RECT& rout);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Marks the end of native drawing */
|
|
|
|
void EndNativeDrawing();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
/* Returns true if the native drawing should be executed again */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldRenderAgain();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
/* Places the result to the context, if necessary */
|
|
|
|
void PaintToContext();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxContext> mContext;
|
2007-03-03 03:18:34 +03:00
|
|
|
gfxRect mNativeRect;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mNativeDrawFlags;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
// what state the rendering is in
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mRenderState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-15 02:00:08 +03:00
|
|
|
mozilla::gfx::Point mDeviceOffset;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> mBlackPattern, mWhitePattern;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
enum TransformType { TRANSLATION_ONLY, AXIS_ALIGNED_SCALE, COMPLEX };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
TransformType mTransformType;
|
|
|
|
gfxPoint mTranslation;
|
|
|
|
gfxSize mScale;
|
|
|
|
XFORM mWorldTransform;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
// saved state
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxWindowsSurface> mWinSurface, mBlackSurface, mWhiteSurface;
|
2007-03-03 03:18:34 +03:00
|
|
|
HDC mDC;
|
|
|
|
XFORM mOldWorldTransform;
|
|
|
|
POINT mOrigViewportOrigin;
|
2015-06-01 11:26:19 +03:00
|
|
|
mozilla::gfx::IntSize mTempSurfaceSize;
|
2007-03-03 03:18:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|