[PATCH v5 05/11] 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
Fri Nov 9 12:21:14 PST 2012
---
src/compositor.c | 11 ++++++-----
src/compositor.h | 7 ++++++-
src/gles2-renderer.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
src/noop-renderer.c | 14 ++++++++++++++
4 files changed, 72 insertions(+), 7 deletions(-)
diff --git a/src/compositor.c b/src/compositor.c
index 83bd244..bd95e8c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -237,6 +237,11 @@ weston_surface_create(struct weston_compositor *compositor)
surface->alpha = 1.0;
surface->pitch = 1;
+ if (compositor->renderer->create_surface(surface) < 0) {
+ free(surface);
+ return NULL;
+ }
+
surface->num_textures = 0;
surface->num_images = 0;
pixman_region32_init(&surface->texture_damage);
@@ -276,11 +281,7 @@ WL_EXPORT void
weston_surface_set_color(struct weston_surface *surface,
float red, float green, float blue, float 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 0992231..35b64f2 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -284,6 +284,10 @@ struct weston_renderer {
pixman_region32_t *output_damage);
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);
};
@@ -421,10 +425,11 @@ struct weston_surface {
struct wl_list link;
struct wl_list layer_link;
struct weston_shader *shader;
- GLfloat color[4];
float alpha;
struct weston_plane *plane;
+ void *renderer_state;
+
/* Surface geometry state, mutable.
* If you change anything, set dirty = 1.
* That includes the transformations referenced from the list.
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index 8fb4f21..f37249e 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -35,6 +35,10 @@ struct gles2_output_state {
EGLSurface egl_surface;
};
+struct gles2_surface_state {
+ GLfloat color[4];
+};
+
struct gles2_renderer {
struct weston_renderer base;
int fragment_shader_debug;
@@ -56,6 +60,12 @@ get_output_state(struct weston_output *output)
return (struct gles2_output_state *)output->renderer_state;
}
+static inline struct gles2_surface_state *
+get_surface_state(struct weston_surface *surface)
+{
+ return (struct gles2_surface_state *)surface->renderer_state;
+}
+
static inline struct gles2_renderer *
get_renderer(struct weston_compositor *ec)
{
@@ -648,10 +658,11 @@ weston_shader_uniforms(struct weston_shader *shader,
struct weston_output *output)
{
int i;
+ struct gles2_surface_state *gs = 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, gs->color);
glUniform1f(shader->alpha_uniform, surface->alpha);
for (i = 0; i < surface->num_textures; i++)
@@ -1123,8 +1134,38 @@ 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 *gs = get_surface_state(surface);
+
+ gs->color[0] = red;
+ gs->color[1] = green;
+ gs->color[2] = blue;
+ gs->color[3] = alpha;
+
+ surface->shader = &surface->compositor->solid_shader;
+}
+
+static int
+gles2_renderer_create_surface(struct weston_surface *surface)
+{
+ struct gles2_surface_state *gs;
+
+ gs = calloc(1, sizeof *gs);
+
+ if (!gs)
+ return -1;
+
+ surface->renderer_state = gs;
+
+ return 0;
+}
+
+static void
gles2_renderer_destroy_surface(struct weston_surface *surface)
{
+ struct gles2_surface_state *gs = get_surface_state(surface);
struct weston_compositor *ec = surface->compositor;
struct gles2_renderer *gr = get_renderer(ec);
int i;
@@ -1133,6 +1174,8 @@ gles2_renderer_destroy_surface(struct weston_surface *surface)
for (i = 0; i < surface->num_images; i++)
ec->destroy_image(gr->egl_display, surface->images[i]);
+
+ free(gs);
}
static const char vertex_shader[] =
@@ -1607,6 +1650,8 @@ gles2_renderer_init(struct weston_compositor *ec, EGLNativeDisplayType display,
gr->base.repaint_output = gles2_renderer_repaint_output;
gr->base.flush_damage = gles2_renderer_flush_damage;
gr->base.attach = gles2_renderer_attach;
+ gr->base.create_surface = gles2_renderer_create_surface;
+ gr->base.surface_set_color = gles2_renderer_surface_set_color;
gr->base.destroy_surface = gles2_renderer_destroy_surface;
gr->egl_display = eglGetDisplay(display);
diff --git a/src/noop-renderer.c b/src/noop-renderer.c
index 76f1e8f..b42f26f 100644
--- a/src/noop-renderer.c
+++ b/src/noop-renderer.c
@@ -51,6 +51,18 @@ noop_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
{
}
+static int
+noop_renderer_create_surface(struct weston_surface *surface)
+{
+ return 0;
+}
+
+static void
+noop_renderer_surface_set_color(struct weston_surface *surface,
+ float red, float green, float blue, float alpha)
+{
+}
+
static void
noop_renderer_destroy_surface(struct weston_surface *surface)
{
@@ -77,6 +89,8 @@ noop_renderer_init(struct weston_compositor *ec)
renderer->repaint_output = noop_renderer_repaint_output;
renderer->flush_damage = noop_renderer_flush_damage;
renderer->attach = noop_renderer_attach;
+ renderer->create_surface = noop_renderer_create_surface;
+ renderer->surface_set_color = noop_renderer_surface_set_color;
renderer->destroy_surface = noop_renderer_destroy_surface;
ec->renderer = renderer;
--
1.8.0
More information about the wayland-devel
mailing list