From 7dfe7a2cd366b91d478caf36e6a683066ac21ca1 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 13 Jun 2019 16:55:37 -0500 Subject: [PATCH] Create drawing contexts when creating windows --- examples/cluster.c | 4 ++-- include/hexagram/window.h | 4 ++-- src/window.c | 25 +++++++++++++++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/examples/cluster.c b/examples/cluster.c index f2aa682..4d6d98c 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -118,8 +118,8 @@ int main(int argc, char **argv) { /* * Set up the rendering surfaces */ - fg = hexagram_window_create_fg_context(window); - bg = hexagram_window_create_bg_context(window); + fg = hexagram_window_get_fg_context(window); + bg = hexagram_window_get_bg_context(window); /* * Draw the background layer diff --git a/include/hexagram/window.h b/include/hexagram/window.h index 1250869..e38fd8f 100644 --- a/include/hexagram/window.h +++ b/include/hexagram/window.h @@ -30,8 +30,8 @@ int hexagram_window_refresh_bg(hexagram_window *window); int hexagram_window_swap_buffer(hexagram_window *window); -cairo_t *hexagram_window_create_bg_context(hexagram_window *window); +cairo_t *hexagram_window_get_bg_context(hexagram_window *window); -cairo_t *hexagram_window_create_fg_context(hexagram_window *window); +cairo_t *hexagram_window_get_fg_context(hexagram_window *window); #endif /* _HEXAGRAM_WINDOW_H */ diff --git a/src/window.c b/src/window.c index 5f4f333..1c6b39e 100644 --- a/src/window.c +++ b/src/window.c @@ -28,6 +28,9 @@ struct _hexagram_window { cairo_surface_t *surface_bg, *surface_fg; + + cairo_t *cairo_bg, + *cairo_fg; }; hexagram_window *hexagram_window_new_x11(const char *display, @@ -121,8 +124,22 @@ hexagram_window *hexagram_window_new_x11(const char *display, width, height); + if ((window->cairo_bg = cairo_create(window->surface_bg)) == NULL) { + goto error_cairo_create_bg; + } + + if ((window->cairo_fg = cairo_create(window->surface_fg)) == NULL) { + goto error_cairo_create_fg; + } + return window; +error_cairo_create_fg: + cairo_destroy(window->cairo_bg); + +error_cairo_create_bg: + cairo_surface_destroy(window->surface_fg); + error_cairo_xlib_surface_create_fg: cairo_surface_destroy(window->surface_bg); @@ -204,10 +221,10 @@ int hexagram_window_swap_buffer(hexagram_window *window) { return XdbeSwapBuffers(window->display, &window->swapinfo, 1) == 0? -1: 1; } -cairo_t *hexagram_window_create_bg_context(hexagram_window *window) { - return cairo_create(window->surface_bg); +cairo_t *hexagram_window_get_bg_context(hexagram_window *window) { + return window->cairo_bg; } -cairo_t *hexagram_window_create_fg_context(hexagram_window *window) { - return cairo_create(window->surface_fg); +cairo_t *hexagram_window_get_fg_context(hexagram_window *window) { + return window->cairo_fg; }