gfx/thebes/gfxXlibNativeRenderer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxXlibNativeRenderer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     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 GFXXLIBNATIVERENDER_H_
    1.10 +#define GFXXLIBNATIVERENDER_H_
    1.11 +
    1.12 +#include "nsPoint.h"
    1.13 +#include "nsRect.h"
    1.14 +#include <X11/Xlib.h>
    1.15 +
    1.16 +namespace mozilla {
    1.17 +namespace gfx {
    1.18 +  class DrawTarget;
    1.19 +}
    1.20 +}
    1.21 +
    1.22 +class gfxASurface;
    1.23 +class gfxContext;
    1.24 +struct nsIntRect;
    1.25 +struct nsIntPoint;
    1.26 +struct nsIntSize;
    1.27 +typedef struct _cairo cairo_t;
    1.28 +typedef struct _cairo_surface cairo_surface_t;
    1.29 +
    1.30 +/**
    1.31 + * This class lets us take code that draws into an X drawable and lets us
    1.32 + * use it to draw into any Thebes context. The user should subclass this class,
    1.33 + * override DrawWithXib, and then call Draw(). The drawing will be subjected
    1.34 + * to all Thebes transformations, clipping etc.
    1.35 + */
    1.36 +class gfxXlibNativeRenderer {
    1.37 +public:
    1.38 +    /**
    1.39 +     * Perform the native drawing.
    1.40 +     * @param surface the cairo_surface_t for drawing. Must be a cairo_xlib_surface_t.
    1.41 +     *                The extents of this surface do not necessarily cover the
    1.42 +     *                entire rectangle with size provided to Draw().
    1.43 +     * @param offset  draw at this offset into the given drawable
    1.44 +     * @param clipRects an array of rectangles; clip to the union.
    1.45 +     *                  Any rectangles provided will be contained by the
    1.46 +     *                  rectangle with size provided to Draw and by the
    1.47 +     *                  surface extents.
    1.48 +     * @param numClipRects the number of rects in the array, or zero if
    1.49 +     *                     no clipping is required.
    1.50 +     */
    1.51 +    virtual nsresult DrawWithXlib(cairo_surface_t* surface,
    1.52 +                                  nsIntPoint offset,
    1.53 +                                  nsIntRect* clipRects, uint32_t numClipRects) = 0;
    1.54 +  
    1.55 +    enum {
    1.56 +        // If set, then Draw() is opaque, i.e., every pixel in the intersection
    1.57 +        // of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
    1.58 +        // will be set and there is no dependence on what the existing pixels
    1.59 +        // in the drawable are set to.
    1.60 +        DRAW_IS_OPAQUE = 0x01,
    1.61 +        // If set, then numClipRects can be zero or one
    1.62 +        DRAW_SUPPORTS_CLIP_RECT = 0x04,
    1.63 +        // If set, then numClipRects can be any value. If neither this
    1.64 +        // nor CLIP_RECT are set, then numClipRects will be zero
    1.65 +        DRAW_SUPPORTS_CLIP_LIST = 0x08,
    1.66 +        // If set, then the surface in the callback may have any visual;
    1.67 +        // otherwise the pixels will have the same format as the visual
    1.68 +        // passed to 'Draw'.
    1.69 +        DRAW_SUPPORTS_ALTERNATE_VISUAL = 0x10,
    1.70 +        // If set, then the Screen 'screen' in the callback can be different
    1.71 +        // from the default Screen of the display passed to 'Draw' and can be
    1.72 +        // on a different display.
    1.73 +        DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20
    1.74 +    };
    1.75 +
    1.76 +    /**
    1.77 +     * @param flags see above
    1.78 +     * @param size the size of the rectangle being drawn;
    1.79 +     * the caller guarantees that drawing will not extend beyond the rectangle
    1.80 +     * (0,0,size.width,size.height).
    1.81 +     * @param screen a Screen to use for the drawing if ctx doesn't have one.
    1.82 +     * @param visual a Visual to use for the drawing if ctx doesn't have one.
    1.83 +     * @param result if non-null, we will try to capture a copy of the
    1.84 +     * rendered image into a surface similar to the surface of ctx; if
    1.85 +     * successful, a pointer to the new gfxASurface is stored in *resultSurface,
    1.86 +     * otherwise *resultSurface is set to nullptr.
    1.87 +     */
    1.88 +    void Draw(gfxContext* ctx, nsIntSize size,
    1.89 +              uint32_t flags, Screen *screen, Visual *visual);
    1.90 +
    1.91 +private:
    1.92 +    bool DrawDirect(gfxContext *ctx, nsIntSize bounds,
    1.93 +                    uint32_t flags, Screen *screen, Visual *visual);
    1.94 +
    1.95 +    bool DrawCairo(cairo_t* cr, nsIntSize size,
    1.96 +                   uint32_t flags, Screen *screen, Visual *visual);
    1.97 +
    1.98 +    void DrawFallback(mozilla::gfx::DrawTarget* dt, gfxContext* ctx,
    1.99 +                      gfxASurface* aSurface, nsIntSize& size,
   1.100 +                      nsIntRect& drawingRect, bool canDrawOverBackground,
   1.101 +                      uint32_t flags, Screen* screen, Visual* visual);
   1.102 +
   1.103 +    bool DrawOntoTempSurface(cairo_surface_t *tempXlibSurface,
   1.104 +                             nsIntPoint offset);
   1.105 +
   1.106 +};
   1.107 +
   1.108 +#endif /*GFXXLIBNATIVERENDER_H_*/

mercurial