From 431597bc7a52a715367b3ee0048096a4ee05da93 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 3 Oct 2023 17:27:16 -0400 Subject: [PATCH] Add GdkDmabufTexture Add a new GdkTexture subclass for supporting dmabuf buffers on Linux. Also add a builder called GdkDmabufTextureBuilder. --- gdk/gdk.h | 2 + gdk/gdkdmabuftexture.c | 426 +++++++++++++++++ gdk/gdkdmabuftexture.h | 43 ++ gdk/gdkdmabuftexturebuilder.c | 856 ++++++++++++++++++++++++++++++++++ gdk/gdkdmabuftexturebuilder.h | 103 ++++ gdk/gdkdmabuftextureprivate.h | 21 + gdk/meson.build | 4 + 7 files changed, 1455 insertions(+) create mode 100644 gdk/gdkdmabuftexture.c create mode 100644 gdk/gdkdmabuftexture.h create mode 100644 gdk/gdkdmabuftexturebuilder.c create mode 100644 gdk/gdkdmabuftexturebuilder.h create mode 100644 gdk/gdkdmabuftextureprivate.h diff --git a/gdk/gdk.h b/gdk/gdk.h index 6b69c4dd89..88e45d1371 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/gdk/gdkdmabuftexture.c b/gdk/gdkdmabuftexture.c new file mode 100644 index 0000000000..f8107511c1 --- /dev/null +++ b/gdk/gdkdmabuftexture.c @@ -0,0 +1,426 @@ +/* gdkdmabuftexture.c + * + * Copyright 2023 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "config.h" + +#include "gdkdmabuftextureprivate.h" + +#ifndef __linux__ + +GType +gdk_dmabuf_texture_get_type (void) +{ + return G_TYPE_INVALID; +} + +#else + +#include "gdkdisplayprivate.h" +#include "gdkmemoryformatprivate.h" +#include "gdkmemorytextureprivate.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +/** + * GdkDmabufTexture: + * + * A `GdkTexture` representing a dma-buf object. + * + * To create a `GdkDmabufTexture`, use the auxiliary + * [class@Gdk.DmabufTextureBuilder] object. + * + * Dma-buf textures can only be created on Linux. + */ + +struct _GdkDmabufTexture +{ + GdkTexture parent_instance; + + GdkDisplay *display; + + unsigned int fourcc; + guint64 modifier; + + /* Per-plane properties. We only support 1 plane for now */ + unsigned int stride; + unsigned int offset; + int fd; + + GDestroyNotify destroy; + gpointer data; +}; + +struct _GdkDmabufTextureClass +{ + GdkTextureClass parent_class; +}; + +G_DEFINE_TYPE (GdkDmabufTexture, gdk_dmabuf_texture, GDK_TYPE_TEXTURE) + +static void +gdk_dmabuf_texture_dispose (GObject *object) +{ + GdkDmabufTexture *self = GDK_DMABUF_TEXTURE (object); + + if (self->destroy) + self->destroy (self->data); + + G_OBJECT_CLASS (gdk_dmabuf_texture_parent_class)->dispose (object); +} + +static struct { + unsigned int fourcc; + guint64 modifier; + GdkMemoryFormat memory; +} supported_formats[] = { + { DRM_FORMAT_RGB888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_R8G8B8 }, + { DRM_FORMAT_BGR888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_B8G8R8 }, + { DRM_FORMAT_ARGB8888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_A8R8G8B8 }, + { DRM_FORMAT_ABGR8888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_A8B8G8R8 }, + { DRM_FORMAT_RGBA8888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_R8G8B8A8 }, + { DRM_FORMAT_BGRA8888, DRM_FORMAT_MOD_LINEAR, GDK_MEMORY_B8G8R8A8 }, +}; + +static gboolean +get_memory_format (GdkDisplay *display, + unsigned int fourcc, + guint64 modifier, + GdkMemoryFormat *format) +{ + /* We can always support simple linear formats */ + for (int i = 0; i < G_N_ELEMENTS (supported_formats); i++) + { + if (supported_formats[i].fourcc == fourcc && + supported_formats[i].modifier == modifier) + { + *format = supported_formats[i].memory; + return TRUE; + } + } + + if (display) + { + const GdkDmabufFormat *formats; + gsize n_formats; + + /* For others, we rely on a detour though GL */ + formats = gdk_display_get_dmabuf_formats (display, &n_formats); + for (gsize i = 0; i < n_formats; i++) + { + if (formats[i].fourcc == fourcc && + formats[i].modifier == modifier) + { + *format = GDK_MEMORY_A8R8G8B8; // FIXME + return TRUE; + } + } + } + + return FALSE; +} + +static int +import_dmabuf_into_gl (GdkDmabufTexture *self) +{ + GdkGLContext *context; + EGLDisplay egl_display; + EGLint attribs[20]; + EGLImage image; + guint texture_id; + int i; + + egl_display = gdk_display_get_egl_display (self->display); + + if (egl_display == EGL_NO_DISPLAY) + { + g_warning ("Can't import dmabufs when not using EGL"); + return 0; + } + + i = 0; + attribs[i++] = EGL_WIDTH; + attribs[i++] = gdk_texture_get_width (GDK_TEXTURE (self)); + attribs[i++] = EGL_HEIGHT; + attribs[i++] = gdk_texture_get_height (GDK_TEXTURE (self)); + attribs[i++] = EGL_LINUX_DRM_FOURCC_EXT; + attribs[i++] = self->fourcc; + + attribs[i++] = EGL_DMA_BUF_PLANE0_FD_EXT; + attribs[i++] = self->fd; + attribs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT; + attribs[i++] = self->modifier & 0xFFFFFFFF; + attribs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT; + attribs[i++] = self->modifier >> 32; + attribs[i++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; + attribs[i++] = self->stride; + attribs[i++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; + attribs[i++] = self->offset; + + attribs[i++] = EGL_NONE; + + image = eglCreateImageKHR (egl_display, + EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + (EGLClientBuffer)NULL, + attribs); + if (image == EGL_NO_IMAGE) + { + g_warning ("Failed to create EGL image: %d", eglGetError ()); + return 0; + } + + context = gdk_display_get_gl_context (self->display); + gdk_gl_context_make_current (context); + + glGenTextures (1, &texture_id); + glBindTexture (GL_TEXTURE_2D, texture_id); + glEGLImageTargetTexture2DOES (GL_TEXTURE_2D, image); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + eglDestroyImageKHR (egl_display, image); + + return texture_id; +} + +static void +do_indirect_download (GdkDmabufTexture *self, + GdkMemoryFormat format, + guchar *data, + gsize stride) +{ + GdkGLTextureBuilder *builder; + int id; + GdkTexture *gl_texture; + GdkTextureDownloader *downloader; + + GDK_DEBUG (MISC, "Using EGLImage and GL import for downloading a dmabuf"); + + g_assert (GDK_IS_DISPLAY (self->display)); + g_assert (GDK_IS_GL_CONTEXT (gdk_display_get_gl_context (self->display))); + + id = import_dmabuf_into_gl (self); + if (id == 0) + return; + + builder = gdk_gl_texture_builder_new (); + + gdk_gl_texture_builder_set_context (builder, gdk_display_get_gl_context (self->display)); + gdk_gl_texture_builder_set_id (builder, id); + gdk_gl_texture_builder_set_width (builder, gdk_texture_get_width (GDK_TEXTURE (self))); + gdk_gl_texture_builder_set_height (builder, gdk_texture_get_height (GDK_TEXTURE (self))); + + gl_texture = gdk_gl_texture_builder_build (builder, NULL, NULL); + + downloader = gdk_texture_downloader_new (gl_texture); + + gdk_texture_downloader_set_format (downloader, format); + + gdk_texture_downloader_download_into (downloader, data, stride); + + gdk_texture_downloader_free (downloader); + g_object_unref (gl_texture); + g_object_unref (builder); +} + +static void +do_direct_download (GdkDmabufTexture *self, + guchar *data, + gsize stride) +{ + gsize size; + unsigned int height; + gsize src_stride; + guchar *src_data; + int bpp; + + GDK_DEBUG (MISC, "Using mmap() and memcpy() for downloading a dmabuf"); + + height = gdk_texture_get_height (GDK_TEXTURE (self)); + bpp = gdk_memory_format_bytes_per_pixel (gdk_texture_get_format (GDK_TEXTURE (self))); + + src_stride = self->stride; + size = self->stride * height; + + if (ioctl (self->fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_START|DMA_BUF_SYNC_READ }) < 0) + g_warning ("Failed to sync dma-buf: %s", g_strerror (errno)); + + src_data = mmap (NULL, size, PROT_READ, MAP_SHARED, self->fd, self->offset); + + if (stride == src_stride) + memcpy (data, src_data, size); + else + { + for (unsigned int i = 0; i < height; i++) + memcpy (data + i * stride, src_data + i * src_stride, height * bpp); + } + + if (ioctl (self->fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_END|DMA_BUF_SYNC_READ }) < 0) + g_warning ("Failed to sync dma-buf: %s", g_strerror (errno)); + + munmap (src_data, size); +} + +static void +gdk_dmabuf_texture_download (GdkTexture *texture, + GdkMemoryFormat format, + guchar *data, + gsize stride) +{ + GdkDmabufTexture *self = GDK_DMABUF_TEXTURE (texture); + GdkMemoryFormat fmt; + GdkMemoryFormat src_format = gdk_texture_get_format (texture); + + if (!get_memory_format (NULL, self->fourcc, self->modifier, &fmt)) + do_indirect_download (self, format, data, stride); + else if (format == src_format) + do_direct_download (self, data, stride); + else + { + unsigned int width, height; + guchar *src_data; + gsize src_stride; + + width = gdk_texture_get_width (texture); + height = gdk_texture_get_height (texture); + + src_stride = self->stride; + src_data = g_new (guchar, src_stride * height); + + do_direct_download (self, src_data, src_stride); + + gdk_memory_convert (data, stride, format, + src_data, src_stride, src_format, + width, height); + + g_free (src_data); + } +} + +static void +gdk_dmabuf_texture_class_init (GdkDmabufTextureClass *klass) +{ + GdkTextureClass *texture_class = GDK_TEXTURE_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + texture_class->download = gdk_dmabuf_texture_download; + + gobject_class->dispose = gdk_dmabuf_texture_dispose; +} + +static void +gdk_dmabuf_texture_init (GdkDmabufTexture *self) +{ + self->fd = -1; +} + +GdkTexture * +gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder, + GDestroyNotify destroy, + gpointer data) +{ + GdkDmabufTexture *self; + GdkTexture *update_texture; + GdkMemoryFormat format; + + if (!get_memory_format (gdk_dmabuf_texture_builder_get_display (builder), + gdk_dmabuf_texture_builder_get_fourcc (builder), + gdk_dmabuf_texture_builder_get_modifier (builder), + &format)) + { + uint32_t f = gdk_dmabuf_texture_builder_get_fourcc (builder); + uint64_t m = gdk_dmabuf_texture_builder_get_modifier(builder); + g_warning ("Unsupported dmabuf format %c%c%c%c:%#lx", f & 0xff, (f >> 8) & 0xff, (f >> 16) & 0xff, (f >> 24) & 0xff, m); + return NULL; + } + + self = g_object_new (GDK_TYPE_DMABUF_TEXTURE, + "width", gdk_dmabuf_texture_builder_get_width (builder), + "height", gdk_dmabuf_texture_builder_get_height (builder), + NULL); + + GDK_TEXTURE (self)->format = format; + + g_set_object (&self->display, gdk_dmabuf_texture_builder_get_display (builder)); + + self->fourcc = gdk_dmabuf_texture_builder_get_fourcc (builder); + self->modifier = gdk_dmabuf_texture_builder_get_modifier (builder); + self->fd = gdk_dmabuf_texture_builder_get_fd (builder); + + self->stride = gdk_dmabuf_texture_builder_get_stride (builder); + if (self->stride == 0) + self->stride = gdk_dmabuf_texture_builder_get_width (builder) * + gdk_memory_format_bytes_per_pixel (format); + self->offset = gdk_dmabuf_texture_builder_get_offset (builder); + update_texture = gdk_dmabuf_texture_builder_get_update_texture (builder); + if (update_texture) + { + cairo_region_t *update_region = gdk_dmabuf_texture_builder_get_update_region (builder); + if (update_region) + { + update_region = cairo_region_copy (update_region); + cairo_region_intersect_rectangle (update_region, + &(cairo_rectangle_int_t) { + 0, 0, + update_texture->width, update_texture->height + }); + gdk_texture_set_diff (GDK_TEXTURE (self), update_texture, update_region); + } + } + + return GDK_TEXTURE (self); +} + +unsigned int +gdk_dmabuf_texture_get_fourcc (GdkDmabufTexture *texture) +{ + return texture->fourcc; +} + +guint64 +gdk_dmabuf_texture_get_modifier (GdkDmabufTexture *texture) +{ + return texture->modifier; +} + +unsigned int +gdk_dmabuf_texture_get_offset (GdkDmabufTexture *texture) +{ + return texture->offset; +} + +unsigned int +gdk_dmabuf_texture_get_stride (GdkDmabufTexture *texture) +{ + return texture->stride; +} + +int +gdk_dmabuf_texture_get_fd (GdkDmabufTexture *texture) +{ + return texture->fd; +} + +#endif /* __linux__ */ diff --git a/gdk/gdkdmabuftexture.h b/gdk/gdkdmabuftexture.h new file mode 100644 index 0000000000..a9ec4cf8b3 --- /dev/null +++ b/gdk/gdkdmabuftexture.h @@ -0,0 +1,43 @@ +/* gdkdmabuftexture.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 Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +G_BEGIN_DECLS + +#define GDK_TYPE_DMABUF_TEXTURE (gdk_dmabuf_texture_get_type ()) + +#define GDK_DMABUF_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_DMABUF_TEXTURE, GdkDmabufTexture)) +#define GDK_IS_DMABUF_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_DMABUF_TEXTURE)) + +typedef struct _GdkDmabufTexture GdkDmabufTexture; +typedef struct _GdkDmabufTextureClass GdkDmabufTextureClass; + +GDK_AVAILABLE_IN_4_14 +GType gdk_dmabuf_texture_get_type (void) G_GNUC_CONST; + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkDmabufTexture, g_object_unref) + +G_END_DECLS diff --git a/gdk/gdkdmabuftexturebuilder.c b/gdk/gdkdmabuftexturebuilder.c new file mode 100644 index 0000000000..33f36f647a --- /dev/null +++ b/gdk/gdkdmabuftexturebuilder.c @@ -0,0 +1,856 @@ +/* + * Copyright © 2023 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Matthias Clasen + */ + +#include "config.h" + +#include "gdkdmabuftexturebuilder.h" + +#include "gdkdisplay.h" +#include "gdkenumtypes.h" +#include "gdkdmabuftextureprivate.h" + +#include + + +struct _GdkDmabufTextureBuilder +{ + GObject parent_instance; + + GdkDisplay *display; + unsigned int width; + unsigned int height; + unsigned int fourcc; + guint64 modifier; + + /* per-plane properties, only a single plane supported so far */ + unsigned int stride; + unsigned int offset; + int fd; + + GdkTexture *update_texture; + cairo_region_t *update_region; +}; + +struct _GdkDmabufTextureBuilderClass +{ + GObjectClass parent_class; +}; + +/** + * GdkDmabufTextureBuilder: + * + * `GdkDmabufTextureBuilder` is a buider used to construct [class@Gdk.Texture] + * objects from dma-buf buffers. + * + * The operation is quite simple: Create a texture builder, set all the necessary + * properties, and then call [method@Gdk.DmabufTextureBuilder.build] to create the + * new texture. + * + * The required properties for a dma-buf texture are + * - The width and height in pixels + * - The `fourcc` code and `modifier` which together identify the + * format and memory layout of the dma-buf. See the `drm_fourcc.h` + * header for more information about these + * - The file descriptor referring to the buffer + * + * `GdkDmabufTextureBuilder` can be used for quick one-shot construction of + * textures as well as kept around and reused to construct multiple textures. + * + * Since: 4.14 + */ + +enum +{ + PROP_0, + PROP_DISPLAY, + PROP_WIDTH, + PROP_HEIGHT, + PROP_FOURCC, + PROP_MODIFIER, + PROP_STRIDE, + PROP_OFFSET, + PROP_FD, + PROP_UPDATE_REGION, + PROP_UPDATE_TEXTURE, + + N_PROPS +}; + +G_DEFINE_TYPE (GdkDmabufTextureBuilder, gdk_dmabuf_texture_builder, G_TYPE_OBJECT) + +static GParamSpec *properties[N_PROPS] = { NULL, }; + +static void +gdk_dmabuf_texture_builder_dispose (GObject *object) +{ + GdkDmabufTextureBuilder *self = GDK_DMABUF_TEXTURE_BUILDER (object); + + g_clear_object (&self->update_texture); + g_clear_pointer (&self->update_region, cairo_region_destroy); + + G_OBJECT_CLASS (gdk_dmabuf_texture_builder_parent_class)->dispose (object); +} + +static void +gdk_dmabuf_texture_builder_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GdkDmabufTextureBuilder *self = GDK_DMABUF_TEXTURE_BUILDER (object); + + switch (property_id) + { + case PROP_DISPLAY: + g_value_set_object (value, self->display); + break; + + case PROP_WIDTH: + g_value_set_uint (value, self->width); + break; + + case PROP_HEIGHT: + g_value_set_uint (value, self->height); + break; + + case PROP_FOURCC: + g_value_set_uint (value, self->fourcc); + break; + + case PROP_MODIFIER: + g_value_set_uint64 (value, self->modifier); + break; + + case PROP_STRIDE: + g_value_set_uint (value, self->stride); + break; + + case PROP_OFFSET: + g_value_set_uint (value, self->offset); + break; + + case PROP_FD: + g_value_set_int (value, self->fd); + break; + + case PROP_UPDATE_REGION: + g_value_set_boxed (value, self->update_region); + break; + + case PROP_UPDATE_TEXTURE: + g_value_set_object (value, self->update_texture); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gdk_dmabuf_texture_builder_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GdkDmabufTextureBuilder *self = GDK_DMABUF_TEXTURE_BUILDER (object); + + switch (property_id) + { + case PROP_DISPLAY: + gdk_dmabuf_texture_builder_set_display (self, g_value_get_object (value)); + break; + + case PROP_WIDTH: + gdk_dmabuf_texture_builder_set_width (self, g_value_get_uint (value)); + break; + + case PROP_HEIGHT: + gdk_dmabuf_texture_builder_set_height (self, g_value_get_uint (value)); + break; + + case PROP_FOURCC: + gdk_dmabuf_texture_builder_set_fourcc (self, g_value_get_uint (value)); + break; + + case PROP_MODIFIER: + gdk_dmabuf_texture_builder_set_modifier (self, g_value_get_uint64 (value)); + break; + + case PROP_STRIDE: + gdk_dmabuf_texture_builder_set_stride (self, g_value_get_uint (value)); + break; + + case PROP_OFFSET: + gdk_dmabuf_texture_builder_set_offset (self, g_value_get_uint (value)); + break; + + case PROP_FD: + gdk_dmabuf_texture_builder_set_fd (self, g_value_get_int (value)); + break; + + case PROP_UPDATE_REGION: + gdk_dmabuf_texture_builder_set_update_region (self, g_value_get_boxed (value)); + break; + + case PROP_UPDATE_TEXTURE: + gdk_dmabuf_texture_builder_set_update_texture (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gdk_dmabuf_texture_builder_class_init (GdkDmabufTextureBuilderClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->dispose = gdk_dmabuf_texture_builder_dispose; + gobject_class->get_property = gdk_dmabuf_texture_builder_get_property; + gobject_class->set_property = gdk_dmabuf_texture_builder_set_property; + + /** + * GdkDmabufTextureBuilder:display: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_display org.gdk.Property.set=gdk_dmabuf_texture_builder_set_display) + * + * The display that this texture will be used on. + * + * Since: 4.14 + */ + properties[PROP_DISPLAY] = + g_param_spec_object ("display", NULL, NULL, + GDK_TYPE_DISPLAY, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:width: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_width org.gdk.Property.set=gdk_dmabuf_texture_builder_set_width) + * + * The width of the texture. + * + * Since: 4.14 + */ + properties[PROP_WIDTH] = + g_param_spec_uint ("width", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:height: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_height org.gdk.Property.set=gdk_dmabuf_texture_builder_set_height) + * + * The height of the texture. + * + * Since: 4.14 + */ + properties[PROP_HEIGHT] = + g_param_spec_uint ("height", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:fourcc: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_fourcc org.gdk.Property.set=gdk_dmabuf_texture_builder_set_fourcc) + * + * The format of the texture, as a fourcc value. + * + * Since: 4.14 + */ + properties[PROP_FOURCC] = + g_param_spec_uint ("fourcc", NULL, NULL, + 0, G_MAXINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:modifier: + * + * The modifier. + * + * Since: 4.14 + */ + properties[PROP_MODIFIER] = + g_param_spec_uint64 ("modifier", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:stride: + * + * The stride. + * + * Since: 4.14 + */ + properties[PROP_STRIDE] = + g_param_spec_uint ("stride", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:offset: + * + * The offset. + * + * Since: 4.14 + */ + properties[PROP_OFFSET] = + g_param_spec_uint ("offset", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:fd: + * + * The file descriptor. + * + * Since: 4.14 + */ + properties[PROP_FD] = + g_param_spec_int ("fd", NULL, NULL, + -1, G_MAXINT, -1, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:update-region: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_update_region org.gdk.Property.set=gdk_dmabuf_texture_builder_set_update_region) + * + * The update region for [property@Gdk.GLTextureBuilder:update-texture]. + * + * Since: 4.14 + */ + properties[PROP_UPDATE_REGION] = + g_param_spec_boxed ("update-region", NULL, NULL, + CAIRO_GOBJECT_TYPE_REGION, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + /** + * GdkDmabufTextureBuilder:update-texture: (attributes org.gdk.Property.get=gdk_dmabuf_texture_builder_get_update_texture org.gdk.Property.set=gdk_dmabuf_texture_builder_set_update_texture) + * + * The texture [property@Gdk.GLTextureBuilder:update-region] is an update for. + * + * Since: 4.14 + */ + properties[PROP_UPDATE_TEXTURE] = + g_param_spec_object ("update-texture", NULL, NULL, + GDK_TYPE_TEXTURE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (gobject_class, N_PROPS, properties); +} + +static void +gdk_dmabuf_texture_builder_init (GdkDmabufTextureBuilder *self) +{ + self->fd = -1; +} + +/** + * gdk_dmabuf_texture_builder_new: (constructor): + * + * Creates a new texture builder. + * + * Returns: the new `GdkTextureBuilder` + * + * Since: 4.14 + **/ +GdkDmabufTextureBuilder * +gdk_dmabuf_texture_builder_new (void) +{ + return g_object_new (GDK_TYPE_DMABUF_TEXTURE_BUILDER, NULL); +} + +/** + * gdk_dmabuf_texture_builder_get_display: + * @self: a `GdkDmabufTextureBuilder + * + * Returns the display that this texture builder is + * associated with. + * + * Returns: (transfer none) (nullable): the display + * + * Since: 4.14 + */ +GdkDisplay * +gdk_dmabuf_texture_builder_get_display (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL); + + return self->display; +} + +/** + * gdk_dmabuf_texture_builder_set_display: + * @self: a `GdkDmabufTextureBuilder + * @display: the display + * + * Sets the display that this texture builder is + * associated with. + * + * The display is used to determine the supported + * dma-buf formats. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_display (GdkDmabufTextureBuilder *self, + GdkDisplay *display) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (g_set_object (&self->display, display)) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DISPLAY]); +} + +/** + * gdk_dmabuf_texture_builder_get_width: (attributes org.gdk.Method.get_property=width) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the width previously set via gdk_dmabuf_texture_builder_set_width() or + * 0 if the width wasn't set. + * + * Returns: The width + * + * Since: 4.14 + */ +unsigned int +gdk_dmabuf_texture_builder_get_width (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->width; +} + +/** + * gdk_dmabuf_texture_builder_set_width: (attributes org.gdk.Method.set_property=width) + * @self: a `GdkDmabufTextureBuilder` + * @width: The texture's width or 0 to unset + * + * Sets the width of the texture. + * + * The width must be set before calling [method@Gdk.GLTextureBuilder.build]. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_width (GdkDmabufTextureBuilder *self, + unsigned int width) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->width == width) + return; + + self->width = width; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WIDTH]); +} + +/** + * gdk_dmabuf_texture_builder_get_height: (attributes org.gdk.Method.get_property=height) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the height previously set via gdk_dmabuf_texture_builder_set_height() or + * 0 if the height wasn't set. + * + * Returns: The height + * + * Since: 4.14 + */ +unsigned int +gdk_dmabuf_texture_builder_get_height (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->height; +} + +/** + * gdk_dmabuf_texture_builder_set_height: (attributes org.gdk.Method.set_property=height) + * @self: a `GdkDmabufTextureBuilder` + * @height: the texture's height or 0 to unset + * + * Sets the height of the texture. + * + * The height must be set before calling [method@Gdk.GLTextureBuilder.build]. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_height (GdkDmabufTextureBuilder *self, + unsigned int height) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->height == height) + return; + + self->height = height; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HEIGHT]); +} + +/** + * gdk_dmabuf_texture_builder_get_fourcc: (attributes org.gdk.Method.get_property=fourcc) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the format previously set via gdk_dmabuf_texture_builder_set_fourcc() + * or 0 if the format wasn't set. + * + * The format is specified as a fourcc code. + * + * Returns: The format + * + * Since: 4.14 + */ +unsigned int +gdk_dmabuf_texture_builder_get_fourcc (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->fourcc; +} + +/** + * gdk_dmabuf_texture_builder_set_fourcc: (attributes org.gdk.Method.set_property=fourcc) + * @self: a `GdkDmabufTextureBuilder` + * @fourcc: the texture's format or 0 to unset + * + * Sets the format of the texture. + * + * The format is specified as a fourcc code. + * + * The format must be set before calling [method@Gdk.GLTextureBuilder.build]. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_fourcc (GdkDmabufTextureBuilder *self, + unsigned int fourcc) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->fourcc == fourcc) + return; + + self->fourcc = fourcc; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FOURCC]); +} + +/** + * gdk_dmabuf_texture_builder_get_modifier: + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the modifier value. + * + * Returns: the modifier + * + * Since: 4.14 + */ +guint64 +gdk_dmabuf_texture_builder_get_modifier (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->modifier; +} + +/** + * gdk_dmabuf_texture_builder_set_modifier: + * @self: a `GdkDmabufTextureBuilder` + * @modifier: the modifier value + * + * Sets the modifier. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_modifier (GdkDmabufTextureBuilder *self, + guint64 modifier) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->modifier == modifier) + return; + + self->modifier = modifier; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODIFIER]); +} + +/** + * gdk_dmabuf_texture_builder_get_stride: + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the stride value. + * + * Returns: the stride + * + * Since: 4.14 + */ +unsigned int +gdk_dmabuf_texture_builder_get_stride (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->stride; +} + +/** + * gdk_dmabuf_texture_builder_set_stride: + * @self: a `GdkDmabufTextureBuilder` + * @stride: the stride value + * + * Sets the stride. + * + * The stride must be set for all planes before calling [method@Gdk.GLTextureBuilder.build]. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_stride (GdkDmabufTextureBuilder *self, + unsigned int stride) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->stride == stride) + return; + + self->stride = stride; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STRIDE]); +} + +/** + * gdk_dmabuf_texture_builder_get_offset: + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the offset value. + * + * Returns: the offset + * + * Since: 4.14 + */ +unsigned int +gdk_dmabuf_texture_builder_get_offset (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->offset; +} + +/** + * gdk_dmabuf_texture_builder_set_offset: + * @self: a `GdkDmabufTextureBuilder` + * @offset: the offset value + * + * Sets the offset. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_offset (GdkDmabufTextureBuilder *self, + unsigned int offset) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->offset == offset) + return; + + self->offset = offset; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_OFFSET]); +} + +/** + * gdk_dmabuf_texture_builder_get_fd: + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the file descriptor. + * + * Returns: the file descriptor + * + * Since: 4.14 + */ +int +gdk_dmabuf_texture_builder_get_fd (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), 0); + + return self->fd; +} + +/** + * gdk_dmabuf_texture_builder_set_fd: + * @self: a `GdkDmabufTextureBuilder` + * @fd: the file descriptor + * + * Sets the file descriptor. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_fd (GdkDmabufTextureBuilder *self, + int fd) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->fd == fd) + return; + + self->fd = fd; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FD]); +} + +/** + * gdk_dmabuf_texture_builder_get_update_texture: (attributes org.gdk.Method.get_property=update_texture) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the texture previously set via gdk_dmabuf_texture_builder_set_update_texture() or + * %NULL if none was set. + * + * Returns: (transfer none) (nullable): The texture + * + * Since: 4.14 + */ +GdkTexture * +gdk_dmabuf_texture_builder_get_update_texture (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL); + + return self->update_texture; +} + +/** + * gdk_dmabuf_texture_builder_set_update_texture: (attributes org.gdk.Method.set_property=update_texture) + * @self: a `GdkDmabufTextureBuilder` + * @texture: (nullable): the texture to update + * + * Sets the texture to be updated by this texture. See + * [method@Gdk.DmabufTextureBuilder.set_update_region] for an explanation. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_update_texture (GdkDmabufTextureBuilder *self, + GdkTexture *texture) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + g_return_if_fail (texture == NULL || GDK_IS_TEXTURE (texture)); + + if (!g_set_object (&self->update_texture, texture)) + return; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UPDATE_TEXTURE]); +} + +/** + * gdk_dmabuf_texture_builder_get_update_region: (attributes org.gdk.Method.get_property=update_region) + * @self: a `GdkDmabufTextureBuilder` + * + * Gets the region previously set via gdk_dmabuf_texture_builder_set_update_region() or + * %NULL if none was set. + * + * Returns: (transfer none) (nullable): The region + * + * Since: 4.14 + */ +cairo_region_t * +gdk_dmabuf_texture_builder_get_update_region (GdkDmabufTextureBuilder *self) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL); + + return self->update_region; +} + +/** + * gdk_dmabuf_texture_builder_set_update_region: (attributes org.gdk.Method.set_property=update_region) + * @self: a `GdkDmabufTextureBuilder` + * @region: (nullable): the region to update + * + * Sets the region to be updated by this texture. Together with + * [property@Gdk.DmabufTextureBuilder:update-texture] this describes an + * update of a previous texture. + * + * When rendering animations of large textures, it is possible that + * consecutive textures are only updating contents in parts of the texture. + * It is then possible to describe this update via these two properties, + * so that GTK can avoid rerendering parts that did not change. + * + * An example would be a screen recording where only the mouse pointer moves. + * + * Since: 4.14 + */ +void +gdk_dmabuf_texture_builder_set_update_region (GdkDmabufTextureBuilder *self, + cairo_region_t *region) +{ + g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self)); + + if (self->update_region == region) + return; + + g_clear_pointer (&self->update_region, cairo_region_destroy); + + if (region) + self->update_region = cairo_region_reference (region); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_UPDATE_REGION]); +} + +/** + * gdk_dmabuf_texture_builder_build: + * @self: a `GdkDmabufTextureBuilder` + * @destroy: (nullable): destroy function to be called when the texture is + * released + * @data: user data to pass to the destroy function + * + * Builds a new `GdkTexture` with the values set up in the builder. + * + * The `destroy` function gets called when the returned texture gets released. + * + * Note that it is a programming error to call this function if any mandatory + * property has not been set. + * + * It is possible to call this function multiple times to create multiple textures, + * possibly with changing properties in between. + * + * Not all formats defined in the `drm_fourcc.h` header are supported. + * + * Returns: (transfer full) (nullable): a newly built `GdkTexture` or `NULL` + * if the format is not supported + * + * Since: 4.14 + */ +GdkTexture * +gdk_dmabuf_texture_builder_build (GdkDmabufTextureBuilder *self, + GDestroyNotify destroy, + gpointer data) +{ + g_return_val_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self), NULL); + g_return_val_if_fail (destroy == NULL || data != NULL, NULL); + g_return_val_if_fail (self->width > 0, NULL); + g_return_val_if_fail (self->height > 0, NULL); + g_return_val_if_fail (self->fourcc != 0, NULL); + g_return_val_if_fail (self->fd != -1, NULL); + +#ifdef __linux__ + return gdk_dmabuf_texture_new_from_builder (self, destroy, data); +#else + return NULL; +#endif +} diff --git a/gdk/gdkdmabuftexturebuilder.h b/gdk/gdkdmabuftexturebuilder.h new file mode 100644 index 0000000000..e56338802d --- /dev/null +++ b/gdk/gdkdmabuftexturebuilder.h @@ -0,0 +1,103 @@ +/* + * Copyright © 2023 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Matthias Clasen + */ + +#pragma once + +#if !defined (__GDK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GDK_TYPE_DMABUF_TEXTURE_BUILDER (gdk_dmabuf_texture_builder_get_type ()) +GDK_AVAILABLE_IN_4_14 +GDK_DECLARE_INTERNAL_TYPE (GdkDmabufTextureBuilder, gdk_dmabuf_texture_builder, GDK, DMABUF_TEXTURE_BUILDER, GObject) + +GDK_AVAILABLE_IN_4_14 +GdkDmabufTextureBuilder *gdk_dmabuf_texture_builder_new (void); + +GDK_AVAILABLE_IN_4_14 +GdkDisplay * gdk_dmabuf_texture_builder_get_display (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_display (GdkDmabufTextureBuilder *self, + GdkDisplay *display); + +GDK_AVAILABLE_IN_4_14 +unsigned int gdk_dmabuf_texture_builder_get_width (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_width (GdkDmabufTextureBuilder *self, + unsigned int width); + +GDK_AVAILABLE_IN_4_14 +unsigned int gdk_dmabuf_texture_builder_get_height (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_height (GdkDmabufTextureBuilder *self, + unsigned int height); + +GDK_AVAILABLE_IN_4_14 +unsigned int gdk_dmabuf_texture_builder_get_fourcc (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_fourcc (GdkDmabufTextureBuilder *self, + unsigned int fourcc); + +GDK_AVAILABLE_IN_4_14 +guint64 gdk_dmabuf_texture_builder_get_modifier (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_modifier (GdkDmabufTextureBuilder *self, + guint64 modifier); + +GDK_AVAILABLE_IN_4_14 +unsigned int gdk_dmabuf_texture_builder_get_stride (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_stride (GdkDmabufTextureBuilder *self, + unsigned int stride); + +GDK_AVAILABLE_IN_4_14 +unsigned int gdk_dmabuf_texture_builder_get_offset (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_offset (GdkDmabufTextureBuilder *self, + unsigned int offset); + +GDK_AVAILABLE_IN_4_14 +int gdk_dmabuf_texture_builder_get_fd (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_fd (GdkDmabufTextureBuilder *self, + int fd); + +GDK_AVAILABLE_IN_4_14 +GdkTexture * gdk_dmabuf_texture_builder_get_update_texture (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_update_texture (GdkDmabufTextureBuilder *self, + GdkTexture *texture); + +GDK_AVAILABLE_IN_4_14 +cairo_region_t * gdk_dmabuf_texture_builder_get_update_region (GdkDmabufTextureBuilder *self) G_GNUC_PURE; +GDK_AVAILABLE_IN_4_14 +void gdk_dmabuf_texture_builder_set_update_region (GdkDmabufTextureBuilder *self, + cairo_region_t *region); + +GDK_AVAILABLE_IN_4_14 +GdkTexture * gdk_dmabuf_texture_builder_build (GdkDmabufTextureBuilder *self, + GDestroyNotify destroy, + gpointer data); + +G_END_DECLS + diff --git a/gdk/gdkdmabuftextureprivate.h b/gdk/gdkdmabuftextureprivate.h new file mode 100644 index 0000000000..b13198903a --- /dev/null +++ b/gdk/gdkdmabuftextureprivate.h @@ -0,0 +1,21 @@ +#pragma once + +#include "gdkdmabuftexture.h" + +#include "gdkdmabuftexturebuilder.h" +#include "gdktextureprivate.h" + +G_BEGIN_DECLS + +GdkTexture * gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder, + GDestroyNotify destroy, + gpointer data); + +unsigned int gdk_dmabuf_texture_get_fourcc (GdkDmabufTexture *texture); +guint64 gdk_dmabuf_texture_get_modifier (GdkDmabufTexture *texture); +unsigned int gdk_dmabuf_texture_get_offset (GdkDmabufTexture *texture); +unsigned int gdk_dmabuf_texture_get_stride (GdkDmabufTexture *texture); +int gdk_dmabuf_texture_get_fd (GdkDmabufTexture *texture); + +G_END_DECLS + diff --git a/gdk/meson.build b/gdk/meson.build index 6b2f50950d..aac4eab1c1 100644 --- a/gdk/meson.build +++ b/gdk/meson.build @@ -17,6 +17,8 @@ gdk_public_sources = files([ 'gdkdevicetool.c', 'gdkdisplay.c', 'gdkdisplaymanager.c', + 'gdkdmabuftexture.c', + 'gdkdmabuftexturebuilder.c', 'gdkdrag.c', 'gdkdragsurface.c', 'gdkdragsurfacesize.c', @@ -79,6 +81,8 @@ gdk_public_headers = files([ 'gdkdisplay.h', 'gdkdisplaymanager.h', 'gdkdrag.h', + 'gdkdmabuftexture.h', + 'gdkdmabuftexturebuilder.h', 'gdkdragsurfacesize.h', 'gdkdrawcontext.h', 'gdkdrop.h',