summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/dri
diff options
context:
space:
mode:
authorVarad Gautam <[email protected]>2017-05-30 17:23:45 +0530
committerEmil Velikov <[email protected]>2017-06-09 14:12:37 +0100
commitcf748242d154994c2405e0e6092b2ae549162f69 (patch)
treeb064d18224a6d0e6e001a25d71df2efaa37d69ec /src/gallium/state_trackers/dri
parent82b3d1fa9a09f60819e789d6f20878d2bc69987b (diff)
st/dri: support format queries
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) v5: stylefix to conform to formatting rules (Brian Paul). add fourcc list here instead of using struct image_format from v4. Signed-off-by: Varad Gautam <[email protected]> Reviewed-by: Lucas Stach <[email protected]> (v4) Cc: Lucas Stach <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/dri')
-rw-r--r--src/gallium/state_trackers/dri/dri2.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 228686c2e1b..b839f8b7cc1 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -56,6 +56,33 @@
#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
#endif
+static const int fourcc_formats[] = {
+ __DRI_IMAGE_FOURCC_ARGB8888,
+ __DRI_IMAGE_FOURCC_ABGR8888,
+ __DRI_IMAGE_FOURCC_SARGB8888,
+ __DRI_IMAGE_FOURCC_XRGB8888,
+ __DRI_IMAGE_FOURCC_XBGR8888,
+ __DRI_IMAGE_FOURCC_ARGB1555,
+ __DRI_IMAGE_FOURCC_RGB565,
+ __DRI_IMAGE_FOURCC_R8,
+ __DRI_IMAGE_FOURCC_R16,
+ __DRI_IMAGE_FOURCC_GR88,
+ __DRI_IMAGE_FOURCC_GR1616,
+ __DRI_IMAGE_FOURCC_YUV410,
+ __DRI_IMAGE_FOURCC_YUV411,
+ __DRI_IMAGE_FOURCC_YUV420,
+ __DRI_IMAGE_FOURCC_YUV422,
+ __DRI_IMAGE_FOURCC_YUV444,
+ __DRI_IMAGE_FOURCC_YVU410,
+ __DRI_IMAGE_FOURCC_YVU411,
+ __DRI_IMAGE_FOURCC_YVU420,
+ __DRI_IMAGE_FOURCC_YVU422,
+ __DRI_IMAGE_FOURCC_YVU444,
+ __DRI_IMAGE_FOURCC_NV12,
+ __DRI_IMAGE_FOURCC_NV16,
+ __DRI_IMAGE_FOURCC_YUYV
+};
+
static int convert_fourcc(int format, int *dri_components_p)
{
int dri_components;
@@ -176,6 +203,70 @@ static enum pipe_format dri2_format_to_pipe_format (int format)
return pf;
}
+static enum pipe_format fourcc_to_pipe_format(int fourcc)
+{
+ 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.
*/
@@ -1321,6 +1412,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(fourcc_formats)) &&
+ (j < max || max == 0); i++) {
+ if (pscreen->is_format_supported(pscreen,
+ fourcc_to_pipe_format(
+ fourcc_formats[i]),
+ screen->target,
+ 0, bind)) {
+ if (j < max)
+ formats[j] = fourcc_formats[i];
+ j++;
+ }
+ }
+ *count = j;
+ return true;
+}
+
static __DRIimage *
dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1916,6 +2032,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;
}
}
@@ -1993,6 +2110,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;