[PATCH v4 08/10] Move weston_surface GL and EGL state into gles2-renderer.

John Kåre Alsaker john.kare.alsaker at gmail.com
Mon Oct 29 14:17:16 PDT 2012


---
 src/compositor.c     |  3 --
 src/compositor.h     |  6 ----
 src/gles2-renderer.c | 87 +++++++++++++++++++++++++++++-----------------------
 3 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index f017052..42d04e0 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -242,9 +242,6 @@ weston_surface_create(struct weston_compositor *compositor)
 		return NULL;
 	}
 
-	surface->num_textures = 0;
-	surface->num_images = 0;
-
 	surface->buffer = NULL;
 	surface->output = NULL;
 	surface->plane = &compositor->primary_plane;
diff --git a/src/compositor.h b/src/compositor.h
index d8332fc..76f9aa8 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -393,8 +393,6 @@ struct weston_region {
 struct weston_surface {
 	struct wl_surface surface;
 	struct weston_compositor *compositor;
-	GLuint textures[3];
-	int num_textures;
 	pixman_region32_t clip;
 	pixman_region32_t damage;
 	pixman_region32_t opaque;
@@ -453,10 +451,6 @@ struct weston_surface {
 
 	struct wl_list frame_callback_list;
 
-	EGLImageKHR images[3];
-	GLenum target;
-	int num_images;
-
 	struct wl_buffer *buffer;
 	struct wl_listener buffer_destroy_listener;
 
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index 820921f..ae4d550 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -46,6 +46,13 @@ struct gles2_output_state {
 struct gles2_surface_state {
 	GLfloat color[4];
 	struct gles2_shader *shader;
+
+	GLuint textures[3];
+	int num_textures;
+
+	EGLImageKHR images[3];
+	GLenum target;
+	int num_images;
 };
 
 struct gles2_renderer {
@@ -684,7 +691,7 @@ shader_uniforms(struct gles2_shader *shader,
 	glUniform4fv(shader->color_uniform, 1, gs->color);
 	glUniform1f(shader->alpha_uniform, surface->alpha);
 
-	for (i = 0; i < surface->num_textures; i++)
+	for (i = 0; i < gs->num_textures; i++)
 		glUniform1i(shader->tex_uniforms[i], i);
 }
 
@@ -729,11 +736,11 @@ draw_surface(struct weston_surface *es, struct weston_output *output,
 	else
 		filter = GL_NEAREST;
 
-	for (i = 0; i < es->num_textures; i++) {
+	for (i = 0; i < gs->num_textures; i++) {
 		glActiveTexture(GL_TEXTURE0 + i);
-		glBindTexture(es->target, es->textures[i]);
-		glTexParameteri(es->target, GL_TEXTURE_MIN_FILTER, filter);
-		glTexParameteri(es->target, GL_TEXTURE_MAG_FILTER, filter);
+		glBindTexture(gs->target, gs->textures[i]);
+		glTexParameteri(gs->target, GL_TEXTURE_MIN_FILTER, filter);
+		glTexParameteri(gs->target, GL_TEXTURE_MAG_FILTER, filter);
 	}
 
 	/* blended region is whole surface minus opaque region: */
@@ -992,13 +999,15 @@ gles2_renderer_read_pixels(struct weston_output *output,
 static void
 gles2_renderer_flush_damage(struct weston_surface *surface)
 {
+	struct gles2_surface_state *gs = get_surface_state(surface);
+
 #ifdef GL_UNPACK_ROW_LENGTH
 	pixman_box32_t *rectangles;
 	void *data;
 	int i, n;
 #endif
 
-	glBindTexture(GL_TEXTURE_2D, surface->textures[0]);
+	glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
 
 	if (!surface->compositor->has_unpack_subimage) {
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
@@ -1027,23 +1036,23 @@ gles2_renderer_flush_damage(struct weston_surface *surface)
 }
 
 static void
-ensure_textures(struct weston_surface *es, int num_textures)
+ensure_textures(struct gles2_surface_state *gs, int num_textures)
 {
 	int i;
 
-	if (num_textures <= es->num_textures)
+	if (num_textures <= gs->num_textures)
 		return;
 
-	for (i = es->num_textures; i < num_textures; i++) {
-		glGenTextures(1, &es->textures[i]);
-		glBindTexture(es->target, es->textures[i]);
-		glTexParameteri(es->target,
+	for (i = gs->num_textures; i < num_textures; i++) {
+		glGenTextures(1, &gs->textures[i]);
+		glBindTexture(gs->target, gs->textures[i]);
+		glTexParameteri(gs->target,
 				GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-		glTexParameteri(es->target,
+		glTexParameteri(gs->target,
 				GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 	}
-	es->num_textures = num_textures;
-	glBindTexture(es->target, 0);
+	gs->num_textures = num_textures;
+	glBindTexture(gs->target, 0);
 }
 
 static void
@@ -1056,22 +1065,22 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 	int i, num_planes;
 
 	if (!buffer) {
-		for (i = 0; i < es->num_images; i++) {
-			ec->destroy_image(gr->egl_display, es->images[i]);
-			es->images[i] = NULL;
+		for (i = 0; i < gs->num_images; i++) {
+			ec->destroy_image(gr->egl_display, gs->images[i]);
+			gs->images[i] = NULL;
 		}
-		es->num_images = 0;
-		glDeleteTextures(es->num_textures, es->textures);
-		es->num_textures = 0;
+		gs->num_images = 0;
+		glDeleteTextures(gs->num_textures, gs->textures);
+		gs->num_textures = 0;
 		return;
 	}
 
 	if (wl_buffer_is_shm(buffer)) {
 		es->pitch = wl_shm_buffer_get_stride(buffer) / 4;
-		es->target = GL_TEXTURE_2D;
+		gs->target = GL_TEXTURE_2D;
 
-		ensure_textures(es, 1);
-		glBindTexture(GL_TEXTURE_2D, es->textures[0]);
+		ensure_textures(gs, 1);
+		glBindTexture(GL_TEXTURE_2D, gs->textures[0]);
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
 			     es->pitch, buffer->height, 0,
 			     GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
@@ -1081,10 +1090,10 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 			gs->shader = &gr->texture_shader_rgba;
 	} else if (ec->query_buffer(gr->egl_display, buffer,
 				    EGL_TEXTURE_FORMAT, &format)) {
-		for (i = 0; i < es->num_images; i++)
-			ec->destroy_image(gr->egl_display, es->images[i]);
-		es->num_images = 0;
-		es->target = GL_TEXTURE_2D;
+		for (i = 0; i < gs->num_images; i++)
+			ec->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:
@@ -1094,7 +1103,7 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 			break;
 		case EGL_TEXTURE_EXTERNAL_WL:
 			num_planes = 1;
-			es->target = GL_TEXTURE_EXTERNAL_OES;
+			gs->target = GL_TEXTURE_EXTERNAL_OES;
 			gs->shader = &gr->texture_shader_egl_external;
 			break;
 		case EGL_TEXTURE_Y_UV_WL:
@@ -1111,25 +1120,25 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 			break;
 		}
 
-		ensure_textures(es, num_planes);
+		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;
-			es->images[i] = ec->create_image(gr->egl_display,
+			gs->images[i] = ec->create_image(gr->egl_display,
 							 NULL,
 							 EGL_WAYLAND_BUFFER_WL,
 							 buffer, attribs);
-			if (!es->images[i]) {
+			if (!gs->images[i]) {
 				weston_log("failed to create img for plane %d\n", i);
 				continue;
 			}
-			es->num_images++;
+			gs->num_images++;
 
 			glActiveTexture(GL_TEXTURE0 + i);
-			glBindTexture(es->target, es->textures[i]);
-			ec->image_target_texture_2d(es->target,
-						    es->images[i]);
+			glBindTexture(gs->target, gs->textures[i]);
+			ec->image_target_texture_2d(gs->target,
+						    gs->images[i]);
 		}
 
 		es->pitch = buffer->width;
@@ -1176,10 +1185,10 @@ gles2_renderer_destroy_surface(struct weston_surface *surface)
 	struct gles2_renderer *gr = get_renderer(ec);
 	int i;
 
-	glDeleteTextures(surface->num_textures, surface->textures);
+	glDeleteTextures(gs->num_textures, gs->textures);
 
-	for (i = 0; i < surface->num_images; i++)
-		ec->destroy_image(gr->egl_display, surface->images[i]);
+	for (i = 0; i < gs->num_images; i++)
+		ec->destroy_image(gr->egl_display, gs->images[i]);
 
 	free(gs);
 }
-- 
1.7.12.4



More information about the wayland-devel mailing list