mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 05:50:10 +00:00
wayland: Break out dmabuf feedback code
This will need to be used in surfaces as well, in the future. Prepare for that by moving this code into its own file and struct.
This commit is contained in:
parent
27fb9917d8
commit
b98c86fb7b
@ -287,97 +287,6 @@ static const struct wl_shm_listener wl_shm_listener = {
|
||||
wl_shm_format
|
||||
};
|
||||
|
||||
static void
|
||||
linux_dmabuf_done (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1)
|
||||
{
|
||||
GDK_DEBUG (MISC, "dmabuf feedback done");
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_format_table (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
int32_t fd,
|
||||
uint32_t size)
|
||||
{
|
||||
GdkWaylandDisplay *display_wayland = data;
|
||||
|
||||
display_wayland->linux_dmabuf_n_formats = size / 16;
|
||||
display_wayland->linux_dmabuf_formats = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
|
||||
GDK_DEBUG (MISC, "got dmabuf format table (%lu entries)", display_wayland->linux_dmabuf_n_formats);
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_main_device (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
struct wl_array *device)
|
||||
{
|
||||
dev_t dev G_GNUC_UNUSED;
|
||||
|
||||
memcpy (&dev, device->data, sizeof (dev_t));
|
||||
|
||||
GDK_DEBUG (MISC, "got dmabuf main device: %u %u", major (dev), minor (dev));
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_done (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1)
|
||||
{
|
||||
GDK_DEBUG (MISC, "dmabuf feedback tranche done");
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_target_device (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
struct wl_array *device)
|
||||
{
|
||||
dev_t dev G_GNUC_UNUSED;
|
||||
|
||||
memcpy (&dev, device->data, sizeof (dev_t));
|
||||
|
||||
GDK_DEBUG (MISC, "got dmabuf tranche target device: %u %u", major (dev), minor (dev));
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_formats (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
struct wl_array *indices)
|
||||
{
|
||||
GdkWaylandDisplay *display_wayland = data;
|
||||
|
||||
GDK_DEBUG (MISC, "got dmabuf tranche formats (%lu entries):", indices->size / sizeof (guint16));
|
||||
guint16 *pos;
|
||||
|
||||
wl_array_for_each (pos, indices)
|
||||
{
|
||||
LinuxDmabufFormat *fmt G_GNUC_UNUSED = &display_wayland->linux_dmabuf_formats[*pos];
|
||||
uint32_t f G_GNUC_UNUSED = fmt->fourcc;
|
||||
uint64_t m G_GNUC_UNUSED = fmt->modifier;
|
||||
GDK_DEBUG (MISC, " %.4s:%#" G_GINT64_MODIFIER "x", (char *) &f, m);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_flags (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1,
|
||||
uint32_t flags)
|
||||
{
|
||||
GDK_DEBUG (MISC,
|
||||
"got dmabuf tranche flags: %s",
|
||||
flags & ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT ? "scanout" : "");
|
||||
}
|
||||
|
||||
static const struct zwp_linux_dmabuf_feedback_v1_listener linux_dmabuf_feedback_listener = {
|
||||
linux_dmabuf_done,
|
||||
linux_dmabuf_format_table,
|
||||
linux_dmabuf_main_device,
|
||||
linux_dmabuf_tranche_done,
|
||||
linux_dmabuf_tranche_target_device,
|
||||
linux_dmabuf_tranche_formats,
|
||||
linux_dmabuf_tranche_flags,
|
||||
};
|
||||
|
||||
static void
|
||||
server_decoration_manager_default_mode (void *data,
|
||||
struct org_kde_kwin_server_decoration_manager *manager,
|
||||
@ -454,12 +363,14 @@ gdk_registry_handle_global (void *data,
|
||||
}
|
||||
else if (strcmp (interface, "zwp_linux_dmabuf_v1") == 0 && version >= 4)
|
||||
{
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback;
|
||||
|
||||
display_wayland->linux_dmabuf =
|
||||
wl_registry_bind (display_wayland->wl_registry, id, &zwp_linux_dmabuf_v1_interface, version);
|
||||
display_wayland->linux_dmabuf_feedback =
|
||||
zwp_linux_dmabuf_v1_get_default_feedback (display_wayland->linux_dmabuf);
|
||||
zwp_linux_dmabuf_feedback_v1_add_listener (display_wayland->linux_dmabuf_feedback,
|
||||
&linux_dmabuf_feedback_listener, display_wayland);
|
||||
feedback = zwp_linux_dmabuf_v1_get_default_feedback (display_wayland->linux_dmabuf);
|
||||
display_wayland->dmabuf_formats_info = dmabuf_formats_info_new (GDK_DISPLAY (display_wayland),
|
||||
"default",
|
||||
feedback);
|
||||
_gdk_wayland_display_async_roundtrip (display_wayland);
|
||||
}
|
||||
else if (strcmp (interface, "xdg_wm_base") == 0)
|
||||
@ -832,9 +743,7 @@ gdk_wayland_display_dispose (GObject *object)
|
||||
g_clear_pointer (&display_wayland->presentation, wp_presentation_destroy);
|
||||
g_clear_pointer (&display_wayland->single_pixel_buffer, wp_single_pixel_buffer_manager_v1_destroy);
|
||||
g_clear_pointer (&display_wayland->linux_dmabuf, zwp_linux_dmabuf_v1_destroy);
|
||||
g_clear_pointer (&display_wayland->linux_dmabuf_feedback, zwp_linux_dmabuf_feedback_v1_destroy);
|
||||
if (display_wayland->linux_dmabuf_formats)
|
||||
munmap (display_wayland->linux_dmabuf_formats, display_wayland->linux_dmabuf_n_formats * 16);
|
||||
g_clear_pointer (&display_wayland->dmabuf_formats_info, dmabuf_formats_info_free);
|
||||
|
||||
g_clear_pointer (&display_wayland->shm, wl_shm_destroy);
|
||||
g_clear_pointer (&display_wayland->wl_registry, wl_registry_destroy);
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
#include "gdkdisplayprivate.h"
|
||||
#include "gdkwaylanddevice.h"
|
||||
#include "gdkdmabuf-wayland-private.h"
|
||||
#include "cursor/wayland-cursor.h"
|
||||
|
||||
#include <epoxy/egl.h>
|
||||
@ -73,13 +74,6 @@ typedef enum _GdkWaylandShellVariant
|
||||
GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6
|
||||
} GdkWaylandShellVariant;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t fourcc;
|
||||
uint32_t padding;
|
||||
uint64_t modifier;
|
||||
} LinuxDmabufFormat;
|
||||
|
||||
struct _GdkWaylandDisplay
|
||||
{
|
||||
GdkDisplay parent_instance;
|
||||
@ -105,9 +99,7 @@ struct _GdkWaylandDisplay
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_shm *shm;
|
||||
struct zwp_linux_dmabuf_v1 *linux_dmabuf;
|
||||
struct zwp_linux_dmabuf_feedback_v1 *linux_dmabuf_feedback;
|
||||
gsize linux_dmabuf_n_formats;
|
||||
LinuxDmabufFormat *linux_dmabuf_formats;
|
||||
DmabufFormatsInfo *dmabuf_formats_info;
|
||||
struct xdg_wm_base *xdg_wm_base;
|
||||
struct zxdg_shell_v6 *zxdg_shell_v6;
|
||||
struct gtk_shell1 *gtk_shell;
|
||||
|
77
gdk/wayland/gdkdmabuf-wayland-private.h
Normal file
77
gdk/wayland/gdkdmabuf-wayland-private.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* gdkdmabuf-wayland.h
|
||||
*
|
||||
* Copyright 2023 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <gdk/gdkkeys.h>
|
||||
#include <gdk/gdksurface.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t fourcc;
|
||||
uint32_t padding;
|
||||
uint64_t modifier;
|
||||
} DmabufFormat;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dev_t target_device;
|
||||
guint32 flags;
|
||||
gsize n_formats;
|
||||
DmabufFormat *formats;
|
||||
} DmabufTranche;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dev_t main_device;
|
||||
GPtrArray *tranches;
|
||||
} DmabufFormats;
|
||||
|
||||
typedef struct DmabufFormatsInfo DmabufFormatsInfo;
|
||||
|
||||
struct DmabufFormatsInfo
|
||||
{
|
||||
GdkDisplay *display;
|
||||
char *name;
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback;
|
||||
|
||||
gsize n_dmabuf_formats;
|
||||
DmabufFormat *dmabuf_format_table;
|
||||
|
||||
DmabufFormats *dmabuf_formats;
|
||||
DmabufFormats *pending_dmabuf_formats;
|
||||
DmabufTranche *pending_tranche;
|
||||
};
|
||||
|
||||
DmabufFormatsInfo * dmabuf_formats_info_new (GdkDisplay *display,
|
||||
const char *name,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback);
|
||||
|
||||
void dmabuf_formats_info_free (DmabufFormatsInfo *info);
|
||||
|
||||
G_END_DECLS
|
241
gdk/wayland/gdkdmabuf-wayland.c
Normal file
241
gdk/wayland/gdkdmabuf-wayland.c
Normal file
@ -0,0 +1,241 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gdkdmabuf-wayland-private.h"
|
||||
|
||||
#include "gdkdebugprivate.h"
|
||||
#include "gdkdmabufformatsprivate.h"
|
||||
#include "gdkdmabufformatsbuilderprivate.h"
|
||||
#include "gdkdmabufformatsprivate.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
||||
|
||||
|
||||
static DmabufTranche *
|
||||
dmabuf_tranche_new (void)
|
||||
{
|
||||
return g_new0 (DmabufTranche, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
dmabuf_tranche_free (DmabufTranche *tranche)
|
||||
{
|
||||
g_free (tranche->formats);
|
||||
g_free (tranche);
|
||||
}
|
||||
|
||||
static DmabufFormats *
|
||||
dmabuf_formats_new (void)
|
||||
{
|
||||
DmabufFormats *formats;
|
||||
|
||||
formats = g_new0 (DmabufFormats, 1);
|
||||
formats->tranches = g_ptr_array_new_with_free_func ((GDestroyNotify) dmabuf_tranche_free);
|
||||
|
||||
return formats;
|
||||
}
|
||||
|
||||
static void
|
||||
dmabuf_formats_free (DmabufFormats *formats)
|
||||
{
|
||||
g_ptr_array_unref (formats->tranches);
|
||||
g_free (formats);
|
||||
}
|
||||
|
||||
static void
|
||||
update_dmabuf_formats (DmabufFormatsInfo *info)
|
||||
{
|
||||
DmabufFormats *formats = info->dmabuf_formats;
|
||||
|
||||
GDK_DISPLAY_DEBUG (info->display, MISC,
|
||||
"dmabuf format table (%lu entries)", info->n_dmabuf_formats);
|
||||
GDK_DISPLAY_DEBUG (info->display, MISC,
|
||||
"dmabuf main device: %u %u",
|
||||
major (formats->main_device),
|
||||
minor (formats->main_device));
|
||||
|
||||
for (gsize i = 0; i < formats->tranches->len; i++)
|
||||
{
|
||||
DmabufTranche *tranche = g_ptr_array_index (formats->tranches, i);
|
||||
|
||||
GDK_DISPLAY_DEBUG (info->display, MISC,
|
||||
"dmabuf tranche target device: %u %u",
|
||||
major (tranche->target_device),
|
||||
minor (tranche->target_device));
|
||||
|
||||
GDK_DISPLAY_DEBUG (info->display, MISC,
|
||||
"dmabuf%s tranche (%lu entries):",
|
||||
tranche->flags & ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT ? " scanout" : "",
|
||||
tranche->n_formats);
|
||||
|
||||
for (gsize j = 0; j < tranche->n_formats; j++)
|
||||
{
|
||||
GDK_DISPLAY_DEBUG (info->display, MISC,
|
||||
" %.4s:%#" G_GINT64_MODIFIER "x",
|
||||
(char *) &(tranche->formats[j].fourcc),
|
||||
tranche->formats[j].modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_done (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
|
||||
g_clear_pointer (&info->dmabuf_formats, dmabuf_formats_free);
|
||||
|
||||
info->dmabuf_formats = info->pending_dmabuf_formats;
|
||||
info->pending_dmabuf_formats = NULL;
|
||||
|
||||
update_dmabuf_formats (info);
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_format_table (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback,
|
||||
int32_t fd,
|
||||
uint32_t size)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
|
||||
if (info->dmabuf_formats)
|
||||
munmap (info->dmabuf_formats, sizeof (DmabufFormat) * info->n_dmabuf_formats);
|
||||
|
||||
info->n_dmabuf_formats = size / 16;
|
||||
info->dmabuf_format_table = mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_main_device (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback,
|
||||
struct wl_array *device)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
dev_t dev;
|
||||
|
||||
memcpy (&dev, device->data, sizeof (dev_t));
|
||||
|
||||
g_assert (info->pending_dmabuf_formats == NULL);
|
||||
|
||||
info->pending_dmabuf_formats = dmabuf_formats_new ();
|
||||
info->pending_dmabuf_formats->main_device = dev;
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_done (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
|
||||
g_ptr_array_add (info->pending_dmabuf_formats->tranches,
|
||||
info->pending_tranche);
|
||||
|
||||
info->pending_tranche = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_target_device (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback,
|
||||
struct wl_array *device)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
dev_t dev;
|
||||
DmabufTranche *tranche;
|
||||
|
||||
memcpy (&dev, device->data, sizeof (dev_t));
|
||||
|
||||
g_assert (info->pending_tranche == NULL);
|
||||
|
||||
tranche = dmabuf_tranche_new ();
|
||||
tranche->target_device = dev;
|
||||
|
||||
info->pending_tranche = tranche;
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_formats (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback,
|
||||
struct wl_array *indices)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
DmabufTranche *tranche;
|
||||
int i;
|
||||
guint16 *pos;
|
||||
|
||||
g_assert (info->pending_tranche != NULL);
|
||||
tranche = info->pending_tranche;
|
||||
|
||||
tranche->n_formats = indices->size / sizeof (guint16);
|
||||
tranche->formats = g_new (DmabufFormat, tranche->n_formats);
|
||||
|
||||
i = 0;
|
||||
wl_array_for_each (pos, indices)
|
||||
{
|
||||
tranche->formats[i++] = info->dmabuf_format_table[*pos];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_tranche_flags (void *data,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback,
|
||||
uint32_t flags)
|
||||
{
|
||||
DmabufFormatsInfo *info = data;
|
||||
DmabufTranche *tranche;
|
||||
|
||||
g_assert (info->pending_tranche != NULL);
|
||||
tranche = info->pending_tranche;
|
||||
tranche->flags = flags;
|
||||
}
|
||||
|
||||
static const struct zwp_linux_dmabuf_feedback_v1_listener feedback_listener = {
|
||||
linux_dmabuf_done,
|
||||
linux_dmabuf_format_table,
|
||||
linux_dmabuf_main_device,
|
||||
linux_dmabuf_tranche_done,
|
||||
linux_dmabuf_tranche_target_device,
|
||||
linux_dmabuf_tranche_formats,
|
||||
linux_dmabuf_tranche_flags,
|
||||
};
|
||||
|
||||
DmabufFormatsInfo *
|
||||
dmabuf_formats_info_new (GdkDisplay *display,
|
||||
const char *name,
|
||||
struct zwp_linux_dmabuf_feedback_v1 *feedback)
|
||||
{
|
||||
DmabufFormatsInfo *info;
|
||||
|
||||
info = g_new0 (DmabufFormatsInfo, 1);
|
||||
|
||||
info->display = display;
|
||||
info->name = g_strdup (name);
|
||||
info->feedback = feedback;
|
||||
|
||||
if (info->feedback)
|
||||
zwp_linux_dmabuf_feedback_v1_add_listener (info->feedback,
|
||||
&feedback_listener, info);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void
|
||||
dmabuf_formats_info_free (DmabufFormatsInfo *info)
|
||||
{
|
||||
g_free (info->name);
|
||||
g_clear_pointer (&info->feedback, zwp_linux_dmabuf_feedback_v1_destroy);
|
||||
if (info->dmabuf_format_table)
|
||||
{
|
||||
munmap (info->dmabuf_format_table, info->n_dmabuf_formats * 16);
|
||||
info->dmabuf_format_table = NULL;
|
||||
}
|
||||
g_clear_pointer (&info->dmabuf_formats, dmabuf_formats_free);
|
||||
g_clear_pointer (&info->pending_dmabuf_formats, dmabuf_formats_free);
|
||||
g_clear_pointer (&info->pending_tranche, dmabuf_tranche_free);
|
||||
|
||||
g_free (info);
|
||||
}
|
@ -8,6 +8,7 @@ gdk_wayland_sources = files([
|
||||
'gdkdevice-wayland.c',
|
||||
'gdkdevicepad-wayland.c',
|
||||
'gdkdisplay-wayland.c',
|
||||
'gdkdmabuf-wayland.c',
|
||||
'gdkdrag-wayland.c',
|
||||
'gdkdragsurface-wayland.c',
|
||||
'gdkdrop-wayland.c',
|
||||
|
Loading…
Reference in New Issue
Block a user