Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created May 30, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcima/205e1dc3edfd26e8c836d15648df4b77 to your computer and use it in GitHub Desktop.
Save jpcima/205e1dc3edfd26e8c836d15648df4b77 to your computer and use it in GitHub Desktop.
diff --git a/pugl/detail/x11_cairo.c b/pugl/detail/x11_cairo.c
index 0112c4e..b70715b 100644
--- a/pugl/detail/x11_cairo.c
+++ b/pugl/detail/x11_cairo.c
@@ -52,21 +52,35 @@ puglX11CairoOpen(PuglView* view)
{
PuglInternals* const impl = view->impl;
PuglX11CairoSurface* const surface = (PuglX11CairoSurface*)impl->surface;
+ int width = (int)view->frame.width;
+ int height = (int)view->frame.height;
+
+ if (!surface->back || cairo_surface_status(surface->back)) {
+ cairo_surface_destroy(surface->back);
+ surface->back = cairo_xlib_surface_create(impl->display,
+ impl->win,
+ impl->vi->visual,
+ width, height);
+ }
+ else {
+ if (width != cairo_xlib_surface_get_width(surface->back) ||
+ height != cairo_xlib_surface_get_height(surface->back)) {
+ cairo_xlib_surface_set_size(surface->back, width, height);
+ }
+ }
- surface->back = cairo_xlib_surface_create(impl->display,
- impl->win,
- impl->vi->visual,
- (int)view->frame.width,
- (int)view->frame.height);
-
- surface->front = cairo_surface_create_similar(
- surface->back,
- cairo_surface_get_content(surface->back),
- (int)view->frame.width,
- (int)view->frame.height);
+ if (!surface->front || cairo_surface_status(surface->front) ||
+ cairo_xlib_surface_get_width(surface->front) != width ||
+ cairo_xlib_surface_get_height(surface->front) != height) {
+ cairo_surface_destroy(surface->front);
+ 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)) {
+ if (!surface->back || cairo_surface_status(surface->back) ||
+ !surface->front || cairo_surface_status(surface->front)) {
puglX11CairoClose(view);
return PUGL_CREATE_CONTEXT_FAILED;
}
@@ -140,7 +154,6 @@ puglX11CairoLeave(PuglView* view, const PuglEventExpose* expose)
// Flush to X and close everything
cairo_destroy(surface->cr);
cairo_surface_flush(surface->back);
- puglX11CairoClose(view);
surface->cr = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment