[Mesa-dev] [PATCH 2/2] egl: move gbm link-time dependency to runtime dependency

sguttula suresh.guttula at amd.com
Sun Nov 12 07:15:52 UTC 2017


This patch will fix build error when we build with_platforms=drm
and without enabling gbm.

Chromiumos uses surfaceless platform and minigbm[not mesa-gbm]
and drm platform needed for va.When we enable drm platform ,
it is failing for dependency on gbm[as we disable mesa-gbm]
at compile time.To fix this moved link dependency to runtime.

Cc: mesa-stable at lists.freedesktop.org
Cc: Emil Velikov <emil.velikov at collabora.com>
Cc: Deepak Sharma <deepak.sharma at amd.com>

Signed-off-by: sguttula <suresh.guttula at amd.com>
Reviewed-by: Deepak Sharma <deepak.sharma at amd.com>
---
 src/egl/Makefile.am                 |   2 +-
 src/egl/drivers/dri2/platform_drm.c | 103 +++++++++++++++++++++++++++++++-----
 src/egl/main/egldisplay.c           |   5 +-
 src/gbm/main/gbm.c                  |  11 ----
 4 files changed, 95 insertions(+), 26 deletions(-)
 mode change 100644 => 100755 src/egl/Makefile.am
 mode change 100644 => 100755 src/egl/drivers/dri2/platform_drm.c
 mode change 100644 => 100755 src/egl/main/egldisplay.c
 mode change 100644 => 100755 src/gbm/main/gbm.c

diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
old mode 100644
new mode 100755
index eeb745f..3bad977
--- a/src/egl/Makefile.am
+++ b/src/egl/Makefile.am
@@ -94,7 +94,7 @@ dri2_backend_FILES += \
 endif
 
 if HAVE_PLATFORM_DRM
-libEGL_common_la_LIBADD += $(top_builddir)/src/gbm/libgbm.la
+
 dri2_backend_FILES += drivers/dri2/platform_drm.c
 endif
 
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
old mode 100644
new mode 100755
index 9005f5d..f489881
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -39,7 +39,19 @@
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
 #include "loader.h"
+static void* gbm_handle =NULL;
 
+/** Destroy the gbm device and free all resources associated with it.
+ *
+ * \param gbm The device created using gbm_create_device()
+ */
+GBM_EXPORT void
+gbm_device_destroy(struct gbm_device *gbm)
+{
+   gbm->refcount--;
+   if (gbm->refcount == 0)
+      gbm->destroy(gbm);
+}
 static struct gbm_bo *
 lock_front_buffer(struct gbm_surface *_surf)
 {
@@ -169,11 +181,18 @@ dri2_drm_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
 
+   void (* gbm_fp)();
    dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
    for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-      if (dri2_surf->color_buffers[i].bo)
-	 gbm_bo_destroy(dri2_surf->color_buffers[i].bo);
+      if (dri2_surf->color_buffers[i].bo){
+         gbm_fp = dlsym(gbm_handle,"gbm_bo_destroy");
+         if(dlerror() != NULL){
+           _eglError(EGL_BAD_PARAMETER,"failed to get gbm_bo_destroy");
+           return EGL_FALSE;
+         }
+         gbm_fp(dri2_surf->color_buffers[i].bo);
+      }
    }
 
    dri2_egl_surface_free_local_buffers(dri2_surf);
@@ -192,6 +211,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
    struct gbm_dri_surface *surf = dri2_surf->gbm_surf;
    int age = 0;
 
+   struct gbm_bo* (* gbm_fp)();
    if (dri2_surf->back == NULL) {
       for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
 	 if (!dri2_surf->color_buffers[i].locked &&
@@ -205,19 +225,32 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
    if (dri2_surf->back == NULL)
       return -1;
    if (dri2_surf->back->bo == NULL) {
-      if (surf->base.modifiers)
-         dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base,
+      if (surf->base.modifiers){
+         gbm_fp = dlsym(gbm_handle,"gbm_bo_create_with_modifiers");
+         if(dlerror() != NULL){
+           _eglError(EGL_BAD_PARAMETER,"failed to"
+                                "get gbm_bo_create_with_modifiers");
+           return -1;
+         }
+         dri2_surf->back->bo = gbm_fp(&dri2_dpy->gbm_dri->base,
                                                             surf->base.width,
                                                             surf->base.height,
                                                             surf->base.format,
                                                             surf->base.modifiers,
                                                             surf->base.count);
-      else
-         dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,
+      }
+      else {
+         gbm_fp = dlsym(gbm_handle,"gbm_bo_create");
+         if(dlerror() != NULL){
+           _eglError(EGL_BAD_PARAMETER,"failed to get gbm_bo_create");
+           return -1;
+         }
+         dri2_surf->back->bo = gbm_fp(&dri2_dpy->gbm_dri->base,
                                              surf->base.width,
                                              surf->base.height,
                                              surf->base.format,
                                              surf->base.flags);
+    }
 
    }
    if (dri2_surf->back->bo == NULL)
@@ -233,15 +266,22 @@ get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
       dri2_egl_display(dri2_surf->base.Resource.Display);
    struct gbm_dri_surface *surf = dri2_surf->gbm_surf;
 
+   struct gbm_bo* (* gbm_fp)();
    if (dri2_surf->current == NULL) {
       assert(!dri2_surf->color_buffers[0].locked);
       dri2_surf->current = &dri2_surf->color_buffers[0];
    }
 
-   if (dri2_surf->current->bo == NULL)
-      dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,
+   if (dri2_surf->current->bo == NULL){
+      gbm_fp = dlsym(gbm_handle,"gbm_bo_create");
+      if(dlerror() != NULL){
+         _eglError(EGL_BAD_PARAMETER,"failed to get gbm_bo_create");
+         return -1;
+      }
+      dri2_surf->current->bo = gbm_fp(&dri2_dpy->gbm_dri->base,
                                              surf->base.width, surf->base.height,
                                              surf->base.format, surf->base.flags);
+   }
    if (dri2_surf->current->bo == NULL)
       return -1;
 
@@ -489,6 +529,7 @@ swrast_put_image2(__DRIdrawable *driDrawable,
    int x_bytes, width_bytes;
    char *src, *dst;
 
+   uint32_t (* gbm_fp)();
    if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&
        op != __DRI_SWRAST_IMAGE_OP_SWAP)
       return;
@@ -498,7 +539,12 @@ swrast_put_image2(__DRIdrawable *driDrawable,
 
    bo = gbm_dri_bo(dri2_surf->current->bo);
 
-   bpp = gbm_bo_get_bpp(&bo->base);
+   gbm_fp = dlsym(gbm_handle,"gbm_bo_get_bpp");
+   if(dlerror() != NULL){
+      _eglError(EGL_BAD_PARAMETER,"failed to get gbm_bo_get_bpp");
+      return;
+   }
+   bpp = gbm_fp(&bo->base);
    if (bpp == 0)
       return;
 
@@ -538,12 +584,18 @@ swrast_get_image(__DRIdrawable *driDrawable,
    int x_bytes, width_bytes;
    char *src, *dst;
 
+   uint32_t (* gbm_fp)();
    if (get_swrast_front_bo(dri2_surf) < 0)
       return;
 
    bo = gbm_dri_bo(dri2_surf->current->bo);
 
-   bpp = gbm_bo_get_bpp(&bo->base);
+   gbm_fp = dlsym(gbm_handle,"gbm_bo_get_bpp");
+   if(dlerror() != NULL){
+      _eglError(EGL_BAD_PARAMETER,"failed to get gbm_bo_get_bpp");
+      return;
+   }
+   bpp = gbm_fp(&bo->base);
    if (bpp == 0)
       return;
 
@@ -652,6 +704,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    struct gbm_device *gbm;
    const char *err;
 
+   int (* gbm_fp)();
    loader_set_logger(_eglLog);
 
    dri2_dpy = calloc(1, sizeof *dri2_dpy);
@@ -660,6 +713,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
 
    dri2_dpy->fd = -1;
    disp->DriverData = (void *) dri2_dpy;
+#if defined(__x86_64__)
+   gbm_handle = dlopen("/usr/lib64/libgbm.so.1", RTLD_LAZY);
+#else
+   gbm_handle = dlopen("/usr/lib/libgbm.so.1", RTLD_LAZY);
+#endif
+   if (!gbm_handle) {
+      err = "DRI2: failed to get gbm handle";
+      goto cleanup;
+   }
 
    gbm = disp->PlatformDisplay;
    if (gbm == NULL) {
@@ -667,21 +729,36 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
       int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);
       if (n != -1 && n < sizeof(buf))
          dri2_dpy->fd = loader_open_device(buf);
-      gbm = gbm_create_device(dri2_dpy->fd);
+      gbm_fp = dlsym(gbm_handle,"gbm_create_device");
+      if(dlerror() != NULL){
+         err = "DRI2: failed to get gbm_create_device";
+         goto cleanup;
+      }
+      gbm = gbm_fp(dri2_dpy->fd);
       if (gbm == NULL) {
          err = "DRI2: failed to create gbm device";
          goto cleanup;
       }
       dri2_dpy->own_device = true;
    } else {
-      dri2_dpy->fd = fcntl(gbm_device_get_fd(gbm), F_DUPFD_CLOEXEC, 3);
+      gbm_fp = dlsym(gbm_handle,"gbm_device_get_fd");
+      if(dlerror() != NULL){
+         err = "DRI2: failed to get gbm_device_get_fd";
+         goto cleanup;
+      }
+      dri2_dpy->fd = fcntl(gbm_fp(gbm), F_DUPFD_CLOEXEC, 3);
       if (dri2_dpy->fd < 0) {
          err = "DRI2: failed to fcntl() existing gbm device";
          goto cleanup;
       }
    }
 
-   if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) {
+   gbm_fp = dlsym(gbm_handle,"gbm_device_get_backend_name");
+   if(dlerror() != NULL){
+      err = "DRI2: failed to get gbm_device_get_backend_name";
+      goto cleanup;
+   }
+   if (strcmp(gbm_fp(gbm), "drm") != 0) {
       err = "DRI2: gbm device using incorrect/incompatible backend";
       goto cleanup;
    }
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
old mode 100644
new mode 100755
index 690728d..831f7bb
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -38,6 +38,7 @@
 #include "c11/threads.h"
 #include "util/u_atomic.h"
 
+#include <dlfcn.h>
 #include "eglcontext.h"
 #include "eglcurrent.h"
 #include "eglsurface.h"
@@ -107,6 +108,7 @@ _eglGetNativePlatformFromEnv(void)
 static _EGLPlatformType
 _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 {
+    Dl_info info;
    if (nativeDisplay == EGL_DEFAULT_DISPLAY)
       return _EGL_INVALID_PLATFORM;
 
@@ -124,7 +126,8 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
 
 #ifdef HAVE_DRM_PLATFORM
       /* gbm has a pointer to its constructor as first element. */
-      if (first_pointer == gbm_create_device)
+      dladdr(first_pointer, &info);
+      if (!strcmp(info.dli_sname,"gbm_create_device"))
          return _EGL_PLATFORM_DRM;
 #endif
 
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
old mode 100644
new mode 100755
index 0bf2922..16de5d0
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -99,17 +99,6 @@ gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
    return gbm->get_format_modifier_plane_count(gbm, format, modifier);
 }
 
-/** Destroy the gbm device and free all resources associated with it.
- *
- * \param gbm The device created using gbm_create_device()
- */
-GBM_EXPORT void
-gbm_device_destroy(struct gbm_device *gbm)
-{
-   gbm->refcount--;
-   if (gbm->refcount == 0)
-      gbm->destroy(gbm);
-}
 
 /** Create a gbm device for allocating buffers
  *
-- 
2.7.4



More information about the mesa-dev mailing list