gfx/thebes/gfxWindowsNativeDrawing.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxWindowsNativeDrawing.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef _GFXWINDOWSNATIVEDRAWING_H_
    1.10 +#define _GFXWINDOWSNATIVEDRAWING_H_
    1.11 +
    1.12 +#include <windows.h>
    1.13 +
    1.14 +#include "gfxContext.h"
    1.15 +#include "gfxWindowsSurface.h"
    1.16 +
    1.17 +class gfxWindowsNativeDrawing {
    1.18 +public:
    1.19 +
    1.20 +    /* Flags for notifying this class what kind of operations the native
    1.21 +     * drawing supports
    1.22 +     */
    1.23 +
    1.24 +    enum {
    1.25 +        /* Whether the native drawing can draw to a surface of content COLOR_ALPHA */
    1.26 +        CAN_DRAW_TO_COLOR_ALPHA    = 1 << 0,
    1.27 +        CANNOT_DRAW_TO_COLOR_ALPHA = 0 << 0,
    1.28 +
    1.29 +        /* Whether the native drawing can be scaled using SetWorldTransform */
    1.30 +        CAN_AXIS_ALIGNED_SCALE     = 1 << 1,
    1.31 +        CANNOT_AXIS_ALIGNED_SCALE  = 0 << 1,
    1.32 +
    1.33 +        /* Whether the native drawing can be both scaled and rotated arbitrarily using SetWorldTransform */
    1.34 +        CAN_COMPLEX_TRANSFORM      = 1 << 2,
    1.35 +        CANNOT_COMPLEX_TRANSFORM   = 0 << 2,
    1.36 +
    1.37 +        /* If we have to do transforms with cairo, should we use nearest-neighbour filtering? */
    1.38 +        DO_NEAREST_NEIGHBOR_FILTERING = 1 << 3,
    1.39 +        DO_BILINEAR_FILTERING         = 0 << 3
    1.40 +    };
    1.41 +
    1.42 +    /* Create native win32 drawing for a rectangle bounded by
    1.43 +     * nativeRect.
    1.44 +     *
    1.45 +     * Typical usage looks like:
    1.46 +     *
    1.47 +     *   gfxWindowsNativeDrawing nativeDraw(ctx, destGfxRect, capabilities);
    1.48 +     *   do {
    1.49 +     *     HDC dc = nativeDraw.BeginNativeDrawing();
    1.50 +     *     if (!dc)
    1.51 +     *       return NS_ERROR_FAILURE;
    1.52 +     *
    1.53 +     *     RECT winRect;
    1.54 +     *     nativeDraw.TransformToNativeRect(rect, winRect);
    1.55 +     *
    1.56 +     *       ... call win32 operations on HDC to draw to winRect ...
    1.57 +     *
    1.58 +     *     nativeDraw.EndNativeDrawing();
    1.59 +     *   } while (nativeDraw.ShouldRenderAgain());
    1.60 +     *   nativeDraw.PaintToContext();
    1.61 +     */
    1.62 +    gfxWindowsNativeDrawing(gfxContext *ctx,
    1.63 +                            const gfxRect& nativeRect,
    1.64 +                            uint32_t nativeDrawFlags = CANNOT_DRAW_TO_COLOR_ALPHA |
    1.65 +                                                       CANNOT_AXIS_ALIGNED_SCALE |
    1.66 +                                                       CANNOT_COMPLEX_TRANSFORM |
    1.67 +                                                       DO_BILINEAR_FILTERING);
    1.68 +
    1.69 +    /* Returns a HDC which may be used for native drawing.  This HDC is valid
    1.70 +     * until EndNativeDrawing is called; if it is used for drawing after that time,
    1.71 +     * the result is undefined. */
    1.72 +    HDC BeginNativeDrawing();
    1.73 +
    1.74 +    /* Transform the native rect into something valid for rendering
    1.75 +     * to the HDC.  This may or may not change RECT, depending on
    1.76 +     * whether SetWorldTransform is used or not. */
    1.77 +    void TransformToNativeRect(const gfxRect& r, RECT& rout);
    1.78 +
    1.79 +    /* Marks the end of native drawing */
    1.80 +    void EndNativeDrawing();
    1.81 +
    1.82 +    /* Returns true if the native drawing should be executed again */
    1.83 +    bool ShouldRenderAgain();
    1.84 +
    1.85 +    /* Returns true if double pass alpha extraction is taking place. */
    1.86 +    bool IsDoublePass();
    1.87 +
    1.88 +    /* Places the result to the context, if necessary */
    1.89 +    void PaintToContext();
    1.90 +
    1.91 +private:
    1.92 +
    1.93 +    nsRefPtr<gfxContext> mContext;
    1.94 +    gfxRect mNativeRect;
    1.95 +    uint32_t mNativeDrawFlags;
    1.96 +
    1.97 +    // what state the rendering is in
    1.98 +    uint8_t mRenderState;
    1.99 +
   1.100 +    gfxPoint mDeviceOffset;
   1.101 +    nsRefPtr<gfxPattern> mBlackPattern, mWhitePattern;
   1.102 +
   1.103 +    enum TransformType {
   1.104 +        TRANSLATION_ONLY,
   1.105 +        AXIS_ALIGNED_SCALE,
   1.106 +        COMPLEX
   1.107 +    };
   1.108 +
   1.109 +    TransformType mTransformType;
   1.110 +    gfxPoint mTranslation;
   1.111 +    gfxSize mScale;
   1.112 +    XFORM mWorldTransform;
   1.113 +
   1.114 +    // saved state
   1.115 +    nsRefPtr<gfxWindowsSurface> mWinSurface, mBlackSurface, mWhiteSurface;
   1.116 +    HDC mDC;
   1.117 +    XFORM mOldWorldTransform;
   1.118 +    POINT mOrigViewportOrigin;
   1.119 +    gfxIntSize mTempSurfaceSize;
   1.120 +};
   1.121 +
   1.122 +#endif

mercurial