wayland: Move some buffer manipulation functions to meta-wayland-buffer
This commit is contained in:
parent
c1613a16c0
commit
f658740043
@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
#include "meta-wayland-buffer.h"
|
#include "meta-wayland-buffer.h"
|
||||||
|
|
||||||
|
#include <clutter/clutter.h>
|
||||||
|
#include <cogl/cogl-wayland-server.h>
|
||||||
|
#include <meta/util.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
meta_wayland_buffer_destroy_handler (struct wl_listener *listener,
|
meta_wayland_buffer_destroy_handler (struct wl_listener *listener,
|
||||||
void *data)
|
void *data)
|
||||||
@ -80,3 +84,54 @@ meta_wayland_buffer_from_resource (struct wl_resource *resource)
|
|||||||
|
|
||||||
return buffer;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#define META_WAYLAND_BUFFER_H
|
#define META_WAYLAND_BUFFER_H
|
||||||
|
|
||||||
#include <cogl/cogl.h>
|
#include <cogl/cogl.h>
|
||||||
|
#include <cairo.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
|
||||||
#include "meta-wayland-types.h"
|
#include "meta-wayland-types.h"
|
||||||
@ -43,5 +44,8 @@ struct _MetaWaylandBuffer
|
|||||||
MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource);
|
MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource);
|
||||||
void meta_wayland_buffer_ref (MetaWaylandBuffer *buffer);
|
void meta_wayland_buffer_ref (MetaWaylandBuffer *buffer);
|
||||||
void meta_wayland_buffer_unref (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 */
|
#endif /* META_WAYLAND_BUFFER_H */
|
||||||
|
@ -107,67 +107,38 @@ static void
|
|||||||
surface_process_damage (MetaWaylandSurface *surface,
|
surface_process_damage (MetaWaylandSurface *surface,
|
||||||
cairo_region_t *region)
|
cairo_region_t *region)
|
||||||
{
|
{
|
||||||
int i, n_rectangles;
|
|
||||||
cairo_rectangle_int_t buffer_rect;
|
cairo_rectangle_int_t buffer_rect;
|
||||||
int scale = surface->scale;
|
int scale = surface->scale;
|
||||||
CoglTexture *texture;
|
int i, n_rectangles;
|
||||||
struct wl_shm_buffer *shm_buffer;
|
|
||||||
|
|
||||||
/* Damage without a buffer makes no sense so ignore that, otherwise we would crash */
|
|
||||||
if (!surface->buffer)
|
if (!surface->buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
texture = surface->buffer->texture;
|
|
||||||
|
|
||||||
buffer_rect.x = 0;
|
buffer_rect.x = 0;
|
||||||
buffer_rect.y = 0;
|
buffer_rect.y = 0;
|
||||||
buffer_rect.width = cogl_texture_get_width (surface->buffer->texture);
|
buffer_rect.width = cogl_texture_get_width (surface->buffer->texture);
|
||||||
buffer_rect.height = cogl_texture_get_height (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
|
/* 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);
|
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);
|
n_rectangles = cairo_region_num_rectangles (region);
|
||||||
|
|
||||||
shm_buffer = wl_shm_buffer_get (surface->buffer->resource);
|
|
||||||
|
|
||||||
for (i = 0; i < n_rectangles; i++)
|
for (i = 0; i < n_rectangles; i++)
|
||||||
{
|
{
|
||||||
cairo_rectangle_int_t rect;
|
cairo_rectangle_int_t rect;
|
||||||
cairo_region_get_rectangle (region, i, &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,
|
meta_surface_actor_process_damage (surface->surface_actor,
|
||||||
rect.x * scale, rect.y * scale, rect.width * scale, rect.height * scale);
|
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
|
static void
|
||||||
cursor_surface_commit (MetaWaylandSurface *surface,
|
cursor_surface_commit (MetaWaylandSurface *surface,
|
||||||
MetaWaylandPendingState *pending)
|
MetaWaylandPendingState *pending)
|
||||||
@ -426,8 +397,8 @@ commit_pending_state (MetaWaylandSurface *surface,
|
|||||||
|
|
||||||
if (pending->buffer)
|
if (pending->buffer)
|
||||||
{
|
{
|
||||||
ensure_buffer_texture (pending->buffer);
|
CoglTexture *texture = meta_wayland_buffer_ensure_texture (pending->buffer);
|
||||||
meta_surface_actor_wayland_set_texture (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), pending->buffer->texture);
|
meta_surface_actor_wayland_set_texture (META_SURFACE_ACTOR_WAYLAND (surface->surface_actor), texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user