compositor: Use surface_attached_to list for shm-buffers

This commit is contained in:
Benjamin Franzke
2011-03-07 18:04:59 +01:00
committed by Kristian Høgsberg
parent 0c347f0d72
commit bab41fb70c
3 changed files with 19 additions and 12 deletions
+4
View File
@@ -132,6 +132,7 @@ wlsc_surface_create(struct wlsc_compositor *compositor,
wl_list_init(&surface->surface.destroy_listener_list); wl_list_init(&surface->surface.destroy_listener_list);
wl_list_init(&surface->link); wl_list_init(&surface->link);
wl_list_init(&surface->buffer_link);
surface->map_type = WLSC_SURFACE_MAP_UNMAPPED; surface->map_type = WLSC_SURFACE_MAP_UNMAPPED;
glGenTextures(1, &surface->texture); glGenTextures(1, &surface->texture);
@@ -145,6 +146,7 @@ wlsc_surface_create(struct wlsc_compositor *compositor,
surface->visual = NULL; surface->visual = NULL;
surface->image = EGL_NO_IMAGE_KHR; surface->image = EGL_NO_IMAGE_KHR;
surface->saved_texture = 0; surface->saved_texture = 0;
surface->buffer = NULL;
surface->x = x; surface->x = x;
surface->y = y; surface->y = y;
surface->width = width; surface->width = width;
@@ -212,6 +214,8 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
eglDestroyImageKHR(surface->compositor->display, eglDestroyImageKHR(surface->compositor->display,
surface->image); surface->image);
wl_list_remove(&surface->buffer_link);
time = get_time(); time = get_time();
wl_list_for_each_safe(l, next, wl_list_for_each_safe(l, next,
&surface->surface.destroy_listener_list, link) &surface->surface.destroy_listener_list, link)
+1
View File
@@ -160,6 +160,7 @@ struct wlsc_surface {
int32_t x, y, width, height; int32_t x, y, width, height;
int32_t saved_x, saved_y; int32_t saved_x, saved_y;
struct wl_list link; struct wl_list link;
struct wl_list buffer_link;
struct wlsc_matrix matrix; struct wlsc_matrix matrix;
struct wlsc_matrix matrix_inv; struct wlsc_matrix matrix_inv;
struct wl_visual *visual; struct wl_visual *visual;
+13 -11
View File
@@ -26,6 +26,7 @@
struct wlsc_shm_buffer { struct wlsc_shm_buffer {
struct wl_buffer buffer; struct wl_buffer buffer;
struct wl_list surfaces_attached_to;
int32_t stride; int32_t stride;
void *data; void *data;
int mapped; int mapped;
@@ -36,18 +37,18 @@ destroy_buffer(struct wl_resource *resource, struct wl_client *client)
{ {
struct wlsc_shm_buffer *buffer = struct wlsc_shm_buffer *buffer =
container_of(resource, struct wlsc_shm_buffer, buffer.resource); container_of(resource, struct wlsc_shm_buffer, buffer.resource);
struct wlsc_compositor *compositor = struct wlsc_surface *es, *next;
(struct wlsc_compositor *) buffer->buffer.compositor;
struct wlsc_surface *es;
if (buffer->mapped) if (buffer->mapped)
munmap(buffer->data, buffer->stride * buffer->buffer.height); munmap(buffer->data, buffer->stride * buffer->buffer.height);
else else
free(buffer->data); free(buffer->data);
wl_list_for_each(es, &compositor->surface_list, link) wl_list_for_each_safe(es, next, &buffer->surfaces_attached_to,
if (es->buffer == (struct wl_buffer *) buffer) buffer_link) {
es->buffer = NULL; es->buffer = NULL;
wl_list_remove(&es->buffer_link);
}
free(buffer); free(buffer);
} }
@@ -58,14 +59,9 @@ buffer_damage(struct wl_client *client, struct wl_buffer *buffer_base,
{ {
struct wlsc_shm_buffer *buffer = struct wlsc_shm_buffer *buffer =
(struct wlsc_shm_buffer *) buffer_base; (struct wlsc_shm_buffer *) buffer_base;
struct wlsc_compositor *compositor =
(struct wlsc_compositor *) buffer->buffer.compositor;
struct wlsc_surface *es; struct wlsc_surface *es;
wl_list_for_each(es, &compositor->surface_list, link) { wl_list_for_each(es, &buffer->surfaces_attached_to, buffer_link) {
if (es->buffer != buffer_base)
continue;
glBindTexture(GL_TEXTURE_2D, es->texture); glBindTexture(GL_TEXTURE_2D, es->texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
buffer->buffer.width, buffer->buffer.height, 0, buffer->buffer.width, buffer->buffer.height, 0,
@@ -111,6 +107,10 @@ wlsc_shm_buffer_attach(struct wl_buffer *buffer_base,
buffer->buffer.width, buffer->buffer.height, 0, buffer->buffer.width, buffer->buffer.height, 0,
GL_BGRA_EXT, GL_UNSIGNED_BYTE, buffer->data); GL_BGRA_EXT, GL_UNSIGNED_BYTE, buffer->data);
es->visual = buffer->buffer.visual; es->visual = buffer->buffer.visual;
if (es->buffer)
wl_list_remove(&es->buffer_link);
wl_list_insert(&buffer->surfaces_attached_to, &es->buffer_link);
} }
static struct wlsc_shm_buffer * static struct wlsc_shm_buffer *
@@ -132,6 +132,8 @@ wlsc_shm_buffer_init(struct wlsc_compositor *compositor,
buffer->stride = stride; buffer->stride = stride;
buffer->data = data; buffer->data = data;
wl_list_init(&buffer->surfaces_attached_to);
buffer->buffer.resource.object.interface = &wl_buffer_interface; buffer->buffer.resource.object.interface = &wl_buffer_interface;
buffer->buffer.resource.object.implementation = (void (**)(void)) buffer->buffer.resource.object.implementation = (void (**)(void))
&buffer_interface; &buffer_interface;