From 48cd15ed4491a15b58274cf86380c95a103a53b7 Mon Sep 17 00:00:00 2001 From: Link Mauve Date: Sat, 30 Nov 2019 22:28:58 +0000 Subject: [PATCH] renderer-gl: Allocate buffer on the stack This avoids an extra heap allocation for each view. --- libweston/renderer-gl/gl-renderer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libweston/renderer-gl/gl-renderer.c b/libweston/renderer-gl/gl-renderer.c index c9d4968b..898cb907 100644 --- a/libweston/renderer-gl/gl-renderer.c +++ b/libweston/renderer-gl/gl-renderer.c @@ -732,9 +732,10 @@ triangle_fan_debug(struct gl_renderer *gr, int first, int count) { int i; - GLushort *buffer; + /* There can be at most eight vertices for a given view. */ + GLushort buffer[(8 - 1 + 8 - 2) * 2]; GLushort *index; - int nelems; + GLsizei nelems; static int color_idx = 0; struct gl_shader_config alt; const GLfloat *col; @@ -766,8 +767,8 @@ triangle_fan_debug(struct gl_renderer *gr, gl_renderer_use_program(gr, &alt); nelems = (count - 1 + count - 2) * 2; + assert((unsigned long)nelems <= ARRAY_LENGTH(buffer)); - buffer = malloc(sizeof(GLushort) * nelems); index = buffer; for (i = 1; i < count; i++) { @@ -782,8 +783,6 @@ triangle_fan_debug(struct gl_renderer *gr, glDrawElements(GL_LINES, nelems, GL_UNSIGNED_SHORT, buffer); - free(buffer); - gl_renderer_use_program(gr, sconf); }