[gtk/wip/baedert/for-master: 2/4] glcontext-wayland: Avoid heap-alloacting small arrays...
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 2/4] glcontext-wayland: Avoid heap-alloacting small arrays...
- Date: Fri, 25 Dec 2020 09:15:48 +0000 (UTC)
commit 2cd6e6a52d790c0f0c963650b75bd7ca99914eda
Author: Timm Bäder <mail baedert org>
Date: Thu Dec 24 09:27:31 2020 +0100
glcontext-wayland: Avoid heap-alloacting small arrays...
every frame.
gdk/wayland/gdkglcontext-wayland.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index d49f2cec0e..d6a4234e54 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -242,14 +242,22 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "wayland", "swap buffers");
if (display_wayland->have_egl_swap_buffers_with_damage)
{
+ EGLint stack_rects[4 * 4]; /* 4 rects */
+ EGLint *heap_rects = NULL;
int i, j, n_rects = cairo_region_num_rectangles (painted);
- EGLint *rects = g_new (EGLint, n_rects * 4);
- cairo_rectangle_int_t rect;
int surface_height = gdk_surface_get_height (surface);
int scale = gdk_surface_get_scale_factor (surface);
+ EGLint *rects;
+
+ if (n_rects < G_N_ELEMENTS (stack_rects) / 4)
+ rects = (EGLint *)&stack_rects;
+ else
+ heap_rects = rects = g_new (EGLint, n_rects * 4);
for (i = 0, j = 0; i < n_rects; i++)
{
+ cairo_rectangle_int_t rect;
+
cairo_region_get_rectangle (painted, i, &rect);
rects[j++] = rect.x * scale;
rects[j++] = (surface_height - rect.height - rect.y) * scale;
@@ -257,7 +265,7 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
rects[j++] = rect.height * scale;
}
eglSwapBuffersWithDamageEXT (display_wayland->egl_display, egl_surface, rects, n_rects);
- g_free (rects);
+ g_free (heap_rects);
}
else
eglSwapBuffers (display_wayland->egl_display, egl_surface);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]