2 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "drm-uapi/drm_fourcc.h"
25 #include "util/u_memory.h"
26 #include "pipe/p_screen.h"
27 #include "state_tracker/st_texture.h"
28 #include "state_tracker/st_context.h"
29 #include "state_tracker/st_cb_fbo.h"
30 #include "main/texobj.h"
32 #include "dri_helpers.h"
35 dri2_is_opencl_interop_loaded_locked(struct dri_screen
*screen
)
37 return screen
->opencl_dri_event_add_ref
&&
38 screen
->opencl_dri_event_release
&&
39 screen
->opencl_dri_event_wait
&&
40 screen
->opencl_dri_event_get_fence
;
44 dri2_load_opencl_interop(struct dri_screen
*screen
)
46 #if defined(RTLD_DEFAULT)
49 mtx_lock(&screen
->opencl_func_mutex
);
51 if (dri2_is_opencl_interop_loaded_locked(screen
)) {
52 mtx_unlock(&screen
->opencl_func_mutex
);
56 screen
->opencl_dri_event_add_ref
=
57 dlsym(RTLD_DEFAULT
, "opencl_dri_event_add_ref");
58 screen
->opencl_dri_event_release
=
59 dlsym(RTLD_DEFAULT
, "opencl_dri_event_release");
60 screen
->opencl_dri_event_wait
=
61 dlsym(RTLD_DEFAULT
, "opencl_dri_event_wait");
62 screen
->opencl_dri_event_get_fence
=
63 dlsym(RTLD_DEFAULT
, "opencl_dri_event_get_fence");
65 success
= dri2_is_opencl_interop_loaded_locked(screen
);
66 mtx_unlock(&screen
->opencl_func_mutex
);
74 struct dri_screen
*driscreen
;
75 struct pipe_fence_handle
*pipe_fence
;
79 static unsigned dri2_fence_get_caps(__DRIscreen
*_screen
)
81 struct dri_screen
*driscreen
= dri_screen(_screen
);
82 struct pipe_screen
*screen
= driscreen
->base
.screen
;
85 if (screen
->get_param(screen
, PIPE_CAP_NATIVE_FENCE_FD
))
86 caps
|= __DRI_FENCE_CAP_NATIVE_FD
;
92 dri2_create_fence(__DRIcontext
*_ctx
)
94 struct st_context_iface
*stapi
= dri_context(_ctx
)->st
;
95 struct dri2_fence
*fence
= CALLOC_STRUCT(dri2_fence
);
100 stapi
->flush(stapi
, 0, &fence
->pipe_fence
, NULL
, NULL
);
102 if (!fence
->pipe_fence
) {
107 fence
->driscreen
= dri_screen(_ctx
->driScreenPriv
);
112 dri2_create_fence_fd(__DRIcontext
*_ctx
, int fd
)
114 struct st_context_iface
*stapi
= dri_context(_ctx
)->st
;
115 struct pipe_context
*ctx
= stapi
->pipe
;
116 struct dri2_fence
*fence
= CALLOC_STRUCT(dri2_fence
);
119 /* exporting driver created fence, flush: */
120 stapi
->flush(stapi
, ST_FLUSH_FENCE_FD
, &fence
->pipe_fence
, NULL
, NULL
);
122 /* importing a foreign fence fd: */
123 ctx
->create_fence_fd(ctx
, &fence
->pipe_fence
, fd
, PIPE_FD_TYPE_NATIVE_SYNC
);
125 if (!fence
->pipe_fence
) {
130 fence
->driscreen
= dri_screen(_ctx
->driScreenPriv
);
135 dri2_get_fence_fd(__DRIscreen
*_screen
, void *_fence
)
137 struct dri_screen
*driscreen
= dri_screen(_screen
);
138 struct pipe_screen
*screen
= driscreen
->base
.screen
;
139 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
141 return screen
->fence_get_fd(screen
, fence
->pipe_fence
);
145 dri2_get_fence_from_cl_event(__DRIscreen
*_screen
, intptr_t cl_event
)
147 struct dri_screen
*driscreen
= dri_screen(_screen
);
148 struct dri2_fence
*fence
;
150 if (!dri2_load_opencl_interop(driscreen
))
153 fence
= CALLOC_STRUCT(dri2_fence
);
157 fence
->cl_event
= (void*)cl_event
;
159 if (!driscreen
->opencl_dri_event_add_ref(fence
->cl_event
)) {
164 fence
->driscreen
= driscreen
;
169 dri2_destroy_fence(__DRIscreen
*_screen
, void *_fence
)
171 struct dri_screen
*driscreen
= dri_screen(_screen
);
172 struct pipe_screen
*screen
= driscreen
->base
.screen
;
173 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
175 if (fence
->pipe_fence
)
176 screen
->fence_reference(screen
, &fence
->pipe_fence
, NULL
);
177 else if (fence
->cl_event
)
178 driscreen
->opencl_dri_event_release(fence
->cl_event
);
186 dri2_client_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
,
189 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
190 struct dri_screen
*driscreen
= fence
->driscreen
;
191 struct pipe_screen
*screen
= driscreen
->base
.screen
;
193 /* No need to flush. The context was flushed when the fence was created. */
195 if (fence
->pipe_fence
)
196 return screen
->fence_finish(screen
, NULL
, fence
->pipe_fence
, timeout
);
197 else if (fence
->cl_event
) {
198 struct pipe_fence_handle
*pipe_fence
=
199 driscreen
->opencl_dri_event_get_fence(fence
->cl_event
);
202 return screen
->fence_finish(screen
, NULL
, pipe_fence
, timeout
);
204 return driscreen
->opencl_dri_event_wait(fence
->cl_event
, timeout
);
213 dri2_server_wait_sync(__DRIcontext
*_ctx
, void *_fence
, unsigned flags
)
215 struct pipe_context
*ctx
= dri_context(_ctx
)->st
->pipe
;
216 struct dri2_fence
*fence
= (struct dri2_fence
*)_fence
;
218 /* We might be called here with a NULL fence as a result of WaitSyncKHR
219 * on a EGL_KHR_reusable_sync fence. Nothing to do here in such case.
224 if (ctx
->fence_server_sync
)
225 ctx
->fence_server_sync(ctx
, fence
->pipe_fence
);
228 const __DRI2fenceExtension dri2FenceExtension
= {
229 .base
= { __DRI2_FENCE
, 2 },
231 .create_fence
= dri2_create_fence
,
232 .get_fence_from_cl_event
= dri2_get_fence_from_cl_event
,
233 .destroy_fence
= dri2_destroy_fence
,
234 .client_wait_sync
= dri2_client_wait_sync
,
235 .server_wait_sync
= dri2_server_wait_sync
,
236 .get_capabilities
= dri2_fence_get_caps
,
237 .create_fence_fd
= dri2_create_fence_fd
,
238 .get_fence_fd
= dri2_get_fence_fd
,
242 dri2_lookup_egl_image(struct dri_screen
*screen
, void *handle
)
244 const __DRIimageLookupExtension
*loader
= screen
->sPriv
->dri2
.image
;
247 if (!loader
->lookupEGLImage
)
250 img
= loader
->lookupEGLImage(screen
->sPriv
,
251 handle
, screen
->sPriv
->loaderPrivate
);
257 dri2_create_image_from_renderbuffer2(__DRIcontext
*context
,
258 int renderbuffer
, void *loaderPrivate
,
261 struct gl_context
*ctx
= ((struct st_context
*)dri_context(context
)->st
)->ctx
;
262 struct gl_renderbuffer
*rb
;
263 struct pipe_resource
*tex
;
266 /* Section 3.9 (EGLImage Specification and Management) of the EGL 1.5
267 * specification says:
269 * "If target is EGL_GL_RENDERBUFFER and buffer is not the name of a
270 * renderbuffer object, or if buffer is the name of a multisampled
271 * renderbuffer object, the error EGL_BAD_PARAMETER is generated."
273 * "If target is EGL_GL_TEXTURE_2D , EGL_GL_TEXTURE_CUBE_MAP_*,
274 * EGL_GL_RENDERBUFFER or EGL_GL_TEXTURE_3D and buffer refers to the
275 * default GL texture object (0) for the corresponding GL target, the
276 * error EGL_BAD_PARAMETER is generated."
277 * (rely on _mesa_lookup_renderbuffer returning NULL in this case)
279 rb
= _mesa_lookup_renderbuffer(ctx
, renderbuffer
);
280 if (!rb
|| rb
->NumSamples
> 0) {
281 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
285 tex
= st_get_renderbuffer_resource(rb
);
287 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
291 img
= CALLOC_STRUCT(__DRIimageRec
);
293 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
297 img
->dri_format
= driGLFormatToImageFormat(rb
->Format
);
298 img
->loader_private
= loaderPrivate
;
300 pipe_resource_reference(&img
->texture
, tex
);
302 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
307 dri2_create_image_from_renderbuffer(__DRIcontext
*context
,
308 int renderbuffer
, void *loaderPrivate
)
311 return dri2_create_image_from_renderbuffer2(context
, renderbuffer
,
312 loaderPrivate
, &error
);
316 dri2_destroy_image(__DRIimage
*img
)
318 pipe_resource_reference(&img
->texture
, NULL
);
324 dri2_create_from_texture(__DRIcontext
*context
, int target
, unsigned texture
,
325 int depth
, int level
, unsigned *error
,
329 struct gl_context
*ctx
= ((struct st_context
*)dri_context(context
)->st
)->ctx
;
330 struct gl_texture_object
*obj
;
331 struct pipe_resource
*tex
;
334 obj
= _mesa_lookup_texture(ctx
, texture
);
335 if (!obj
|| obj
->Target
!= target
) {
336 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
340 tex
= st_get_texobj_resource(obj
);
342 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
346 if (target
== GL_TEXTURE_CUBE_MAP
)
349 _mesa_test_texobj_completeness(ctx
, obj
);
350 if (!obj
->_BaseComplete
|| (level
> 0 && !obj
->_MipmapComplete
)) {
351 *error
= __DRI_IMAGE_ERROR_BAD_PARAMETER
;
355 if (level
< obj
->BaseLevel
|| level
> obj
->_MaxLevel
) {
356 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
360 if (target
== GL_TEXTURE_3D
&& obj
->Image
[face
][level
]->Depth
< depth
) {
361 *error
= __DRI_IMAGE_ERROR_BAD_MATCH
;
365 img
= CALLOC_STRUCT(__DRIimageRec
);
367 *error
= __DRI_IMAGE_ERROR_BAD_ALLOC
;
373 img
->dri_format
= driGLFormatToImageFormat(obj
->Image
[face
][level
]->TexFormat
);
375 img
->loader_private
= loaderPrivate
;
377 pipe_resource_reference(&img
->texture
, tex
);
379 *error
= __DRI_IMAGE_ERROR_SUCCESS
;
383 static const struct dri2_format_mapping dri2_format_table
[] = {
384 { DRM_FORMAT_ABGR16161616F
, __DRI_IMAGE_FORMAT_ABGR16161616F
,
385 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_R16G16B16A16_FLOAT
, 1,
386 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR16161616F
, 4 } } },
387 { DRM_FORMAT_XBGR16161616F
, __DRI_IMAGE_FORMAT_XBGR16161616F
,
388 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_R16G16B16X16_FLOAT
, 1,
389 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR16161616F
, 4 } } },
390 { DRM_FORMAT_ARGB2101010
, __DRI_IMAGE_FORMAT_ARGB2101010
,
391 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_B10G10R10A2_UNORM
, 1,
392 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB2101010
, 4 } } },
393 { DRM_FORMAT_XRGB2101010
, __DRI_IMAGE_FORMAT_XRGB2101010
,
394 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_B10G10R10X2_UNORM
, 1,
395 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB2101010
, 4 } } },
396 { DRM_FORMAT_ABGR2101010
, __DRI_IMAGE_FORMAT_ABGR2101010
,
397 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_R10G10B10A2_UNORM
, 1,
398 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR2101010
, 4 } } },
399 { DRM_FORMAT_XBGR2101010
, __DRI_IMAGE_FORMAT_XBGR2101010
,
400 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_R10G10B10X2_UNORM
, 1,
401 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR2101010
, 4 } } },
402 { DRM_FORMAT_ARGB8888
, __DRI_IMAGE_FORMAT_ARGB8888
,
403 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_BGRA8888_UNORM
, 1,
404 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
405 { DRM_FORMAT_ABGR8888
, __DRI_IMAGE_FORMAT_ABGR8888
,
406 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_RGBA8888_UNORM
, 1,
407 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
408 { __DRI_IMAGE_FOURCC_SARGB8888
, __DRI_IMAGE_FORMAT_SARGB8
,
409 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_BGRA8888_SRGB
, 1,
410 { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8
, 4 } } },
411 { DRM_FORMAT_XRGB8888
, __DRI_IMAGE_FORMAT_XRGB8888
,
412 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_BGRX8888_UNORM
, 1,
413 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888
, 4 }, } },
414 { DRM_FORMAT_XBGR8888
, __DRI_IMAGE_FORMAT_XBGR8888
,
415 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_RGBX8888_UNORM
, 1,
416 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 }, } },
417 { DRM_FORMAT_ARGB1555
, __DRI_IMAGE_FORMAT_ARGB1555
,
418 __DRI_IMAGE_COMPONENTS_RGBA
, PIPE_FORMAT_B5G5R5A1_UNORM
, 1,
419 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555
, 2 } } },
420 { DRM_FORMAT_RGB565
, __DRI_IMAGE_FORMAT_RGB565
,
421 __DRI_IMAGE_COMPONENTS_RGB
, PIPE_FORMAT_B5G6R5_UNORM
, 1,
422 { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565
, 2 } } },
423 { DRM_FORMAT_R8
, __DRI_IMAGE_FORMAT_R8
,
424 __DRI_IMAGE_COMPONENTS_R
, PIPE_FORMAT_R8_UNORM
, 1,
425 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 }, } },
426 { DRM_FORMAT_R16
, __DRI_IMAGE_FORMAT_R16
,
427 __DRI_IMAGE_COMPONENTS_R
, PIPE_FORMAT_R16_UNORM
, 1,
428 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 1 }, } },
429 { DRM_FORMAT_GR88
, __DRI_IMAGE_FORMAT_GR88
,
430 __DRI_IMAGE_COMPONENTS_RG
, PIPE_FORMAT_RG88_UNORM
, 1,
431 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 }, } },
432 { DRM_FORMAT_GR1616
, __DRI_IMAGE_FORMAT_GR1616
,
433 __DRI_IMAGE_COMPONENTS_RG
, PIPE_FORMAT_RG1616_UNORM
, 1,
434 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616
, 2 }, } },
436 { DRM_FORMAT_YUV410
, __DRI_IMAGE_FORMAT_NONE
,
437 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
438 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
439 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
440 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
441 { DRM_FORMAT_YUV411
, __DRI_IMAGE_FORMAT_NONE
,
442 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
443 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
444 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
445 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
446 { DRM_FORMAT_YUV420
, __DRI_IMAGE_FORMAT_NONE
,
447 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
448 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
449 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
450 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
451 { DRM_FORMAT_YUV422
, __DRI_IMAGE_FORMAT_NONE
,
452 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
453 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
454 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
455 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
456 { DRM_FORMAT_YUV444
, __DRI_IMAGE_FORMAT_NONE
,
457 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
458 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
459 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
460 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
462 { DRM_FORMAT_YVU410
, __DRI_IMAGE_FORMAT_NONE
,
463 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
464 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
465 { 2, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 },
466 { 1, 2, 2, __DRI_IMAGE_FORMAT_R8
, 1 } } },
467 { DRM_FORMAT_YVU411
, __DRI_IMAGE_FORMAT_NONE
,
468 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
469 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
470 { 2, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
471 { 1, 2, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
472 { DRM_FORMAT_YVU420
, __DRI_IMAGE_FORMAT_NONE
,
473 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
474 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
475 { 2, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 },
476 { 1, 1, 1, __DRI_IMAGE_FORMAT_R8
, 1 } } },
477 { DRM_FORMAT_YVU422
, __DRI_IMAGE_FORMAT_NONE
,
478 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
479 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
480 { 2, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
481 { 1, 1, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
482 { DRM_FORMAT_YVU444
, __DRI_IMAGE_FORMAT_NONE
,
483 __DRI_IMAGE_COMPONENTS_Y_U_V
, PIPE_FORMAT_IYUV
, 3,
484 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
485 { 2, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
486 { 1, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 } } },
488 { DRM_FORMAT_NV12
, __DRI_IMAGE_FORMAT_NONE
,
489 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_NV12
, 2,
490 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
491 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
493 { DRM_FORMAT_P010
, __DRI_IMAGE_FORMAT_NONE
,
494 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_P016
, 2,
495 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
496 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
497 { DRM_FORMAT_P012
, __DRI_IMAGE_FORMAT_NONE
,
498 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_P016
, 2,
499 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
500 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
501 { DRM_FORMAT_P016
, __DRI_IMAGE_FORMAT_NONE
,
502 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_P016
, 2,
503 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16
, 2 },
504 { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616
, 4 } } },
506 { DRM_FORMAT_NV16
, __DRI_IMAGE_FORMAT_NONE
,
507 __DRI_IMAGE_COMPONENTS_Y_UV
, PIPE_FORMAT_NV12
, 2,
508 { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8
, 1 },
509 { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88
, 2 } } },
511 { DRM_FORMAT_AYUV
, __DRI_IMAGE_FORMAT_ABGR8888
,
512 __DRI_IMAGE_COMPONENTS_AYUV
, PIPE_FORMAT_AYUV
, 1,
513 { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } },
514 { DRM_FORMAT_XYUV8888
, __DRI_IMAGE_FORMAT_XBGR8888
,
515 __DRI_IMAGE_COMPONENTS_XYUV
, PIPE_FORMAT_XYUV
, 1,
516 { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888
, 4 } } },
518 /* For YUYV and UYVY buffers, we set up two overlapping DRI images
519 * and treat them as planar buffers in the compositors.
520 * Plane 0 is GR88 and samples YU or YV pairs and places Y into
521 * the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
522 * clusters and places pairs and places U into the G component and
523 * V into A. This lets the texture sampler interpolate the Y
524 * components correctly when sampling from plane 0, and interpolate
525 * U and V correctly when sampling from plane 1. */
526 { DRM_FORMAT_YUYV
, __DRI_IMAGE_FORMAT_NONE
,
527 __DRI_IMAGE_COMPONENTS_Y_XUXV
, PIPE_FORMAT_YUYV
, 2,
528 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
529 { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888
, 4 } } },
530 { DRM_FORMAT_UYVY
, __DRI_IMAGE_FORMAT_NONE
,
531 __DRI_IMAGE_COMPONENTS_Y_UXVX
, PIPE_FORMAT_UYVY
, 2,
532 { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88
, 2 },
533 { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888
, 4 } } }
536 const struct dri2_format_mapping
*
537 dri2_get_mapping_by_fourcc(int fourcc
)
539 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_format_table
); i
++) {
540 if (dri2_format_table
[i
].dri_fourcc
== fourcc
)
541 return &dri2_format_table
[i
];
547 const struct dri2_format_mapping
*
548 dri2_get_mapping_by_format(int format
)
550 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_format_table
); i
++) {
551 if (dri2_format_table
[i
].dri_format
== format
)
552 return &dri2_format_table
[i
];
559 dri2_get_pipe_format_for_dri_format(int format
)
561 for (unsigned i
= 0; i
< ARRAY_SIZE(dri2_format_table
); i
++) {
562 if (dri2_format_table
[i
].dri_format
== format
)
563 return dri2_format_table
[i
].pipe_format
;
566 return PIPE_FORMAT_NONE
;
570 dri2_yuv_dma_buf_supported(struct dri_screen
*screen
,
571 const struct dri2_format_mapping
*map
)
573 struct pipe_screen
*pscreen
= screen
->base
.screen
;
575 for (unsigned i
= 0; i
< map
->nplanes
; i
++) {
576 if (!pscreen
->is_format_supported(pscreen
,
577 dri2_get_pipe_format_for_dri_format(map
->planes
[i
].dri_format
),
578 screen
->target
, 0, 0, PIPE_BIND_SAMPLER_VIEW
))
585 dri2_query_dma_buf_formats(__DRIscreen
*_screen
, int max
, int *formats
,
588 struct dri_screen
*screen
= dri_screen(_screen
);
589 struct pipe_screen
*pscreen
= screen
->base
.screen
;
592 for (i
= 0, j
= 0; (i
< ARRAY_SIZE(dri2_format_table
)) &&
593 (j
< max
|| max
== 0); i
++) {
594 const struct dri2_format_mapping
*map
= &dri2_format_table
[i
];
596 /* The sRGB format is not a real FourCC as defined by drm_fourcc.h, so we
597 * must not leak it out to clients.
599 if (dri2_format_table
[i
].dri_fourcc
== __DRI_IMAGE_FOURCC_SARGB8888
)
602 if (pscreen
->is_format_supported(pscreen
, map
->pipe_format
,
603 screen
->target
, 0, 0,
604 PIPE_BIND_RENDER_TARGET
) ||
605 pscreen
->is_format_supported(pscreen
, map
->pipe_format
,
606 screen
->target
, 0, 0,
607 PIPE_BIND_SAMPLER_VIEW
) ||
608 dri2_yuv_dma_buf_supported(screen
, map
)) {
610 formats
[j
] = map
->dri_fourcc
;
618 /* vim: set sw=3 ts=8 sts=3 expandtab: */