From d69f53b735eec46a802e5ffaff9ee4dbc0ccb391 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 23 Jan 2017 08:38:08 +0200 Subject: Make it possible hook into EGL Remove glXGetProcAddressEXT, I don't think such thing even exists --- glcapture.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/glcapture.c b/glcapture.c index 12f4f62..4ae6bad 100644 --- a/glcapture.c +++ b/glcapture.c @@ -18,6 +18,7 @@ #define GL_GLEXT_PROTOTYPES #include #include +#include #include #include #include @@ -98,17 +99,18 @@ struct fifo { }; static void* (*_dlsym)(void*, const char*) = NULL; +static EGLBoolean (*_eglSwapBuffers)(EGLDisplay, EGLSurface) = NULL; +static __eglMustCastToProperFunctionPointerType (*_eglGetProcAddress)(const char*) = NULL; static void (*_glXSwapBuffers)(Display*, GLXDrawable) = NULL; -static void* (*_glXGetProcAddress)(const GLubyte*) = NULL; -static void* (*_glXGetProcAddressARB)(const GLubyte*) = NULL; -static void* (*_glXGetProcAddressEXT)(const GLubyte*) = NULL; -static snd_pcm_sframes_t (*_snd_pcm_writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size) = NULL; -static snd_pcm_sframes_t (*_snd_pcm_writen)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size) = NULL; -static snd_pcm_sframes_t (*_snd_pcm_mmap_writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size) = NULL; -static snd_pcm_sframes_t (*_snd_pcm_mmap_writen)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size) = NULL; -static int (*_clock_gettime)(clockid_t clk_id, struct timespec *tp) = NULL; -static void* store_real_symbol_and_return_fake_symbol(const char *symbol, void *ret); -static void hook_function(void **ptr, const char *name, const bool versioned); +static __GLXextFuncPtr (*_glXGetProcAddress)(const GLubyte*) = NULL; +static __GLXextFuncPtr (*_glXGetProcAddressARB)(const GLubyte*) = NULL; +static snd_pcm_sframes_t (*_snd_pcm_writei)(snd_pcm_t*, const void*, snd_pcm_uframes_t) = NULL; +static snd_pcm_sframes_t (*_snd_pcm_writen)(snd_pcm_t*, void**, snd_pcm_uframes_t) = NULL; +static snd_pcm_sframes_t (*_snd_pcm_mmap_writei)(snd_pcm_t*, const void*, snd_pcm_uframes_t) = NULL; +static snd_pcm_sframes_t (*_snd_pcm_mmap_writen)(snd_pcm_t*, void**, snd_pcm_uframes_t) = NULL; +static int (*_clock_gettime)(clockid_t, struct timespec*) = NULL; +static void* store_real_symbol_and_return_fake_symbol(const char*, void*); +static void hook_function(void**, const char*, const bool); #define WARN(x, ...) do { warn("glcapture: "x, ##__VA_ARGS__); } while (0) #define WARNX(x, ...) do { warnx("glcapture: "x, ##__VA_ARGS__); } while (0) @@ -439,11 +441,9 @@ draw_indicator(const GLint view[4]) glPopAttrib(); } -void -glXSwapBuffers(Display *dpy, GLXDrawable drawable) +static void +swap_buffers(void) { - HOOK(glXSwapBuffers); - GLint view[4] = {0}; static __thread struct gl gl; const GLenum error0 = glGetError(); @@ -455,15 +455,29 @@ glXSwapBuffers(Display *dpy, GLXDrawable drawable) WARNX("glError occured"); reset_capture(&gl); } +} - _glXSwapBuffers(dpy, drawable); +EGLBoolean +eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) +{ + HOOK(eglSwapBuffers); + swap_buffers(); + return _eglSwapBuffers(dpy, surface); } -__GLXextFuncPtr -glXGetProcAddressEXT(const GLubyte *procname) +__eglMustCastToProperFunctionPointerType +eglGetProcAddress(const char *procname) +{ + HOOK(eglGetProcAddress); + return (_eglGetProcAddress ? store_real_symbol_and_return_fake_symbol(procname, _eglGetProcAddress(procname)) : NULL); +} + +void +glXSwapBuffers(Display *dpy, GLXDrawable drawable) { - HOOK(glXGetProcAddressEXT); - return (_glXGetProcAddressEXT ? store_real_symbol_and_return_fake_symbol((const char*)procname, _glXGetProcAddressEXT(procname)) : NULL); + HOOK(glXSwapBuffers); + swap_buffers(); + _glXSwapBuffers(dpy, drawable); } __GLXextFuncPtr @@ -552,8 +566,9 @@ store_real_symbol_and_return_fake_symbol(const char *symbol, void *ret) if (0) {} #define SET_IF_NOT_HOOKED(x, y) do { if (!_##x) { _##x = y; WARNX("SET %s to %p", #x, y); } } while (0) #define FAKE_SYMBOL(x) else if (!strcmp(symbol, #x)) { SET_IF_NOT_HOOKED(x, ret); return x; } + FAKE_SYMBOL(eglSwapBuffers) + FAKE_SYMBOL(eglGetProcAddress) FAKE_SYMBOL(glXSwapBuffers) - FAKE_SYMBOL(glXGetProcAddressEXT) FAKE_SYMBOL(glXGetProcAddressARB) FAKE_SYMBOL(glXGetProcAddress) FAKE_SYMBOL(snd_pcm_writei) -- cgit v1.2.3-70-g09d2