summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/dri/dri2.c
diff options
context:
space:
mode:
authorNicolas Dufresne <[email protected]>2016-04-16 20:49:43 -0400
committerMichel Dänzer <[email protected]>2016-04-20 17:34:03 +0900
commit4463f38766061bd058dc668e0ac2820a4cba79e7 (patch)
tree788ca8eb8111c05b7b2540053a68d62ae92f291c /src/gallium/state_trackers/dri/dri2.c
parent899bd63acefd49a668e11c42d2ad92fa55aa157d (diff)
st/dri: Factor out DRI2 to PIPE_FORMAT conversion
This code is already duplicated twice and will be useful again. This will also help when adding formats. Signed-off-by: Nicolas Dufresne <[email protected]> Reviewed-by: Michel Dänzer <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/dri/dri2.c')
-rw-r--r--src/gallium/state_trackers/dri/dri2.c61
1 files changed, 27 insertions, 34 deletions
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index fb0a1802cf2..d46d131fce4 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -101,6 +101,31 @@ static int convert_to_fourcc(int format)
return format;
}
+static enum pipe_format dri2_format_to_pipe_format (int format)
+{
+ enum pipe_format pf;
+
+ switch (format) {
+ case __DRI_IMAGE_FORMAT_RGB565:
+ pf = PIPE_FORMAT_B5G6R5_UNORM;
+ break;
+ case __DRI_IMAGE_FORMAT_XRGB8888:
+ pf = PIPE_FORMAT_BGRX8888_UNORM;
+ break;
+ case __DRI_IMAGE_FORMAT_ARGB8888:
+ pf = PIPE_FORMAT_BGRA8888_UNORM;
+ break;
+ case __DRI_IMAGE_FORMAT_ABGR8888:
+ pf = PIPE_FORMAT_RGBA8888_UNORM;
+ break;
+ default:
+ pf = PIPE_FORMAT_NONE;
+ break;
+ }
+
+ return pf;
+}
+
/**
* DRI2 flush extension.
*/
@@ -722,23 +747,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
- switch (format) {
- case __DRI_IMAGE_FORMAT_RGB565:
- pf = PIPE_FORMAT_B5G6R5_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_XRGB8888:
- pf = PIPE_FORMAT_BGRX8888_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_ARGB8888:
- pf = PIPE_FORMAT_BGRA8888_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_ABGR8888:
- pf = PIPE_FORMAT_RGBA8888_UNORM;
- break;
- default:
- pf = PIPE_FORMAT_NONE;
- break;
- }
+ pf = dri2_format_to_pipe_format (format);
if (pf == PIPE_FORMAT_NONE)
return NULL;
@@ -845,23 +854,7 @@ dri2_create_image(__DRIscreen *_screen,
tex_usage |= PIPE_BIND_CURSOR;
}
- switch (format) {
- case __DRI_IMAGE_FORMAT_RGB565:
- pf = PIPE_FORMAT_B5G6R5_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_XRGB8888:
- pf = PIPE_FORMAT_BGRX8888_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_ARGB8888:
- pf = PIPE_FORMAT_BGRA8888_UNORM;
- break;
- case __DRI_IMAGE_FORMAT_ABGR8888:
- pf = PIPE_FORMAT_RGBA8888_UNORM;
- break;
- default:
- pf = PIPE_FORMAT_NONE;
- break;
- }
+ pf = dri2_format_to_pipe_format (format);
if (pf == PIPE_FORMAT_NONE)
return NULL;