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 CAIROXLIBUTILS_H_ michael@0: #define CAIROXLIBUTILS_H_ michael@0: michael@0: #include "cairo.h" michael@0: #include michael@0: michael@0: CAIRO_BEGIN_DECLS michael@0: michael@0: /** michael@0: * This callback encapsulates Xlib-based rendering. We assume that the michael@0: * execution of the callback is equivalent to compositing some RGBA image of michael@0: * size (bounds_width, bounds_height) onto the drawable at offset (offset_x, michael@0: * offset_y), clipped to the union of the clip_rects if num_rects is greater michael@0: * than zero. This includes the assumption that the same RGBA image michael@0: * is composited if you call the callback multiple times with the same closure, michael@0: * display and visual during a single cairo_draw_with_xlib call. michael@0: * michael@0: * @return True on success, False on non-recoverable error michael@0: */ michael@0: typedef cairo_bool_t (* cairo_xlib_drawing_callback) michael@0: (void *closure, michael@0: Screen *screen, michael@0: Drawable drawable, michael@0: Visual *visual, michael@0: short offset_x, short offset_y, michael@0: XRectangle* clip_rects, unsigned int num_rects); michael@0: michael@0: /** michael@0: * This structure captures the result of the native drawing, in case the michael@0: * caller may wish to reapply the drawing efficiently later. michael@0: */ michael@0: typedef struct { michael@0: cairo_surface_t *surface; michael@0: cairo_bool_t uniform_alpha; michael@0: cairo_bool_t uniform_color; michael@0: double alpha; /* valid only if uniform_alpha is TRUE */ michael@0: double r, g, b; /* valid only if uniform_color is TRUE */ michael@0: } cairo_xlib_drawing_result_t; michael@0: michael@0: /** michael@0: * This type specifies whether the native drawing callback draws all pixels michael@0: * in its bounds opaquely, independent of the contents of the target drawable, michael@0: * or whether it leaves pixels transparent/translucent or depends on the michael@0: * existing contents of the target drawable in some way. michael@0: */ michael@0: typedef enum _cairo_xlib_drawing_opacity { michael@0: CAIRO_XLIB_DRAWING_OPAQUE, michael@0: CAIRO_XLIB_DRAWING_TRANSPARENT michael@0: } cairo_xlib_drawing_opacity_t; michael@0: michael@0: /** michael@0: * This type encodes the capabilities of the native drawing callback. michael@0: * michael@0: * If CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET is set, 'offset_x' and 'offset_y' michael@0: * can be nonzero in the call to the callback; otherwise they will be zero. michael@0: * michael@0: * If CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT is set, then 'num_rects' can be michael@0: * zero or one in the call to the callback. If michael@0: * CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST is set, then 'num_rects' can be michael@0: * anything in the call to the callback. Otherwise 'num_rects' will be zero. michael@0: * Do not set both of these values. michael@0: * michael@0: * If CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN is set, then 'screen' can michael@0: * be any screen on any display, otherwise it will be the default screen of michael@0: * the display passed into cairo_draw_with_xlib. michael@0: * michael@0: * If CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL is set, then 'visual' can be michael@0: * any visual, otherwise it will be equal to michael@0: * DefaultVisualOfScreen (screen). michael@0: */ michael@0: typedef enum { michael@0: CAIRO_XLIB_DRAWING_SUPPORTS_OFFSET = 0x01, michael@0: CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_RECT = 0x02, michael@0: CAIRO_XLIB_DRAWING_SUPPORTS_CLIP_LIST = 0x04, michael@0: CAIRO_XLIB_DRAWING_SUPPORTS_ALTERNATE_SCREEN = 0x08, michael@0: CAIRO_XLIB_DRAWING_SUPPORTS_NONDEFAULT_VISUAL = 0x10 michael@0: } cairo_xlib_drawing_support_t; michael@0: michael@0: /** michael@0: * Draw Xlib output into any cairo context. All cairo transforms and effects michael@0: * are honored, including the current operator. This is equivalent to a michael@0: * cairo_set_source_surface and then cairo_paint. michael@0: * @param cr the context to draw into michael@0: * @param callback the code to perform Xlib rendering michael@0: * @param closure associated data michael@0: * @param dpy an X display to use in case the cairo context has no associated X display michael@0: * @param width the width of the putative image drawn by the callback michael@0: * @param height the height of the putative image drawn by the callback michael@0: * @param is_opaque set to CAIRO_XLIB_DRAWING_IS_OPAQUE to indicate michael@0: * that all alpha values of the putative image will be 1.0; the pixels drawn into michael@0: * the Drawable must not depend on the prior contents of the Drawable michael@0: * in any way michael@0: * @param capabilities the capabilities of the callback as described above. michael@0: * @param result if non-NULL, we *may* fill in the struct with information about michael@0: * the rendered image. 'surface' may be filled in with a surface representing michael@0: * the image, similar to the target of 'cr'. If 'uniform_alpha' is True then michael@0: * every pixel of the image has the same alpha value 'alpha'. If michael@0: * 'uniform_color' is True then every pixel of the image has the same RGB michael@0: * color (r, g, b). If the image has uniform color and alpha (or alpha is zero, michael@0: * in which case the color is always uniform) then we won't bother returning michael@0: * a surface for it. michael@0: */ michael@0: void cairo_draw_with_xlib (cairo_t *cr, michael@0: cairo_xlib_drawing_callback callback, michael@0: void *closure, michael@0: Display *dpy, michael@0: unsigned int width, unsigned int height, michael@0: cairo_xlib_drawing_opacity_t is_opaque, michael@0: cairo_xlib_drawing_support_t capabilities, michael@0: cairo_xlib_drawing_result_t *result); michael@0: michael@0: CAIRO_END_DECLS michael@0: michael@0: #endif /*CAIROXLIBUTILS_H_*/