1From 78032ab9467c3217375d917beff219468893649a Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Thu, 12 May 2022 11:26:31 +0800
4Subject: [PATCH] NativeStateDRM: Honor visual configuration
5
6Create GBM surface that matches visual configuration.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 src/native-state-drm.cpp | 22 ++++++++++++----------
11 1 file changed, 12 insertions(+), 10 deletions(-)
12
13diff --git a/src/native-state-drm.cpp b/src/native-state-drm.cpp
14index 2979917..dad4154 100644
15--- a/src/native-state-drm.cpp
16+++ b/src/native-state-drm.cpp
17@@ -50,13 +50,22 @@ NativeStateDRM::display()
18 }
19
20 bool
21-NativeStateDRM::create_window(WindowProperties const& /*properties*/)
22+NativeStateDRM::create_window(WindowProperties const& properties)
23 {
24     if (!dev_) {
25         Log::error("Error: DRM device has not been initialized!\n");
26         return false;
27     }
28
29+    /* egl config's native visual id is drm fourcc */
30+    surface_ = gbm_surface_create(dev_, mode_->hdisplay, mode_->vdisplay,
31+                                  properties.visual_id,
32+                                  GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
33+    if (!surface_) {
34+        Log::error("Failed to create GBM surface\n");
35+        return false;
36+    }
37+
38     return true;
39 }
40
41@@ -427,8 +436,9 @@ NativeStateDRM::fb_get_from_bo(gbm_bo* bo)
42     unsigned int height = gbm_bo_get_height(bo);
43     unsigned int stride = gbm_bo_get_stride(bo);
44     unsigned int handle = gbm_bo_get_handle(bo).u32;
45+    unsigned int bpp = gbm_bo_get_bpp(bo);
46     unsigned int fb_id(0);
47-    int status = drmModeAddFB(fd_, width, height, 24, 32, stride, handle, &fb_id);
48+    int status = drmModeAddFB(fd_, width, height, bpp, bpp, stride, handle, &fb_id);
49     if (status < 0) {
50         Log::error("Failed to create FB: %d\n", status);
51         return 0;
52@@ -452,14 +462,6 @@ NativeStateDRM::init_gbm()
53         return false;
54     }
55
56-    surface_ = gbm_surface_create(dev_, mode_->hdisplay, mode_->vdisplay,
57-                                  GBM_FORMAT_XRGB8888,
58-                                  GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
59-    if (!surface_) {
60-        Log::error("Failed to create GBM surface\n");
61-        return false;
62-    }
63-
64     return true;
65 }
66
67--
682.20.1
69
70