[PATCH xserver 10/10] modesetting: allow display node has no gbm support

Qiang Yu Qiang.Yu at amd.com
Fri Jan 6 14:25:32 UTC 2017


Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c            |  2 +
 hw/xfree86/drivers/modesetting/driver.c          |  3 +-
 hw/xfree86/drivers/modesetting/drmmode_display.c | 89 +++++++++++++++++-------
 hw/xfree86/drivers/modesetting/dumb_bo.c         | 11 +++
 hw/xfree86/drivers/modesetting/dumb_bo.h         |  1 +
 hw/xfree86/drivers/modesetting/present.c         |  2 +
 6 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index e93a805..f4331be 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -570,6 +570,8 @@ can_exchange(ScrnInfoPtr scrn, DrawablePtr draw,
         if (drmmode_crtc->rotate_bo.gbm)
             return FALSE;
 #endif
+        if (drmmode_crtc->rotate_bo.dumb)
+            return FALSE;
 
         if (ms_crtc_on(config->crtc[i]))
             num_crtcs_on++;
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 782159a..bce6346 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1634,7 +1634,8 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
         else {
             ms->drmmode.gbm = gbm_create_device(ms->fd);
             if (!ms->drmmode.gbm)
-                return FALSE;
+                xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                           "all in one: display node dosen't support GBM\n");
             ms->drmmode.rgbm = glamor_egl_get_gbm_device(pScreen);
         }
     }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4ed5f6b..824f4ce 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -171,30 +171,56 @@ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
 {
 #ifdef GLAMOR_HAS_GBM
     if (drmmode->glamor) {
-        int usage = GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT;
-        if (drmmode->rgbm)
-            usage |= GBM_BO_USE_LINEAR;
-        bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
-                                GBM_FORMAT_ARGB8888, usage);
+        if (drmmode->gbm) {
+            int usage = GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT;
+            if (drmmode->rgbm)
+                usage |= GBM_BO_USE_LINEAR;
+            bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
+                                    GBM_FORMAT_ARGB8888, usage);
+            bo->dumb = NULL;
+        }
+        else {
+            bo->gbm = NULL;
+            bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp);
+        }
         bo->rgbm = NULL;
-        if (drmmode->rgbm && bo->gbm) {
-            int fd = gbm_bo_get_fd(bo->gbm);
+
+        if (drmmode->rgbm) {
+            int fd = -1;
+
+            if (bo->gbm)
+                fd = gbm_bo_get_fd(bo->gbm);
+            else if (bo->dumb)
+                fd = dumb_get_fd_from_bo(drmmode->fd, bo->dumb);
+
             if (fd >= 0) {
                 struct gbm_import_fd_data import_data = { 0 };
+
                 import_data.fd = fd;
-                import_data.width = gbm_bo_get_width(bo->gbm);
-                import_data.height = gbm_bo_get_height(bo->gbm);
-                import_data.stride = gbm_bo_get_stride(bo->gbm);
-                import_data.format = gbm_bo_get_format(bo->gbm);
+                import_data.width = width;
+                import_data.height = height;
+                import_data.format = GBM_FORMAT_ARGB8888;
+                if (bo->gbm)
+                    import_data.stride = gbm_bo_get_stride(bo->gbm);
+                else
+                    import_data.stride = bo->dumb->pitch;
+
                 bo->rgbm = gbm_bo_import(drmmode->rgbm, GBM_BO_IMPORT_FD, &import_data, 0);
                 close(fd);
             }
+
             if (!bo->rgbm) {
-                gbm_bo_destroy(bo->gbm);
-                bo->gbm = NULL;
+                if (bo->gbm) {
+                    gbm_bo_destroy(bo->gbm);
+                    bo->gbm = NULL;
+                }
+                if (bo->dumb) {
+                    dumb_bo_destroy(drmmode->fd, bo->dumb);
+                    bo->dumb = NULL;
+                }
             }
         }
-        return bo->gbm != NULL;
+        return bo->gbm != NULL || bo->dumb != NULL;
     }
 #endif
 
@@ -214,33 +240,44 @@ drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
 #ifdef GLAMOR_HAS_GBM
     if (drmmode->glamor) {
         struct gbm_bo *gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
-        if (!gbm)
+        if (!gbm) {
             bo->gbm = bo->rgbm = NULL;
+            bo->dumb = NULL;
+        }
         else if (!drmmode->rgbm) {
             bo->gbm = gbm;
             bo->rgbm = NULL;
+            bo->dumb = NULL;
         }
         else {
             bo->rgbm = gbm;
             bo->gbm = NULL;
+            bo->dumb = NULL;
             fd = gbm_bo_get_fd(bo->rgbm);
             if (fd >= 0) {
-                struct gbm_import_fd_data import_data = { 0 };
-                import_data.fd = fd;
-                import_data.width = gbm_bo_get_width(bo->rgbm);
-                import_data.height = gbm_bo_get_height(bo->rgbm);
-                import_data.stride = gbm_bo_get_stride(bo->rgbm);
-                import_data.format = gbm_bo_get_format(bo->rgbm);
-                bo->gbm = gbm_bo_import(drmmode->gbm, GBM_BO_IMPORT_FD, &import_data, 0);
+                int stride = gbm_bo_get_stride(bo->rgbm);
+                int height = gbm_bo_get_height(bo->rgbm);
+                if (drmmode->gbm) {
+                    struct gbm_import_fd_data import_data = { 0 };
+                    import_data.fd = fd;
+                    import_data.width = gbm_bo_get_width(bo->rgbm);
+                    import_data.height = height;
+                    import_data.stride = stride;
+                    import_data.format = gbm_bo_get_format(bo->rgbm);
+                    bo->gbm = gbm_bo_import(drmmode->gbm, GBM_BO_IMPORT_FD,
+                                            &import_data, 0);
+                }
+                else
+                    bo->dumb = dumb_get_bo_from_fd(drmmode->fd, fd, stride,
+                                                   stride * height);
                 close(fd);
             }
-            if (!bo->gbm) {
+            if (!bo->gbm && !bo->dumb) {
                 gbm_bo_destroy(bo->rgbm);
                 bo->rgbm = NULL;
             }
         }
-        bo->dumb = NULL;
-        return bo->gbm != NULL;
+        return bo->gbm != NULL || bo->dumb != NULL;
     }
 #endif
 
@@ -1089,7 +1126,7 @@ drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
     }
 
 #ifdef GLAMOR_HAS_GBM
-    if (drmmode->gbm)
+    if (drmmode->gbm && drmmode_crtc->rotate_bo.gbm)
         return drmmode_crtc->rotate_bo.gbm;
 #endif
     return drmmode_crtc->rotate_bo.dumb;
diff --git a/hw/xfree86/drivers/modesetting/dumb_bo.c b/hw/xfree86/drivers/modesetting/dumb_bo.c
index cf13f0a..0662408 100644
--- a/hw/xfree86/drivers/modesetting/dumb_bo.c
+++ b/hw/xfree86/drivers/modesetting/dumb_bo.c
@@ -37,6 +37,7 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <xf86drm.h>
 
 struct dumb_bo *
@@ -136,3 +137,13 @@ dumb_get_bo_from_fd(int fd, int handle, int pitch, int size)
     bo->size = size;
     return bo;
 }
+
+int
+dumb_get_fd_from_bo(int fd, struct dumb_bo *bo)
+{
+    int prime_fd;
+
+    if (drmPrimeHandleToFD(fd, bo->handle, DRM_CLOEXEC, &prime_fd))
+        return -errno;
+    return prime_fd;
+}
diff --git a/hw/xfree86/drivers/modesetting/dumb_bo.h b/hw/xfree86/drivers/modesetting/dumb_bo.h
index 9235e61..3844d12 100644
--- a/hw/xfree86/drivers/modesetting/dumb_bo.h
+++ b/hw/xfree86/drivers/modesetting/dumb_bo.h
@@ -41,5 +41,6 @@ struct dumb_bo *dumb_bo_create(int fd, const unsigned width,
 int dumb_bo_map(int fd, struct dumb_bo *bo);
 int dumb_bo_destroy(int fd, struct dumb_bo *bo);
 struct dumb_bo *dumb_get_bo_from_fd(int fd, int handle, int pitch, int size);
+int dumb_get_fd_from_bo(int fd, struct dumb_bo *bo);
 
 #endif
diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index 83add7d..fd0fa61 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -259,6 +259,8 @@ ms_present_check_flip(RRCrtcPtr crtc,
         if (drmmode_crtc->rotate_bo.gbm)
             return FALSE;
 #endif
+        if (drmmode_crtc->rotate_bo.dumb)
+            return FALSE;
 
         if (ms_crtc_on(config->crtc[i]))
             num_crtcs_on++;
-- 
2.7.4



More information about the xorg-devel mailing list