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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
From 45f93e3ad9402a718d3c5104ac5c9479a5c21afe Mon Sep 17 00:00:00 2001
From: Luigi Santivetti <luigi.santivetti@imgtec.com>
Date: Thu, 2 Sep 2021 22:47:54 +0100
Subject: [PATCH] egl/null: expose EXT_yuv_surface support
---
src/egl/drivers/dri2/platform_null.c | 247 +++++++++++++++++++++++++--
1 file changed, 233 insertions(+), 14 deletions(-)
diff --git a/src/egl/drivers/dri2/platform_null.c b/src/egl/drivers/dri2/platform_null.c
index 0ce7e60..c78e1fe 100644
--- a/src/egl/drivers/dri2/platform_null.c
+++ b/src/egl/drivers/dri2/platform_null.c
@@ -79,6 +79,70 @@ uint32_t get_back_buffer_id(struct dri2_egl_surface *dri2_surf)
.prop_value = value, \
}
+static const struct dri2_null_yuv_attrib {
+ uint32_t order;
+ uint32_t subsample;
+ uint32_t num_planes;
+ uint32_t plane_bpp;
+} dri2_null_yuv_attribs[] = {
+ {
+ /* __DRI_IMAGE_FORMAT_YUYV */
+ .order = __DRI_ATTRIB_YUV_ORDER_YUYV_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_2_BIT,
+ .num_planes = 1,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_NV12 */
+ .order = __DRI_ATTRIB_YUV_ORDER_YUV_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_0_BIT,
+ .num_planes = 2,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_NV21 */
+ .order = __DRI_ATTRIB_YUV_ORDER_YVU_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_0_BIT,
+ .num_planes = 2,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_YU12 */
+ .order = __DRI_ATTRIB_YUV_ORDER_YUV_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_0_BIT,
+ .num_planes = 3,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_YV12 */
+ .order = __DRI_ATTRIB_YUV_ORDER_YVU_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_0_BIT,
+ .num_planes = 3,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_UYVY */
+ .order = __DRI_ATTRIB_YUV_ORDER_UYVY_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_2_BIT,
+ .num_planes = 1,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_YVYU */
+ .order = __DRI_ATTRIB_YUV_ORDER_YVYU_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_2_BIT,
+ .num_planes = 1,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+ {
+ /* __DRI_IMAGE_FORMAT_VYUY */
+ .order = __DRI_ATTRIB_YUV_ORDER_VYUY_BIT,
+ .subsample = __DRI_ATTRIB_YUV_SUBSAMPLE_4_2_2_BIT,
+ .num_planes = 1,
+ .plane_bpp = __DRI_ATTRIB_YUV_PLANE_BPP_8_BIT,
+ },
+};
+
/*
* The index of entries in this table is used as a bitmask in
* dri2_dpy->formats, which tracks the formats supported by the display.
@@ -88,24 +152,84 @@ static const struct dri2_null_format {
int dri_image_format;
int rgba_shifts[4];
unsigned int rgba_sizes[4];
+ const struct dri2_null_yuv_attrib *yuv;
} dri2_null_formats[] = {
{
.drm_format = DRM_FORMAT_XRGB8888,
.dri_image_format = __DRI_IMAGE_FORMAT_XRGB8888,
.rgba_shifts = { 16, 8, 0, -1 },
.rgba_sizes = { 8, 8, 8, 0 },
+ .yuv = NULL,
},
{
.drm_format = DRM_FORMAT_ARGB8888,
.dri_image_format = __DRI_IMAGE_FORMAT_ARGB8888,
.rgba_shifts = { 16, 8, 0, 24 },
.rgba_sizes = { 8, 8, 8, 8 },
+ .yuv = NULL,
},
{
.drm_format = DRM_FORMAT_RGB565,
.dri_image_format = __DRI_IMAGE_FORMAT_RGB565,
.rgba_shifts = { 11, 5, 0, -1 },
.rgba_sizes = { 5, 6, 5, 0 },
+ .yuv = NULL,
+ },
+ {
+ .drm_format = DRM_FORMAT_YUYV,
+ .dri_image_format = __DRI_IMAGE_FORMAT_YUYV,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[0],
+ },
+ {
+ .drm_format = DRM_FORMAT_NV12,
+ .dri_image_format = __DRI_IMAGE_FORMAT_NV12,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[1],
+ },
+ {
+ .drm_format = DRM_FORMAT_NV21,
+ .dri_image_format = __DRI_IMAGE_FORMAT_NV21,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[2],
+ },
+ {
+ .drm_format = DRM_FORMAT_YUV420,
+ .dri_image_format = __DRI_IMAGE_FORMAT_YU12,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[3],
+ },
+ {
+ .drm_format = DRM_FORMAT_YVU420,
+ .dri_image_format = __DRI_IMAGE_FORMAT_YV12,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[4],
+ },
+ {
+ .drm_format = DRM_FORMAT_UYVY,
+ .dri_image_format = __DRI_IMAGE_FORMAT_UYVY,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[5],
+ },
+ {
+ .drm_format = DRM_FORMAT_YVYU,
+ .dri_image_format = __DRI_IMAGE_FORMAT_YVYU,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[6],
+ },
+ {
+ .drm_format = DRM_FORMAT_VYUY,
+ .dri_image_format = __DRI_IMAGE_FORMAT_VYUY,
+ .rgba_shifts = { -1, -1, -1, -1 },
+ .rgba_sizes = { 0, 0, 0, 0 },
+ .yuv = &dri2_null_yuv_attribs[7],
},
};
@@ -137,6 +261,36 @@ format_idx_get_from_config(struct dri2_egl_display *dri2_dpy,
return -1;
}
+static int
+yuv_format_idx_get_from_config(struct dri2_egl_display *dri2_dpy,
+ const __DRIconfig *dri_config)
+{
+ for (unsigned int i = 0; i < ARRAY_SIZE(dri2_null_formats); i++) {
+ const struct dri2_null_yuv_attrib *yuv = dri2_null_formats[i].yuv;
+ unsigned order, subsample, num_planes, plane_bpp;
+
+ if (!yuv)
+ continue;
+
+ dri2_dpy->core->getConfigAttrib(dri_config, __DRI_ATTRIB_YUV_ORDER,
+ &order);
+ dri2_dpy->core->getConfigAttrib(dri_config, __DRI_ATTRIB_YUV_SUBSAMPLE,
+ &subsample);
+ dri2_dpy->core->getConfigAttrib(dri_config, __DRI_ATTRIB_YUV_NUMBER_OF_PLANES,
+ &num_planes);
+ dri2_dpy->core->getConfigAttrib(dri_config, __DRI_ATTRIB_YUV_PLANE_BPP,
+ &plane_bpp);
+
+ if (order != yuv->order || subsample != yuv->subsample ||
+ num_planes != yuv->num_planes || plane_bpp != yuv->plane_bpp)
+ continue;
+
+ return i;
+ }
+
+ return -1;
+}
+
static int
format_idx_get_from_dri_image_format(uint32_t dri_image_format)
{
@@ -1082,23 +1236,21 @@ static bool
add_fb_for_dri_image(struct dri2_egl_display *dri2_dpy, __DRIimage *image,
uint32_t *fb_id_out)
{
- uint64_t modifiers[4] = {0};
+ int handle, stride, width, height, format, l_mod, h_mod, offset;
+ uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+ uint64_t *modifiers = NULL, mods[4] = {0};
uint32_t handles[4] = {0};
uint32_t pitches[4] = {0};
uint32_t offsets[4] = {0};
+ __DRIimage *p_image;
uint32_t flags = 0;
- int handle, stride, width, height, format, l_mod, h_mod;
int format_idx;
+ int num_planes;
- dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &handle);
- dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width);
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height);
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &format);
- handles[0] = (uint32_t) handle;
- pitches[0] = (uint32_t) stride;
-
format_idx = format_idx_get_from_dri_image_format(format);
assert(format_idx != -1);
@@ -1106,10 +1258,44 @@ add_fb_for_dri_image(struct dri2_egl_display *dri2_dpy, __DRIimage *image,
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &h_mod);
dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &l_mod);
- modifiers[0] = combine_u32_into_u64((uint32_t) h_mod, (uint32_t) l_mod);
+ modifier = combine_u32_into_u64((uint32_t) h_mod, (uint32_t) l_mod);
+ modifiers = mods;
+
flags |= DRM_MODE_FB_MODIFIERS;
}
+ dri2_dpy->image->queryImage(image,
+ __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes);
+ if (num_planes <= 0)
+ num_planes = 1;
+
+ for (int i = 0; i < num_planes; i++) {
+ if (dri2_dpy->in_formats_enabled) {
+ assert(modifiers && modifier != DRM_FORMAT_MOD_INVALID);
+ modifiers[i] = modifier;
+ }
+
+ p_image = dri2_dpy->image->fromPlanar(image, i, NULL);
+ if (!p_image) {
+ assert(i == 0);
+ p_image = image;
+ }
+
+ dri2_dpy->image->queryImage(p_image, __DRI_IMAGE_ATTRIB_STRIDE,
+ &stride);
+ dri2_dpy->image->queryImage(p_image, __DRI_IMAGE_ATTRIB_OFFSET,
+ &offset);
+ dri2_dpy->image->queryImage(p_image, __DRI_IMAGE_ATTRIB_HANDLE,
+ &handle);
+
+ if (p_image != image)
+ dri2_dpy->image->destroyImage(p_image);
+
+ pitches[i] = (uint32_t) stride;
+ offsets[i] = (uint32_t) offset;
+ handles[i] = (uint32_t) handle;
+ }
+
return !drmModeAddFB2WithModifiers(dri2_dpy->fd, width, height,
dri2_null_formats[format_idx].drm_format,
handles, pitches, offsets, modifiers,
@@ -1256,6 +1442,7 @@ create_surface(_EGLDisplay *disp, _EGLConfig *config, EGLint type,
struct dri2_egl_config *dri2_config = dri2_egl_config(config);
struct dri2_egl_surface *dri2_surf;
const __DRIconfig *dri_config;
+ unsigned int render_type;
_EGLSurface *surf;
int format_idx;
bool ret;
@@ -1286,7 +1473,14 @@ create_surface(_EGLDisplay *disp, _EGLConfig *config, EGLint type,
goto err_free_surface;
}
- format_idx = format_idx_get_from_config(dri2_dpy, dri_config);
+ if (!dri2_dpy->core->getConfigAttrib(dri_config, __DRI_ATTRIB_RENDER_TYPE,
+ &render_type))
+ goto err_free_surface;
+
+ if (render_type & __DRI_ATTRIB_YUV_BIT)
+ format_idx = yuv_format_idx_get_from_config(dri2_dpy, dri_config);
+ else
+ format_idx = format_idx_get_from_config(dri2_dpy, dri_config);
assert(format_idx != -1);
dri2_surf->format = dri2_null_formats[format_idx].dri_image_format;
@@ -1627,6 +1821,17 @@ dri2_null_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
return 1;
}
+static unsigned
+dri2_null_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
+{
+ switch (cap) {
+ case DRI_LOADER_CAP_YUV_SURFACE_IMG:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
static void
dri2_null_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
{
@@ -1635,10 +1840,11 @@ dri2_null_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
}
static const __DRIimageLoaderExtension image_loader_extension = {
- .base = { __DRI_IMAGE_LOADER, 1 },
+ .base = { __DRI_IMAGE_LOADER, 2 },
.getBuffers = dri2_null_image_get_buffers,
.flushFrontBuffer = dri2_null_flush_front_buffer,
+ .getCapability = dri2_null_get_capability,
};
static const __DRIextension *image_loader_extensions[] = {
@@ -1720,10 +1926,24 @@ dri2_null_add_configs_for_formats(_EGLDisplay *disp)
for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) {
struct dri2_egl_config *dri2_conf;
+ EGLint surface_type = EGL_WINDOW_BIT;
+ unsigned int render_type;
int format_idx;
- format_idx = format_idx_get_from_config(dri2_dpy,
- dri2_dpy->driver_configs[i]);
+ if (!dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+ __DRI_ATTRIB_RENDER_TYPE,
+ &render_type))
+ continue;
+
+ if (render_type & __DRI_ATTRIB_YUV_BIT) {
+ format_idx = yuv_format_idx_get_from_config(dri2_dpy,
+ dri2_dpy->driver_configs[i]);
+ } else {
+ format_idx = format_idx_get_from_config(dri2_dpy,
+ dri2_dpy->driver_configs[i]);
+ surface_type |= EGL_PBUFFER_BIT;
+ }
+
if (format_idx == -1)
continue;
@@ -1735,8 +1955,7 @@ dri2_null_add_configs_for_formats(_EGLDisplay *disp)
dri2_conf = dri2_add_config(disp,
dri2_dpy->driver_configs[i], count + 1,
- EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
- NULL, NULL, NULL);
+ surface_type, NULL, NULL, NULL);
if (dri2_conf)
count++;
}
|