wayland: Move some buffer manipulation functions to meta-wayland-buffer

This commit is contained in:
Jasper St. Pierre 2014-10-07 19:48:49 -07:00
parent c1613a16c0
commit f658740043
3 changed files with 68 additions and 38 deletions

View File

@ -26,6 +26,10 @@
#include "meta-wayland-buffer.h"
#include <clutter/clutter.h>
#include <cogl/cogl-wayland-server.h>
#include <meta/util.h>
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);
}
}
}

View File

@ -26,6 +26,7 @@
#define META_WAYLAND_BUFFER_H
#include <cogl/cogl.h>
#include <cairo.h>
#include <wayland-server.h>
#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 */

View File

@ -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);
/* 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);
shm_buffer = wl_shm_buffer_get (surface->buffer->resource);
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);
}
}