[PATCH 9/9] compositor: Add a function to set surface color in weston_renderer and move color state to gles2-renderer.

John Kåre Alsaker john.kare.alsaker at gmail.com
Sat Sep 15 11:34:07 PDT 2012


---
 src/compositor.c     |  6 +-----
 src/compositor.h     |  4 +++-
 src/gles2-renderer.c | 19 ++++++++++++++++++-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 45eeb5f..961009a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -274,11 +274,7 @@ WL_EXPORT void
 weston_surface_set_color(struct weston_surface *surface,
 		 GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
 {
-	surface->color[0] = red;
-	surface->color[1] = green;
-	surface->color[2] = blue;
-	surface->color[3] = alpha;
-	surface->shader = &surface->compositor->solid_shader;
+	surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha);
 }
 
 WL_EXPORT void
diff --git a/src/compositor.h b/src/compositor.h
index 776048f..cf5d7e5 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -279,6 +279,9 @@ struct weston_renderer {
 	void (*flush_damage)(struct weston_surface *surface);
 	void (*attach)(struct weston_surface *es, struct wl_buffer *buffer);
 	int (*create_surface)(struct weston_surface *surface);
+	void (*surface_set_color)(struct weston_surface *surface,
+			       float red, float green,
+			       float blue, float alpha);
 	void (*destroy_surface)(struct weston_surface *surface);
 };
 
@@ -413,7 +416,6 @@ struct weston_surface {
 	struct wl_list link;
 	struct wl_list layer_link;
 	struct weston_shader *shader;
-	GLfloat color[4];
 	GLfloat alpha;
 	struct weston_plane *plane;
 
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index 24aa19d..683ca48 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -35,6 +35,7 @@ struct gles2_output_state {
 };
 
 struct gles2_surface_state {
+	GLfloat color[4];
 };
 
 struct gles2_renderer {
@@ -645,10 +646,11 @@ weston_shader_uniforms(struct weston_shader *shader,
 		       struct weston_output *output)
 {
 	int i;
+	struct gles2_surface_state *state = get_surface_state(surface);
 
 	glUniformMatrix4fv(shader->proj_uniform,
 			   1, GL_FALSE, output->matrix.d);
-	glUniform4fv(shader->color_uniform, 1, surface->color);
+	glUniform4fv(shader->color_uniform, 1, state->color);
 	glUniform1f(shader->alpha_uniform, surface->alpha);
 
 	for (i = 0; i < surface->num_textures; i++)
@@ -981,6 +983,20 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 	}
 }
 
+static void
+gles2_renderer_surface_set_color(struct weston_surface *surface,
+		 float red, float green, float blue, float alpha)
+{
+	struct gles2_surface_state *state = get_surface_state(surface);
+
+	state->color[0] = red;
+	state->color[1] = green;
+	state->color[2] = blue;
+	state->color[3] = alpha;
+
+	surface->shader = &surface->compositor->solid_shader;
+}
+
 static int
 gles2_renderer_create_surface(struct weston_surface *surface)
 {
@@ -1238,6 +1254,7 @@ create_renderer(struct weston_compositor *ec)
 	renderer->base.flush_damage = gles2_renderer_flush_damage;
 	renderer->base.attach = gles2_renderer_attach;
 	renderer->base.create_surface = gles2_renderer_create_surface;
+	renderer->base.surface_set_color = gles2_renderer_surface_set_color;
 	renderer->base.destroy_surface = gles2_renderer_destroy_surface;
 
 	ec->renderer = &renderer->base;
-- 
1.7.12



More information about the wayland-devel mailing list