Loading opengl/libs/Android.mk +3 −1 Original line number Diff line number Diff line Loading @@ -27,11 +27,12 @@ LOCAL_SRC_FILES:= \ EGL/egl_object.cpp \ EGL/egl.cpp \ EGL/eglApi.cpp \ EGL/trace.cpp \ EGL/getProcAddress.cpp.arm \ EGL/Loader.cpp \ # LOCAL_SHARED_LIBRARIES += libcutils libutils liblog LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libGLES_trace LOCAL_MODULE:= libEGL LOCAL_LDFLAGS += -Wl,--exclude-libs=ALL LOCAL_SHARED_LIBRARIES += libdl Loading @@ -41,6 +42,7 @@ LOCAL_C_INCLUDES += bionic/libc/private LOCAL_CFLAGS += -DLOG_TAG=\"libEGL\" LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -fvisibility=hidden LOCAL_CFLAGS += -DEGL_TRACE=1 ifeq ($(BOARD_ALLOW_EGL_HIBERNATION),true) LOCAL_CFLAGS += -DBOARD_ALLOW_EGL_HIBERNATION Loading opengl/libs/EGL/Loader.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include <EGL/egl.h> #include "../glestrace.h" #include "egldefs.h" #include "Loader.h" Loading Loading @@ -156,6 +158,7 @@ Loader::Loader() } Loader::~Loader() { GLTrace_stop(); } static void* load_wrapper(const char* path) { Loading opengl/libs/EGL/egl.cpp +156 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ #include <utils/String8.h> #include "../egl_impl.h" #include "../glestrace.h" #include "egl_tls.h" #include "egldefs.h" Loading @@ -53,10 +54,161 @@ pthread_key_t gGLWrapperKey = -1; // ---------------------------------------------------------------------------- #if EGL_TRACE EGLAPI pthread_key_t gGLTraceKey = -1; // ---------------------------------------------------------------------------- /** * There are three different tracing methods: * 1. libs/EGL/trace.cpp: Traces all functions to systrace. * To enable: * - set system property "debug.egl.trace" to "systrace" to trace all apps. * 2. libs/EGL/trace.cpp: Logs a stack trace for GL errors after each function call. * To enable: * - set system property "debug.egl.trace" to "error" to trace all apps. * 3. libs/EGL/trace.cpp: Traces all functions to logcat. * To enable: * - set system property "debug.egl.trace" to 1 to trace all apps. * - or call setGLTraceLevel(1) from an app to enable tracing for that app. * 4. libs/GLES_trace: Traces all functions via protobuf to host. * To enable: * - set system property "debug.egl.debug_proc" to the application name. * - or call setGLDebugLevel(1) from the app. */ static int sEGLTraceLevel; static int sEGLApplicationTraceLevel; static bool sEGLSystraceEnabled; static bool sEGLGetErrorEnabled; static volatile int sEGLDebugLevel; extern gl_hooks_t gHooksTrace; extern gl_hooks_t gHooksSystrace; extern gl_hooks_t gHooksErrorTrace; int getEGLDebugLevel() { return sEGLDebugLevel; } void setEGLDebugLevel(int level) { sEGLDebugLevel = level; } static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { pthread_setspecific(gGLTraceKey, value); } gl_hooks_t const* getGLTraceThreadSpecific() { return static_cast<gl_hooks_t*>(pthread_getspecific(gGLTraceKey)); } void initEglTraceLevel() { char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.trace", value, "0"); sEGLGetErrorEnabled = !strcasecmp(value, "error"); if (sEGLGetErrorEnabled) { sEGLSystraceEnabled = false; sEGLTraceLevel = 0; return; } sEGLSystraceEnabled = !strcasecmp(value, "systrace"); if (sEGLSystraceEnabled) { sEGLTraceLevel = 0; return; } int propertyLevel = atoi(value); int applicationLevel = sEGLApplicationTraceLevel; sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; } void initEglDebugLevel() { if (getEGLDebugLevel() == 0) { char value[PROPERTY_VALUE_MAX]; // check system property only on userdebug or eng builds property_get("ro.debuggable", value, "0"); if (value[0] == '0') return; property_get("debug.egl.debug_proc", value, ""); if (strlen(value) > 0) { FILE * file = fopen("/proc/self/cmdline", "r"); if (file) { char cmdline[256]; if (fgets(cmdline, sizeof(cmdline), file)) { if (!strncmp(value, cmdline, strlen(value))) { // set EGL debug if the "debug.egl.debug_proc" property // matches the prefix of this application's command line setEGLDebugLevel(1); } } fclose(file); } } } if (getEGLDebugLevel() > 0) { if (GLTrace_start() < 0) { ALOGE("Error starting Tracer for OpenGL ES. Disabling.."); setEGLDebugLevel(0); } } } void setGLHooksThreadSpecific(gl_hooks_t const *value) { if (sEGLGetErrorEnabled) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksErrorTrace); } else if (sEGLSystraceEnabled) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksSystrace); } else if (sEGLTraceLevel > 0) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksTrace); } else if (getEGLDebugLevel() > 0 && value != &gHooksNoContext) { setGlTraceThreadSpecific(value); setGlThreadSpecific(GLTrace_getGLHooks()); } else { setGlTraceThreadSpecific(NULL); setGlThreadSpecific(value); } } /* * Global entry point to allow applications to modify their own trace level. * The effective trace level is the max of this level and the value of debug.egl.trace. */ extern "C" void setGLTraceLevel(int level) { sEGLApplicationTraceLevel = level; } /* * Global entry point to allow applications to modify their own debug level. * Debugging is enabled if either the application requested it, or if the system property * matches the application's name. * Note that this only sets the debug level. The value is read and used either in * initEglDebugLevel() if the application hasn't initialized its display yet, or when * eglSwapBuffers() is called next. */ void EGLAPI setGLDebugLevel(int level) { setEGLDebugLevel(level); } #else void setGLHooksThreadSpecific(gl_hooks_t const *value) { setGlThreadSpecific(value); } #endif /*****************************************************************************/ static int gl_no_context() { Loading @@ -79,6 +231,10 @@ static int gl_no_context() { static void early_egl_init(void) { #if EGL_TRACE pthread_key_create(&gGLTraceKey, NULL); initEglTraceLevel(); #endif int numHooks = sizeof(gHooksNoContext) / sizeof(EGLFuncPointer); EGLFuncPointer *iter = reinterpret_cast<EGLFuncPointer*>(&gHooksNoContext); for (int hook = 0; hook < numHooks; ++hook) { Loading opengl/libs/EGL/eglApi.cpp +52 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ #include <utils/Trace.h> #include "../egl_impl.h" #include "../glestrace.h" #include "../hooks.h" #include "egl_display.h" Loading Loading @@ -230,6 +231,8 @@ static void(*findProcAddress(const char* name, extern void setGLHooksThreadSpecific(gl_hooks_t const *value); extern EGLBoolean egl_init_drivers(); extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; extern int getEGLDebugLevel(); extern void setEGLDebugLevel(int level); extern gl_hooks_t gHooksTrace; } // namespace android; Loading Loading @@ -671,6 +674,10 @@ EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, } egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglCreateContext(version, c); #endif return c; } } Loading Loading @@ -776,6 +783,10 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, if (c) { setGLHooksThreadSpecific(c->cnx->hooks[c->version]); egl_tls_t::setContext(ctx); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); #endif _c.acquire(); _r.acquire(); _d.acquire(); Loading Loading @@ -960,6 +971,10 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) "no more slots for eglGetProcAddress(\"%s\")", procname); #if EGL_TRACE gl_hooks_t *debugHooks = GLTrace_getGLHooks(); #endif if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { bool found = false; Loading @@ -969,6 +984,10 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) addr = cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = #if EGL_TRACE debugHooks->ext.extensions[slot] = gHooksTrace.ext.extensions[slot] = #endif cnx->egl.eglGetProcAddress(procname); if (addr) found = true; } Loading Loading @@ -1060,6 +1079,34 @@ EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); #if EGL_TRACE gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); if (getEGLDebugLevel() > 0) { if (trace_hooks == NULL) { if (GLTrace_start() < 0) { ALOGE("Disabling Tracer for OpenGL ES"); setEGLDebugLevel(0); } else { // switch over to the trace version of hooks EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) { setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); } } } GLTrace_eglSwapBuffers(dpy, draw); } else if (trace_hooks != NULL) { // tracing is now disabled, so switch back to the non trace version EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_stop(); } #endif egl_surface_t const * const s = get_surface(draw); if (CC_UNLIKELY(dp->traceGpuCompletion)) { Loading Loading @@ -1309,6 +1356,11 @@ EGLBoolean eglReleaseThread(void) { clearError(); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglReleaseThread(); #endif // If there is context bound to the thread, release it egl_display_t::loseCurrent(get_context(getContext())); Loading opengl/libs/EGL/egl_display.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ static char const * const sClientApiString = "OpenGL_ES"; extern char const * const gBuiltinExtensionString; extern char const * const gExtensionString; extern void initEglTraceLevel(); extern void initEglDebugLevel(); extern void setGLHooksThreadSpecific(gl_hooks_t const *value); // ---------------------------------------------------------------------------- Loading Loading @@ -137,6 +139,15 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { { Mutex::Autolock _l(lock); #if EGL_TRACE // Called both at early_init time and at this time. (Early_init is pre-zygote, so // the information from that call may be stale.) initEglTraceLevel(); initEglDebugLevel(); #endif setGLHooksThreadSpecific(&gHooksNoContext); // initialize each EGL and Loading Loading
opengl/libs/Android.mk +3 −1 Original line number Diff line number Diff line Loading @@ -27,11 +27,12 @@ LOCAL_SRC_FILES:= \ EGL/egl_object.cpp \ EGL/egl.cpp \ EGL/eglApi.cpp \ EGL/trace.cpp \ EGL/getProcAddress.cpp.arm \ EGL/Loader.cpp \ # LOCAL_SHARED_LIBRARIES += libcutils libutils liblog LOCAL_SHARED_LIBRARIES += libcutils libutils liblog libGLES_trace LOCAL_MODULE:= libEGL LOCAL_LDFLAGS += -Wl,--exclude-libs=ALL LOCAL_SHARED_LIBRARIES += libdl Loading @@ -41,6 +42,7 @@ LOCAL_C_INCLUDES += bionic/libc/private LOCAL_CFLAGS += -DLOG_TAG=\"libEGL\" LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES LOCAL_CFLAGS += -fvisibility=hidden LOCAL_CFLAGS += -DEGL_TRACE=1 ifeq ($(BOARD_ALLOW_EGL_HIBERNATION),true) LOCAL_CFLAGS += -DBOARD_ALLOW_EGL_HIBERNATION Loading
opengl/libs/EGL/Loader.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include <EGL/egl.h> #include "../glestrace.h" #include "egldefs.h" #include "Loader.h" Loading Loading @@ -156,6 +158,7 @@ Loader::Loader() } Loader::~Loader() { GLTrace_stop(); } static void* load_wrapper(const char* path) { Loading
opengl/libs/EGL/egl.cpp +156 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ #include <utils/String8.h> #include "../egl_impl.h" #include "../glestrace.h" #include "egl_tls.h" #include "egldefs.h" Loading @@ -53,10 +54,161 @@ pthread_key_t gGLWrapperKey = -1; // ---------------------------------------------------------------------------- #if EGL_TRACE EGLAPI pthread_key_t gGLTraceKey = -1; // ---------------------------------------------------------------------------- /** * There are three different tracing methods: * 1. libs/EGL/trace.cpp: Traces all functions to systrace. * To enable: * - set system property "debug.egl.trace" to "systrace" to trace all apps. * 2. libs/EGL/trace.cpp: Logs a stack trace for GL errors after each function call. * To enable: * - set system property "debug.egl.trace" to "error" to trace all apps. * 3. libs/EGL/trace.cpp: Traces all functions to logcat. * To enable: * - set system property "debug.egl.trace" to 1 to trace all apps. * - or call setGLTraceLevel(1) from an app to enable tracing for that app. * 4. libs/GLES_trace: Traces all functions via protobuf to host. * To enable: * - set system property "debug.egl.debug_proc" to the application name. * - or call setGLDebugLevel(1) from the app. */ static int sEGLTraceLevel; static int sEGLApplicationTraceLevel; static bool sEGLSystraceEnabled; static bool sEGLGetErrorEnabled; static volatile int sEGLDebugLevel; extern gl_hooks_t gHooksTrace; extern gl_hooks_t gHooksSystrace; extern gl_hooks_t gHooksErrorTrace; int getEGLDebugLevel() { return sEGLDebugLevel; } void setEGLDebugLevel(int level) { sEGLDebugLevel = level; } static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { pthread_setspecific(gGLTraceKey, value); } gl_hooks_t const* getGLTraceThreadSpecific() { return static_cast<gl_hooks_t*>(pthread_getspecific(gGLTraceKey)); } void initEglTraceLevel() { char value[PROPERTY_VALUE_MAX]; property_get("debug.egl.trace", value, "0"); sEGLGetErrorEnabled = !strcasecmp(value, "error"); if (sEGLGetErrorEnabled) { sEGLSystraceEnabled = false; sEGLTraceLevel = 0; return; } sEGLSystraceEnabled = !strcasecmp(value, "systrace"); if (sEGLSystraceEnabled) { sEGLTraceLevel = 0; return; } int propertyLevel = atoi(value); int applicationLevel = sEGLApplicationTraceLevel; sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; } void initEglDebugLevel() { if (getEGLDebugLevel() == 0) { char value[PROPERTY_VALUE_MAX]; // check system property only on userdebug or eng builds property_get("ro.debuggable", value, "0"); if (value[0] == '0') return; property_get("debug.egl.debug_proc", value, ""); if (strlen(value) > 0) { FILE * file = fopen("/proc/self/cmdline", "r"); if (file) { char cmdline[256]; if (fgets(cmdline, sizeof(cmdline), file)) { if (!strncmp(value, cmdline, strlen(value))) { // set EGL debug if the "debug.egl.debug_proc" property // matches the prefix of this application's command line setEGLDebugLevel(1); } } fclose(file); } } } if (getEGLDebugLevel() > 0) { if (GLTrace_start() < 0) { ALOGE("Error starting Tracer for OpenGL ES. Disabling.."); setEGLDebugLevel(0); } } } void setGLHooksThreadSpecific(gl_hooks_t const *value) { if (sEGLGetErrorEnabled) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksErrorTrace); } else if (sEGLSystraceEnabled) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksSystrace); } else if (sEGLTraceLevel > 0) { setGlTraceThreadSpecific(value); setGlThreadSpecific(&gHooksTrace); } else if (getEGLDebugLevel() > 0 && value != &gHooksNoContext) { setGlTraceThreadSpecific(value); setGlThreadSpecific(GLTrace_getGLHooks()); } else { setGlTraceThreadSpecific(NULL); setGlThreadSpecific(value); } } /* * Global entry point to allow applications to modify their own trace level. * The effective trace level is the max of this level and the value of debug.egl.trace. */ extern "C" void setGLTraceLevel(int level) { sEGLApplicationTraceLevel = level; } /* * Global entry point to allow applications to modify their own debug level. * Debugging is enabled if either the application requested it, or if the system property * matches the application's name. * Note that this only sets the debug level. The value is read and used either in * initEglDebugLevel() if the application hasn't initialized its display yet, or when * eglSwapBuffers() is called next. */ void EGLAPI setGLDebugLevel(int level) { setEGLDebugLevel(level); } #else void setGLHooksThreadSpecific(gl_hooks_t const *value) { setGlThreadSpecific(value); } #endif /*****************************************************************************/ static int gl_no_context() { Loading @@ -79,6 +231,10 @@ static int gl_no_context() { static void early_egl_init(void) { #if EGL_TRACE pthread_key_create(&gGLTraceKey, NULL); initEglTraceLevel(); #endif int numHooks = sizeof(gHooksNoContext) / sizeof(EGLFuncPointer); EGLFuncPointer *iter = reinterpret_cast<EGLFuncPointer*>(&gHooksNoContext); for (int hook = 0; hook < numHooks; ++hook) { Loading
opengl/libs/EGL/eglApi.cpp +52 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ #include <utils/Trace.h> #include "../egl_impl.h" #include "../glestrace.h" #include "../hooks.h" #include "egl_display.h" Loading Loading @@ -230,6 +231,8 @@ static void(*findProcAddress(const char* name, extern void setGLHooksThreadSpecific(gl_hooks_t const *value); extern EGLBoolean egl_init_drivers(); extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; extern int getEGLDebugLevel(); extern void setEGLDebugLevel(int level); extern gl_hooks_t gHooksTrace; } // namespace android; Loading Loading @@ -671,6 +674,10 @@ EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, } egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglCreateContext(version, c); #endif return c; } } Loading Loading @@ -776,6 +783,10 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, if (c) { setGLHooksThreadSpecific(c->cnx->hooks[c->version]); egl_tls_t::setContext(ctx); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); #endif _c.acquire(); _r.acquire(); _d.acquire(); Loading Loading @@ -960,6 +971,10 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) "no more slots for eglGetProcAddress(\"%s\")", procname); #if EGL_TRACE gl_hooks_t *debugHooks = GLTrace_getGLHooks(); #endif if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { bool found = false; Loading @@ -969,6 +984,10 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) addr = cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = #if EGL_TRACE debugHooks->ext.extensions[slot] = gHooksTrace.ext.extensions[slot] = #endif cnx->egl.eglGetProcAddress(procname); if (addr) found = true; } Loading Loading @@ -1060,6 +1079,34 @@ EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); #if EGL_TRACE gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); if (getEGLDebugLevel() > 0) { if (trace_hooks == NULL) { if (GLTrace_start() < 0) { ALOGE("Disabling Tracer for OpenGL ES"); setEGLDebugLevel(0); } else { // switch over to the trace version of hooks EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) { setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); } } } GLTrace_eglSwapBuffers(dpy, draw); } else if (trace_hooks != NULL) { // tracing is now disabled, so switch back to the non trace version EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_stop(); } #endif egl_surface_t const * const s = get_surface(draw); if (CC_UNLIKELY(dp->traceGpuCompletion)) { Loading Loading @@ -1309,6 +1356,11 @@ EGLBoolean eglReleaseThread(void) { clearError(); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglReleaseThread(); #endif // If there is context bound to the thread, release it egl_display_t::loseCurrent(get_context(getContext())); Loading
opengl/libs/EGL/egl_display.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,8 @@ static char const * const sClientApiString = "OpenGL_ES"; extern char const * const gBuiltinExtensionString; extern char const * const gExtensionString; extern void initEglTraceLevel(); extern void initEglDebugLevel(); extern void setGLHooksThreadSpecific(gl_hooks_t const *value); // ---------------------------------------------------------------------------- Loading Loading @@ -137,6 +139,15 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { { Mutex::Autolock _l(lock); #if EGL_TRACE // Called both at early_init time and at this time. (Early_init is pre-zygote, so // the information from that call may be stale.) initEglTraceLevel(); initEglDebugLevel(); #endif setGLHooksThreadSpecific(&gHooksNoContext); // initialize each EGL and Loading