]> git.cworth.org Git - fips/commitdiff
eglwrap: Add EGLWRAP_DEFER and EGLWRAP_DEFER_WITH_RETURN macros
authorCarl Worth <cworth@cworth.org>
Wed, 12 Jun 2013 23:35:59 +0000 (16:35 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 12 Jun 2013 23:40:00 +0000 (16:40 -0700)
There are parallel to GLWRAP_DEFER and GLWRAP_DEFER_WITH_RETURN, (differing
only in calling eglwrap_lookup rathern than glwrap_lookup).

Having these macros around will avoid some code duplication as we start
adding more functions to the eglwrap.c file.

eglwrap.c

index 00a8284b1352de7951f6999f40067466cb20b3f7..6f009c35c53f3017d49cf8e22caa5a8725ca0966 100644 (file)
--- a/eglwrap.c
+++ b/eglwrap.c
 #include "dlwrap.h"
 #include "metrics.h"
 
+/* Defer to the real 'function' (from libEGL.so.1) to do the real work.
+ * The symbol is looked up once and cached in a static variable for
+ * future uses.
+ */
+#define EGLWRAP_DEFER(function,...) do {                       \
+       static typeof(&function) real_ ## function;             \
+       if (! real_ ## function)                                \
+               real_ ## function = eglwrap_lookup (#function); \
+       real_ ## function(__VA_ARGS__);                         \
+} while (0);
+
+/* As EGLWRAP_DEFER, but also set 'ret' to the return value */
+#define EGLWRAP_DEFER_WITH_RETURN(ret, function,...) do {      \
+       static typeof(&function) real_ ## function;             \
+       if (! real_ ## function)                                \
+               real_ ## function = eglwrap_lookup (#function); \
+       (ret) = real_ ## function(__VA_ARGS__);                 \
+} while (0);
+
+
 static void *
 eglwrap_lookup (char *name)
 {
@@ -48,13 +68,8 @@ EGLBoolean
 eglSwapBuffers (EGLDisplay dpy, EGLSurface surface)
 {
        EGLBoolean ret;
-       static typeof(&eglSwapBuffers) eglwrap_real_eglSwapBuffers;
-
-       if (! eglwrap_real_eglSwapBuffers)
-               eglwrap_real_eglSwapBuffers = eglwrap_lookup ("eglSwapBuffers");
-
-       ret = eglwrap_real_eglSwapBuffers (dpy, surface);
 
+       EGLWRAP_DEFER_WITH_RETURN (ret, eglSwapBuffers, dpy, surface);
        metrics_end_frame ();
 
        return ret;