2003-09-30 18:56:22 +00:00
|
|
|
|
/*
|
2003-10-23 07:47:29 +00:00
|
|
|
|
* Copyright <EFBFBD> 2002 University of Southern California
|
2003-09-30 18:56:22 +00:00
|
|
|
|
*
|
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
|
|
* appear in supporting documentation, and that the name of the
|
|
|
|
|
|
* University of Southern California not be used in advertising or
|
|
|
|
|
|
* publicity pertaining to distribution of the software without
|
|
|
|
|
|
* specific, written prior permission. The University of Southern
|
|
|
|
|
|
* California makes no representations about the suitability of this
|
|
|
|
|
|
* software for any purpose. It is provided "as is" without express
|
|
|
|
|
|
* or implied warranty.
|
|
|
|
|
|
*
|
|
|
|
|
|
* THE UNIVERSITY OF SOUTHERN CALIFORNIA DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
|
|
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
|
* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF
|
|
|
|
|
|
* SOUTHERN CALIFORNIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Author: Carl D. Worth <cworth@isi.edu>
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "cairoint.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
cairo_set_target_drawable (cairo_t *cr,
|
|
|
|
|
|
Display *dpy,
|
|
|
|
|
|
Drawable drawable)
|
|
|
|
|
|
{
|
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
|
|
|
|
if (cr->status && cr->status != CAIRO_STATUS_NO_TARGET_SURFACE)
|
2003-10-23 15:22:28 +00:00
|
|
|
|
return;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
surface = cairo_xlib_surface_create (dpy, drawable,
|
|
|
|
|
|
DefaultVisual (dpy, DefaultScreen (dpy)),
|
|
|
|
|
|
0,
|
|
|
|
|
|
DefaultColormap (dpy, DefaultScreen (dpy)));
|
|
|
|
|
|
if (surface == NULL) {
|
|
|
|
|
|
cr->status = CAIRO_STATUS_NO_MEMORY;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cairo_set_target_surface (cr, surface);
|
2003-10-31 10:41:37 +00:00
|
|
|
|
|
|
|
|
|
|
/* cairo_set_target_surface takes a reference, so we must destroy ours */
|
2003-09-30 18:56:22 +00:00
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct cairo_xlib_surface {
|
|
|
|
|
|
cairo_surface_t base;
|
|
|
|
|
|
|
|
|
|
|
|
Display *dpy;
|
|
|
|
|
|
GC gc;
|
|
|
|
|
|
Drawable drawable;
|
|
|
|
|
|
int owns_pixmap;
|
|
|
|
|
|
Visual *visual;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
cairo_format_t format;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
int render_major;
|
|
|
|
|
|
int render_minor;
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
int width;
|
|
|
|
|
|
int height;
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
Picture picture;
|
2003-10-27 18:40:55 +00:00
|
|
|
|
} cairo_xlib_surface_t;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_AT_LEAST(surface, major, minor) \
|
|
|
|
|
|
(((surface)->render_major > major) || \
|
|
|
|
|
|
(((surface)->render_major == major) && ((surface)->render_minor >= minor)))
|
|
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_CREATE_PICTURE(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 0)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_COMPOSITE(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLE(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 1)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLES(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 1)
|
|
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_DISJOINT(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 2)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_CONJOINT(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 2)
|
|
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_TRAPEZOIDS(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 4)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_TRIANGLES(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 4)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_TRISTRIP(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 4)
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_TRIFAN(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 4)
|
|
|
|
|
|
|
|
|
|
|
|
#define CAIRO_SURFACE_RENDER_HAS_PICTURE_TRANSFORM(surface) CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 6)
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
|
_CAIRO_FORMAT_DEPTH (cairo_format_t format)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
|
case CAIRO_FORMAT_A1:
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
case CAIRO_FORMAT_A8:
|
|
|
|
|
|
return 8;
|
|
|
|
|
|
case CAIRO_FORMAT_RGB24:
|
|
|
|
|
|
return 24;
|
|
|
|
|
|
case CAIRO_FORMAT_ARGB32:
|
|
|
|
|
|
default:
|
|
|
|
|
|
return 32;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
static cairo_surface_t *
|
|
|
|
|
|
_cairo_xlib_surface_create_similar (void *abstract_src,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
cairo_format_t format,
|
|
|
|
|
|
int width,
|
|
|
|
|
|
int height)
|
|
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *src = abstract_src;
|
|
|
|
|
|
Display *dpy = src->dpy;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
int scr;
|
|
|
|
|
|
Pixmap pix;
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
/* XXX: There's a pretty lame heuristic here. This assumes that
|
|
|
|
|
|
* all non-Render X servers do not support depth-32 pixmaps, (and
|
|
|
|
|
|
* that they do support depths 1, 8, and 24). Obviously, it would
|
|
|
|
|
|
* be much better to check the depths that are actually
|
|
|
|
|
|
* supported. */
|
|
|
|
|
|
if (!dpy
|
2003-10-27 18:40:55 +00:00
|
|
|
|
|| (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (src)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
&& format == CAIRO_FORMAT_ARGB32))
|
2003-10-31 10:41:37 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return NULL;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
}
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
scr = DefaultScreen (dpy);
|
|
|
|
|
|
|
|
|
|
|
|
pix = XCreatePixmap (dpy, DefaultRootWindow (dpy),
|
|
|
|
|
|
width, height,
|
|
|
|
|
|
_CAIRO_FORMAT_DEPTH (format));
|
2003-10-31 10:41:37 +00:00
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
surface = (cairo_xlib_surface_t *)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
cairo_xlib_surface_create (dpy, pix, NULL, format, DefaultColormap (dpy, scr));
|
|
|
|
|
|
surface->owns_pixmap = 1;
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
surface->width = width;
|
|
|
|
|
|
surface->height = height;
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return &surface->base;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-10-27 18:40:55 +00:00
|
|
|
|
_cairo_xlib_surface_destroy (void *abstract_surface)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (surface->picture)
|
|
|
|
|
|
XRenderFreePicture (surface->dpy, surface->picture);
|
|
|
|
|
|
|
|
|
|
|
|
if (surface->owns_pixmap)
|
|
|
|
|
|
XFreePixmap (surface->dpy, surface->drawable);
|
|
|
|
|
|
|
2003-10-30 18:39:20 +00:00
|
|
|
|
if (surface->gc)
|
|
|
|
|
|
XFreeGC (surface->dpy, surface->gc);
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
surface->dpy = 0;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
|
|
|
|
|
|
free (surface);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-28 12:18:29 +00:00
|
|
|
|
static double
|
|
|
|
|
|
_cairo_xlib_surface_pixels_per_inch (void *abstract_surface)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* XXX: We should really get this value from somewhere like Xft.dpy */
|
|
|
|
|
|
return 96.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
static cairo_image_surface_t *
|
|
|
|
|
|
_cairo_xlib_surface_get_image (void *abstract_surface)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
cairo_image_surface_t *image;
|
|
|
|
|
|
|
|
|
|
|
|
XImage *ximage;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
Window root_ignore;
|
|
|
|
|
|
int x_ignore, y_ignore, bwidth_ignore, depth_ignore;
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XGetGeometry (surface->dpy,
|
|
|
|
|
|
surface->drawable,
|
|
|
|
|
|
&root_ignore, &x_ignore, &y_ignore,
|
|
|
|
|
|
&surface->width, &surface->height,
|
|
|
|
|
|
&bwidth_ignore, &depth_ignore);
|
|
|
|
|
|
|
|
|
|
|
|
ximage = XGetImage (surface->dpy,
|
|
|
|
|
|
surface->drawable,
|
|
|
|
|
|
0, 0,
|
|
|
|
|
|
surface->width, surface->height,
|
|
|
|
|
|
AllPlanes, ZPixmap);
|
|
|
|
|
|
|
|
|
|
|
|
if (surface->visual) {
|
|
|
|
|
|
cairo_format_masks_t masks;
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX: Add support here for pictures with external alpha? */
|
|
|
|
|
|
|
|
|
|
|
|
masks.bpp = ximage->bits_per_pixel;
|
|
|
|
|
|
masks.alpha_mask = 0;
|
|
|
|
|
|
masks.red_mask = surface->visual->red_mask;
|
|
|
|
|
|
masks.green_mask = surface->visual->green_mask;
|
|
|
|
|
|
masks.blue_mask = surface->visual->blue_mask;
|
|
|
|
|
|
|
|
|
|
|
|
image = _cairo_image_surface_create_with_masks (ximage->data,
|
|
|
|
|
|
&masks,
|
|
|
|
|
|
ximage->width,
|
|
|
|
|
|
ximage->height,
|
|
|
|
|
|
ximage->bytes_per_line);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
image = (cairo_image_surface_t *)
|
|
|
|
|
|
cairo_image_surface_create_for_data (ximage->data,
|
|
|
|
|
|
surface->format,
|
|
|
|
|
|
ximage->width,
|
|
|
|
|
|
ximage->height,
|
|
|
|
|
|
ximage->bytes_per_line);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
/* Let the surface take ownership of the data */
|
|
|
|
|
|
/* XXX: Can probably come up with a cleaner API here. */
|
|
|
|
|
|
_cairo_image_surface_assume_ownership_of_data (image);
|
|
|
|
|
|
ximage->data = NULL;
|
|
|
|
|
|
XDestroyImage (ximage);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_image_surface_set_repeat (image, surface->base.repeat);
|
|
|
|
|
|
_cairo_image_surface_set_matrix (image, &(surface->base.matrix));
|
|
|
|
|
|
|
|
|
|
|
|
return image;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-10-27 18:40:55 +00:00
|
|
|
|
_cairo_xlib_surface_ensure_gc (cairo_xlib_surface_t *surface)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (surface->gc)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
surface->gc = XCreateGC (surface->dpy, surface->drawable, 0, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
static cairo_status_t
|
|
|
|
|
|
_cairo_xlib_surface_set_image (void *abstract_surface,
|
|
|
|
|
|
cairo_image_surface_t *image)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XImage *ximage;
|
|
|
|
|
|
unsigned bitmap_pad;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
if (image->depth > 16)
|
|
|
|
|
|
bitmap_pad = 32;
|
|
|
|
|
|
else if (image->depth > 8)
|
|
|
|
|
|
bitmap_pad = 16;
|
|
|
|
|
|
else
|
|
|
|
|
|
bitmap_pad = 8;
|
|
|
|
|
|
|
|
|
|
|
|
ximage = XCreateImage (surface->dpy,
|
|
|
|
|
|
DefaultVisual(surface->dpy, DefaultScreen(surface->dpy)),
|
2003-12-11 10:01:10 +00:00
|
|
|
|
image->depth,
|
2003-10-31 10:41:37 +00:00
|
|
|
|
ZPixmap,
|
|
|
|
|
|
0,
|
|
|
|
|
|
image->data,
|
|
|
|
|
|
image->width,
|
|
|
|
|
|
image->height,
|
|
|
|
|
|
bitmap_pad,
|
|
|
|
|
|
image->stride);
|
|
|
|
|
|
if (ximage == NULL)
|
|
|
|
|
|
return CAIRO_STATUS_NO_MEMORY;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
_cairo_xlib_surface_ensure_gc (surface);
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XPutImage(surface->dpy, surface->drawable, surface->gc,
|
|
|
|
|
|
ximage, 0, 0, 0, 0,
|
|
|
|
|
|
surface->width,
|
|
|
|
|
|
surface->height);
|
|
|
|
|
|
|
|
|
|
|
|
/* Foolish XDestroyImage thinks it can free my data, but I won't
|
|
|
|
|
|
stand for it. */
|
|
|
|
|
|
ximage->data = NULL;
|
|
|
|
|
|
XDestroyImage (ximage);
|
|
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_xlib_surface_set_matrix (void *abstract_surface, cairo_matrix_t *matrix)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XTransform xtransform;
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (!surface->picture)
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
xtransform.matrix[0][0] = _cairo_fixed_from_double (matrix->m[0][0]);
|
|
|
|
|
|
xtransform.matrix[0][1] = _cairo_fixed_from_double (matrix->m[1][0]);
|
|
|
|
|
|
xtransform.matrix[0][2] = _cairo_fixed_from_double (matrix->m[2][0]);
|
|
|
|
|
|
|
|
|
|
|
|
xtransform.matrix[1][0] = _cairo_fixed_from_double (matrix->m[0][1]);
|
|
|
|
|
|
xtransform.matrix[1][1] = _cairo_fixed_from_double (matrix->m[1][1]);
|
|
|
|
|
|
xtransform.matrix[1][2] = _cairo_fixed_from_double (matrix->m[2][1]);
|
|
|
|
|
|
|
|
|
|
|
|
xtransform.matrix[2][0] = 0;
|
|
|
|
|
|
xtransform.matrix[2][1] = 0;
|
|
|
|
|
|
xtransform.matrix[2][2] = _cairo_fixed_from_double (1);
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (CAIRO_SURFACE_RENDER_HAS_PICTURE_TRANSFORM (surface))
|
|
|
|
|
|
{
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XRenderSetPictureTransform (surface->dpy, surface->picture, &xtransform);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
/* XXX: Need support here if using an old RENDER without support
|
|
|
|
|
|
for SetPictureTransform */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
static cairo_status_t
|
|
|
|
|
|
_cairo_xlib_surface_set_filter (void *abstract_surface, cairo_filter_t filter)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-31 10:41:37 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
|
|
|
|
|
char *render_filter;
|
|
|
|
|
|
|
|
|
|
|
|
if (!surface->picture)
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
switch (filter) {
|
|
|
|
|
|
case CAIRO_FILTER_FAST:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterFast;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
case CAIRO_FILTER_GOOD:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterGood;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
case CAIRO_FILTER_BEST:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterBest;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
case CAIRO_FILTER_NEAREST:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterNearest;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
case CAIRO_FILTER_BILINEAR:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterBilinear;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
default:
|
2004-01-30 14:44:18 +00:00
|
|
|
|
render_filter = FilterBest;
|
2004-01-24 01:46:20 +00:00
|
|
|
|
break;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XRenderSetPictureFilter (surface->dpy, surface->picture,
|
2003-10-31 10:41:37 +00:00
|
|
|
|
render_filter, NULL, 0);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static cairo_status_t
|
2003-10-27 18:40:55 +00:00
|
|
|
|
_cairo_xlib_surface_set_repeat (void *abstract_surface, int repeat)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
XRenderPictureAttributes pa;
|
|
|
|
|
|
|
|
|
|
|
|
if (!surface->picture)
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
mask = CPRepeat;
|
|
|
|
|
|
pa.repeat = repeat;
|
|
|
|
|
|
|
|
|
|
|
|
XRenderChangePicture (surface->dpy, surface->picture, mask, &pa);
|
|
|
|
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
static cairo_xlib_surface_t *
|
|
|
|
|
|
_cairo_xlib_surface_clone_similar (cairo_surface_t *src,
|
|
|
|
|
|
cairo_xlib_surface_t *template,
|
|
|
|
|
|
cairo_format_t format,
|
|
|
|
|
|
int depth)
|
2003-09-30 18:56:22 +00:00
|
|
|
|
{
|
2003-10-31 10:41:37 +00:00
|
|
|
|
cairo_xlib_surface_t *clone;
|
|
|
|
|
|
cairo_image_surface_t *src_image;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
src_image = _cairo_surface_get_image (src);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
clone = (cairo_xlib_surface_t *)
|
|
|
|
|
|
_cairo_xlib_surface_create_similar (template, format,
|
|
|
|
|
|
src_image->width,
|
|
|
|
|
|
src_image->height);
|
|
|
|
|
|
if (clone == NULL)
|
|
|
|
|
|
return NULL;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2004-01-30 14:44:18 +00:00
|
|
|
|
_cairo_xlib_surface_set_filter (clone, cairo_surface_get_filter(src_image));
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_xlib_surface_set_image (clone, src_image);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_xlib_surface_set_matrix (clone, &(src_image->base.matrix));
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
cairo_surface_destroy (&src_image->base);
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
return clone;
|
|
|
|
|
|
}
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
static int
|
|
|
|
|
|
_render_operator (cairo_operator_t operator)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (operator) {
|
|
|
|
|
|
case CAIRO_OPERATOR_CLEAR:
|
|
|
|
|
|
return PictOpClear;
|
|
|
|
|
|
case CAIRO_OPERATOR_SRC:
|
|
|
|
|
|
return PictOpSrc;
|
|
|
|
|
|
case CAIRO_OPERATOR_DST:
|
|
|
|
|
|
return PictOpDst;
|
|
|
|
|
|
case CAIRO_OPERATOR_OVER:
|
|
|
|
|
|
return PictOpOver;
|
|
|
|
|
|
case CAIRO_OPERATOR_OVER_REVERSE:
|
|
|
|
|
|
return PictOpOverReverse;
|
|
|
|
|
|
case CAIRO_OPERATOR_IN:
|
|
|
|
|
|
return PictOpIn;
|
|
|
|
|
|
case CAIRO_OPERATOR_IN_REVERSE:
|
|
|
|
|
|
return PictOpInReverse;
|
|
|
|
|
|
case CAIRO_OPERATOR_OUT:
|
|
|
|
|
|
return PictOpOut;
|
|
|
|
|
|
case CAIRO_OPERATOR_OUT_REVERSE:
|
|
|
|
|
|
return PictOpOutReverse;
|
|
|
|
|
|
case CAIRO_OPERATOR_ATOP:
|
|
|
|
|
|
return PictOpAtop;
|
|
|
|
|
|
case CAIRO_OPERATOR_ATOP_REVERSE:
|
|
|
|
|
|
return PictOpAtopReverse;
|
|
|
|
|
|
case CAIRO_OPERATOR_XOR:
|
|
|
|
|
|
return PictOpXor;
|
|
|
|
|
|
case CAIRO_OPERATOR_ADD:
|
|
|
|
|
|
return PictOpAdd;
|
|
|
|
|
|
case CAIRO_OPERATOR_SATURATE:
|
|
|
|
|
|
return PictOpSaturate;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return PictOpOver;
|
|
|
|
|
|
}
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
static cairo_int_status_t
|
2003-09-30 18:56:22 +00:00
|
|
|
|
_cairo_xlib_surface_composite (cairo_operator_t operator,
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_surface_t *generic_src,
|
|
|
|
|
|
cairo_surface_t *generic_mask,
|
|
|
|
|
|
void *abstract_dst,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
int src_x,
|
|
|
|
|
|
int src_y,
|
|
|
|
|
|
int mask_x,
|
|
|
|
|
|
int mask_y,
|
|
|
|
|
|
int dst_x,
|
|
|
|
|
|
int dst_y,
|
|
|
|
|
|
unsigned int width,
|
|
|
|
|
|
unsigned int height)
|
|
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *dst = abstract_dst;
|
|
|
|
|
|
cairo_xlib_surface_t *src = (cairo_xlib_surface_t *) generic_src;
|
|
|
|
|
|
cairo_xlib_surface_t *mask = (cairo_xlib_surface_t *) generic_mask;
|
2003-10-30 18:39:20 +00:00
|
|
|
|
cairo_xlib_surface_t *src_clone = NULL;
|
|
|
|
|
|
cairo_xlib_surface_t *mask_clone = NULL;
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE (dst))
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
if (generic_src->backend != dst->base.backend || src->dpy != dst->dpy) {
|
2003-10-31 10:41:37 +00:00
|
|
|
|
src_clone = _cairo_xlib_surface_clone_similar (generic_src, dst,
|
|
|
|
|
|
CAIRO_FORMAT_ARGB32, 32);
|
2003-10-30 18:39:20 +00:00
|
|
|
|
if (!src_clone)
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-10-30 18:39:20 +00:00
|
|
|
|
src = src_clone;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
2003-10-27 18:40:55 +00:00
|
|
|
|
if (generic_mask && (generic_mask->backend != dst->base.backend || mask->dpy != dst->dpy)) {
|
2003-10-31 10:41:37 +00:00
|
|
|
|
mask_clone = _cairo_xlib_surface_clone_similar (generic_mask, dst,
|
|
|
|
|
|
CAIRO_FORMAT_A8, 8);
|
2003-10-30 18:39:20 +00:00
|
|
|
|
if (!mask_clone)
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-10-30 18:39:20 +00:00
|
|
|
|
mask = mask_clone;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XRenderComposite (dst->dpy,
|
|
|
|
|
|
_render_operator (operator),
|
2003-09-30 18:56:22 +00:00
|
|
|
|
src->picture,
|
|
|
|
|
|
mask ? mask->picture : 0,
|
|
|
|
|
|
dst->picture,
|
|
|
|
|
|
src_x, src_y,
|
|
|
|
|
|
mask_x, mask_y,
|
|
|
|
|
|
dst_x, dst_y,
|
|
|
|
|
|
width, height);
|
|
|
|
|
|
|
2003-10-30 18:39:20 +00:00
|
|
|
|
/* XXX: This is messed up. If I can xlib_surface_create, then I
|
|
|
|
|
|
should be able to xlib_surface_destroy. */
|
|
|
|
|
|
if (src_clone)
|
|
|
|
|
|
cairo_surface_destroy (&src_clone->base);
|
|
|
|
|
|
if (mask_clone)
|
|
|
|
|
|
cairo_surface_destroy (&mask_clone->base);
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
|
_cairo_xlib_surface_fill_rectangles (void *abstract_surface,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
cairo_operator_t operator,
|
|
|
|
|
|
const cairo_color_t *color,
|
|
|
|
|
|
cairo_rectangle_t *rects,
|
|
|
|
|
|
int num_rects)
|
|
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface = abstract_surface;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
XRenderColor render_color;
|
|
|
|
|
|
|
|
|
|
|
|
if (!CAIRO_SURFACE_RENDER_HAS_FILL_RECTANGLE (surface))
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
render_color.red = color->red_short;
|
|
|
|
|
|
render_color.green = color->green_short;
|
|
|
|
|
|
render_color.blue = color->blue_short;
|
|
|
|
|
|
render_color.alpha = color->alpha_short;
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX: This XRectangle cast is evil... it needs to go away somehow. */
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XRenderFillRectangles (surface->dpy,
|
|
|
|
|
|
_render_operator (operator),
|
|
|
|
|
|
surface->picture,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
&render_color, (XRectangle *) rects, num_rects);
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
static cairo_int_status_t
|
2003-09-30 18:56:22 +00:00
|
|
|
|
_cairo_xlib_surface_composite_trapezoids (cairo_operator_t operator,
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_surface_t *generic_src,
|
|
|
|
|
|
void *abstract_dst,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
int xSrc,
|
|
|
|
|
|
int ySrc,
|
|
|
|
|
|
cairo_trapezoid_t *traps,
|
|
|
|
|
|
int num_traps)
|
|
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *dst = abstract_dst;
|
|
|
|
|
|
cairo_xlib_surface_t *src = (cairo_xlib_surface_t *) generic_src;
|
2003-10-30 18:39:20 +00:00
|
|
|
|
cairo_xlib_surface_t *src_clone = NULL;
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (!CAIRO_SURFACE_RENDER_HAS_TRAPEZOIDS (dst))
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
if (generic_src->backend != dst->base.backend || src->dpy != dst->dpy) {
|
2003-10-31 10:41:37 +00:00
|
|
|
|
src_clone = _cairo_xlib_surface_clone_similar (generic_src, dst,
|
|
|
|
|
|
CAIRO_FORMAT_ARGB32, 32);
|
2003-10-30 18:39:20 +00:00
|
|
|
|
if (!src_clone)
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
2003-10-30 18:39:20 +00:00
|
|
|
|
src = src_clone;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX: The XTrapezoid cast is evil and needs to go away somehow. */
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XRenderCompositeTrapezoids (dst->dpy,
|
|
|
|
|
|
_render_operator (operator),
|
|
|
|
|
|
src->picture, dst->picture,
|
2003-09-30 18:56:22 +00:00
|
|
|
|
XRenderFindStandardFormat (dst->dpy, PictStandardA8),
|
|
|
|
|
|
xSrc, ySrc, (XTrapezoid *) traps, num_traps);
|
|
|
|
|
|
|
2003-10-30 18:39:20 +00:00
|
|
|
|
/* XXX: This is messed up. If I can xlib_surface_create, then I
|
|
|
|
|
|
should be able to xlib_surface_destroy. */
|
|
|
|
|
|
if (src_clone)
|
|
|
|
|
|
cairo_surface_destroy (&src_clone->base);
|
|
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-11-03 19:17:31 +00:00
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
|
_cairo_xlib_surface_copy_page (void *abstract_surface)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 21:30:35 +00:00
|
|
|
|
static cairo_int_status_t
|
|
|
|
|
|
_cairo_xlib_surface_show_page (void *abstract_surface)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CAIRO_INT_STATUS_UNSUPPORTED;
|
|
|
|
|
|
}
|
2003-10-23 15:22:28 +00:00
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
static const struct cairo_surface_backend cairo_xlib_surface_backend = {
|
2003-10-27 18:40:55 +00:00
|
|
|
|
_cairo_xlib_surface_create_similar,
|
|
|
|
|
|
_cairo_xlib_surface_destroy,
|
2003-10-28 12:18:29 +00:00
|
|
|
|
_cairo_xlib_surface_pixels_per_inch,
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_xlib_surface_get_image,
|
|
|
|
|
|
_cairo_xlib_surface_set_image,
|
2003-10-27 18:40:55 +00:00
|
|
|
|
_cairo_xlib_surface_set_matrix,
|
|
|
|
|
|
_cairo_xlib_surface_set_filter,
|
|
|
|
|
|
_cairo_xlib_surface_set_repeat,
|
|
|
|
|
|
_cairo_xlib_surface_composite,
|
|
|
|
|
|
_cairo_xlib_surface_fill_rectangles,
|
|
|
|
|
|
_cairo_xlib_surface_composite_trapezoids,
|
2003-11-03 19:17:31 +00:00
|
|
|
|
_cairo_xlib_surface_copy_page,
|
2003-10-31 21:30:35 +00:00
|
|
|
|
_cairo_xlib_surface_show_page
|
2003-09-30 18:56:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
|
|
cairo_xlib_surface_create (Display *dpy,
|
|
|
|
|
|
Drawable drawable,
|
|
|
|
|
|
Visual *visual,
|
|
|
|
|
|
cairo_format_t format,
|
|
|
|
|
|
Colormap colormap)
|
|
|
|
|
|
{
|
2003-10-27 18:40:55 +00:00
|
|
|
|
cairo_xlib_surface_t *surface;
|
2003-10-31 10:41:37 +00:00
|
|
|
|
int render_standard;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
2003-10-27 18:40:55 +00:00
|
|
|
|
surface = malloc (sizeof (cairo_xlib_surface_t));
|
2003-09-30 18:56:22 +00:00
|
|
|
|
if (surface == NULL)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
_cairo_surface_init (&surface->base, &cairo_xlib_surface_backend);
|
|
|
|
|
|
|
|
|
|
|
|
surface->visual = visual;
|
|
|
|
|
|
surface->format = format;
|
2003-09-30 18:56:22 +00:00
|
|
|
|
|
|
|
|
|
|
surface->dpy = dpy;
|
|
|
|
|
|
|
|
|
|
|
|
surface->gc = 0;
|
|
|
|
|
|
surface->drawable = drawable;
|
|
|
|
|
|
surface->owns_pixmap = 0;
|
|
|
|
|
|
surface->visual = visual;
|
|
|
|
|
|
|
|
|
|
|
|
if (! XRenderQueryVersion (dpy, &surface->render_major, &surface->render_minor)) {
|
|
|
|
|
|
surface->render_major = -1;
|
|
|
|
|
|
surface->render_minor = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-10-31 10:41:37 +00:00
|
|
|
|
switch (format) {
|
|
|
|
|
|
case CAIRO_FORMAT_A1:
|
|
|
|
|
|
render_standard = PictStandardA1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CAIRO_FORMAT_A8:
|
|
|
|
|
|
render_standard = PictStandardA8;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CAIRO_FORMAT_RGB24:
|
|
|
|
|
|
render_standard = PictStandardRGB24;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CAIRO_FORMAT_ARGB32:
|
|
|
|
|
|
default:
|
|
|
|
|
|
render_standard = PictStandardARGB32;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-30 18:56:22 +00:00
|
|
|
|
/* XXX: I'm currently ignoring the colormap. Is that bad? */
|
|
|
|
|
|
if (CAIRO_SURFACE_RENDER_HAS_CREATE_PICTURE (surface))
|
|
|
|
|
|
surface->picture = XRenderCreatePicture (dpy, drawable,
|
|
|
|
|
|
visual ?
|
|
|
|
|
|
XRenderFindVisualFormat (dpy, visual) :
|
2003-10-31 10:41:37 +00:00
|
|
|
|
XRenderFindStandardFormat (dpy, render_standard),
|
2003-09-30 18:56:22 +00:00
|
|
|
|
0, NULL);
|
|
|
|
|
|
else
|
|
|
|
|
|
surface->picture = 0;
|
|
|
|
|
|
|
|
|
|
|
|
return (cairo_surface_t *) surface;
|
|
|
|
|
|
}
|
|
|
|
|
|
DEPRECATE (cairo_surface_create_for_drawable, cairo_xlib_surface_create);
|