From f658740043e43340b5a92bd95022ed2cb5af8896 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 7 Oct 2014 19:48:49 -0700 Subject: wayland: Move some buffer manipulation functions to meta-wayland-buffer --- src/wayland/meta-wayland-buffer.c | 55 ++++++++++++++++++++++++++++++++++++++ src/wayland/meta-wayland-buffer.h | 4 +++ src/wayland/meta-wayland-surface.c | 47 +++++++------------------------- 3 files changed, 68 insertions(+), 38 deletions(-) diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 1c1e76e7c..40db3b0fb 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -26,6 +26,10 @@ #include "meta-wayland-buffer.h" +#include +#include +#include + static void meta_wayland_buffer_destroy_handler (struct wl_listener *listener, void *data) @@ -80,3 +84,54 @@ meta_wayland_buffer_from_resource (struct wl_resource *resource) return buffer; } + +CoglTexture * +meta_wayland_buffer_ensure_texture (MetaWaylandBuffer *buffer) +{ + CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); + CoglError *catch_error = NULL; + CoglTexture *texture; + + if (buffer->texture) + goto out; + + texture = COGL_TEXTURE (cogl_wayland_texture_2d_new_from_buffer (ctx, + buffer->resource, + &catch_error)); + if (!texture) + { + cogl_error_free (catch_error); + meta_fatal ("Could not import pending buffer, ignoring commit\n"); + } + + buffer->texture = texture; + + out: + return buffer->texture; +} + +void +meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer, + cairo_region_t *region) +{ + struct wl_shm_buffer *shm_buffer; + + shm_buffer = wl_shm_buffer_get (buffer->resource); + + if (shm_buffer) + { + int i, n_rectangles; + + n_rectangles = cairo_region_num_rectangles (region); + + for (i = 0; i < n_rectangles; i++) + { + cairo_rectangle_int_t rect; + cairo_region_get_rectangle (region, i, &rect); + cogl_wayland_texture_set_region_from_shm_buffer (buffer->texture, + rect.x, rect.y, rect.width, rect.height, + shm_buffer, + rect.x, rect.y, 0, NULL); + } + } +} diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h index 1b0833395..8d81c7226 100644 --- a/src/wayland/meta-wayland-buffer.h +++ b/src/wayland/meta-wayland-buffer.h @@ -26,6 +26,7 @@ #define META_WAYLAND_BUFFER_H #include +#include #include #include "meta-wayland-types.h" @@ -43,5 +44,8 @@ struct _MetaWaylandBuffer MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource); void meta_wayland_buffer_ref (MetaWaylandBuffer *buffer); void meta_wayland_buffer_unref (MetaWaylandBuffer *buffer); +CoglTexture * meta_wayland_buffer_ensure_texture (MetaWaylandBuffer *buffer); +void meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer, + cairo_region_t *region); #endif /* META_WAYLAND_BUFFER_H */ diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c index e17888947..d7cc8a61e 100644 --- a/src/wayland/meta-wayland-surface.c +++ b/src/wayland/meta-wayland-surface.c @@ -107,67 +107,38 @@ static void surface_process_damage (MetaWaylandSurface *surface, cairo_region_t *region) { - int i, n_rectangles; cairo_rectangle_int_t buffer_rect; int scale = surface->scale; - CoglTexture *texture; - struct wl_shm_buffer *shm_buffer; + int i, n_rectangles; - /* Damage without a buffer makes no sense so ignore that, otherwise we would crash */ if (!surface->buffer) return; - texture = surface->buffer->texture; - buffer_rect.x = 0; buffer_rect.y = 0; buffer_rect.width = cogl_texture_get_width (surface->buffer->texture); buffer_rect.height = cogl_texture_get_height (surface->buffer->texture); /* The region will get destroyed after this call anyway so we can - just modify it here to avoid a copy */ + * just modify it here to avoid a copy. */ cairo_region_intersect_rectangle (region, &buffer_rect); - n_rectangles = cairo_region_num_rectangles (region); - - shm_buffer = wl_shm_buffer_get (surface->buffer->resource); + /* First update the buffer. */ + meta_wayland_buffer_process_damage (surface->buffer, region); + /* Now damage the actor. */ + /* XXX: Should this be a signal / callback on MetaWaylandBuffer instead? */ + n_rectangles = cairo_region_num_rectangles (region); for (i = 0; i < n_rectangles; i++) { cairo_rectangle_int_t rect; cairo_region_get_rectangle (region, i, &rect); - if (shm_buffer) - cogl_wayland_texture_set_region_from_shm_buffer (texture, rect.x, rect.y, rect.width, rect.height, shm_buffer, rect.x, rect.y, 0, NULL); - meta_surface_actor_process_damage (surface->surface_actor, rect.x * scale, rect.y * scale, rect.width * scale, rect.height * scale); } } -static void -ensure_buffer_texture (MetaWaylandBuffer *buffer) -{ - CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); - CoglError *catch_error = NULL; - CoglTexture *texture; - - if (buffer->texture) - return; - - texture = COGL_TEXTURE (cogl_wayland_texture_2d_new_from_buffer (ctx, - buffer->resource, - &catch_error)); - if (!texture) - { - cogl_error_free (catch_error); - meta_warning ("Could not import pending buffer, ignoring commit\n"); - return; - } - - buffer->texture = texture; -} - static void cursor_surface_commit (MetaWaylandSurface *surface, MetaWaylandPendingState *pending) @@ -426,8 +397,8 @@ commit_pending_state (MetaWaylandSurface *surface, if (pending->buffer) { - ensure_buffer_texture (pending->buffer); - meta_surface_actor_wayland_set_texture (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), pending->buffer->texture); + CoglTexture *texture = meta_wayland_buffer_ensure_texture (pending->buffer); + meta_surface_actor_wayland_set_texture (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), texture); } } -- cgit v1.2.1