From a0dbffb8f2d49b2fe5d244ca2ec34b095fa1ff1d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 26 Dec 2017 20:07:29 +0100 Subject: [PATCH] Set decorations as opaque, to optimise composition --- src/wl_window.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 90db32fa..afc52d76 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -224,9 +224,12 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image) static void createDecoration(_GLFWdecorationWayland* decoration, struct wl_surface* parent, - struct wl_buffer* buffer, int x, int y, + struct wl_buffer* buffer, GLFWbool opaque, + int x, int y, int width, int height) { + struct wl_region* region; + decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); decoration->subsurface = wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, @@ -236,13 +239,24 @@ static void createDecoration(_GLFWdecorationWayland* decoration, decoration->surface); wp_viewport_set_destination(decoration->viewport, width, height); wl_surface_attach(decoration->surface, buffer, 0, 0); - wl_surface_commit(decoration->surface); + + if (opaque) + { + region = wl_compositor_create_region(_glfw.wl.compositor); + wl_region_add(region, 0, 0, width, height); + wl_surface_set_opaque_region(decoration->surface, region); + wl_surface_commit(decoration->surface); + wl_region_destroy(region); + } + else + wl_surface_commit(decoration->surface); } static void createDecorations(_GLFWwindow* window) { unsigned char data[] = { 224, 224, 224, 255 }; const GLFWimage image = { 1, 1, data }; + GLFWbool opaque = (data[3] == 255); if (!_glfw.wl.viewporter) return; @@ -251,19 +265,19 @@ static void createDecorations(_GLFWwindow* window) window->wl.decorations.buffer = createShmBuffer(&image); createDecoration(&window->wl.decorations.top, window->wl.surface, - window->wl.decorations.buffer, + window->wl.decorations.buffer, opaque, 0, -_GLFW_DECORATION_TOP, window->wl.width, _GLFW_DECORATION_TOP); createDecoration(&window->wl.decorations.left, window->wl.surface, - window->wl.decorations.buffer, + window->wl.decorations.buffer, opaque, -_GLFW_DECORATION_WIDTH, -_GLFW_DECORATION_TOP, _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP); createDecoration(&window->wl.decorations.right, window->wl.surface, - window->wl.decorations.buffer, + window->wl.decorations.buffer, opaque, window->wl.width, -_GLFW_DECORATION_TOP, _GLFW_DECORATION_WIDTH, window->wl.height + _GLFW_DECORATION_TOP); createDecoration(&window->wl.decorations.bottom, window->wl.surface, - window->wl.decorations.buffer, + window->wl.decorations.buffer, opaque, -_GLFW_DECORATION_WIDTH, window->wl.height, window->wl.width + _GLFW_DECORATION_HORIZONTAL, _GLFW_DECORATION_WIDTH); }