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>
|
|
|
|
*/
|
|
|
|
|
2019-10-21 06:23:21 -04:00
|
|
|
/**
|
|
|
|
* SECTION:meta-wayland-buffer
|
|
|
|
* @title: MetaWaylandBuffer
|
|
|
|
* @short_description: A wrapper for wayland buffers
|
|
|
|
*
|
|
|
|
* #MetaWaylandBuffer is a general wrapper around wl_buffer, the basic way of
|
|
|
|
* passing rendered data from Wayland clients to the compositor. Note that a
|
|
|
|
* buffer can be backed by several types of memory, as specified by
|
|
|
|
* #MetaWaylandBufferType.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MetaWaylandBufferType:
|
|
|
|
* @META_WAYLAND_BUFFER_TYPE_UNKNOWN: Unknown type.
|
|
|
|
* @META_WAYLAND_BUFFER_TYPE_SHM: wl_buffer backed by shared memory
|
|
|
|
* @META_WAYLAND_BUFFER_TYPE_EGL_IMAGE: wl_buffer backed by an EGLImage
|
|
|
|
* @META_WAYLAND_BUFFER_TYPE_EGL_STREAM: wl_buffer backed by an EGLStream (NVIDIA-specific)
|
|
|
|
* @META_WAYLAND_BUFFER_TYPE_DMA_BUF: wl_buffer backed by a Linux DMA-BUF
|
|
|
|
*
|
|
|
|
* Specifies the backing memory for a #MetaWaylandBuffer. Depending on the type
|
|
|
|
* of buffer, this will lead to different handling for the compositor. For
|
|
|
|
* example, a shared-memory buffer will still need to be uploaded to the GPU.
|
|
|
|
*/
|
|
|
|
|
2014-10-07 22:39:00 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-wayland-buffer.h"
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2017-07-11 11:03:26 -04:00
|
|
|
#include <drm_fourcc.h>
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "cogl/cogl-egl.h"
|
|
|
|
#include "meta/util.h"
|
|
|
|
#include "wayland/meta-wayland-dma-buf.h"
|
2019-09-18 10:18:58 -04:00
|
|
|
#include "wayland/meta-wayland-private.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
|
2019-09-12 05:44:59 -04:00
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
|
|
|
#include "backends/native/meta-drm-buffer-gbm.h"
|
2020-07-29 06:01:40 -04:00
|
|
|
#include "backends/native/meta-kms-utils.h"
|
2021-02-07 09:58:32 -05:00
|
|
|
#include "backends/native/meta-onscreen-native.h"
|
2019-09-12 05:44:59 -04:00
|
|
|
#include "backends/native/meta-renderer-native.h"
|
|
|
|
#endif
|
|
|
|
|
2017-07-11 11:03:26 -04:00
|
|
|
#ifndef DRM_FORMAT_MOD_INVALID
|
|
|
|
#define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
|
|
|
|
#endif
|
|
|
|
|
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,
|
2022-08-19 11:13:01 -04:00
|
|
|
void *data)
|
2014-10-07 22:39:00 -04:00
|
|
|
{
|
|
|
|
MetaWaylandBuffer *buffer =
|
|
|
|
wl_container_of (listener, buffer, destroy_listener);
|
|
|
|
|
2016-02-26 04:47:21 -05:00
|
|
|
buffer->resource = NULL;
|
2022-08-19 11:13:01 -04:00
|
|
|
wl_list_remove (&buffer->destroy_listener.link);
|
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 *
|
2022-05-13 15:51:53 -04:00
|
|
|
meta_wayland_buffer_from_resource (MetaWaylandCompositor *compositor,
|
|
|
|
struct wl_resource *resource)
|
2014-10-07 22:39:00 -04:00
|
|
|
{
|
|
|
|
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;
|
2022-05-13 15:51:53 -04:00
|
|
|
buffer->compositor = compositor;
|
2014-10-07 22:39:00 -04:00
|
|
|
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
|
|
|
{
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
2016-12-08 22:15:11 -05:00
|
|
|
MetaWaylandEglStream *stream;
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif
|
2017-07-11 11:03:26 -04:00
|
|
|
MetaWaylandDmaBufBuffer *dma_buf;
|
2022-01-19 05:49:32 -05:00
|
|
|
MetaWaylandSinglePixelBuffer *single_pixel_buffer;
|
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
|
|
|
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
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;
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
buffer->egl_stream.texture = COGL_TEXTURE (texture);
|
2017-05-05 21:23:57 -04:00
|
|
|
buffer->is_y_inverted = meta_wayland_egl_stream_is_y_inverted (stream);
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif /* HAVE_WAYLAND_EGLSTREAM */
|
2016-10-20 03:59:09 -04:00
|
|
|
|
2022-05-13 15:51:53 -04:00
|
|
|
if (meta_wayland_compositor_is_egl_display_bound (buffer->compositor))
|
2019-03-05 18:39:15 -05:00
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (buffer->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2022-05-13 15:51:53 -04:00
|
|
|
EGLint format;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (meta_egl_query_wayland_buffer (egl, egl_display, buffer->resource,
|
|
|
|
EGL_TEXTURE_FORMAT, &format,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_IMAGE;
|
2021-05-22 12:32:44 -04:00
|
|
|
buffer->dma_buf.dma_buf =
|
|
|
|
meta_wayland_dma_buf_fds_for_wayland_buffer (buffer);
|
2022-05-13 15:51:53 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-03-05 18:39:15 -05: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;
|
|
|
|
}
|
|
|
|
|
2022-01-19 05:49:32 -05:00
|
|
|
single_pixel_buffer = meta_wayland_single_pixel_buffer_from_buffer (buffer);
|
|
|
|
if (single_pixel_buffer)
|
|
|
|
{
|
|
|
|
buffer->single_pixel.single_pixel_buffer = single_pixel_buffer;
|
|
|
|
buffer->type = META_WAYLAND_BUFFER_TYPE_SINGLE_PIXEL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-12-08 22:15:11 -05:00
|
|
|
return FALSE;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:54:58 -04:00
|
|
|
static gboolean
|
|
|
|
shm_format_to_cogl_pixel_format (enum wl_shm_format shm_format,
|
|
|
|
CoglPixelFormat *format_out,
|
|
|
|
CoglTextureComponents *components_out)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
|
|
|
CoglPixelFormat format;
|
|
|
|
CoglTextureComponents components = COGL_TEXTURE_COMPONENTS_RGBA;
|
|
|
|
|
2019-09-19 15:54:58 -04:00
|
|
|
switch (shm_format)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
|
|
|
#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;
|
2022-03-29 13:03:08 -04:00
|
|
|
case WL_SHM_FORMAT_XBGR8888:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ABGR8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_ABGR_8888_PRE;
|
|
|
|
break;
|
2016-10-20 03:35:29 -04:00
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2019-09-18 10:18:58 -04:00
|
|
|
case WL_SHM_FORMAT_RGB565:
|
|
|
|
format = COGL_PIXEL_FORMAT_RGB_565;
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
break;
|
2016-10-20 03:35:29 -04:00
|
|
|
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;
|
2022-03-29 13:03:08 -04:00
|
|
|
case WL_SHM_FORMAT_XBGR8888:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ABGR8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
|
|
|
|
break;
|
2019-09-18 10:38:20 -04:00
|
|
|
case WL_SHM_FORMAT_XRGB2101010:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ARGB2101010:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_2101010_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XBGR2101010:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ABGR2101010:
|
|
|
|
format = COGL_PIXEL_FORMAT_ABGR_2101010_PRE;
|
|
|
|
break;
|
2019-09-18 12:38:22 -04:00
|
|
|
case WL_SHM_FORMAT_XRGB16161616F:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ARGB16161616F:
|
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_FP_16161616_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XBGR16161616F:
|
|
|
|
components = COGL_TEXTURE_COMPONENTS_RGB;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case WL_SHM_FORMAT_ABGR16161616F:
|
|
|
|
format = COGL_PIXEL_FORMAT_RGBA_FP_16161616_PRE;
|
|
|
|
break;
|
2016-10-20 03:35:29 -04:00
|
|
|
#endif
|
|
|
|
default:
|
2019-09-19 15:54:58 -04:00
|
|
|
return FALSE;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (format_out)
|
|
|
|
*format_out = format;
|
|
|
|
if (components_out)
|
|
|
|
*components_out = components;
|
2019-09-19 15:54:58 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2022-05-30 17:48:44 -04:00
|
|
|
shm_buffer_get_cogl_pixel_format (MetaWaylandBuffer *buffer,
|
|
|
|
struct wl_shm_buffer *shm_buffer,
|
2019-09-19 15:54:58 -04:00
|
|
|
CoglPixelFormat *format_out,
|
|
|
|
CoglTextureComponents *components_out)
|
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (buffer->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2019-09-18 10:38:20 -04:00
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context =
|
|
|
|
clutter_backend_get_cogl_context (clutter_backend);
|
2019-09-19 15:54:58 -04:00
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
CoglTextureComponents cogl_components;
|
|
|
|
|
|
|
|
if (!shm_format_to_cogl_pixel_format (wl_shm_buffer_get_format (shm_buffer),
|
|
|
|
&cogl_format,
|
|
|
|
&cogl_components))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-09-18 10:38:20 -04:00
|
|
|
if (!cogl_context_format_supports_upload (cogl_context, cogl_format))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-09-19 15:54:58 -04:00
|
|
|
if (format_out)
|
|
|
|
*format_out = cogl_format;
|
|
|
|
if (components_out)
|
|
|
|
*components_out = cogl_components;
|
|
|
|
|
|
|
|
return TRUE;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2020-07-29 06:01:40 -04:00
|
|
|
static const char *
|
|
|
|
shm_format_to_string (MetaDrmFormatBuf *format_buf,
|
|
|
|
uint32_t shm_format)
|
|
|
|
{
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
switch (shm_format)
|
|
|
|
{
|
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
result = "ARGB8888";
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
result = "XRGB8888";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = meta_drm_format_to_string (format_buf, shm_format);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
static gboolean
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
shm_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
CoglTexture **texture,
|
|
|
|
GError **error)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (buffer->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2016-10-20 03:35:29 -04:00
|
|
|
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;
|
2019-02-16 07:35:22 -05:00
|
|
|
CoglTexture *new_texture;
|
2020-07-29 06:01:40 -04:00
|
|
|
MetaDrmFormatBuf format_buf;
|
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);
|
2022-05-30 17:48:44 -04:00
|
|
|
if (!shm_buffer_get_cogl_pixel_format (buffer, shm_buffer,
|
|
|
|
&format, &components))
|
2019-09-19 15:54:58 -04:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Invalid shm pixel format");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2020-07-29 06:01:40 -04:00
|
|
|
meta_topic (META_DEBUG_WAYLAND,
|
|
|
|
"[wl-shm] wl_buffer@%u wl_shm_format %s -> CoglPixelFormat %s",
|
|
|
|
wl_resource_get_id (meta_wayland_buffer_get_resource (buffer)),
|
|
|
|
shm_format_to_string (&format_buf,
|
|
|
|
wl_shm_buffer_get_format (shm_buffer)),
|
|
|
|
cogl_pixel_format_to_string (format));
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
if (*texture &&
|
|
|
|
cogl_texture_get_width (*texture) == width &&
|
|
|
|
cogl_texture_get_height (*texture) == height &&
|
|
|
|
cogl_texture_get_components (*texture) == components &&
|
|
|
|
_cogl_texture_get_format (*texture) == format)
|
|
|
|
{
|
|
|
|
buffer->is_y_inverted = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
cogl_clear_object (texture);
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access (shm_buffer);
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
bitmap = cogl_bitmap_new_for_data (cogl_context,
|
|
|
|
width, height,
|
|
|
|
format,
|
|
|
|
stride,
|
|
|
|
wl_shm_buffer_get_data (shm_buffer));
|
|
|
|
|
2019-02-16 07:35:22 -05:00
|
|
|
new_texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap));
|
|
|
|
cogl_texture_set_components (new_texture, components);
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2019-02-16 07:35:22 -05:00
|
|
|
if (!cogl_texture_allocate (new_texture, error))
|
|
|
|
{
|
|
|
|
g_clear_pointer (&new_texture, cogl_object_unref);
|
|
|
|
if (g_error_matches (*error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE))
|
|
|
|
{
|
|
|
|
CoglTexture2DSliced *texture_sliced;
|
|
|
|
|
|
|
|
g_clear_error (error);
|
|
|
|
|
|
|
|
texture_sliced =
|
|
|
|
cogl_texture_2d_sliced_new_from_bitmap (bitmap,
|
|
|
|
COGL_TEXTURE_MAX_WASTE);
|
|
|
|
new_texture = COGL_TEXTURE (texture_sliced);
|
|
|
|
cogl_texture_set_components (new_texture, components);
|
|
|
|
|
|
|
|
if (!cogl_texture_allocate (new_texture, error))
|
|
|
|
g_clear_pointer (&new_texture, cogl_object_unref);
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2019-02-16 07:35:22 -05:00
|
|
|
cogl_object_unref (bitmap);
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
wl_shm_buffer_end_access (shm_buffer);
|
|
|
|
|
2019-02-16 07:35:22 -05:00
|
|
|
if (!new_texture)
|
2016-10-20 03:35:29 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2019-02-16 07:35:22 -05:00
|
|
|
*texture = new_texture;
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
buffer->is_y_inverted = TRUE;
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
egl_image_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
CoglTexture **texture,
|
|
|
|
GError **error)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (buffer->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2016-10-20 03:35:29 -04:00
|
|
|
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;
|
2019-07-16 12:29:29 -04:00
|
|
|
CoglEglImageFlags flags;
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
CoglTexture2D *texture_2d;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
if (buffer->egl_image.texture)
|
|
|
|
{
|
|
|
|
cogl_clear_object (texture);
|
|
|
|
*texture = cogl_object_ref (buffer->egl_image.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;
|
|
|
|
|
2019-07-16 12:29:29 -04:00
|
|
|
flags = COGL_EGL_IMAGE_FLAG_NONE;
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
texture_2d = cogl_egl_texture_2d_new_from_image (cogl_context,
|
|
|
|
width, height,
|
|
|
|
cogl_format,
|
|
|
|
egl_image,
|
2019-07-16 12:29:29 -04:00
|
|
|
flags,
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
error);
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
meta_egl_destroy_image (egl, egl_display, egl_image, NULL);
|
2015-01-09 10:09:23 -05:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
if (!texture_2d)
|
2016-10-20 03:35:29 -04:00
|
|
|
return FALSE;
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
buffer->egl_image.texture = COGL_TEXTURE (texture_2d);
|
2016-10-20 03:44:27 -04:00
|
|
|
buffer->is_y_inverted = !!y_inverted;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
cogl_clear_object (texture);
|
|
|
|
*texture = cogl_object_ref (buffer->egl_image.texture);
|
|
|
|
|
2016-10-20 03:35:29 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
2016-10-20 03:59:09 -04:00
|
|
|
static gboolean
|
|
|
|
egl_stream_buffer_attach (MetaWaylandBuffer *buffer,
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
CoglTexture **texture,
|
2016-10-20 03:59:09 -04:00
|
|
|
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;
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
cogl_clear_object (texture);
|
|
|
|
*texture = cogl_object_ref (buffer->egl_stream.texture);
|
|
|
|
|
2016-10-20 03:59:09 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif /* HAVE_WAYLAND_EGLSTREAM */
|
2016-10-20 03:59:09 -04:00
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
/**
|
|
|
|
* meta_wayland_buffer_attach:
|
|
|
|
* @buffer: a pointer to a #MetaWaylandBuffer
|
|
|
|
* @texture: (inout) (transfer full): a #CoglTexture representing the surface
|
|
|
|
* content
|
|
|
|
* @error: return location for error or %NULL
|
|
|
|
*
|
|
|
|
* This function should be passed a pointer to the texture used to draw the
|
|
|
|
* surface content. The texture will either be replaced by a new texture, or
|
|
|
|
* stay the same, in which case, it may later be updated with new content when
|
|
|
|
* processing damage. The new texture might be newly created, or it may be a
|
|
|
|
* reference to an already existing one.
|
|
|
|
*
|
|
|
|
* If replaced, the old texture will have its reference count decreased by one,
|
|
|
|
* potentially freeing it. When a new texture is set, the caller (i.e. the
|
|
|
|
* surface) will be the owner of one reference count. It must free it, either
|
|
|
|
* using g_object_unref() or have it updated again using
|
|
|
|
* meta_wayland_buffer_attach(), which also might free it, as described above.
|
|
|
|
*/
|
2016-10-20 03:35:29 -04:00
|
|
|
gboolean
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
meta_wayland_buffer_attach (MetaWaylandBuffer *buffer,
|
|
|
|
CoglTexture **texture,
|
|
|
|
GError **error)
|
2016-10-20 03:35:29 -04:00
|
|
|
{
|
2020-11-30 06:04:48 -05:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaWaylandBufferAttach, "WaylandBuffer (attach)");
|
|
|
|
|
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:
|
2019-12-06 12:57:10 -05:00
|
|
|
return shm_buffer_attach (buffer, texture, error);
|
2016-10-20 03:35:29 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_IMAGE:
|
2019-12-06 12:57:10 -05:00
|
|
|
return egl_image_buffer_attach (buffer, texture, error);
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
2016-10-20 03:59:09 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_STREAM:
|
2019-12-06 12:57:10 -05:00
|
|
|
return egl_stream_buffer_attach (buffer, texture, error);
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif
|
2017-07-11 11:03:26 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_DMA_BUF:
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
return meta_wayland_dma_buf_buffer_attach (buffer,
|
|
|
|
texture,
|
|
|
|
error);
|
2022-01-19 05:49:32 -05:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_SINGLE_PIXEL:
|
|
|
|
return meta_wayland_single_pixel_buffer_attach (buffer,
|
|
|
|
texture,
|
|
|
|
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 ();
|
2019-01-24 18:47:44 -05:00
|
|
|
return FALSE;
|
2016-10-20 03:35:29 -04:00
|
|
|
}
|
2014-10-07 22:48:49 -04:00
|
|
|
|
2019-10-21 06:23:21 -04:00
|
|
|
/**
|
|
|
|
* meta_wayland_buffer_create_snippet:
|
|
|
|
* @buffer: A #MetaWaylandBuffer object
|
|
|
|
*
|
|
|
|
* If needed, this method creates a #CoglSnippet to make sure the buffer can be
|
|
|
|
* dealt with appropriately in a #CoglPipeline that renders it.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): A new #CoglSnippet, or %NULL.
|
|
|
|
*/
|
2016-10-20 03:59:09 -04:00
|
|
|
CoglSnippet *
|
|
|
|
meta_wayland_buffer_create_snippet (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
2016-10-20 03:59:09 -04:00
|
|
|
if (!buffer->egl_stream.stream)
|
|
|
|
return NULL;
|
|
|
|
|
2019-12-05 13:43:07 -05:00
|
|
|
return meta_wayland_egl_stream_create_snippet (buffer->egl_stream.stream);
|
2018-11-06 11:09:03 -05:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif /* HAVE_WAYLAND_EGLSTREAM */
|
2016-10-20 03:59:09 -04:00
|
|
|
}
|
|
|
|
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
void
|
|
|
|
meta_wayland_buffer_inc_use_count (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
g_warn_if_fail (buffer->resource);
|
|
|
|
|
|
|
|
buffer->use_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_buffer_dec_use_count (MetaWaylandBuffer *buffer)
|
|
|
|
{
|
|
|
|
g_return_if_fail (buffer->use_count > 0);
|
|
|
|
|
|
|
|
buffer->use_count--;
|
|
|
|
|
|
|
|
if (buffer->use_count == 0 && buffer->resource)
|
|
|
|
wl_buffer_send_release (buffer->resource);
|
|
|
|
}
|
|
|
|
|
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,
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
CoglTexture *texture,
|
2016-10-20 03:35:29 -04:00
|
|
|
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;
|
2019-10-14 12:56:25 -04:00
|
|
|
CoglPixelFormat format;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
|
|
|
n_rectangles = cairo_region_num_rectangles (region);
|
2014-10-07 22:48:49 -04:00
|
|
|
|
|
|
|
shm_buffer = wl_shm_buffer_get (buffer->resource);
|
2019-10-14 12:56:25 -04:00
|
|
|
|
2022-05-30 17:48:44 -04:00
|
|
|
shm_buffer_get_cogl_pixel_format (buffer, shm_buffer, &format, NULL);
|
2019-10-14 12:56:25 -04:00
|
|
|
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, FALSE);
|
|
|
|
|
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);
|
|
|
|
cairo_rectangle_int_t rect;
|
2019-10-14 12:56:25 -04:00
|
|
|
int bpp;
|
2016-10-20 03:35:29 -04:00
|
|
|
|
2019-10-14 12:56:25 -04:00
|
|
|
bpp = cogl_pixel_format_get_bytes_per_pixel (format, 0);
|
2016-10-20 03:35:29 -04:00
|
|
|
cairo_region_get_rectangle (region, i, &rect);
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
if (!_cogl_texture_set_region (texture,
|
2016-10-20 03:35:29 -04:00
|
|
|
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,
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
CoglTexture *texture,
|
2016-10-20 03:35:29 -04:00
|
|
|
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:
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
res = process_shm_buffer_damage (buffer, texture, 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:
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
2016-10-20 03:59:09 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_STREAM:
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif
|
2017-07-11 11:03:26 -04:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_DMA_BUF:
|
2022-01-19 05:49:32 -05:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_SINGLE_PIXEL:
|
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
|
|
|
|
2019-09-12 05:44:59 -04:00
|
|
|
static CoglScanout *
|
|
|
|
try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
|
|
|
|
CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_NATIVE_BACKEND
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context =
|
|
|
|
meta_wayland_compositor_get_context (buffer->compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2019-09-12 05:44:59 -04:00
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
|
|
|
MetaGpuKms *gpu_kms;
|
2021-04-12 10:13:29 -04:00
|
|
|
MetaDeviceFile *device_file;
|
2019-09-12 05:44:59 -04:00
|
|
|
struct gbm_device *gbm_device;
|
|
|
|
struct gbm_bo *gbm_bo;
|
2021-05-05 04:15:18 -04:00
|
|
|
MetaDrmBufferFlags flags;
|
2021-12-08 15:23:54 -05:00
|
|
|
g_autoptr (MetaDrmBufferGbm) fb = NULL;
|
2019-09-12 05:44:59 -04:00
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
|
|
|
gpu_kms = meta_renderer_native_get_primary_gpu (renderer_native);
|
2021-04-12 10:13:29 -04:00
|
|
|
device_file = meta_renderer_native_get_primary_device_file (renderer_native);
|
2019-09-12 05:44:59 -04:00
|
|
|
gbm_device = meta_gbm_device_from_gpu (gpu_kms);
|
|
|
|
|
|
|
|
gbm_bo = gbm_bo_import (gbm_device,
|
|
|
|
GBM_BO_IMPORT_WL_BUFFER, buffer->resource,
|
|
|
|
GBM_BO_USE_SCANOUT);
|
|
|
|
if (!gbm_bo)
|
|
|
|
return NULL;
|
|
|
|
|
2021-05-05 04:15:18 -04:00
|
|
|
flags = META_DRM_BUFFER_FLAG_NONE;
|
2021-12-08 15:23:54 -05:00
|
|
|
if (gbm_bo_get_modifier (gbm_bo) == DRM_FORMAT_MOD_INVALID)
|
2021-05-05 04:15:18 -04:00
|
|
|
flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
|
|
|
|
|
|
|
fb = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags, &error);
|
2019-09-12 05:44:59 -04:00
|
|
|
if (!fb)
|
|
|
|
{
|
|
|
|
g_debug ("Failed to create scanout buffer: %s", error->message);
|
|
|
|
gbm_bo_destroy (gbm_bo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-12-08 15:23:54 -05:00
|
|
|
if (!meta_onscreen_native_is_buffer_scanout_compatible (onscreen,
|
|
|
|
META_DRM_BUFFER (fb)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return COGL_SCANOUT (g_steal_pointer (&fb));
|
2019-09-12 05:44:59 -04:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglScanout *
|
|
|
|
meta_wayland_buffer_try_acquire_scanout (MetaWaylandBuffer *buffer,
|
|
|
|
CoglOnscreen *onscreen)
|
|
|
|
{
|
2021-12-08 15:23:54 -05:00
|
|
|
COGL_TRACE_BEGIN_SCOPED (MetaWaylandBufferTryScanout,
|
|
|
|
"WaylandBuffer (try scanout)");
|
|
|
|
|
2019-09-12 05:44:59 -04:00
|
|
|
switch (buffer->type)
|
|
|
|
{
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_SHM:
|
2022-01-19 05:49:32 -05:00
|
|
|
case META_WAYLAND_BUFFER_TYPE_SINGLE_PIXEL:
|
2022-10-30 18:04:57 -04:00
|
|
|
meta_topic (META_DEBUG_RENDER,
|
|
|
|
"Buffer type not scanout compatible");
|
2019-09-12 05:44:59 -04:00
|
|
|
return NULL;
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_IMAGE:
|
|
|
|
return try_acquire_egl_image_scanout (buffer, onscreen);
|
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_EGL_STREAM:
|
2022-10-30 18:04:57 -04:00
|
|
|
meta_topic (META_DEBUG_RENDER,
|
|
|
|
"Buffer type not scanout compatible");
|
2019-09-12 05:44:59 -04:00
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_DMA_BUF:
|
|
|
|
{
|
|
|
|
MetaWaylandDmaBufBuffer *dma_buf;
|
|
|
|
|
|
|
|
dma_buf = meta_wayland_dma_buf_from_buffer (buffer);
|
|
|
|
if (!dma_buf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return meta_wayland_dma_buf_try_acquire_scanout (dma_buf, onscreen);
|
|
|
|
}
|
|
|
|
case META_WAYLAND_BUFFER_TYPE_UNKNOWN:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:47:21 -05:00
|
|
|
static void
|
|
|
|
meta_wayland_buffer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaWaylandBuffer *buffer = META_WAYLAND_BUFFER (object);
|
|
|
|
|
wayland/surface: Overhaul handling of buffer use count
Move the use count from a separate MetaWaylandBufferRef struct to the
MetaWaylandBuffer class, and remove the former.
The buffer use count is now incremented already in
meta_wayland_surface_commit, since the Wayland protocol defines the
buffer to be in use by the compositor at that point. If the buffer
attachment ends up being dropped again before it is applied to the
surface state (e.g. because another buffer is committed to a
synchronized sub-surface before the parent surface is committed),
the use count is now decremented, and a buffer release event is sent if
the use count drops to 0.
Buffer release events were previously incorrectly not sent under these
circumstances. Test case: Run the weston-subsurfaces demo with the -r1
and/or -t1 command line parameter. Resize the window. Before this
change, weston-subsurfaces would freeze or abort after a few resize
operations, because mutter failed to send release events and the
client ran out of usable buffers.
v2:
* Handle NULL priv->buffer_ref in
meta_wayland_cursor_surface_apply_state.
v3:
* Remove MetaWaylandBufferRef altogether, move the use count tracking
to MetaWaylandBuffer itself. Much simpler, and doesn't run into
lifetime issues when mutter shuts down.
v4:
* Warn if use count isn't 0 in meta_wayland_buffer_finalize.
* Keep pending_buffer_resource_destroyed for attached but not yet
committed buffers. If the client attaches a buffer and then destroys
it before commit, we ignore the buffer attachement, same as before
this MR.
v5:
* Rebase on top of new commit which splits up surface->texture.
* MetaWaylandSurfaceState::buffer can only be non-NULL if
::newly_attached is TRUE, simplify accordingly.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880>
2022-06-22 12:43:11 -04:00
|
|
|
g_warn_if_fail (buffer->use_count == 0);
|
|
|
|
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
g_clear_pointer (&buffer->egl_image.texture, cogl_object_unref);
|
2018-11-06 11:09:03 -05:00
|
|
|
#ifdef HAVE_WAYLAND_EGLSTREAM
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
g_clear_pointer (&buffer->egl_stream.texture, cogl_object_unref);
|
2016-10-20 03:59:09 -04:00
|
|
|
g_clear_object (&buffer->egl_stream.stream);
|
2018-11-06 11:09:03 -05:00
|
|
|
#endif
|
wayland: Move surface texture ownership to MetaWaylandSurface
Prior to this commit, MetaWaylandSurface held a reference to
MetaWaylandBuffer, who owned the texture drawn by the surface. When
switching buffer, the texture change with it.
This is problematic when dealing with SHM buffer damage management, as
when having one texture per buffer, damaged regions uploaded to one,
will not follow along to the next one attached. It also wasted GPU
memory as there would be one texture per buffer, instead of one one
texture per surface.
Instead, move the texture ownership to MetaWaylandSurface, and have the
SHM buffer damage management update the surface texture. This ensures
damage is processed properly, and that we won't end up with stale
texture content when doing partial texture uploads. If the same SHM
buffer is attached to multiple surfaces, each surface will get their own
copy, and damage is tracked and uploaded separately.
Non-SHM types of buffers still has their own texture reference, as the
texture is just a representation of the GPU memory associated with the
buffer. When such a buffer is attached to a surface, instead the surface
just gets a reference to that texture, instead of a separately allocated
one.
Fixes: https://gitlab.gnome.org/GNOME/mutter/issues/199
2019-02-08 05:46:48 -05:00
|
|
|
g_clear_pointer (&buffer->dma_buf.texture, cogl_object_unref);
|
2017-07-11 11:03:26 -04:00
|
|
|
g_clear_object (&buffer->dma_buf.dma_buf);
|
2022-01-19 05:49:32 -05:00
|
|
|
g_clear_pointer (&buffer->single_pixel.single_pixel_buffer,
|
|
|
|
meta_wayland_single_pixel_buffer_free);
|
|
|
|
cogl_clear_object (&buffer->single_pixel.texture);
|
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
|
|
|
|
2019-10-21 06:23:21 -04:00
|
|
|
/**
|
|
|
|
* MetaWaylandBuffer::resource-destroyed:
|
|
|
|
*
|
|
|
|
* Called when the underlying wl_resource was destroyed.
|
|
|
|
*/
|
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
|
|
|
}
|
2019-09-18 10:18:58 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_init_shm (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
2022-05-30 17:48:44 -04:00
|
|
|
MetaContext *context = meta_wayland_compositor_get_context (compositor);
|
|
|
|
MetaBackend *backend = meta_context_get_backend (context);
|
2019-09-18 10:38:20 -04:00
|
|
|
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
|
|
|
|
CoglContext *cogl_context =
|
|
|
|
clutter_backend_get_cogl_context (clutter_backend);
|
|
|
|
|
2019-09-18 10:18:58 -04:00
|
|
|
static const enum wl_shm_format shm_formats[] = {
|
2022-03-29 13:03:08 -04:00
|
|
|
WL_SHM_FORMAT_ABGR8888,
|
|
|
|
WL_SHM_FORMAT_XBGR8888,
|
2019-09-18 10:18:58 -04:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
WL_SHM_FORMAT_RGB565,
|
2019-09-18 10:38:20 -04:00
|
|
|
WL_SHM_FORMAT_ARGB2101010,
|
|
|
|
WL_SHM_FORMAT_XRGB2101010,
|
|
|
|
WL_SHM_FORMAT_ABGR2101010,
|
|
|
|
WL_SHM_FORMAT_XBGR2101010,
|
2019-09-18 12:38:22 -04:00
|
|
|
WL_SHM_FORMAT_ARGB16161616F,
|
|
|
|
WL_SHM_FORMAT_XRGB16161616F,
|
|
|
|
WL_SHM_FORMAT_ABGR16161616F,
|
|
|
|
WL_SHM_FORMAT_XBGR16161616F,
|
2019-09-18 10:18:58 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wl_display_init_shm (compositor->wayland_display);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (shm_formats); i++)
|
2019-09-18 10:38:20 -04:00
|
|
|
{
|
|
|
|
CoglPixelFormat cogl_format;
|
|
|
|
|
|
|
|
if (!shm_format_to_cogl_pixel_format (shm_formats[i],
|
|
|
|
&cogl_format,
|
|
|
|
NULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!cogl_context_format_supports_upload (cogl_context, cogl_format))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wl_display_add_shm_format (compositor->wayland_display, shm_formats[i]);
|
|
|
|
}
|
2019-09-18 10:18:58 -04:00
|
|
|
}
|