169b9a
From df989559119707094b17269d025bcdf83df765f1 Mon Sep 17 00:00:00 2001
169b9a
From: Tarun Gupta <tgupta@redhat.com>
169b9a
Date: Wed, 20 Jun 2018 18:54:17 +0200
169b9a
Subject: [PATCH 09/17] ui/pixman: add qemu_drm_format_to_pixman()
169b9a
169b9a
RH-Author: Tarun Gupta <tgupta@redhat.com>
169b9a
Message-id: <1529520865-18127-4-git-send-email-tgupta@redhat.com>
169b9a
Patchwork-id: 80911
169b9a
O-Subject: [RHEL7.6 qemu-kvm PATCH v3 03/11] ui/pixman: add qemu_drm_format_to_pixman()
169b9a
Bugzilla: 1555246
169b9a
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
169b9a
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
169b9a
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
169b9a
169b9a
Map drm fourcc codes to pixman formats.
169b9a
169b9a
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
169b9a
Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
169b9a
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
169b9a
169b9a
(cherry picked from a5127bd73f77b90b50d63014be10cef467c1c3f9)
169b9a
169b9a
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
169b9a
---
169b9a
 include/ui/qemu-pixman.h |  6 ++++++
169b9a
 ui/qemu-pixman.c         | 22 ++++++++++++++++++++++
169b9a
 2 files changed, 28 insertions(+)
169b9a
169b9a
diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
169b9a
index 500725c..8deb008 100644
169b9a
--- a/include/ui/qemu-pixman.h
169b9a
+++ b/include/ui/qemu-pixman.h
169b9a
@@ -27,9 +27,13 @@
169b9a
 
169b9a
 #ifdef HOST_WORDS_BIGENDIAN
169b9a
 # define PIXMAN_BE_r8g8b8     PIXMAN_r8g8b8
169b9a
+# define PIXMAN_LE_r8g8b8     PIXMAN_b8g8r8
169b9a
+# define PIXMAN_LE_a8r8g8b8   PIXMAN_b8g8r8a8
169b9a
 # define PIXMAN_LE_x8r8g8b8   PIXMAN_b8g8r8x8
169b9a
 #else
169b9a
 # define PIXMAN_BE_r8g8b8     PIXMAN_b8g8r8
169b9a
+# define PIXMAN_LE_r8g8b8     PIXMAN_r8g8b8
169b9a
+# define PIXMAN_LE_a8r8g8b8   PIXMAN_a8r8g8b8
169b9a
 # define PIXMAN_LE_x8r8g8b8   PIXMAN_x8r8g8b8
169b9a
 #endif
169b9a
 
169b9a
@@ -46,6 +50,8 @@ pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
169b9a
                                           pixman_image_t *image);
169b9a
 void qemu_pixman_image_unref(pixman_image_t *image);
169b9a
 
169b9a
+pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format);
169b9a
+
169b9a
 pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color);
169b9a
 pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
169b9a
                                                unsigned int ch);
169b9a
diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
169b9a
index 254bd8c..4be422c 100644
169b9a
--- a/ui/qemu-pixman.c
169b9a
+++ b/ui/qemu-pixman.c
169b9a
@@ -5,6 +5,28 @@
169b9a
 
169b9a
 #include "qemu-common.h"
169b9a
 #include "ui/console.h"
169b9a
+#include "drm_fourcc.h"
169b9a
+
169b9a
+/* Note: drm is little endian, pixman is native endian */
169b9a
+pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format)
169b9a
+{
169b9a
+    static const struct {
169b9a
+        uint32_t drm_format;
169b9a
+        pixman_format_code_t pixman;
169b9a
+    } map[] = {
169b9a
+        { DRM_FORMAT_RGB888,   PIXMAN_LE_r8g8b8   },
169b9a
+        { DRM_FORMAT_ARGB8888, PIXMAN_LE_a8r8g8b8 },
169b9a
+        { DRM_FORMAT_XRGB8888, PIXMAN_LE_x8r8g8b8 }
169b9a
+    };
169b9a
+    int i;
169b9a
+
169b9a
+    for (i = 0; i < ARRAY_SIZE(map); i++) {
169b9a
+        if (drm_format == map[i].drm_format) {
169b9a
+            return map[i].pixman;
169b9a
+        }
169b9a
+    }
169b9a
+    return 0;
169b9a
+}
169b9a
 
169b9a
 int qemu_pixman_get_type(int rshift, int gshift, int bshift)
169b9a
 {
169b9a
-- 
169b9a
1.8.3.1
169b9a