2014-10-07 22:39:00 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Endless Mobile
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "meta-wayland-buffer.h"
|
2017-07-11 11:03:26 -04:00
|
|
|
#include "meta-wayland-dma-buf.h"
|
2014-10-07 22:39:00 -04:00
|
|
|
|
2014-10-07 22:48:49 -04:00
|
|
|
#include <clutter/clutter.h>
|
2016-10-20 03:35:29 -04:00
|
|
|
#include <cogl/cogl-egl.h>
|
2014-10-07 22:48:49 -04:00
|
|
|
#include <meta/util.h>
|
|
|
|
|
2017-07-11 11:03:26 -04:00
|
|
|
#include <drm_fourcc.h>
|
|
|
|
|
|
|
|
#ifndef DRM_FORMAT_MOD_INVALID
|
|
|
|
#define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
|
|
|
|
#endif
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
|
2016-03-15 00:46:06 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RESOURCE_DESTROYED,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
guint signals[LAST_SIGNAL];
|
|
|
|
|
2016-02-26 04:47:21 -05:00
|
|
|
G_DEFINE_TYPE (MetaWaylandBuffer, meta_wayland_buffer, G_TYPE_OBJECT);
|
|
|
|
|
2014-10-07 22:39:00 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_buffer_destroy_handler (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
MetaWaylandBuffer *buffer =
|
|
|
|
wl_container_of (listener, buffer, destroy_listener);
|
|
|
|
|
2016-02-26 04:47:21 -05:00
|
|
|
buffer->resource = NULL;
|
2016-03-15 00:46:06 -04:00
|
|
|
g_signal_emit (buffer, signals[RESOURCE_DESTROYED], 0);
|
2016-02-26 04:47:21 -05:00
|
|
|
g_object_unref (buffer);
|
2014-10-07 22:39:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaWaylandBuffer *
|
|
|
|
meta_wayland_buffer_from_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
MetaWaylandBuffer *buffer;
|
|
|
|
struct wl_listener *listener;
|
|
|
|
|
|
|
|
listener =
|
|
|
|
wl_resource_get_destroy_listener (resource,
|
|
|
|
meta_wayland_buffer_destroy_handler);
|
|
|
|
|
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
buffer = wl_container_of (listener, buffer, destroy_listener);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-26 04:47:21 -05:00
|
|
|
buffer = g_object_new (META_TYPE_WAYLAND_BUFFER, NULL);
|
2014-10-07 22:39:00 -04:00
|
|
|
|
|
|
|
buffer->resource = resource;
|
|
|
|
buffer->destroy_listener.notify = meta_wayland_buffer_destroy_handler;
|
|
|
|
wl_resource_add_destroy_listener (resource, &buffer->destroy_listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2018-05-02 06:27:02 -04:00
|
|
|
struct wl_resource *
|
|
|
|
meta_wayland_buffer_get_resource (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
return buffer->resource;
|
|
|
|
}
|
|
|
|
|
2017-05-05 21:41:51 -04:00
|
|
|
gboolean
|
2016-12-08 22:15:11 -05:00
|
|
|
meta_wayland_buffer_is_realized (MetaWaylandBuffer *buffer)
|
2014-10-07 22:48:49 -04:00
|
|
|
{
|
2016-12-08 22:15:11 -05:00
|
|
|
return buffer->type != META_WAYLAND_BUFFER_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2017-05-05 21:41:51 -04:00
|
|
|
gboolean
|
2016-12-08 22:15:11 -05:00
|
|
|
meta_wayland_buffer_realize (MetaWaylandBuffer *buffer)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
|
|
|
EGLint format;
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
EGLDisplay egl_display = cogl_egl_context_get_egl_display (cogl_context);
|
2016-12-08 22:15:11 -05:00
|
|
|
MetaWaylandEglStream *stream;
|
2017-07-11 11:03:26 -04:00
|
|
|
MetaWaylandDmaBufBuffer *dma_buf;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
if (wl_shm_buffer_get (buffer->resource) != NULL)
|
2016-12-08 22:15:11 -05:00
|
|
|
{
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_SHM;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
if (meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_TEXTURE_FORMAT, &format,
|
|
|
|
NULL))
|
2016-12-08 22:15:11 -05:00
|
|
|
{
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_IMAGE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
stream = meta_wayland_egl_stream_new (buffer, NULL);
|
|
|
|
if (stream)
|
|
|
|
{
|
2017-05-05 21:23:57 -04:00
|
|
|
CoglTexture2D *texture;
|
|
|
|
|
|
|
|
texture = meta_wayland_egl_stream_create_texture (stream, NULL);
|
|
|
|
if (!texture)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-05-05 21:41:51 -04:00
|
|
|
buffer->egl_stream.stream = stream;
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_STREAM;
|
2017-05-05 21:23:57 -04:00
|
|
|
buffer->texture = COGL_TEXTURE (texture);
|
|
|
|
buffer->is_y_inverted = meta_wayland_egl_stream_is_y_inverted (stream);
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-10-20 03:59:09 -04:00
|
|
|
|
2017-07-11 11:03:26 -04:00
|
|
|
dma_buf = meta_wayland_dma_buf_from_buffer (buffer);
|
|
|
|
if (dma_buf)
|
|
|
|
{
|
|
|
|
buffer->dma_buf.dma_buf = dma_buf;
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_DMA_BUF;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
return FALSE;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
|
|
|
|
CoglPixelFormat *format_out,
|
|
|
|
CoglTextureComponents *components_out)
|
|
|
|
{
|
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglTextureComponents components = COGL_TEXTURE_COMPONENTS_RGBA;
|
|
|
|
|
|
|
|
switch (wl_shm_buffer_get_format (shm_buffer))
|
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
break;
|
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888;
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format_out)
|
|
|
|
*format_out = format;
|
|
|
|
if (components_out)
|
|
|
|
*components_out = components;
|
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
static gboolean
|
|
|
|
shm_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
struct wl_shm_buffer *shm_buffer;
|
|
|
|
int stride, width, height;
|
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglTextureComponents components;
|
|
|
|
CoglBitmap *bitmap;
|
|
|
|
CoglTexture *texture;
|
2016-01-31 15:57:29 -05:00
|
|
|
|
2014-10-07 22:48:49 -04:00
|
|
|
if (buffer->texture)
|
2016-10-20 03:35:29 -04:00
|
|
|
return TRUE;
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2015-01-09 10:09:23 -05:00
|
|
|
shm_buffer = wl_shm_buffer_get (buffer->resource);
|
2016-10-20 03:35:29 -04:00
|
|
|
stride = wl_shm_buffer_get_stride (shm_buffer);
|
|
|
|
width = wl_shm_buffer_get_width (shm_buffer);
|
|
|
|
height = wl_shm_buffer_get_height (shm_buffer);
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access (shm_buffer);
|
|
|
|
|
|
|
|
shm_buffer_get_cogl_pixel_format (shm_buffer, &format, &components);
|
|
|
|
|
|
|
|
bitmap = cogl_bitmap_new_for_data (cogl_context,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
stride,
|
|
|
|
wl_shm_buffer_get_data (shm_buffer));
|
|
|
|
|
|
|
|
texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap));
|
|
|
|
cogl_texture_set_components (COGL_TEXTURE (texture), components);
|
|
|
|
|
|
|
|
cogl_object_unref (bitmap);
|
|
|
|
|
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (texture), error))
|
|
|
|
g_clear_pointer (&texture, cogl_object_unref);
|
|
|
|
|
|
|
|
wl_shm_buffer_end_access (shm_buffer);
|
|
|
|
|
|
|
|
buffer->texture = texture;
|
2016-10-20 03:44:27 -04:00
|
|
|
buffer->is_y_inverted = TRUE;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
if (!buffer->texture)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
egl_image_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
EGLDisplay egl_display = cogl_egl_context_get_egl_display (cogl_context);
|
2016-10-20 03:44:27 -04:00
|
|
|
int format, width, height, y_inverted;
|
2016-10-20 03:35:29 -04:00
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
EGLImageKHR egl_image;
|
|
|
|
CoglTexture2D *texture;
|
|
|
|
|
|
|
|
if (buffer->texture)
|
|
|
|
return TRUE;
|
2015-01-09 10:09:23 -05:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_TEXTURE_FORMAT, &format,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
2015-01-09 10:09:23 -05:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_WIDTH, &width,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
2015-01-09 10:09:23 -05:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_HEIGHT, &height,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
if (!meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_WAYLAND_Y_INVERTED_WL, &y_inverted,
|
|
|
|
NULL))
|
|
|
|
y_inverted = EGL_TRUE;
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case EGL_TEXTURE_RGB:
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_RGB_888;
|
|
|
|
break;
|
|
|
|
case EGL_TEXTURE_RGBA:
|
|
|
|
cogl_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Unsupported buffer format %d", format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-11 08:30:06 -04:00
|
|
|
/* The WL_bind_wayland_display spec states that EGL_NO_CONTEXT is to be used
|
|
|
|
* in conjunction with the EGL_WAYLAND_BUFFER_WL target. */
|
|
|
|
egl_image = meta_egl_create_image (egl, egl_display, EGL_NO_CONTEXT,
|
2016-10-20 03:35:29 -04:00
|
|
|
EGL_WAYLAND_BUFFER_WL, buffer->resource,
|
|
|
|
NULL,
|
|
|
|
error);
|
|
|
|
if (egl_image == EGL_NO_IMAGE_KHR)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
texture = cogl_egl_texture_2d_new_from_image (cogl_context,
|
|
|
|
width, height,
|
|
|
|
cogl_format,
|
|
|
|
egl_image,
|
|
|
|
error);
|
|
|
|
|
|
|
|
meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
|
2015-01-09 10:09:23 -05:00
|
|
|
|
2014-10-07 22:48:49 -04:00
|
|
|
if (!texture)
|
2016-10-20 03:35:29 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
buffer->texture = COGL_TEXTURE (texture);
|
2016-10-20 03:44:27 -04:00
|
|
|
buffer->is_y_inverted = !!y_inverted;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:59:09 -04:00
|
|
|
static gboolean
|
|
|
|
egl_stream_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
GError **error)
|
|
|
|
{
|
2016-12-08 22:15:11 -05:00
|
|
|
MetaWaylandEglStream *stream = buffer->egl_stream.stream;
|
2016-10-20 03:59:09 -04:00
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
g_assert (stream);
|
2016-10-20 03:59:09 -04:00
|
|
|
|
|
|
|
if (!meta_wayland_egl_stream_attach (stream, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
gboolean
|
|
|
|
meta_wayland_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (buffer->resource, FALSE);
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
if (!meta_wayland_buffer_is_realized (buffer))
|
|
|
|
{
|
2017-05-05 21:41:51 -04:00
|
|
|
/* The buffer should have been realized at surface commit time */
|
|
|
|
g_set_error (error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Unknown buffer type");
|
|
|
|
return FALSE;
|
2016-12-08 22:15:11 -05:00
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
switch (buffer->type)
|
2014-10-07 22:48:49 -04:00
|
|
|
{
|
2016-10-20 03:35:29 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_SHM:
|
|
|
|
return shm_buffer_attach (buffer, error);
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_IMAGE:
|
|
|
|
return egl_image_buffer_attach (buffer, error);
|
2016-10-20 03:59:09 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_STREAM:
|
|
|
|
return egl_stream_buffer_attach (buffer, error);
|
2017-07-11 11:03:26 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_DMA_BUF:
|
|
|
|
return meta_wayland_dma_buf_buffer_attach (buffer, error);
|
2016-10-20 03:35:29 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_UNKNOWN:
|
2016-12-08 22:15:11 -05:00
|
|
|
g_assert_not_reached ();
|
2016-10-20 03:35:29 -04:00
|
|
|
return FALSE;
|
2014-10-07 22:48:49 -04:00
|
|
|
}
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
CoglTexture *
|
|
|
|
meta_wayland_buffer_get_texture (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
2014-10-07 22:48:49 -04:00
|
|
|
return buffer->texture;
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:59:09 -04:00
|
|
|
CoglSnippet *
|
|
|
|
meta_wayland_buffer_create_snippet (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
if (!buffer->egl_stream.stream)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return meta_wayland_egl_stream_create_snippet ();
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:44:27 -04:00
|
|
|
gboolean
|
|
|
|
meta_wayland_buffer_is_y_inverted (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
return buffer->is_y_inverted;
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
static gboolean
|
|
|
|
process_shm_buffer_damage (MetaWaylandBuffer *buffer,
|
|
|
|
cairo_region_t *region,
|
|
|
|
GError **error)
|
2014-10-07 22:48:49 -04:00
|
|
|
{
|
|
|
|
struct wl_shm_buffer *shm_buffer;
|
2016-10-20 03:35:29 -04:00
|
|
|
int i, n_rectangles;
|
|
|
|
gboolean set_texture_failed = FALSE;
|
|
|
|
|
|
|
|
n_rectangles = cairo_region_num_rectangles (region);
|
2014-10-07 22:48:49 -04:00
|
|
|
|
|
|
|
shm_buffer = wl_shm_buffer_get (buffer->resource);
|
2016-10-20 03:35:29 -04:00
|
|
|
wl_shm_buffer_begin_access (shm_buffer);
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
for (i = 0; i < n_rectangles; i++)
|
2014-10-07 22:48:49 -04:00
|
|
|
{
|
2016-10-20 03:35:29 -04:00
|
|
|
const uint8_t *data = wl_shm_buffer_get_data (shm_buffer);
|
|
|
|
int32_t stride = wl_shm_buffer_get_stride (shm_buffer);
|
|
|
|
CoglPixelFormat format;
|
|
|
|
int bpp;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
shm_buffer_get_cogl_pixel_format (shm_buffer, &format, NULL);
|
|
|
|
bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
|
|
|
|
cairo_region_get_rectangle (region, i, &rect);
|
|
|
|
|
|
|
|
if (!_cogl_texture_set_region (buffer->texture,
|
|
|
|
rect.width, rect.height,
|
|
|
|
format,
|
|
|
|
stride,
|
|
|
|
data + rect.x * bpp + rect.y * stride,
|
|
|
|
rect.x, rect.y,
|
|
|
|
0,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
set_texture_failed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
wl_shm_buffer_end_access (shm_buffer);
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
return !set_texture_failed;
|
|
|
|
}
|
2015-01-09 10:09:23 -05:00
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
void
|
|
|
|
meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer,
|
|
|
|
cairo_region_t *region)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (buffer->resource);
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
switch (buffer->type)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_SHM:
|
|
|
|
res = process_shm_buffer_damage (buffer, region, &error);
|
2017-08-01 05:15:57 -04:00
|
|
|
break;
|
2016-10-20 03:35:29 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_IMAGE:
|
2016-10-20 03:59:09 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_STREAM:
|
2017-07-11 11:03:26 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_DMA_BUF:
|
2016-10-20 03:35:29 -04:00
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_UNKNOWN:
|
|
|
|
g_set_error (&error, G_IO_ERROR,
|
|
|
|
G_IO_ERROR_FAILED,
|
|
|
|
"Unknown buffer type");
|
|
|
|
res = FALSE;
|
2017-08-01 05:15:57 -04:00
|
|
|
break;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
g_warning ("Failed to process Wayland buffer damage: %s", error->message);
|
|
|
|
g_error_free (error);
|
2014-10-07 22:48:49 -04:00
|
|
|
}
|
|
|
|
}
|
2016-02-26 04:47:21 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_buffer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandBuffer *buffer = META_WAYLAND_BUFFER (object);
|
|
|
|
|
|
|
|
g_clear_pointer (&buffer->texture, cogl_object_unref);
|
2016-10-20 03:59:09 -04:00
|
|
|
g_clear_object (&buffer->egl_stream.stream);
|
2017-07-11 11:03:26 -04:00
|
|
|
g_clear_object (&buffer->dma_buf.dma_buf);
|
2016-02-26 04:47:21 -05:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_wayland_buffer_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_buffer_init (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_wayland_buffer_class_init (MetaWaylandBufferClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = meta_wayland_buffer_finalize;
|
2016-03-15 00:46:06 -04:00
|
|
|
|
|
|
|
signals[RESOURCE_DESTROYED] = g_signal_new ("resource-destroyed",
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2016-02-26 04:47:21 -05:00
|
|
|
}
|