[cairo] [PATCH v8 16/71] drm: inline helper for cairo_format_t -> fourcc conversion

Enrico Weigelt, metux IT consult enrico.weigelt at gr13.net
Thu Jun 30 15:45:54 UTC 2016


Signed-off-by: Enrico Weigelt, metux IT consult <enrico.weigelt at gr13.net>
---
 src/drm/cairo-drm-private.h | 46 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/drm/cairo-drm-private.h b/src/drm/cairo-drm-private.h
index 2c621a0..4ba8f5b 100644
--- a/src/drm/cairo-drm-private.h
+++ b/src/drm/cairo-drm-private.h
@@ -36,14 +36,16 @@
 #ifndef CAIRO_DRM_PRIVATE_H
 #define CAIRO_DRM_PRIVATE_H
 
+#include <sys/types.h> /* dev_t */
+#include <libdrm/drm.h>
+#include <libdrm/drm_fourcc.h>
+
 #include "cairo-drm.h"
 
 #include "cairo-device-private.h"
 #include "cairo-reference-count-private.h"
 #include "cairo-surface-private.h"
 
-#include <sys/types.h> /* dev_t */
-
 typedef struct _cairo_drm_device cairo_drm_device_t;
 
 typedef cairo_drm_device_t *
@@ -157,6 +159,46 @@ cairo_drm_bo_destroy (cairo_device_t *abstract_device,
     }
 }
 
+static inline uint32_t _cairo_drm_format_fourcc(const cairo_format_t format)
+{
+    switch (format)
+    {
+	case CAIRO_FORMAT_ARGB32:	return DRM_FORMAT_ARGB8888;
+	case CAIRO_FORMAT_RGB24:	return DRM_FORMAT_RGB888;
+	case CAIRO_FORMAT_RGB16_565:	return DRM_FORMAT_RGB565;
+	case CAIRO_FORMAT_RGB30:	return DRM_FORMAT_ARGB2101010;
+
+	/* hmm, not actually supported by DRM */
+	case CAIRO_FORMAT_A8:		return fourcc_code ('A', '8', 0, 0);
+	case CAIRO_FORMAT_A1:		return fourcc_code ('A', '1', 0, 0);
+
+	/* invalid format */
+	case CAIRO_FORMAT_INVALID:	return fourcc_code (0, 0, 0, 0);
+    }
+
+    return fourcc_code (0, 0, 0, 0);
+}
+
+static inline uint32_t _cairo_drm_format_bpp(const cairo_format_t format)
+{
+    switch (format)
+    {
+	case CAIRO_FORMAT_ARGB32:	return 32;
+	case CAIRO_FORMAT_RGB24:	return 24;
+	case CAIRO_FORMAT_RGB16_565:	return 16;
+	case CAIRO_FORMAT_RGB30:	return 32;
+
+	/* hmm, not actually supported by DRM */
+	case CAIRO_FORMAT_A8:		return 8;
+	case CAIRO_FORMAT_A1:		return 1;
+
+	/* invalid format */
+	case CAIRO_FORMAT_INVALID:	return 0;
+    }
+
+    return fourcc_code (0, 0, 0, 0);
+}
+
 cairo_private cairo_status_t
 _cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
 			     cairo_drm_bo_t *bo,
-- 
2.6.4.442.g545299f



More information about the cairo mailing list