This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5daec103f1e638ea98a132786d9c42858c4c7aa9
Author: Zhe Weng <[email protected]>
AuthorDate: Tue Dec 23 16:54:43 2025 +0800

    drivers/virtio-gpu: add RGB565 support
    
    Although RGB565 does not belong to the standard virtio spec,
    virtio-gpu-gl can accept it.
    
    Usage example:
    -device virtio-gpu-gl-device,bus=virtio-mmio-bus.1 -display sdl,gl=on
    
    Ref:
    
https://gitlab.freedesktop.org/virgl/virglrenderer/-/blob/1.2.0/src/virgl_hw.h
    
https://gitlab.freedesktop.org/virgl/virglrenderer/-/blob/1.2.0/src/vrend/vrend_formats.c#L56-365
    
    Signed-off-by: Zhe Weng <[email protected]>
---
 drivers/virtio/Kconfig      | 13 +++++++++++++
 drivers/virtio/virtio-gpu.c | 12 +++++++++---
 drivers/virtio/virtio-gpu.h |  9 +++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 442416bde90..6e915b9920d 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -49,6 +49,19 @@ config DRIVERS_VIRTIO_GPU
        select FB_UPDATE
        select DRIVERS_VIRTIO
 
+choice
+       prompt "Select virtio-gpu framebuffer format"
+       default DRIVERS_VIRTIO_GPU_XRGB8888
+       depends on DRIVERS_VIRTIO_GPU
+
+config DRIVERS_VIRTIO_GPU_XRGB8888
+       bool "XRGB8888"
+
+config DRIVERS_VIRTIO_GPU_RGB565
+       bool "RGB565 (Supported by virtio-gpu-gl)"
+
+endchoice
+
 config DRIVERS_VIRTIO_INPUT
        bool "Virtio input support"
        depends on INPUT
diff --git a/drivers/virtio/virtio-gpu.c b/drivers/virtio/virtio-gpu.c
index 19d720a147c..56b44ba6db7 100644
--- a/drivers/virtio/virtio-gpu.c
+++ b/drivers/virtio/virtio-gpu.c
@@ -37,9 +37,15 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define VIRTIO_GPU_BPP          32
-#define VIRTIO_GPU_FB_FMT       FB_FMT_RGB32
-#define VIRTIO_GPU_FMT          VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM
+#ifdef CONFIG_DRIVERS_VIRTIO_GPU_RGB565
+#  define VIRTIO_GPU_BPP        16
+#  define VIRTIO_GPU_FB_FMT     FB_FMT_RGB16_565
+#  define VIRTIO_GPU_FMT        VIRTIO_GPU_FORMAT_B5G6R5_UNORM
+#else
+#  define VIRTIO_GPU_BPP        32
+#  define VIRTIO_GPU_FB_FMT     FB_FMT_RGB32
+#  define VIRTIO_GPU_FMT        VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM
+#endif
 
 #define VIRTIO_GPU_CTL          0
 #define VIRTIO_GPU_NUM          1
diff --git a/drivers/virtio/virtio-gpu.h b/drivers/virtio/virtio-gpu.h
index 6e47f506c75..dc80f02d3f8 100644
--- a/drivers/virtio/virtio-gpu.h
+++ b/drivers/virtio/virtio-gpu.h
@@ -410,6 +410,15 @@ enum virtio_gpu_formats
 
   VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM  = 121,
   VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM  = 134,
+
+  /* We can only use below formats under VirGL, e.g., virtio-gpu-gl-device
+   * Example:
+   *   -device virtio-gpu-gl-device,bus=virtio-mmio-bus.1 -display sdl,gl=on
+   */
+
+  VIRTIO_GPU_FORMAT_B5G5R5A1_UNORM  = 5,
+  VIRTIO_GPU_FORMAT_B4G4R4A4_UNORM  = 6,
+  VIRTIO_GPU_FORMAT_B5G6R5_UNORM    = 7,
 };
 
 /* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID */

Reply via email to