Module: Mesa
Branch: main
Commit: b4ec0b51ce47d87d21609444dddd50c91968f26d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4ec0b51ce47d87d21609444dddd50c91968f26d

Author: Simon Ser <[email protected]>
Date:   Wed Nov 15 12:51:57 2023 +0100

egl: extract EGLDevice setup in dedicated function

Extract the logic responsible for populating disp->Device via
_eglFindDevice(). This isn't much for now but will grow in a
following commit.

No functional changes.

Signed-off-by: Simon Ser <[email protected]>
Reviewed-by: Iago Toral Quiroga <[email protected]>
Reviewed-by: Leandro Ribeiro <[email protected]>
Tested-by: Iago Toral Quiroga <[email protected]>
Tested-by: Alejandro PiƱeiro <[email protected]>
Backport-to: 23.3
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26205>

---

 src/egl/drivers/dri2/egl_dri2.c         | 14 ++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h         |  3 +++
 src/egl/drivers/dri2/platform_android.c |  8 ++------
 src/egl/drivers/dri2/platform_drm.c     |  8 ++------
 src/egl/drivers/dri2/platform_wayland.c | 16 ++++------------
 src/egl/drivers/dri2/platform_x11.c     | 24 ++++++------------------
 6 files changed, 31 insertions(+), 42 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ec057e5e199..27b1e4aede9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1075,6 +1075,20 @@ dri2_setup_extensions(_EGLDisplay *disp)
    return EGL_TRUE;
 }
 
+EGLBoolean
+dri2_setup_device(_EGLDisplay *disp, EGLBoolean software)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   _EGLDevice *dev;
+
+   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, software);
+   if (!dev)
+      return EGL_FALSE;
+
+   disp->Device = dev;
+   return EGL_TRUE;
+}
+
 /**
  * Called via eglInitialize(), drv->Initialize().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index bb09ceb8e93..5edd810f476 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -483,6 +483,9 @@ dri2_create_screen(_EGLDisplay *disp);
 EGLBoolean
 dri2_setup_extensions(_EGLDisplay *disp);
 
+EGLBoolean
+dri2_setup_device(_EGLDisplay *disp, EGLBoolean software);
+
 __DRIdrawable *
 dri2_surface_get_dri_drawable(_EGLSurface *surf);
 
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index b0b327036fe..476f4cca73c 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -1476,7 +1476,6 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
 EGLBoolean
 dri2_initialize_android(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    bool device_opened = false;
    struct dri2_egl_display *dri2_dpy;
    const char *err;
@@ -1505,14 +1504,11 @@ dri2_initialize_android(_EGLDisplay *disp)
 
    dri2_dpy->fd_display_gpu = dri2_dpy->fd_render_gpu;
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, false);
-   if (!dev) {
-      err = "DRI2: failed to find EGLDevice";
+   if (!dri2_setup_device(disp, false)) {
+      err = "DRI2: failed to setup EGLDevice";
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    if (!dri2_setup_extensions(disp)) {
       err = "DRI2: failed to setup extensions";
       goto cleanup;
diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index ec492d5e76d..2f15ee7a47a 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -579,7 +579,6 @@ get_fd_render_gpu_drm(struct gbm_dri_device *gbm_dri, int 
fd_display_gpu)
 EGLBoolean
 dri2_initialize_drm(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct gbm_device *gbm;
    const char *err;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
@@ -640,14 +639,11 @@ dri2_initialize_drm(_EGLDisplay *disp)
       goto cleanup;
    }
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, dri2_dpy->gbm_dri->software);
-   if (!dev) {
-      err = "DRI2: failed to find EGLDevice";
+   if (!dri2_setup_device(disp, dri2_dpy->gbm_dri->software)) {
+      err = "DRI2: failed to setup EGLDevice";
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name);
 
    if (!dri2_load_driver_dri3(disp)) {
diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 8922a1e1a8b..ea54c5434cc 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -2161,7 +2161,6 @@ dri2_initialize_wayland_drm_extensions(struct 
dri2_egl_display *dri2_dpy)
 static EGLBoolean
 dri2_initialize_wayland_drm(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
    if (!dri2_dpy)
       return EGL_FALSE;
@@ -2205,14 +2204,11 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp)
    loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu,
                                 &dri2_dpy->fd_display_gpu);
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, false);
-   if (!dev) {
-      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice");
+   if (!dri2_setup_device(disp, false)) {
+      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to setup EGLDevice");
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) {
       free(dri2_dpy->device_name);
       dri2_dpy->device_name =
@@ -2730,7 +2726,6 @@ static const __DRIextension *swrast_loader_extensions[] = 
{
 static EGLBoolean
 dri2_initialize_wayland_swrast(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
    if (!dri2_dpy)
       return EGL_FALSE;
@@ -2776,14 +2771,11 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp)
    if (disp->Options.Zink)
       dri2_initialize_wayland_drm_extensions(dri2_dpy);
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, true);
-   if (!dev) {
-      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice");
+   if (!dri2_setup_device(disp, true)) {
+      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to setup EGLDevice");
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    dri2_dpy->driver_name = strdup(disp->Options.Zink ? "zink" : "swrast");
    if (!dri2_load_driver_swrast(disp))
       goto cleanup;
diff --git a/src/egl/drivers/dri2/platform_x11.c 
b/src/egl/drivers/dri2/platform_x11.c
index a4c64f8fe08..c6d88d03e28 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -1505,7 +1505,6 @@ dri2_x11_setup_swap_interval(_EGLDisplay *disp)
 static EGLBoolean
 dri2_initialize_x11_swrast(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
    if (!dri2_dpy)
       return EGL_FALSE;
@@ -1513,14 +1512,11 @@ dri2_initialize_x11_swrast(_EGLDisplay *disp)
    if (!dri2_get_xcb_connection(disp, dri2_dpy))
       goto cleanup;
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, true);
-   if (!dev) {
-      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice");
+   if (!dri2_setup_device(disp, true)) {
+      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to setup EGLDevice");
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    /*
     * Every hardware driver_name is set using strdup. Doing the same in
     * here will allow is to simply free the memory at dri2_terminate().
@@ -1595,7 +1591,6 @@ static const __DRIextension 
*dri3_image_loader_extensions[] = {
 static EGLBoolean
 dri2_initialize_x11_dri3(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
 
    if (!dri2_dpy)
@@ -1607,14 +1602,11 @@ dri2_initialize_x11_dri3(_EGLDisplay *disp)
    if (!dri3_x11_connect(dri2_dpy))
       goto cleanup;
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, false);
-   if (!dev) {
-      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice");
+   if (!dri2_setup_device(disp, false)) {
+      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to setup EGLDevice");
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    if (!dri2_load_driver_dri3(disp))
       goto cleanup;
 
@@ -1705,7 +1697,6 @@ static const __DRIextension *dri2_loader_extensions[] = {
 static EGLBoolean
 dri2_initialize_x11_dri2(_EGLDisplay *disp)
 {
-   _EGLDevice *dev;
    struct dri2_egl_display *dri2_dpy = dri2_display_create();
    if (!dri2_dpy)
       return EGL_FALSE;
@@ -1716,14 +1707,11 @@ dri2_initialize_x11_dri2(_EGLDisplay *disp)
    if (!dri2_x11_connect(dri2_dpy))
       goto cleanup;
 
-   dev = _eglFindDevice(dri2_dpy->fd_render_gpu, false);
-   if (!dev) {
-      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to find EGLDevice");
+   if (!dri2_setup_device(disp, false)) {
+      _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to setup EGLDevice");
       goto cleanup;
    }
 
-   disp->Device = dev;
-
    if (!dri2_load_driver(disp))
       goto cleanup;
 

Reply via email to