[Mesa-dev] [PATCH 02/25] egl/dri2: Move dri2_egl_display virtual funcs to vtbl

Chad Versace chad.versace at linux.intel.com
Sun Feb 9 13:37:38 PST 2014


dri2_egl_display has only one virtual function, 'authenticate'.  Define
dri2_egl_display::vtbl and move 'authenticate' there.

This prepares for the EGL platform extensions, which will add many
more virtual functions to dri2_egl_display.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c         |  2 +-
 src/egl/drivers/dri2/egl_dri2.h         |  9 +++++++--
 src/egl/drivers/dri2/platform_android.c |  9 +++++++++
 src/egl/drivers/dri2/platform_drm.c     | 10 +++++++++-
 src/egl/drivers/dri2/platform_wayland.c | 10 +++++++++-
 src/egl/drivers/dri2/platform_x11.c     | 20 ++++++++++++++++++--
 6 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 892f1f4..308b49b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1879,7 +1879,7 @@ dri2_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *disp,
 	   return EGL_FALSE;
 
    wl_drm_callbacks.authenticate =
-      (int(*)(void *, uint32_t)) dri2_dpy->authenticate;
+      (int(*)(void *, uint32_t)) dri2_dpy->vtbl->authenticate;
 
    ret = drmGetCap(dri2_dpy->fd, DRM_CAP_PRIME, &cap);
    if (ret == 0 && cap == (DRM_PRIME_CAP_IMPORT | DRM_PRIME_CAP_EXPORT) &&
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index dfc5927..3411883 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -84,8 +84,15 @@ struct dri2_egl_driver
    void (*glFlush)(void);
 };
 
+struct dri2_egl_display_vtbl {
+   int
+   (*authenticate)(_EGLDisplay *disp, uint32_t id);
+};
+
 struct dri2_egl_display
 {
+   const struct dri2_egl_display_vtbl *vtbl;
+
    int                       dri2_major;
    int                       dri2_minor;
    __DRIscreen              *dri_screen;
@@ -134,8 +141,6 @@ struct dri2_egl_display
    int			     formats;
    uint32_t                  capabilities;
 #endif
-
-   int (*authenticate) (_EGLDisplay *disp, uint32_t id);
 };
 
 struct dri2_egl_context
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 4a201c8..73aff4f 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -652,6 +652,10 @@ droid_log(EGLint level, const char *msg)
    }
 }
 
+static struct dri2_egl_display_vtbl droid_display_vtbl = {
+   .authenticate = NULL,
+};
+
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -716,6 +720,11 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 
    droid_init_driver_functions(drv);
 
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &droid_display_vtbl;
+
    return EGL_TRUE;
 
 cleanup_screen:
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index a2b387d..c082df7 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -440,6 +440,10 @@ dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)
    return drmAuthMagic(dri2_dpy->fd, id);
 }
 
+static struct dri2_egl_display_vtbl dri2_drm_display_vtbl = {
+   .authenticate = dri2_drm_authenticate,
+};
+
 EGLBoolean
 dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
 {
@@ -543,11 +547,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
 #ifdef HAVE_WAYLAND_PLATFORM
    disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
 #endif
-   dri2_dpy->authenticate = dri2_drm_authenticate;
 
    /* we're supporting EGL 1.4 */
    disp->VersionMajor = 1;
    disp->VersionMinor = 4;
 
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &dri2_drm_display_vtbl;
+
    return EGL_TRUE;
 }
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 50750a9..6622808 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -951,6 +951,10 @@ dri2_setup_swap_interval(struct dri2_egl_display *dri2_dpy)
    }
 }
 
+static struct dri2_egl_display_vtbl dri2_wl_display_vtbl = {
+   .authenticate = dri2_wayland_authenticate,
+};
+
 EGLBoolean
 dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
 {
@@ -1061,7 +1065,6 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
    disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
    disp->Extensions.WL_create_wayland_buffer_from_image = EGL_TRUE;
    disp->Extensions.EXT_buffer_age = EGL_TRUE;
-   dri2_dpy->authenticate = dri2_wayland_authenticate;
 
    disp->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE;
 
@@ -1069,6 +1072,11 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
    disp->VersionMajor = 1;
    disp->VersionMinor = 4;
 
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &dri2_wl_display_vtbl;
+
    return EGL_TRUE;
 
  cleanup_driver:
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index d878b77..b5df0f9 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -985,6 +985,14 @@ dri2_x11_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
    }
 }
 
+static struct dri2_egl_display_vtbl dri2_x11_swrast_display_vtbl = {
+   .authenticate = NULL,
+};
+
+static struct dri2_egl_display_vtbl dri2_x11_display_vtbl = {
+   .authenticate = dri2_x11_authenticate,
+};
+
 static EGLBoolean
 dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
 {
@@ -1044,6 +1052,11 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
    disp->VersionMajor = 1;
    disp->VersionMinor = 4;
 
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &dri2_x11_swrast_display_vtbl;
+
    return EGL_TRUE;
 
  cleanup_configs:
@@ -1209,12 +1222,15 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
 	 goto cleanup_configs;
    }
 
-   dri2_dpy->authenticate = dri2_x11_authenticate;
-
    /* we're supporting EGL 1.4 */
    disp->VersionMajor = 1;
    disp->VersionMinor = 4;
 
+   /* Fill vtbl last to prevent accidentally calling virtual function during
+    * initialization.
+    */
+   dri2_dpy->vtbl = &dri2_x11_display_vtbl;
+
    return EGL_TRUE;
 
  cleanup_configs:
-- 
1.8.5.3



More information about the mesa-dev mailing list