From b1a31412b687419fc177fa6f09ff12c3df81ef59 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 12 Jun 2013 16:35:59 -0700 Subject: [PATCH] eglwrap: Add EGLWRAP_DEFER and EGLWRAP_DEFER_WITH_RETURN macros 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 | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/eglwrap.c b/eglwrap.c index 00a8284..6f009c3 100644 --- a/eglwrap.c +++ b/eglwrap.c @@ -26,6 +26,26 @@ #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; -- 2.43.0