diff options
author | David Robillard <d@drobilla.net> | 2023-01-02 17:04:16 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-01-02 17:04:16 -0500 |
commit | bc50edc0c5bfc4f42289150c8b9f3556cb6bff5c (patch) | |
tree | ebfc125207847a8a5ff4b7a1c032c269ccb7e848 /src | |
parent | 23a1b165950d2f7b738ed42144e1569f0c82793c (diff) | |
download | pugl-bc50edc0c5bfc4f42289150c8b9f3556cb6bff5c.tar.gz pugl-bc50edc0c5bfc4f42289150c8b9f3556cb6bff5c.tar.bz2 pugl-bc50edc0c5bfc4f42289150c8b9f3556cb6bff5c.zip |
X11: Create Cairo drawing surface with precisely the needed size
This decouples drawing from the view frame, which can be out of sync with the
drawing that is currently happening.
Diffstat (limited to 'src')
-rw-r--r-- | src/x11_cairo.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/x11_cairo.c b/src/x11_cairo.c index 74de735..be9ae09 100644 --- a/src/x11_cairo.c +++ b/src/x11_cairo.c @@ -11,6 +11,7 @@ #include <cairo-xlib.h> #include <cairo.h> +#include <math.h> #include <stdlib.h> typedef struct { @@ -31,22 +32,20 @@ puglX11CairoClose(PuglView* view) } static PuglStatus -puglX11CairoOpen(PuglView* view) +puglX11CairoOpen(PuglView* view, + const double expose_width, + const double expose_height) { PuglInternals* const impl = view->impl; PuglX11CairoSurface* const surface = (PuglX11CairoSurface*)impl->surface; + const int width = (int)ceil(expose_width); + const int height = (int)ceil(expose_height); - surface->back = cairo_xlib_surface_create(view->world->impl->display, - impl->win, - impl->vi->visual, - (int)view->frame.width, - (int)view->frame.height); + surface->back = cairo_xlib_surface_create( + view->world->impl->display, impl->win, impl->vi->visual, width, height); - surface->front = - cairo_surface_create_similar(surface->back, - cairo_surface_get_content(surface->back), - (int)view->frame.width, - (int)view->frame.height); + surface->front = cairo_surface_create_similar( + surface->back, cairo_surface_get_content(surface->back), width, height); if (cairo_surface_status(surface->back) || cairo_surface_status(surface->front)) { @@ -84,7 +83,7 @@ puglX11CairoEnter(PuglView* view, const PuglExposeEvent* expose) PuglX11CairoSurface* const surface = (PuglX11CairoSurface*)impl->surface; PuglStatus st = PUGL_SUCCESS; - if (expose && !(st = puglX11CairoOpen(view))) { + if (expose && !(st = puglX11CairoOpen(view, expose->width, expose->height))) { surface->cr = cairo_create(surface->front); st = cairo_status(surface->cr) ? PUGL_CREATE_CONTEXT_FAILED : PUGL_SUCCESS; } |