mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-08 08:00:29 +01:00
[script] Expose a normal xlib window for replay
Provide a visible surface for replaying scripts against.
This commit is contained in:
parent
8e1f103540
commit
2df611a381
1 changed files with 67 additions and 57 deletions
|
|
@ -6,10 +6,8 @@
|
|||
|
||||
static const cairo_user_data_key_t _key;
|
||||
|
||||
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
|
||||
#if CAIRO_HAS_XLIB_SURFACE
|
||||
#include <cairo-xlib.h>
|
||||
#include <cairo-xlib-xrender.h>
|
||||
|
||||
static Display *
|
||||
_get_display (void)
|
||||
{
|
||||
|
|
@ -27,12 +25,6 @@ _get_display (void)
|
|||
return dpy;
|
||||
}
|
||||
|
||||
static void
|
||||
_destroy_pixmap (void *closure)
|
||||
{
|
||||
XFreePixmap (_get_display(), (Pixmap) closure);
|
||||
}
|
||||
|
||||
static void
|
||||
_destroy_window (void *closure)
|
||||
{
|
||||
|
|
@ -40,72 +32,85 @@ _destroy_window (void *closure)
|
|||
XDestroyWindow (_get_display(), (Window) closure);
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
_xlib_surface_create (void *closure,
|
||||
cairo_content_t content,
|
||||
double width, double height)
|
||||
{
|
||||
Display *dpy;
|
||||
XSetWindowAttributes attr;
|
||||
Visual *visual;
|
||||
int depth;
|
||||
Window w;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
dpy = _get_display ();
|
||||
|
||||
visual = DefaultVisual (dpy, DefaultScreen (dpy));
|
||||
depth = DefaultDepth (dpy, DefaultScreen (dpy));
|
||||
attr.override_redirect = True;
|
||||
w = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0,
|
||||
width <= 0 ? 1 : width,
|
||||
height <= 0 ? 1 : height,
|
||||
0, depth,
|
||||
InputOutput, visual, CWOverrideRedirect, &attr);
|
||||
XMapWindow (dpy, w);
|
||||
|
||||
surface = cairo_xlib_surface_create (dpy, w, visual, width, height);
|
||||
cairo_surface_set_user_data (surface, &_key, (void *) w, _destroy_window);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
|
||||
#include <cairo-xlib-xrender.h>
|
||||
|
||||
static void
|
||||
_destroy_pixmap (void *closure)
|
||||
{
|
||||
XFreePixmap (_get_display(), (Pixmap) closure);
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
_xrender_surface_create (void *closure,
|
||||
cairo_content_t content,
|
||||
double width, double height)
|
||||
{
|
||||
Display *dpy;
|
||||
Pixmap pixmap;
|
||||
XRenderPictFormat *xrender_format;
|
||||
cairo_surface_t *surface;
|
||||
|
||||
dpy = _get_display ();
|
||||
|
||||
content = CAIRO_CONTENT_COLOR_ALPHA;
|
||||
if (1) {
|
||||
Pixmap pixmap;
|
||||
|
||||
switch (content) {
|
||||
case CAIRO_CONTENT_COLOR_ALPHA:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
|
||||
break;
|
||||
case CAIRO_CONTENT_COLOR:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24);
|
||||
break;
|
||||
case CAIRO_CONTENT_ALPHA:
|
||||
default:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardA8);
|
||||
}
|
||||
|
||||
pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
|
||||
width, height, xrender_format->depth);
|
||||
|
||||
surface = cairo_xlib_surface_create_with_xrender_format (dpy, pixmap,
|
||||
DefaultScreenOfDisplay (dpy),
|
||||
xrender_format,
|
||||
width, height);
|
||||
cairo_surface_set_user_data (surface, &_key,
|
||||
(void *) pixmap, _destroy_pixmap);
|
||||
} else {
|
||||
XSetWindowAttributes attr;
|
||||
Visual *visual;
|
||||
Window w;
|
||||
|
||||
visual = DefaultVisual (dpy, DefaultScreen (dpy));
|
||||
xrender_format = XRenderFindVisualFormat (dpy, visual);
|
||||
if (xrender_format == NULL) {
|
||||
fprintf (stderr, "X server does not have the Render extension.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
attr.override_redirect = True;
|
||||
w = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0,
|
||||
width <= 0 ? 1 : width,
|
||||
height <= 0 ? 1 : height,
|
||||
0, xrender_format->depth,
|
||||
InputOutput, visual, CWOverrideRedirect, &attr);
|
||||
XMapWindow (dpy, w);
|
||||
|
||||
surface = cairo_xlib_surface_create_with_xrender_format (dpy, w,
|
||||
DefaultScreenOfDisplay (dpy),
|
||||
xrender_format,
|
||||
width, height);
|
||||
cairo_surface_set_user_data (surface, &_key, (void *) w, _destroy_window);
|
||||
switch (content) {
|
||||
case CAIRO_CONTENT_COLOR_ALPHA:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
|
||||
break;
|
||||
case CAIRO_CONTENT_COLOR:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardRGB24);
|
||||
break;
|
||||
case CAIRO_CONTENT_ALPHA:
|
||||
default:
|
||||
xrender_format = XRenderFindStandardFormat (dpy, PictStandardA8);
|
||||
}
|
||||
|
||||
pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
|
||||
width, height, xrender_format->depth);
|
||||
|
||||
surface = cairo_xlib_surface_create_with_xrender_format (dpy, pixmap,
|
||||
DefaultScreenOfDisplay (dpy),
|
||||
xrender_format,
|
||||
width, height);
|
||||
cairo_surface_set_user_data (surface, &_key,
|
||||
(void *) pixmap, _destroy_pixmap);
|
||||
|
||||
return surface;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CAIRO_HAS_PDF_SURFACE
|
||||
#include <cairo-pdf.h>
|
||||
|
|
@ -155,6 +160,8 @@ main (int argc, char **argv)
|
|||
cairo_script_interpreter_hooks_t hooks = {
|
||||
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
|
||||
.surface_create = _xrender_surface_create
|
||||
#elif CAIRO_HAS_XLIB_SURFACE
|
||||
.surface_create = _xlib_surface_create
|
||||
#elif CAIRO_PDF_SURFACE
|
||||
.surface_create = _pdf_surface_create
|
||||
#elif CAIRO_PS_SURFACE
|
||||
|
|
@ -174,6 +181,9 @@ main (int argc, char **argv)
|
|||
#if CAIRO_HAS_XLIB_XRENDER_SURFACE
|
||||
{ "--xrender", _xrender_surface_create },
|
||||
#endif
|
||||
#if CAIRO_HAS_XLIB_SURFACE
|
||||
{ "--xlib", _xlib_surface_create },
|
||||
#endif
|
||||
#if CAIRO_HAS_PDF_SURFACE
|
||||
{ "--pdf", _pdf_surface_create },
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue