summarylogtreecommitdiffstats
path: root/0023-libobs-graphics-Add-Linux-only-device_texture_create.patch
blob: f9f7f672d5a5ba2cd51359e0229d22105cbae4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
From ebefca8cedc271fcea12f85fe26521a40dc7baa8 Mon Sep 17 00:00:00 2001
From: Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
Date: Thu, 12 Mar 2020 23:50:18 -0300
Subject: [PATCH 23/25] libobs/graphics: Add Linux-only
 device_texture_create_from_dmabuf

The implementation are stubs as of now
---
 libobs-opengl/gl-nix.c              | 11 +++++++++++
 libobs-opengl/gl-nix.h              |  6 ++++++
 libobs-opengl/gl-wayland-egl.c      | 21 +++++++++++++++++++++
 libobs-opengl/gl-x11-egl.c          | 21 +++++++++++++++++++++
 libobs-opengl/gl-x11-glx.c          | 21 +++++++++++++++++++++
 libobs/graphics/device-exports.h    | 10 ++++++++++
 libobs/graphics/graphics-imports.c  |  2 ++
 libobs/graphics/graphics-internal.h |  6 ++++++
 libobs/graphics/graphics.c          | 19 +++++++++++++++++++
 libobs/graphics/graphics.h          |  9 +++++++++
 10 files changed, 126 insertions(+)

diff --git a/libobs-opengl/gl-nix.c b/libobs-opengl/gl-nix.c
index 6c272c3d..acbd154a 100644
--- a/libobs-opengl/gl-nix.c
+++ b/libobs-opengl/gl-nix.c
@@ -123,3 +123,14 @@ extern void device_present(gs_device_t *device)
 {
 	gl_vtable->device_present(device);
 }
+
+extern struct gs_texture *device_texture_create_from_dmabuf(
+	gs_device_t *device, unsigned int width, unsigned int height,
+	enum gs_color_format color_format, uint32_t n_planes, const int *fds,
+	const uint32_t *strides, const uint32_t *offsets,
+	const uint64_t *modifiers)
+{
+	return gl_vtable->device_texture_create_from_dmabuf(
+		device, width, height, color_format, n_planes, fds, strides,
+		offsets, modifiers);
+}
diff --git a/libobs-opengl/gl-nix.h b/libobs-opengl/gl-nix.h
index 741154da..3038c0cf 100644
--- a/libobs-opengl/gl-nix.h
+++ b/libobs-opengl/gl-nix.h
@@ -53,4 +53,10 @@ struct gl_winsys_vtable {
 				      gs_swapchain_t *swap);
 
 	void (*device_present)(gs_device_t *device);
+
+	struct gs_texture *(*device_texture_create_from_dmabuf)(
+		gs_device_t *device, unsigned int width, unsigned int height,
+		enum gs_color_format color_format, uint32_t n_planes,
+		const int *fds, const uint32_t *strides,
+		const uint32_t *offsets, const uint64_t *modifiers);
 };
diff --git a/libobs-opengl/gl-wayland-egl.c b/libobs-opengl/gl-wayland-egl.c
index aad6993e..3968736d 100644
--- a/libobs-opengl/gl-wayland-egl.c
+++ b/libobs-opengl/gl-wayland-egl.c
@@ -319,6 +319,25 @@ static void gl_wayland_egl_device_present(gs_device_t *device)
 	}
 }
 
+static struct gs_texture *gl_wayland_egl_device_texture_create_from_dmabuf(
+	gs_device_t *device, unsigned int width, unsigned int height,
+	enum gs_color_format color_format, uint32_t n_planes, const int *fds,
+	const uint32_t *strides, const uint32_t *offsets,
+	const uint64_t *modifiers)
+{
+	UNUSED_PARAMETER(device);
+	UNUSED_PARAMETER(width);
+	UNUSED_PARAMETER(height);
+	UNUSED_PARAMETER(color_format);
+	UNUSED_PARAMETER(n_planes);
+	UNUSED_PARAMETER(fds);
+	UNUSED_PARAMETER(strides);
+	UNUSED_PARAMETER(offsets);
+	UNUSED_PARAMETER(modifiers);
+
+	return NULL;
+}
+
 static const struct gl_winsys_vtable egl_wayland_winsys_vtable = {
 	.windowinfo_create = gl_wayland_egl_windowinfo_create,
 	.windowinfo_destroy = gl_wayland_egl_windowinfo_destroy,
@@ -334,6 +353,8 @@ static const struct gl_winsys_vtable egl_wayland_winsys_vtable = {
 	.update = gl_wayland_egl_update,
 	.device_load_swapchain = gl_wayland_egl_device_load_swapchain,
 	.device_present = gl_wayland_egl_device_present,
+	.device_texture_create_from_dmabuf =
+		gl_wayland_egl_device_texture_create_from_dmabuf,
 };
 
 const struct gl_winsys_vtable *gl_wayland_egl_get_winsys_vtable(void)
diff --git a/libobs-opengl/gl-x11-egl.c b/libobs-opengl/gl-x11-egl.c
index 47b8e420..7a9c5975 100644
--- a/libobs-opengl/gl-x11-egl.c
+++ b/libobs-opengl/gl-x11-egl.c
@@ -634,6 +634,25 @@ static void gl_x11_egl_device_present(gs_device_t *device)
 		     get_egl_error_string());
 }
 
+static struct gs_texture *gl_x11_egl_device_texture_create_from_dmabuf(
+	gs_device_t *device, unsigned int width, unsigned int height,
+	enum gs_color_format color_format, uint32_t n_planes, const int *fds,
+	const uint32_t *strides, const uint32_t *offsets,
+	const uint64_t *modifiers)
+{
+	UNUSED_PARAMETER(device);
+	UNUSED_PARAMETER(width);
+	UNUSED_PARAMETER(height);
+	UNUSED_PARAMETER(color_format);
+	UNUSED_PARAMETER(n_planes);
+	UNUSED_PARAMETER(fds);
+	UNUSED_PARAMETER(strides);
+	UNUSED_PARAMETER(offsets);
+	UNUSED_PARAMETER(modifiers);
+
+	return NULL;
+}
+
 static const struct gl_winsys_vtable egl_x11_winsys_vtable = {
 	.windowinfo_create = gl_x11_egl_windowinfo_create,
 	.windowinfo_destroy = gl_x11_egl_windowinfo_destroy,
@@ -649,6 +668,8 @@ static const struct gl_winsys_vtable egl_x11_winsys_vtable = {
 	.update = gl_x11_egl_update,
 	.device_load_swapchain = gl_x11_egl_device_load_swapchain,
 	.device_present = gl_x11_egl_device_present,
+	.device_texture_create_from_dmabuf =
+		gl_x11_egl_device_texture_create_from_dmabuf,
 };
 
 const struct gl_winsys_vtable *gl_x11_egl_get_winsys_vtable(void)
diff --git a/libobs-opengl/gl-x11-glx.c b/libobs-opengl/gl-x11-glx.c
index a562b564..802be3ef 100644
--- a/libobs-opengl/gl-x11-glx.c
+++ b/libobs-opengl/gl-x11-glx.c
@@ -579,6 +579,25 @@ static void gl_x11_glx_device_present(gs_device_t *device)
 	glXSwapBuffers(display, window);
 }
 
+static struct gs_texture *gl_x11_glx_device_texture_create_from_dmabuf(
+	gs_device_t *device, unsigned int width, unsigned int height,
+	enum gs_color_format color_format, uint32_t n_planes, const int *fds,
+	const uint32_t *strides, const uint32_t *offsets,
+	const uint64_t *modifiers)
+{
+	UNUSED_PARAMETER(device);
+	UNUSED_PARAMETER(width);
+	UNUSED_PARAMETER(height);
+	UNUSED_PARAMETER(color_format);
+	UNUSED_PARAMETER(n_planes);
+	UNUSED_PARAMETER(fds);
+	UNUSED_PARAMETER(strides);
+	UNUSED_PARAMETER(offsets);
+	UNUSED_PARAMETER(modifiers);
+
+	return NULL;
+}
+
 static const struct gl_winsys_vtable glx_winsys_vtable = {
 	.windowinfo_create = gl_x11_glx_windowinfo_create,
 	.windowinfo_destroy = gl_x11_glx_windowinfo_destroy,
@@ -594,6 +613,8 @@ static const struct gl_winsys_vtable glx_winsys_vtable = {
 	.update = gl_x11_glx_update,
 	.device_load_swapchain = gl_x11_glx_device_load_swapchain,
 	.device_present = gl_x11_glx_device_present,
+	.device_texture_create_from_dmabuf =
+		gl_x11_glx_device_texture_create_from_dmabuf,
 };
 
 const struct gl_winsys_vtable *gl_x11_glx_get_winsys_vtable(void)
diff --git a/libobs/graphics/device-exports.h b/libobs/graphics/device-exports.h
index 9b4e14b7..06ae4885 100644
--- a/libobs/graphics/device-exports.h
+++ b/libobs/graphics/device-exports.h
@@ -166,6 +166,16 @@ EXPORT void device_debug_marker_begin(gs_device_t *device,
 				      const float color[4]);
 EXPORT void device_debug_marker_end(gs_device_t *device);
 
+#if __linux__
+
+EXPORT gs_texture_t *device_texture_create_from_dmabuf(
+	gs_device_t *device, unsigned int width, unsigned int height,
+	enum gs_color_format color_format, uint32_t n_planes, const int *fds,
+	const uint32_t *strides, const uint32_t *offsets,
+	const uint64_t *modifiers);
+
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libobs/graphics/graphics-imports.c b/libobs/graphics/graphics-imports.c
index 0d3c2593..1b5b6fda 100644
--- a/libobs/graphics/graphics-imports.c
+++ b/libobs/graphics/graphics-imports.c
@@ -216,6 +216,8 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
 	GRAPHICS_IMPORT_OPTIONAL(device_stagesurface_create_nv12);
 	GRAPHICS_IMPORT_OPTIONAL(device_register_loss_callbacks);
 	GRAPHICS_IMPORT_OPTIONAL(device_unregister_loss_callbacks);
+#elif __linux__
+	GRAPHICS_IMPORT(device_texture_create_from_dmabuf);
 #endif
 
 	return success;
diff --git a/libobs/graphics/graphics-internal.h b/libobs/graphics/graphics-internal.h
index 4154688c..4e8f4e53 100644
--- a/libobs/graphics/graphics-internal.h
+++ b/libobs/graphics/graphics-internal.h
@@ -315,6 +315,12 @@ struct gs_exports {
 		gs_device_t *device, const struct gs_device_loss *callbacks);
 	void (*device_unregister_loss_callbacks)(gs_device_t *device,
 						 void *data);
+#elif __linux__
+	struct gs_texture *(*device_texture_create_from_dmabuf)(
+		gs_device_t *device, unsigned int width, unsigned int height,
+		enum gs_color_format color_format, uint32_t n_planes,
+		const int *fds, const uint32_t *strides,
+		const uint32_t *offsets, const uint64_t *modifiers);
 #endif
 };
 
diff --git a/libobs/graphics/graphics.c b/libobs/graphics/graphics.c
index e403edb0..a2785d82 100644
--- a/libobs/graphics/graphics.c
+++ b/libobs/graphics/graphics.c
@@ -1363,6 +1363,25 @@ gs_texture_t *gs_texture_create(uint32_t width, uint32_t height,
 						       levels, data, flags);
 }
 
+#if __linux__
+
+gs_texture_t *gs_texture_create_from_dmabuf(unsigned int width,
+					    unsigned int height,
+					    enum gs_color_format color_format,
+					    uint32_t n_planes, const int *fds,
+					    const uint32_t *strides,
+					    const uint32_t *offsets,
+					    const uint64_t *modifiers)
+{
+	graphics_t *graphics = thread_graphics;
+
+	return graphics->exports.device_texture_create_from_dmabuf(
+		graphics->device, width, height, color_format, n_planes, fds,
+		strides, offsets, modifiers);
+}
+
+#endif
+
 gs_texture_t *gs_cubetexture_create(uint32_t size,
 				    enum gs_color_format color_format,
 				    uint32_t levels, const uint8_t **data,
diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h
index 341a55d1..b60ee9fd 100644
--- a/libobs/graphics/graphics.h
+++ b/libobs/graphics/graphics.h
@@ -892,6 +892,15 @@ EXPORT gs_stagesurf_t *gs_stagesurface_create_nv12(uint32_t width,
 EXPORT void gs_register_loss_callbacks(const struct gs_device_loss *callbacks);
 EXPORT void gs_unregister_loss_callbacks(void *data);
 
+#elif __linux__
+
+EXPORT gs_texture_t *
+gs_texture_create_from_dmabuf(unsigned int width, unsigned int height,
+			      enum gs_color_format color_format,
+			      uint32_t n_planes, const int *fds,
+			      const uint32_t *strides, const uint32_t *offsets,
+			      const uint64_t *modifiers);
+
 #endif
 
 /* inline functions used by modules */
-- 
2.28.0