From 8894894d9d34d169efa39d6d86ebefcb2ba69fe1 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 24 Aug 2007 13:40:26 +0100 Subject: [PATCH] [cairo-boilerplate-xlib] Check that the surface will fit in the screen. Whilst testing the fallback surface, the resultant image was being clipped to the screen size. Be conservative and refuse to create windows (for CAIRO_CONTENT_COLOR surfaces) that are larger than the screen. --- boilerplate/cairo-boilerplate-xlib.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/boilerplate/cairo-boilerplate-xlib.c b/boilerplate/cairo-boilerplate-xlib.c index c0553ef06..781f8f9e2 100644 --- a/boilerplate/cairo-boilerplate-xlib.c +++ b/boilerplate/cairo-boilerplate-xlib.c @@ -110,6 +110,18 @@ _cairo_boilerplate_xlib_test_create_surface (Display *dpy, width, height); } + +static cairo_bool_t +_cairo_boilerplate_xlib_check_screen_size (Display *dpy, + int screen, + int width, + int height) +{ + Screen *scr = XScreenOfDisplay (dpy, screen); + return width <= WidthOfScreen (scr) && height <= HeightOfScreen (scr); +} + + static cairo_surface_t * _cairo_boilerplate_xlib_perf_create_surface (Display *dpy, cairo_content_t content, @@ -135,6 +147,13 @@ _cairo_boilerplate_xlib_perf_create_surface (Display *dpy, break; case CAIRO_CONTENT_COLOR: + if (! _cairo_boilerplate_xlib_check_screen_size (dpy, + DefaultScreen (dpy), + width, height)) { + CAIRO_BOILERPLATE_LOG ("Surface is larger than the Screen.\n"); + return NULL; + } + visual = DefaultVisual (dpy, DefaultScreen (dpy)); xrender_format = XRenderFindVisualFormat (dpy, visual); if (xrender_format == NULL) { @@ -244,6 +263,12 @@ _cairo_boilerplate_xlib_fallback_create_surface (const char *name, XSynchronize (dpy, 1); screen = DefaultScreen (dpy); + if (! _cairo_boilerplate_xlib_check_screen_size (dpy, screen, + width, height)) { + CAIRO_BOILERPLATE_LOG ("Surface is larger than the Screen.\n"); + return NULL; + } + attr.override_redirect = True; xtc->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0,