summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnder Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>2012-03-27 17:36:40 +0300
committerKristian Høgsberg <krh@bitplanet.net>2012-03-27 16:36:53 -0400
commite11683aab28e297c1162d00dd3acba4a8c265538 (patch)
tree1e5016b43655cfe09d74b068c64aa322e8f95028
parentd6ea33dfd6f71e070f1be77cf9c81707d818f468 (diff)
compositor: refactor surface_attach()
surface_attach() does two things: sets up a new buffer as the contents of the given surface and then calls into shell so it can setup the position of the surface and map it if necessary. However we do not want the shell to meddle with some internal surfaces such as drag surfaces. The intention of this refactoring is to make room for making the part that calls into shell a virtual function that the compositor can override for these internal surfaces. This changes weston_buffer_attach() so it handle all the logic of tying a buffer to a surface, including unmapping it when the buffer is NULL. The shell map() vs. configure() logic is then split into a another function: surface_configure(). In a later commit, this function will be turned into a function pointer in struct weston_surface.
-rw-r--r--src/compositor.c103
1 files changed, 53 insertions, 50 deletions
diff --git a/src/compositor.c b/src/compositor.c
index 5172c70..2bf375c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -677,6 +677,30 @@ weston_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface)
struct weston_surface *es = (struct weston_surface *) surface;
struct weston_compositor *ec = es->compositor;
+ if (es->buffer) {
+ weston_buffer_post_release(es->buffer);
+ wl_list_remove(&es->buffer_destroy_listener.link);
+ }
+
+ es->buffer = buffer;
+
+ if (!buffer) {
+ if (weston_surface_is_mapped(es))
+ weston_surface_unmap(es);
+ return;
+ }
+
+ buffer->busy_count++;
+ wl_list_insert(es->buffer->resource.destroy_listener_list.prev,
+ &es->buffer_destroy_listener.link);
+
+ if (es->geometry.width != buffer->width ||
+ es->geometry.height != buffer->height) {
+ undef_region(&es->input);
+ pixman_region32_fini(&es->opaque);
+ pixman_region32_init(&es->opaque);
+ }
+
if (!es->texture) {
glGenTextures(1, &es->texture);
glBindTexture(GL_TEXTURE_2D, es->texture);
@@ -697,7 +721,7 @@ weston_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface)
es->image = ec->create_image(ec->display, NULL,
EGL_WAYLAND_BUFFER_WL,
buffer, NULL);
-
+
ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
es->pitch = buffer->width;
@@ -1127,46 +1151,16 @@ weston_surface_assign_output(struct weston_surface *es)
}
static void
-surface_attach(struct wl_client *client,
- struct wl_resource *resource,
- struct wl_resource *buffer_resource, int32_t sx, int32_t sy)
+surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
{
- struct weston_surface *es = resource->data;
struct weston_shell *shell = es->compositor->shell;
- struct wl_buffer *buffer;
-
- if (!buffer_resource && !weston_surface_is_mapped(es))
- return;
-
- if (es->buffer) {
- weston_buffer_post_release(es->buffer);
- wl_list_remove(&es->buffer_destroy_listener.link);
- }
-
- if (!buffer_resource && weston_surface_is_mapped(es)) {
- weston_surface_unmap(es);
- es->buffer = NULL;
- return;
- }
-
- buffer = buffer_resource->data;
- buffer->busy_count++;
- es->buffer = buffer;
- wl_list_insert(es->buffer->resource.destroy_listener_list.prev,
- &es->buffer_destroy_listener.link);
-
- if (es->geometry.width != buffer->width ||
- es->geometry.height != buffer->height) {
- undef_region(&es->input);
- pixman_region32_fini(&es->opaque);
- pixman_region32_init(&es->opaque);
- }
if (!weston_surface_is_mapped(es)) {
- shell->map(shell, es, buffer->width, buffer->height, sx, sy);
+ shell->map(shell, es, es->buffer->width, es->buffer->height,
+ sx, sy);
} else if (es->force_configure || sx != 0 || sy != 0 ||
- es->geometry.width != buffer->width ||
- es->geometry.height != buffer->height) {
+ es->geometry.width != es->buffer->width ||
+ es->geometry.height != es->buffer->height) {
GLfloat from_x, from_y;
GLfloat to_x, to_y;
@@ -1175,11 +1169,26 @@ surface_attach(struct wl_client *client,
shell->configure(shell, es,
es->geometry.x + to_x - from_x,
es->geometry.y + to_y - from_y,
- buffer->width, buffer->height);
+ es->buffer->width, es->buffer->height);
es->force_configure = 0;
}
+}
+
+static void
+surface_attach(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *buffer_resource, int32_t sx, int32_t sy)
+{
+ struct weston_surface *es = resource->data;
+ struct wl_buffer *buffer = NULL;
+
+ if (buffer_resource)
+ buffer = buffer_resource->data;
weston_buffer_attach(buffer, &es->surface);
+
+ if (buffer)
+ surface_configure(es, sx, sy);
}
static void
@@ -1882,7 +1891,7 @@ input_device_attach(struct wl_client *client,
{
struct weston_input_device *device = resource->data;
struct weston_compositor *compositor = device->compositor;
- struct wl_buffer *buffer;
+ struct wl_buffer *buffer = NULL;
if (time < device->input_device.pointer_focus_time)
return;
@@ -1891,14 +1900,13 @@ input_device_attach(struct wl_client *client,
if (device->input_device.pointer_focus->resource.client != client)
return;
- if (device->sprite->buffer)
- wl_list_remove(&device->sprite->buffer_destroy_listener.link);
+ if (buffer_resource)
+ buffer = buffer_resource->data;
+
+ weston_buffer_attach(buffer, &device->sprite->surface);
- if (!buffer_resource) {
- if (weston_surface_is_mapped(device->sprite))
- weston_surface_unmap(device->sprite);
+ if (!buffer)
return;
- }
if (!weston_surface_is_mapped(device->sprite)) {
wl_list_insert(&compositor->cursor_layer.surface_list,
@@ -1906,7 +1914,7 @@ input_device_attach(struct wl_client *client,
weston_surface_assign_output(device->sprite);
}
- buffer = buffer_resource->data;
+
device->hotspot_x = x;
device->hotspot_y = y;
weston_surface_configure(device->sprite,
@@ -1914,11 +1922,6 @@ input_device_attach(struct wl_client *client,
device->input_device.y - device->hotspot_y,
buffer->width, buffer->height);
- device->sprite->buffer = buffer;
- wl_list_insert(buffer->resource.destroy_listener_list.prev,
- &device->sprite->buffer_destroy_listener.link);
-
- weston_buffer_attach(buffer, &device->sprite->surface);
surface_damage(NULL, &device->sprite->surface.resource,
0, 0, buffer->width, buffer->height);
}