gfx/thebes/cairo-xlib-utils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/cairo-xlib-utils.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 CAIROXLIBUTILS_H_
    1.10 +#define CAIROXLIBUTILS_H_
    1.11 +
    1.12 +#include "cairo.h"
    1.13 +#include <X11/Xlib.h>
    1.14 +
    1.15 +CAIRO_BEGIN_DECLS
    1.16 +
    1.17 +/**
    1.18 + * This callback encapsulates Xlib-based rendering. We assume that the
    1.19 + * execution of the callback is equivalent to compositing some RGBA image of
    1.20 + * size (bounds_width, bounds_height) onto the drawable at offset (offset_x,
    1.21 + * offset_y), clipped to the union of the clip_rects if num_rects is greater
    1.22 + * than zero. This includes the assumption that the same RGBA image
    1.23 + * is composited if you call the callback multiple times with the same closure,
    1.24 + * display and visual during a single cairo_draw_with_xlib call.
    1.25 + * 
    1.26 + * @return True on success, False on non-recoverable error
    1.27 + */
    1.28 +typedef cairo_bool_t (* cairo_xlib_drawing_callback)
    1.29 +    (void *closure,
    1.30 +     Screen *screen,
    1.31 +     Drawable drawable,
    1.32 +     Visual *visual,
    1.33 +     short offset_x, short offset_y,
    1.34 +     XRectangle* clip_rects, unsigned int num_rects);
    1.35 +
    1.36 +/**
    1.37 + * This structure captures the result of the native drawing, in case the
    1.38 + * caller may wish to reapply the drawing efficiently later.
    1.39 + */
    1.40 +typedef struct {
    1.41 +    cairo_surface_t *surface;
    1.42 +    cairo_bool_t    uniform_alpha;
    1.43 +    cairo_bool_t    uniform_color;
    1.44 +    double          alpha; /* valid only if uniform_alpha is TRUE */
    1.45 +    double          r, g, b; /* valid only if uniform_color is TRUE */
    1.46 +} cairo_xlib_drawing_result_t;
    1.47 +
    1.48 +/**
    1.49 + * This type specifies whether the native drawing callback draws all pixels
    1.50 + * in its bounds opaquely, independent of the contents of the target drawable,
    1.51 + * or whether it leaves pixels transparent/translucent or depends on the
    1.52 + * existing contents of the target drawable in some way.
    1.53 + */
    1.54 +typedef enum _cairo_xlib_drawing_opacity {
    1.55 +    CAIRO_XLIB_DRAWING_OPAQUE,
    1.56 +    CAIRO_XLIB_DRAWING_TRANSPARENT
    1.57 +} cairo_xlib_drawing_opacity_t;
    1.58 +
    1.59 +/**
    1.60 + * This type encodes the capabilities of the native drawing callback.
    1.61 + * 
    1.62 + * If CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET is set, 'offset_x' and 'offset_y'
    1.63 + * can be nonzero in the call to the callback; otherwise they will be zero.
    1.64 + * 
    1.65 + * If CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT is set, then 'num_rects' can be
    1.66 + * zero or one in the call to the callback. If
    1.67 + * CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST is set, then 'num_rects' can be
    1.68 + * anything in the call to the callback. Otherwise 'num_rects' will be zero.
    1.69 + * Do not set both of these values.
    1.70 + * 
    1.71 + * If CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN is set, then 'screen' can
    1.72 + * be any screen on any display, otherwise it will be the default screen of
    1.73 + * the display passed into cairo_draw_with_xlib.
    1.74 + * 
    1.75 + * If CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL is set, then 'visual' can be
    1.76 + * any visual, otherwise it will be equal to
    1.77 + * DefaultVisualOfScreen (screen).
    1.78 + */
    1.79 +typedef enum {
    1.80 +    CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET = 0x01,
    1.81 +    CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT = 0x02,
    1.82 +    CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST = 0x04,
    1.83 +    CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN = 0x08,
    1.84 +    CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL = 0x10
    1.85 +} cairo_xlib_drawing_support_t;
    1.86 +
    1.87 +/**
    1.88 + * Draw Xlib output into any cairo context. All cairo transforms and effects
    1.89 + * are honored, including the current operator. This is equivalent to a
    1.90 + * cairo_set_source_surface and then cairo_paint.
    1.91 + * @param cr the context to draw into
    1.92 + * @param callback the code to perform Xlib rendering
    1.93 + * @param closure associated data
    1.94 + * @param dpy an X display to use in case the cairo context has no associated X display
    1.95 + * @param width the width of the putative image drawn by the callback
    1.96 + * @param height the height of the putative image drawn by the callback
    1.97 + * @param is_opaque set to CAIRO_XLIB_DRAWING_IS_OPAQUE to indicate
    1.98 + * that all alpha values of the putative image will be 1.0; the pixels drawn into
    1.99 + * the Drawable must not depend on the prior contents of the Drawable
   1.100 + * in any way
   1.101 + * @param capabilities the capabilities of the callback as described above.
   1.102 + * @param result if non-NULL, we *may* fill in the struct with information about
   1.103 + * the rendered image. 'surface' may be filled in with a surface representing
   1.104 + * the image, similar to the target of 'cr'. If 'uniform_alpha' is True then
   1.105 + * every pixel of the image has the same alpha value 'alpha'. If
   1.106 + * 'uniform_color' is True then every pixel of the image has the same RGB
   1.107 + * color (r, g, b). If the image has uniform color and alpha (or alpha is zero,
   1.108 + * in which case the color is always uniform) then we won't bother returning
   1.109 + * a surface for it.
   1.110 + */
   1.111 +void cairo_draw_with_xlib (cairo_t *cr,
   1.112 +                           cairo_xlib_drawing_callback callback,
   1.113 +                           void *closure,
   1.114 +                           Display *dpy,
   1.115 +                           unsigned int width, unsigned int height,
   1.116 +                           cairo_xlib_drawing_opacity_t is_opaque,
   1.117 +                           cairo_xlib_drawing_support_t capabilities,
   1.118 +                           cairo_xlib_drawing_result_t *result);
   1.119 +
   1.120 +CAIRO_END_DECLS
   1.121 +
   1.122 +#endif /*CAIROXLIBUTILS_H_*/

mercurial