[waffle] [PATCH 7/7] glx: drop explicit linking against libGL.so

Emil Velikov emil.l.velikov at gmail.com
Mon Nov 10 07:56:39 PST 2014


Use the function pointers stored in glx_platform, to communicate
with the library.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 .../Modules/WafflePrintConfigurationSummary.cmake  |  1 -
 src/waffle/CMakeLists.txt                          |  5 ---
 src/waffle/glx/glx_config.c                        |  7 +--
 src/waffle/glx/glx_context.c                       |  7 ++-
 src/waffle/glx/glx_display.c                       |  5 ++-
 src/waffle/glx/glx_platform.c                      | 12 +++---
 src/waffle/glx/glx_window.c                        |  4 +-
 src/waffle/glx/glx_window.h                        |  2 -
 src/waffle/glx/glx_wrappers.h                      | 50 +++++++++++++---------
 9 files changed, 52 insertions(+), 41 deletions(-)

diff --git a/cmake/Modules/WafflePrintConfigurationSummary.cmake b/cmake/Modules/WafflePrintConfigurationSummary.cmake
index 81e738d..5adee03 100644
--- a/cmake/Modules/WafflePrintConfigurationSummary.cmake
+++ b/cmake/Modules/WafflePrintConfigurationSummary.cmake
@@ -51,7 +51,6 @@ if(waffle_has_egl)
 endif()
 if(waffle_has_glx)
     message("    gl_INCLUDE_DIRS: ${gl_INCLUDE_DIRS}")
-    message("    gl_LDFLAGS:      ${gl_LDFLAGS}")
 endif()
 if(waffle_has_wayland)
     message("    wayland-client_INCLUDE_DIRS: ${wayland-client_INCLUDE_DIRS}")
diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt
index 5d703f4..5005d8e 100644
--- a/src/waffle/CMakeLists.txt
+++ b/src/waffle/CMakeLists.txt
@@ -37,11 +37,6 @@ list(APPEND waffle_libdeps
     )
 
 if(waffle_on_linux)
-    if(waffle_has_glx)
-        list(APPEND waffle_libdeps
-            ${gl_LDFLAGS}
-            )
-    endif()
     if(waffle_has_wayland)
         list(APPEND waffle_libdeps
             ${wayland-client_LDFLAGS}
diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index bad3531..f47e705 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -168,6 +168,7 @@ glx_config_choose(struct wcore_platform *wc_plat,
 {
     struct glx_config *self;
     struct glx_display *dpy = glx_display(wc_dpy);
+    struct glx_platform *plat = glx_platform(wc_plat);
 
     GLXFBConfig *configs = NULL;
     int num_configs = 0;
@@ -220,7 +221,7 @@ glx_config_choose(struct wcore_platform *wc_plat,
     };
 
     // Set glx_fbconfig.
-    configs = wrapped_glXChooseFBConfig(dpy->x11.xlib,
+    configs = wrapped_glXChooseFBConfig(plat, dpy->x11.xlib,
                                         dpy->x11.screen,
                                         attrib_list,
                                         &num_configs);
@@ -233,7 +234,7 @@ glx_config_choose(struct wcore_platform *wc_plat,
     self->glx_fbconfig = configs[0];
 
     // Set glx_fbconfig_id.
-    ok = !wrapped_glXGetFBConfigAttrib(dpy->x11.xlib,
+    ok = !wrapped_glXGetFBConfigAttrib(plat, dpy->x11.xlib,
                                        self->glx_fbconfig,
                                        GLX_FBCONFIG_ID,
                                        &self->glx_fbconfig_id);
@@ -243,7 +244,7 @@ glx_config_choose(struct wcore_platform *wc_plat,
     }
 
     // Set xcb_visual_id.
-    vi = wrapped_glXGetVisualFromFBConfig(dpy->x11.xlib,
+    vi = wrapped_glXGetVisualFromFBConfig(plat, dpy->x11.xlib,
                                           self->glx_fbconfig);
     if (!vi) {
         wcore_errorf(WAFFLE_ERROR_UNKNOWN,
diff --git a/src/waffle/glx/glx_context.c b/src/waffle/glx/glx_context.c
index 62573dc..57db2ba 100644
--- a/src/waffle/glx/glx_context.c
+++ b/src/waffle/glx/glx_context.c
@@ -45,6 +45,7 @@ glx_context_destroy(struct wcore_context *wc_self)
 {
     struct glx_context *self;
     struct glx_display *dpy;
+    struct glx_platform *platform;
     bool ok = true;
 
     if (!wc_self)
@@ -52,9 +53,10 @@ glx_context_destroy(struct wcore_context *wc_self)
 
     self = glx_context(wc_self);
     dpy = glx_display(wc_self->display);
+    platform = glx_platform(wc_self->display->platform);
 
     if (self->glx)
-        wrapped_glXDestroyContext(dpy->x11.xlib, self->glx);
+        wrapped_glXDestroyContext(platform, dpy->x11.xlib, self->glx);
 
     ok &= wcore_context_teardown(wc_self);
     free(self);
@@ -182,7 +184,8 @@ glx_context_create_native(struct glx_config *config,
         }
     }
     else {
-        ctx = wrapped_glXCreateNewContext(dpy->x11.xlib,
+        ctx = wrapped_glXCreateNewContext(platform,
+                                          dpy->x11.xlib,
                                           config->glx_fbconfig,
                                           GLX_RGBA_TYPE,
                                           real_share_ctx,
diff --git a/src/waffle/glx/glx_display.c b/src/waffle/glx/glx_display.c
index 184438f..567d442 100644
--- a/src/waffle/glx/glx_display.c
+++ b/src/waffle/glx/glx_display.c
@@ -51,8 +51,9 @@ glx_display_destroy(struct wcore_display *wc_self)
 static bool
 glx_display_set_extensions(struct glx_display *self)
 {
-
-    const char *s = wrapped_glXQueryExtensionsString(self->x11.xlib,
+    struct glx_platform *platform = glx_platform(self->wcore.platform);
+    const char *s = wrapped_glXQueryExtensionsString(platform,
+                                                     self->x11.xlib,
                                                      self->x11.screen);
     if (!s) {
         wcore_errorf(WAFFLE_ERROR_UNKNOWN,
diff --git a/src/waffle/glx/glx_platform.c b/src/waffle/glx/glx_platform.c
index ae0cf46..4fb2eed 100644
--- a/src/waffle/glx/glx_platform.c
+++ b/src/waffle/glx/glx_platform.c
@@ -118,7 +118,7 @@ glx_platform_create(void)
     if (!self->linux)
         goto error;
 
-    self->glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const uint8_t*) "glXCreateContextAttribsARB");
+    self->glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) self->glXGetProcAddress((const uint8_t*) "glXCreateContextAttribsARB");
 
     self->wcore.vtbl = &glx_platform_vtbl;
     return &self->wcore;
@@ -134,12 +134,13 @@ glx_platform_make_current(struct wcore_platform *wc_self,
                           struct wcore_window *wc_window,
                           struct wcore_context *wc_ctx)
 {
-    bool ok;
+    struct glx_platform *self = glx_platform(wc_self);
     Display *dpy = glx_display(wc_dpy)->x11.xlib;
     GLXDrawable win = wc_window ? glx_window(wc_window)->x11.xcb : 0;
     GLXContext ctx = wc_ctx ? glx_context(wc_ctx)->glx : NULL;
-    
-    ok = wrapped_glXMakeCurrent(dpy, win, ctx);
+    bool ok;
+
+    ok = wrapped_glXMakeCurrent(self, dpy, win, ctx);
     if (!ok) {
         wcore_errorf(WAFFLE_ERROR_UNKNOWN, "glXMakeCurrent failed");
     }
@@ -151,7 +152,8 @@ static void*
 glx_platform_get_proc_address(struct wcore_platform *wc_self,
                               const char *name)
 {
-    return glXGetProcAddress((const GLubyte*) name);
+    struct glx_platform *self = glx_platform(wc_self);
+    return self->glXGetProcAddress((const GLubyte*) name);
 }
 
 static bool
diff --git a/src/waffle/glx/glx_window.c b/src/waffle/glx/glx_window.c
index 702ed3f..34fa784 100644
--- a/src/waffle/glx/glx_window.c
+++ b/src/waffle/glx/glx_window.c
@@ -25,6 +25,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <xcb/xcb.h>
 
 #include "wcore_error.h"
 
@@ -100,8 +101,9 @@ glx_window_swap_buffers(struct wcore_window *wc_self)
 {
     struct glx_window *self = glx_window(wc_self);
     struct glx_display *dpy = glx_display(wc_self->display);
+    struct glx_platform *plat = glx_platform(wc_self->display->platform);
 
-    wrapped_glXSwapBuffers(dpy->x11.xlib, self->x11.xcb);
+    wrapped_glXSwapBuffers(plat, dpy->x11.xlib, self->x11.xcb);
 
     return true;
 }
diff --git a/src/waffle/glx/glx_window.h b/src/waffle/glx/glx_window.h
index 4cf44e3..5aed497 100644
--- a/src/waffle/glx/glx_window.h
+++ b/src/waffle/glx/glx_window.h
@@ -27,8 +27,6 @@
 
 #include <stdbool.h>
 
-#include <xcb/xcb.h>
-
 #include "wcore_window.h"
 #include "wcore_util.h"
 
diff --git a/src/waffle/glx/glx_wrappers.h b/src/waffle/glx/glx_wrappers.h
index 5f53332..1411c86 100644
--- a/src/waffle/glx/glx_wrappers.h
+++ b/src/waffle/glx/glx_wrappers.h
@@ -45,19 +45,22 @@
 #include "x11_wrappers.h"
 
 static inline GLXFBConfig*
-wrapped_glXChooseFBConfig(Display *dpy, int screen,
+wrapped_glXChooseFBConfig(struct glx_platform *platform,
+                          Display *dpy, int screen,
                           const int *attribList, int *nitems)
 {
     X11_SAVE_ERROR_HANDLER
-    GLXFBConfig *configs = glXChooseFBConfig(dpy, screen, attribList, nitems);
+    GLXFBConfig *configs = platform->glXChooseFBConfig(dpy, screen,
+                                                       attribList, nitems);
     X11_RESTORE_ERROR_HANDLER
     return configs;
 }
 
 static inline GLXContext
-wrapped_glXCreateContextAttribsARB(
-        struct glx_platform *platform, Display *dpy, GLXFBConfig config,
-        GLXContext share_context, Bool direct, const int *attrib_list)
+wrapped_glXCreateContextAttribsARB(struct glx_platform *platform,
+                                   Display *dpy, GLXFBConfig config,
+                                   GLXContext share_context, Bool direct,
+                                   const int *attrib_list)
 {
     X11_SAVE_ERROR_HANDLER
     GLXContext ctx = platform->glXCreateContextAttribsARB(
@@ -67,65 +70,72 @@ wrapped_glXCreateContextAttribsARB(
 }
 
 static inline GLXContext
-wrapped_glXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType,
+wrapped_glXCreateNewContext(struct glx_platform *platform,
+                            Display *dpy, GLXFBConfig config, int renderType,
                             GLXContext shareList, Bool direct)
 {
     X11_SAVE_ERROR_HANDLER
-    GLXContext ctx = glXCreateNewContext(dpy, config, renderType, shareList,
-                                         direct);
+    GLXContext ctx = platform->glXCreateNewContext(dpy, config, renderType,
+                                                   shareList, direct);
     X11_RESTORE_ERROR_HANDLER
     return ctx;
 }
 
 static inline int
-wrapped_glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
+wrapped_glXGetFBConfigAttrib(struct glx_platform *platform,
+                             Display *dpy, GLXFBConfig config,
                              int attribute, int *value)
 {
     X11_SAVE_ERROR_HANDLER
-    int error = glXGetFBConfigAttrib(dpy, config, attribute, value);
+    int error = platform->glXGetFBConfigAttrib(dpy, config, attribute, value);
     X11_RESTORE_ERROR_HANDLER
     return error;
 }
 
 static inline XVisualInfo*
-wrapped_glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
+wrapped_glXGetVisualFromFBConfig(struct glx_platform *platform,
+                                 Display *dpy, GLXFBConfig config)
 {
     X11_SAVE_ERROR_HANDLER
-    XVisualInfo *vi = glXGetVisualFromFBConfig(dpy, config);
+    XVisualInfo *vi = platform->glXGetVisualFromFBConfig(dpy, config);
     X11_RESTORE_ERROR_HANDLER
     return vi;
 }
 
 static inline void
-wrapped_glXDestroyContext(Display *dpy, GLXContext ctx)
+wrapped_glXDestroyContext(struct glx_platform *platform,
+                          Display *dpy, GLXContext ctx)
 {
     X11_SAVE_ERROR_HANDLER
-    glXDestroyContext(dpy, ctx);
+    platform->glXDestroyContext(dpy, ctx);
     X11_RESTORE_ERROR_HANDLER
 }
 
 static inline Bool
-wrapped_glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
+wrapped_glXMakeCurrent(struct glx_platform *platform,
+                       Display *dpy, GLXDrawable drawable, GLXContext ctx)
 {
     X11_SAVE_ERROR_HANDLER
-    Bool ok = glXMakeCurrent(dpy, drawable, ctx);
+    Bool ok = platform->glXMakeCurrent(dpy, drawable, ctx);
     X11_RESTORE_ERROR_HANDLER
     return ok;
 }
 
 static inline const char*
-wrapped_glXQueryExtensionsString(Display *dpy, int screen)
+wrapped_glXQueryExtensionsString(struct glx_platform *platform,
+                                 Display *dpy, int screen)
 {
     X11_SAVE_ERROR_HANDLER
-    const char *s = glXQueryExtensionsString(dpy, screen);
+    const char *s = platform->glXQueryExtensionsString(dpy, screen);
     X11_RESTORE_ERROR_HANDLER
     return s;
 }
 
 static inline void
-wrapped_glXSwapBuffers(Display *dpy, GLXDrawable drawable)
+wrapped_glXSwapBuffers(struct glx_platform *platform,
+                       Display *dpy, GLXDrawable drawable)
 {
     X11_SAVE_ERROR_HANDLER
-    glXSwapBuffers(dpy, drawable);
+    platform->glXSwapBuffers(dpy, drawable);
     X11_RESTORE_ERROR_HANDLER
 }
-- 
2.1.3



More information about the waffle mailing list