[PATCH] modesetting/glamor: attempt to use GBM instead of dumb bos.

Dave Airlie airlied at gmail.com
Thu Nov 20 20:18:24 PST 2014


From: Dave Airlie <airlied at redhat.com>

This should use gbm to set things up instead of dumb bos
so that we can later accelerate them.

I'm sure this needs severe cleaning up and build testing.

bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=86191
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 glamor/glamor.h                                  |   1 +
 glamor/glamor_egl.c                              |  12 ++
 hw/xfree86/drivers/modesetting/driver.c          |  35 +++--
 hw/xfree86/drivers/modesetting/drmmode_display.c | 171 ++++++++++++++++-------
 hw/xfree86/drivers/modesetting/drmmode_display.h |   4 +
 5 files changed, 161 insertions(+), 62 deletions(-)

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 405dbe8..3dd77ea 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -170,6 +170,7 @@ extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr,
                                                       unsigned int, Bool,
                                                       CARD16 *, CARD32 *);
 
+extern _X_EXPORT void *glamor_egl_get_gbm_device(ScreenPtr scrn);
 /* @glamor_supports_pixmap_import_export: Returns whether
  * glamor_fd_from_pixmap(), glamor_name_from_pixmap(), and
  * glamor_pixmap_from_fd() are supported.
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 182e2e8..2b9dc4e 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -176,6 +176,18 @@ glamor_create_texture_from_image(ScreenPtr screen,
     return TRUE;
 }
 
+void *
+glamor_egl_get_gbm_device(ScreenPtr screen)
+{
+#ifdef GLAMOR_HAS_GBM
+    struct glamor_egl_screen_private *glamor_egl;
+    glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
+    return glamor_egl->gbm;
+#else
+    return NULL;
+#endif
+}
+
 unsigned int
 glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h)
 {
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index e0391db..94d9e8b 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -64,6 +64,7 @@
 #ifdef GLAMOR
 #define GLAMOR_FOR_XORG 1
 #include "glamor.h"
+#include "gbm.h"
 #endif
 
 static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
@@ -889,7 +890,7 @@ CreateScreenResources(ScreenPtr pScreen)
 #ifdef GLAMOR
     if (ms->glamor) {
         if (!glamor_egl_create_textured_screen_ext(pScreen,
-                                                   ms->drmmode.front_bo->handle,
+                                                   gbm_bo_get_handle(ms->drmmode.gbm_front_bo).u32,
                                                    pScrn->displayWidth *
                                                    pScrn->bitsPerPixel / 8,
                                                    NULL)) {
@@ -904,26 +905,30 @@ CreateScreenResources(ScreenPtr pScreen)
 
     if (!ms->drmmode.sw_cursor)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
-    pixels = drmmode_map_front_bo(&ms->drmmode);
-    if (!pixels)
-        return FALSE;
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
-    if (ms->drmmode.shadow_enable)
-        pixels = ms->drmmode.shadow_fb;
+    if (!ms->glamor) {
+        pixels = drmmode_map_front_bo(&ms->drmmode);
+        if (!pixels)
+            return FALSE;
 
-    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
-        FatalError("Couldn't adjust screen pixmap\n");
+        if (ms->drmmode.shadow_enable)
+            pixels = ms->drmmode.shadow_fb;
+
+        if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
+            FatalError("Couldn't adjust screen pixmap\n");
+
+        if (ms->drmmode.shadow_enable) {
+            if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
+                           msShadowWindow, 0, 0))
+                return FALSE;
+        }
 
-    if (ms->drmmode.shadow_enable) {
-        if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
-                       msShadowWindow, 0, 0))
-            return FALSE;
     }
 
     ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
-                              pScreen, rootPixmap);
+                                  pScreen, rootPixmap);
 
     if (ms->damage) {
         DamageRegister(&rootPixmap->drawable, ms->damage);
@@ -998,8 +1003,6 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
-    if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
-        return FALSE;
 
     if (ms->drmmode.shadow_enable) {
         ms->drmmode.shadow_fb =
@@ -1064,6 +1067,8 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
         }
     }
 #endif
+    if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
+        return FALSE;
 
     if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n");
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ef9009e..f5aff94 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -48,7 +48,8 @@
 #include <X11/extensions/dpmsconst.h>
 
 #include "driver.h"
-
+#include "glamor.h"
+#include "gbm.h"
 static struct dumb_bo *
 dumb_bo_create(int fd,
                const unsigned width, const unsigned height, const unsigned bpp)
@@ -312,11 +313,23 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     height = pScrn->virtualY;
 
     if (drmmode->fb_id == 0) {
-        ret = drmModeAddFB(drmmode->fd,
-                           pScrn->virtualX, height,
-                           pScrn->depth, pScrn->bitsPerPixel,
-                           drmmode->front_bo->pitch,
-                           drmmode->front_bo->handle, &drmmode->fb_id);
+#ifdef GLAMOR_HAS_GBM
+        if (drmmode->gbm_front_bo) {
+            uint32_t handle = gbm_bo_get_handle(drmmode->gbm_front_bo).u32;
+            ret = drmModeAddFB(drmmode->fd,
+                               pScrn->virtualX, height,
+                               pScrn->depth, pScrn->bitsPerPixel,
+                               gbm_bo_get_stride(drmmode->gbm_front_bo),
+                               handle, &drmmode->fb_id);
+        } else
+#endif
+        {
+            ret = drmModeAddFB(drmmode->fd,
+                               pScrn->virtualX, height,
+                               pScrn->depth, pScrn->bitsPerPixel,
+                               drmmode->front_bo->pitch,
+                               drmmode->front_bo->handle, &drmmode->fb_id);
+        }
         if (ret < 0) {
             ErrorF("failed to add fb %d\n", ret);
             return FALSE;
@@ -1181,6 +1194,9 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
         drmmode_crtc = xf86_config->crtc[0]->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
     struct dumb_bo *old_front = NULL;
+#ifdef GLAMOR_HAS_GBM
+    struct gbm_bo *old_gbm_front = NULL;
+#endif
     Bool ret;
     ScreenPtr screen = xf86ScrnToScreen(scrn);
     uint32_t old_fb_id;
@@ -1202,47 +1218,76 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
 
     old_width = scrn->virtualX;
     old_height = scrn->virtualY;
-    old_pitch = drmmode->front_bo->pitch;
+
     old_fb_id = drmmode->fb_id;
-    old_front = drmmode->front_bo;
 
-    drmmode->front_bo =
-        dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
-    if (!drmmode->front_bo)
-        goto fail;
+#ifdef GLAMOR_HAS_GBM    
+    if (drmmode->gbm_front_bo) {
+        old_pitch = gbm_bo_get_stride(drmmode->gbm_front_bo);
+        old_gbm_front = drmmode->gbm_front_bo;
+
+        /* TODO format from bpp */
+        drmmode->gbm_front_bo = gbm_bo_create(drmmode->gbm,
+                                              width, height, GBM_FORMAT_ARGB8888,
+                                              GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+        if (!drmmode->gbm_front_bo)
+            goto fail;
 
-    pitch = drmmode->front_bo->pitch;
+        pitch = gbm_bo_get_stride(drmmode->gbm_front_bo);
 
-    scrn->virtualX = width;
-    scrn->virtualY = height;
-    scrn->displayWidth = pitch / cpp;
+        scrn->virtualX = width;
+        scrn->virtualY = height;
+        scrn->displayWidth = pitch / cpp;
 
-    ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
-                       scrn->bitsPerPixel, pitch,
-                       drmmode->front_bo->handle, &drmmode->fb_id);
-    if (ret)
-        goto fail;
-
-    new_pixels = drmmode_map_front_bo(drmmode);
-    if (!new_pixels)
-        goto fail;
-
-    if (!drmmode->shadow_enable)
-        screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-                                   pitch, new_pixels);
-    else {
-        void *new_shadow;
-        uint32_t size = scrn->displayWidth * scrn->virtualY *
-            ((scrn->bitsPerPixel + 7) >> 3);
-        new_shadow = calloc(1, size);
-        if (new_shadow == NULL)
+        ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+                           scrn->bitsPerPixel, pitch,
+                           gbm_bo_get_handle(drmmode->gbm_front_bo).u32, &drmmode->fb_id);
+        if (ret)
+            goto fail;
+      
+    } else if (drmmode->front_bo)
+#endif
+    {
+        old_pitch = drmmode->front_bo->pitch;
+        old_front = drmmode->front_bo;
+
+        drmmode->front_bo =
+            dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
+        if (!drmmode->front_bo)
+            goto fail;
+
+        pitch = drmmode->front_bo->pitch;
+
+        scrn->virtualX = width;
+        scrn->virtualY = height;
+        scrn->displayWidth = pitch / cpp;
+
+        ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+                           scrn->bitsPerPixel, pitch,
+                           drmmode->front_bo->handle, &drmmode->fb_id);
+        if (ret)
             goto fail;
-        free(drmmode->shadow_fb);
-        drmmode->shadow_fb = new_shadow;
-        screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-                                   pitch, drmmode->shadow_fb);
-    }
 
+        new_pixels = drmmode_map_front_bo(drmmode);
+        if (!new_pixels)
+            goto fail;
+
+        if (!drmmode->shadow_enable)
+            screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+                                       pitch, new_pixels);
+        else {
+            void *new_shadow;
+            uint32_t size = scrn->displayWidth * scrn->virtualY *
+                ((scrn->bitsPerPixel + 7) >> 3);
+            new_shadow = calloc(1, size);
+            if (new_shadow == NULL)
+                goto fail;
+            free(drmmode->shadow_fb);
+            drmmode->shadow_fb = new_shadow;
+            screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+                                       pitch, drmmode->shadow_fb);
+        }
+    }
     for (i = 0; i < xf86_config->num_crtc; i++) {
         xf86CrtcPtr crtc = xf86_config->crtc[i];
 
@@ -1255,15 +1300,25 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
 
     if (old_fb_id) {
         drmModeRmFB(drmmode->fd, old_fb_id);
-        dumb_bo_destroy(drmmode->fd, old_front);
+        if (old_front)
+            dumb_bo_destroy(drmmode->fd, old_front);
+#ifdef GLAMOR_HAS_GBM
+        if (old_gbm_front)
+            gbm_bo_destroy(old_gbm_front);
+#endif
     }
 
     return TRUE;
 
  fail:
+#ifdef GLAMOR_HAS_GBM
+    if (drmmode->gbm_front_bo)
+        gbm_bo_destroy(drmmode->gbm_front_bo);
+#endif
     if (drmmode->front_bo)
         dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
     drmmode->front_bo = old_front;
+    drmmode->gbm_front_bo = old_gbm_front;
     scrn->virtualX = old_width;
     scrn->virtualY = old_height;
     scrn->displayWidth = old_pitch / cpp;
@@ -1544,14 +1599,30 @@ drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
     int bpp = pScrn->bitsPerPixel;
     int i;
     int cpp = (bpp + 7) / 8;
+    int id = 0;
 
     width = pScrn->virtualX;
     height = pScrn->virtualY;
 
-    drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
-    if (!drmmode->front_bo)
-        return FALSE;
-    pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
+#ifdef GLAMOR_HAS_GBM
+    if (ms->glamor) {
+        drmmode->gbm = glamor_egl_get_gbm_device(xf86ScrnToScreen(pScrn));
+        drmmode->gbm_front_bo = gbm_bo_create(drmmode->gbm, width,
+                                              height, GBM_FORMAT_ARGB8888,
+                                              GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+        if (!drmmode->gbm_front_bo)
+            return 0;
+        pScrn->displayWidth = gbm_bo_get_stride(drmmode->gbm_front_bo) / cpp;
+        id = 1;
+    }
+#endif
+    if (id == 0) {
+        drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+        if (!drmmode->front_bo)
+            return FALSE;
+        pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
+    }
+
 
     width = ms->cursor_width;
     height = ms->cursor_height;
@@ -1625,8 +1696,14 @@ drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
         drmmode->fb_id = 0;
     }
 
-    dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
-    drmmode->front_bo = NULL;
+    if (drmmode->gbm_front_bo) {
+        gbm_bo_destroy(drmmode->gbm_front_bo);
+        drmmode->gbm_front_bo = NULL;
+    }
+    if (drmmode->front_bo) {
+        dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+        drmmode->front_bo = NULL;
+    }
 
     for (i = 0; i < xf86_config->num_crtc; i++) {
         xf86CrtcPtr crtc = xf86_config->crtc[i];
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 987608c..1a20206 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -54,6 +54,10 @@ typedef struct {
 #endif
     drmEventContext event_context;
     struct dumb_bo *front_bo;
+#ifdef GLAMOR_HAS_GBM
+    struct gbm_device *gbm;
+    struct gbm_bo *gbm_front_bo;
+#endif
     Bool sw_cursor;
 
     Bool shadow_enable;
-- 
2.1.0



More information about the xorg-devel mailing list