[PATCH weston 3/3] gl-renderer: Split gl_renderer_attach() into smaller functions

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Fri Jun 7 06:52:46 PDT 2013


---
 src/gl-renderer.c |  187 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 105 insertions(+), 82 deletions(-)

diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index c5d683c..b853b7f 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -1201,14 +1201,115 @@ ensure_textures(struct gl_surface_state *gs, int num_textures)
 }
 
 static void
-gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
+gl_renderer_attach_shm(struct weston_surface *es, struct wl_buffer *buffer)
 {
 	struct weston_compositor *ec = es->compositor;
 	struct gl_renderer *gr = get_renderer(ec);
 	struct gl_surface_state *gs = get_surface_state(es);
-	EGLint attribs[3], format;
+
+	/* Only allocate a texture if it doesn't match existing one.
+	 * If a switch from DRM allocated buffer to a SHM buffer is
+	 * happening, we need to allocate a new texture buffer. */
+	if (wl_shm_buffer_get_stride(buffer) / 4 != gs->pitch ||
+	    wl_shm_buffer_get_height(buffer) != gs->height ||
+	    gs->buffer_type != BUFFER_TYPE_SHM) {
+		gs->pitch = wl_shm_buffer_get_stride(buffer) / 4;
+		gs->height = wl_shm_buffer_get_height(buffer);
+		gs->target = GL_TEXTURE_2D;
+
+		ensure_textures(gs, 1);
+		glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
+			     gs->pitch, buffer->height, 0,
+			     GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
+
+		gs->needs_full_upload = 1;
+	}
+
+	if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888)
+		gs->shader = &gr->texture_shader_rgbx;
+	else
+		gs->shader = &gr->texture_shader_rgba;
+
+	gs->buffer_type = BUFFER_TYPE_SHM;
+}
+
+static void
+gl_renderer_attach_egl(struct weston_surface *es, struct wl_buffer *buffer,
+		       EGLint format)
+{
+	struct weston_compositor *ec = es->compositor;
+	struct gl_renderer *gr = get_renderer(ec);
+	struct gl_surface_state *gs = get_surface_state(es);
+	EGLint attribs[3];
 	int i, num_planes;
 
+	for (i = 0; i < gs->num_images; i++)
+		gr->destroy_image(gr->egl_display, gs->images[i]);
+	gs->num_images = 0;
+	gs->target = GL_TEXTURE_2D;
+	switch (format) {
+	case EGL_TEXTURE_RGB:
+	case EGL_TEXTURE_RGBA:
+	default:
+		num_planes = 1;
+		gs->shader = &gr->texture_shader_rgba;
+		break;
+	case EGL_TEXTURE_EXTERNAL_WL:
+		num_planes = 1;
+		gs->target = GL_TEXTURE_EXTERNAL_OES;
+		gs->shader = &gr->texture_shader_egl_external;
+		break;
+	case EGL_TEXTURE_Y_UV_WL:
+		num_planes = 2;
+		gs->shader = &gr->texture_shader_y_uv;
+		break;
+	case EGL_TEXTURE_Y_U_V_WL:
+		num_planes = 3;
+		gs->shader = &gr->texture_shader_y_u_v;
+		break;
+	case EGL_TEXTURE_Y_XUXV_WL:
+		num_planes = 2;
+		gs->shader = &gr->texture_shader_y_xuxv;
+		break;
+	}
+
+	ensure_textures(gs, num_planes);
+	for (i = 0; i < num_planes; i++) {
+		attribs[0] = EGL_WAYLAND_PLANE_WL;
+		attribs[1] = i;
+		attribs[2] = EGL_NONE;
+		gs->images[i] = gr->create_image(gr->egl_display,
+						 NULL,
+						 EGL_WAYLAND_BUFFER_WL,
+						 buffer, attribs);
+		if (!gs->images[i]) {
+			weston_log("failed to create img for plane %d\n", i);
+			continue;
+		}
+		gs->num_images++;
+
+		glActiveTexture(GL_TEXTURE0 + i);
+		glBindTexture(gs->target, gs->textures[i]);
+		gr->image_target_texture_2d(gs->target,
+					    gs->images[i]);
+	}
+
+	gs->pitch = buffer->width;
+	gs->height = buffer->height;
+
+	gs->buffer_type = BUFFER_TYPE_EGL;
+}
+
+static void
+gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
+{
+	struct weston_compositor *ec = es->compositor;
+	struct gl_renderer *gr = get_renderer(ec);
+	struct gl_surface_state *gs = get_surface_state(es);
+	EGLint format;
+	int i;
+
 	weston_buffer_reference(&gs->buffer_ref, buffer);
 
 	if (!buffer) {
@@ -1224,88 +1325,10 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 	}
 
 	if (wl_buffer_is_shm(buffer)) {
-		/* Only allocate a texture if it doesn't match existing one.
-		 * If a switch from DRM allocated buffer to a SHM buffer is
-		 * happening, we need to allocate a new texture buffer. */
-		if (wl_shm_buffer_get_stride(buffer) / 4 != gs->pitch ||
-		    wl_shm_buffer_get_height(buffer) != gs->height ||
-		    gs->buffer_type != BUFFER_TYPE_SHM) {
-			gs->pitch = wl_shm_buffer_get_stride(buffer) / 4;
-			gs->height = wl_shm_buffer_get_height(buffer);
-			gs->target = GL_TEXTURE_2D;
-
-			ensure_textures(gs, 1);
-			glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
-			glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
-				     gs->pitch, buffer->height, 0,
-				     GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
-
-			gs->needs_full_upload = 1;
-		}
-
-		if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888)
-			gs->shader = &gr->texture_shader_rgbx;
-		else
-			gs->shader = &gr->texture_shader_rgba;
-
-		gs->buffer_type = BUFFER_TYPE_SHM;
+		gl_renderer_attach_shm(es, buffer);
 	} else if (gr->query_buffer(gr->egl_display, buffer,
 				    EGL_TEXTURE_FORMAT, &format)) {
-		for (i = 0; i < gs->num_images; i++)
-			gr->destroy_image(gr->egl_display, gs->images[i]);
-		gs->num_images = 0;
-		gs->target = GL_TEXTURE_2D;
-		switch (format) {
-		case EGL_TEXTURE_RGB:
-		case EGL_TEXTURE_RGBA:
-		default:
-			num_planes = 1;
-			gs->shader = &gr->texture_shader_rgba;
-			break;
-		case EGL_TEXTURE_EXTERNAL_WL:
-			num_planes = 1;
-			gs->target = GL_TEXTURE_EXTERNAL_OES;
-			gs->shader = &gr->texture_shader_egl_external;
-			break;
-		case EGL_TEXTURE_Y_UV_WL:
-			num_planes = 2;
-			gs->shader = &gr->texture_shader_y_uv;
-			break;
-		case EGL_TEXTURE_Y_U_V_WL:
-			num_planes = 3;
-			gs->shader = &gr->texture_shader_y_u_v;
-			break;
-		case EGL_TEXTURE_Y_XUXV_WL:
-			num_planes = 2;
-			gs->shader = &gr->texture_shader_y_xuxv;
-			break;
-		}
-
-		ensure_textures(gs, num_planes);
-		for (i = 0; i < num_planes; i++) {
-			attribs[0] = EGL_WAYLAND_PLANE_WL;
-			attribs[1] = i;
-			attribs[2] = EGL_NONE;
-			gs->images[i] = gr->create_image(gr->egl_display,
-							 NULL,
-							 EGL_WAYLAND_BUFFER_WL,
-							 buffer, attribs);
-			if (!gs->images[i]) {
-				weston_log("failed to create img for plane %d\n", i);
-				continue;
-			}
-			gs->num_images++;
-
-			glActiveTexture(GL_TEXTURE0 + i);
-			glBindTexture(gs->target, gs->textures[i]);
-			gr->image_target_texture_2d(gs->target,
-						    gs->images[i]);
-		}
-
-		gs->pitch = buffer->width;
-		gs->height = buffer->height;
-
-		gs->buffer_type = BUFFER_TYPE_EGL;
+		gl_renderer_attach_egl(es, buffer, format);
 	} else {
 		weston_log("unhandled buffer type!\n");
 		weston_buffer_reference(&gs->buffer_ref, NULL);
-- 
1.7.10.4



More information about the wayland-devel mailing list