[Mesa-dev] [PATCH v13 13/36] st/dri: support format queries
Brian Paul
brianp at vmware.com
Mon May 22 13:47:47 UTC 2017
On 05/19/2017 08:48 AM, Lucas Stach wrote:
> Am Freitag, den 19.05.2017, 10:37 +0100 schrieb Daniel Stone:
>> From: Varad Gautam <varad.gautam at collabora.com>
>>
>> ask the driver for supported dmabuf formats
>>
>> v2: rebase to master.
>> v3: return false on failure.
>> v4: use pscreen->is_format_supported instead of adding a new query.
>> (Lucas Stach)
>> Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
>> Signed-off-by: Daniel Stone <daniels at collabora.com>
>
> Reviewed-by: Lucas Stach <l.stach at pengutronix.de>
>
>> ---
>> src/gallium/state_trackers/dri/dri2.c | 91 +++++++++++++++++++++++++++++++++++
>> 1 file changed, 91 insertions(+)
>>
>> diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
>> index 3f83cc96cc..814a08e3cb 100644
>> --- a/src/gallium/state_trackers/dri/dri2.c
>> +++ b/src/gallium/state_trackers/dri/dri2.c
>> @@ -216,6 +216,69 @@ static enum pipe_format dri2_format_to_pipe_format (int format)
>> return pf;
>> }
>>
>> +static enum pipe_format fourcc_to_pipe_format(int fourcc) {
FWIW, the Mesa formatting standard would be:
static enum pipe_format
fourcc_to_pipe_format(int fourcc)
{
-Brian
>> + enum pipe_format pf;
>> +
>> + switch (fourcc) {
>> + case __DRI_IMAGE_FOURCC_R8:
>> + pf = PIPE_FORMAT_R8_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_GR88:
>> + pf = PIPE_FORMAT_RG88_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_ARGB1555:
>> + pf = PIPE_FORMAT_B5G5R5A1_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_R16:
>> + pf = PIPE_FORMAT_R16_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_GR1616:
>> + pf = PIPE_FORMAT_RG1616_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_RGB565:
>> + pf = PIPE_FORMAT_B5G6R5_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_ARGB8888:
>> + pf = PIPE_FORMAT_BGRA8888_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_XRGB8888:
>> + pf = PIPE_FORMAT_BGRX8888_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_ABGR8888:
>> + pf = PIPE_FORMAT_RGBA8888_UNORM;
>> + break;
>> + case __DRI_IMAGE_FOURCC_XBGR8888:
>> + pf = PIPE_FORMAT_RGBX8888_UNORM;
>> + break;
>> +
>> + case __DRI_IMAGE_FOURCC_NV12:
>> + pf = PIPE_FORMAT_NV12;
>> + break;
>> + case __DRI_IMAGE_FOURCC_YUYV:
>> + pf = PIPE_FORMAT_YUYV;
>> + break;
>> + case __DRI_IMAGE_FOURCC_YUV420:
>> + case __DRI_IMAGE_FOURCC_YVU420:
>> + pf = PIPE_FORMAT_YV12;
>> + break;
>> +
>> + case __DRI_IMAGE_FOURCC_SARGB8888:
>> + case __DRI_IMAGE_FOURCC_YUV410:
>> + case __DRI_IMAGE_FOURCC_YUV411:
>> + case __DRI_IMAGE_FOURCC_YUV422:
>> + case __DRI_IMAGE_FOURCC_YUV444:
>> + case __DRI_IMAGE_FOURCC_NV16:
>> + case __DRI_IMAGE_FOURCC_YVU410:
>> + case __DRI_IMAGE_FOURCC_YVU411:
>> + case __DRI_IMAGE_FOURCC_YVU422:
>> + case __DRI_IMAGE_FOURCC_YVU444:
>> + default:
>> + pf = PIPE_FORMAT_NONE;
>> + }
>> +
>> + return pf;
>> +}
>> +
>> /**
>> * DRI2 flush extension.
>> */
>> @@ -1343,6 +1406,31 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
>> return img;
>> }
>>
>> +static boolean
>> +dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
>> + int *count)
>> +{
>> + struct dri_screen *screen = dri_screen(_screen);
>> + struct pipe_screen *pscreen = screen->base.screen;
>> + const unsigned bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
>> + int i, j;
>> +
>> + for (i = 0, j = 0; (i < ARRAY_SIZE(image_formats)) &&
>> + (j < max || max == 0); i++) {
>> + if (pscreen->is_format_supported(pscreen,
>> + fourcc_to_pipe_format(
>> + image_formats[i].fourcc),
>> + screen->target,
>> + 0, bind)) {
>> + if (j < max)
>> + formats[j] = image_formats[i].fourcc;
>> + j++;
>> + }
>> + }
>> + *count = j;
>> + return true;
>> +}
>> +
>> static __DRIimage *
>> dri2_from_dma_bufs(__DRIscreen *screen,
>> int width, int height, int fourcc,
>> @@ -1529,6 +1617,7 @@ static __DRIimageExtension dri2ImageExtension = {
>> .unmapImage = dri2_unmap_image,
>> .createImageWithModifiers = NULL,
>> .createImageFromDmaBufs2 = NULL,
>> + .queryDmaBufFormats = NULL,
>> };
>>
>>
>> @@ -2075,6 +2164,7 @@ dri2_init_screen(__DRIscreen * sPriv)
>> dri2ImageExtension.createImageFromFds = dri2_from_fds;
>> dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
>> dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
>> + dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
>> }
>> }
>>
>> @@ -2152,6 +2242,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
>> dri2ImageExtension.createImageFromFds = dri2_from_fds;
>> dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
>> dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
>> + dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
>> }
>>
>> sPriv->extensions = dri_screen_extensions;
>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list