2013-02-08 19:13:46 +00:00
|
|
|
/*
|
2009-03-04 03:31:44 +00:00
|
|
|
** Copyright 2007, The Android Open Source Project
|
|
|
|
**
|
2013-02-08 19:13:46 +00:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
2009-03-04 03:31:44 +00:00
|
|
|
**
|
2013-02-08 19:13:46 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2009-03-04 03:31:44 +00:00
|
|
|
**
|
2013-02-08 19:13:46 +00:00
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
2009-03-04 03:31:44 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2009-05-18 01:50:16 +00:00
|
|
|
#include <stdlib.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
#include <hardware/gralloc.h>
|
|
|
|
#include <system/window.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
|
|
|
|
#include <cutils/log.h>
|
|
|
|
#include <cutils/atomic.h>
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#include <cutils/memory.h>
|
|
|
|
|
2011-07-11 22:33:51 +00:00
|
|
|
#include <utils/CallStack.h>
|
2010-08-03 00:34:32 +00:00
|
|
|
#include <utils/String8.h>
|
2009-08-21 09:18:25 +00:00
|
|
|
|
2013-04-05 06:17:56 +00:00
|
|
|
#include "../egl_impl.h"
|
|
|
|
#include "../glestrace.h"
|
|
|
|
|
2011-03-28 17:39:28 +00:00
|
|
|
#include "egl_tls.h"
|
2013-04-05 06:17:56 +00:00
|
|
|
#include "egldefs.h"
|
2011-05-13 23:21:08 +00:00
|
|
|
#include "Loader.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
#include "egl_display.h"
|
|
|
|
#include "egl_object.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-02-14 01:09:30 +00:00
|
|
|
egl_connection_t gEGLImpl;
|
|
|
|
gl_hooks_t gHooks[2];
|
2011-05-13 23:21:08 +00:00
|
|
|
gl_hooks_t gHooksNoContext;
|
|
|
|
pthread_key_t gGLWrapperKey = -1;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-10-26 22:21:24 +00:00
|
|
|
#if EGL_TRACE
|
|
|
|
|
|
|
|
EGLAPI pthread_key_t gGLTraceKey = -1;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-03-09 22:51:28 +00:00
|
|
|
/**
|
2012-10-18 23:16:10 +00:00
|
|
|
* 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.
|
2012-03-09 22:51:28 +00:00
|
|
|
* 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.
|
2012-10-18 23:16:10 +00:00
|
|
|
* 4. libs/GLES_trace: Traces all functions via protobuf to host.
|
2012-03-09 22:51:28 +00:00
|
|
|
* To enable:
|
|
|
|
* - set system property "debug.egl.debug_proc" to the application name.
|
|
|
|
* - or call setGLDebugLevel(1) from the app.
|
|
|
|
*/
|
2011-05-13 23:21:08 +00:00
|
|
|
static int sEGLTraceLevel;
|
|
|
|
static int sEGLApplicationTraceLevel;
|
|
|
|
|
2012-10-18 23:16:10 +00:00
|
|
|
static bool sEGLSystraceEnabled;
|
|
|
|
static bool sEGLGetErrorEnabled;
|
|
|
|
|
2012-12-18 22:56:55 +00:00
|
|
|
static volatile int sEGLDebugLevel;
|
2012-03-09 22:51:28 +00:00
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
extern gl_hooks_t gHooksTrace;
|
2012-10-18 23:16:10 +00:00
|
|
|
extern gl_hooks_t gHooksSystrace;
|
|
|
|
extern gl_hooks_t gHooksErrorTrace;
|
2010-10-26 22:21:24 +00:00
|
|
|
|
2012-12-18 22:56:55 +00:00
|
|
|
int getEGLDebugLevel() {
|
|
|
|
return sEGLDebugLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEGLDebugLevel(int level) {
|
|
|
|
sEGLDebugLevel = level;
|
|
|
|
}
|
|
|
|
|
2010-10-26 22:21:24 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
void initEglTraceLevel() {
|
2010-10-26 22:21:24 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.egl.trace", value, "0");
|
2012-10-18 23:16:10 +00:00
|
|
|
|
|
|
|
sEGLGetErrorEnabled = !strcasecmp(value, "error");
|
|
|
|
if (sEGLGetErrorEnabled) {
|
|
|
|
sEGLSystraceEnabled = false;
|
|
|
|
sEGLTraceLevel = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sEGLSystraceEnabled = !strcasecmp(value, "systrace");
|
|
|
|
if (sEGLSystraceEnabled) {
|
|
|
|
sEGLTraceLevel = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-26 22:21:24 +00:00
|
|
|
int propertyLevel = atoi(value);
|
2011-05-13 23:21:08 +00:00
|
|
|
int applicationLevel = sEGLApplicationTraceLevel;
|
|
|
|
sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel;
|
2012-03-09 22:51:28 +00:00
|
|
|
}
|
2011-04-09 01:43:16 +00:00
|
|
|
|
2012-03-09 22:51:28 +00:00
|
|
|
void initEglDebugLevel() {
|
2012-12-18 22:56:55 +00:00
|
|
|
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);
|
|
|
|
}
|
2012-03-09 22:51:28 +00:00
|
|
|
}
|
2012-12-18 22:56:55 +00:00
|
|
|
fclose(file);
|
2011-12-14 20:19:56 +00:00
|
|
|
}
|
2011-04-09 01:43:16 +00:00
|
|
|
}
|
2011-03-02 00:08:10 +00:00
|
|
|
}
|
2011-04-09 01:43:16 +00:00
|
|
|
|
2012-12-18 22:56:55 +00:00
|
|
|
if (getEGLDebugLevel() > 0) {
|
|
|
|
if (GLTrace_start() < 0) {
|
|
|
|
ALOGE("Error starting Tracer for OpenGL ES. Disabling..");
|
|
|
|
setEGLDebugLevel(0);
|
|
|
|
}
|
2011-03-11 03:07:42 +00:00
|
|
|
}
|
2010-10-26 22:21:24 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
void setGLHooksThreadSpecific(gl_hooks_t const *value) {
|
2012-10-18 23:16:10 +00:00
|
|
|
if (sEGLGetErrorEnabled) {
|
|
|
|
setGlTraceThreadSpecific(value);
|
|
|
|
setGlThreadSpecific(&gHooksErrorTrace);
|
|
|
|
} else if (sEGLSystraceEnabled) {
|
|
|
|
setGlTraceThreadSpecific(value);
|
|
|
|
setGlThreadSpecific(&gHooksSystrace);
|
|
|
|
} else if (sEGLTraceLevel > 0) {
|
2010-10-26 22:21:24 +00:00
|
|
|
setGlTraceThreadSpecific(value);
|
|
|
|
setGlThreadSpecific(&gHooksTrace);
|
2012-12-18 22:56:55 +00:00
|
|
|
} else if (getEGLDebugLevel() > 0 && value != &gHooksNoContext) {
|
2011-03-02 00:08:10 +00:00
|
|
|
setGlTraceThreadSpecific(value);
|
2011-11-30 23:05:37 +00:00
|
|
|
setGlThreadSpecific(GLTrace_getGLHooks());
|
2010-10-26 22:21:24 +00:00
|
|
|
} else {
|
2012-12-18 22:56:55 +00:00
|
|
|
setGlTraceThreadSpecific(NULL);
|
2010-10-26 22:21:24 +00:00
|
|
|
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) {
|
2011-05-13 23:21:08 +00:00
|
|
|
sEGLApplicationTraceLevel = level;
|
2010-10-26 22:21:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 22:51:28 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2012-12-18 22:56:55 +00:00
|
|
|
* 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.
|
2012-03-09 22:51:28 +00:00
|
|
|
*/
|
|
|
|
void EGLAPI setGLDebugLevel(int level) {
|
2012-12-18 22:56:55 +00:00
|
|
|
setEGLDebugLevel(level);
|
2012-03-09 22:51:28 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 22:21:24 +00:00
|
|
|
#else
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
void setGLHooksThreadSpecific(gl_hooks_t const *value) {
|
2010-10-26 22:21:24 +00:00
|
|
|
setGlThreadSpecific(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2010-09-23 23:38:38 +00:00
|
|
|
static int gl_no_context() {
|
2011-05-13 23:21:08 +00:00
|
|
|
if (egl_tls_t::logNoContextCall()) {
|
2012-09-27 00:19:48 +00:00
|
|
|
char const* const error = "call to OpenGL ES API with "
|
|
|
|
"no current context (logged once per thread)";
|
|
|
|
if (LOG_NDEBUG) {
|
|
|
|
ALOGE(error);
|
|
|
|
} else {
|
|
|
|
LOG_ALWAYS_FATAL(error);
|
|
|
|
}
|
2011-09-07 00:24:05 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.egl.callstack", value, "0");
|
|
|
|
if (atoi(value)) {
|
2013-03-22 00:12:40 +00:00
|
|
|
CallStack stack(LOG_TAG);
|
2011-09-07 00:24:05 +00:00
|
|
|
}
|
2009-07-31 23:21:17 +00:00
|
|
|
}
|
2010-09-23 23:38:38 +00:00
|
|
|
return 0;
|
2010-09-23 18:32:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:13:46 +00:00
|
|
|
static void early_egl_init(void)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2010-10-26 22:21:24 +00:00
|
|
|
#if EGL_TRACE
|
|
|
|
pthread_key_create(&gGLTraceKey, NULL);
|
|
|
|
initEglTraceLevel();
|
2009-03-04 03:31:44 +00:00
|
|
|
#endif
|
|
|
|
uint32_t addr = (uint32_t)((void*)gl_no_context);
|
|
|
|
android_memset32(
|
2013-02-08 19:13:46 +00:00
|
|
|
(uint32_t*)(void*)&gHooksNoContext,
|
|
|
|
addr,
|
2009-10-14 09:06:37 +00:00
|
|
|
sizeof(gHooksNoContext));
|
2010-09-23 18:32:52 +00:00
|
|
|
|
2010-10-26 22:21:24 +00:00
|
|
|
setGLHooksThreadSpecific(&gHooksNoContext);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
|
|
|
static int sEarlyInitState = pthread_once(&once_control, &early_egl_init);
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-04-04 23:53:42 +00:00
|
|
|
egl_display_ptr validate_display(EGLDisplay dpy) {
|
|
|
|
egl_display_ptr dp = get_display(dpy);
|
2011-05-17 01:58:55 +00:00
|
|
|
if (!dp)
|
2012-04-04 23:53:42 +00:00
|
|
|
return setError(EGL_BAD_DISPLAY, egl_display_ptr(NULL));
|
2011-05-17 01:58:55 +00:00
|
|
|
if (!dp->isReady())
|
2012-04-04 23:53:42 +00:00
|
|
|
return setError(EGL_NOT_INITIALIZED, egl_display_ptr(NULL));
|
2011-03-23 22:59:00 +00:00
|
|
|
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2012-04-04 23:53:42 +00:00
|
|
|
egl_display_ptr validate_display_connection(EGLDisplay dpy,
|
|
|
|
egl_connection_t*& cnx) {
|
|
|
|
cnx = NULL;
|
|
|
|
egl_display_ptr dp = validate_display(dpy);
|
2011-05-17 01:58:55 +00:00
|
|
|
if (!dp)
|
2012-04-04 23:53:42 +00:00
|
|
|
return dp;
|
|
|
|
cnx = &gEGLImpl;
|
2009-03-04 03:31:44 +00:00
|
|
|
if (cnx->dso == 0) {
|
2012-04-04 23:53:42 +00:00
|
|
|
return setError(EGL_BAD_CONFIG, egl_display_ptr(NULL));
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2012-04-04 23:53:42 +00:00
|
|
|
return dp;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2012-01-29 05:44:00 +00:00
|
|
|
const GLubyte * egl_get_string_for_current_context(GLenum name) {
|
|
|
|
// NOTE: returning NULL here will fall-back to the default
|
|
|
|
// implementation.
|
|
|
|
|
|
|
|
EGLContext context = egl_tls_t::getContext();
|
|
|
|
if (context == EGL_NO_CONTEXT)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
egl_context_t const * const c = get_context(context);
|
|
|
|
if (c == NULL) // this should never happen, by construction
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (name != GL_EXTENSIONS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (const GLubyte *)c->gl_extensions.string();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-08-18 01:07:06 +00:00
|
|
|
// this mutex protects:
|
2009-08-25 04:47:13 +00:00
|
|
|
// d->disp[]
|
2009-08-18 01:07:06 +00:00
|
|
|
// egl_init_drivers_locked()
|
|
|
|
//
|
2011-05-13 23:21:08 +00:00
|
|
|
static EGLBoolean egl_init_drivers_locked() {
|
2009-03-04 03:31:44 +00:00
|
|
|
if (sEarlyInitState) {
|
2009-08-18 01:07:06 +00:00
|
|
|
// initialized by static ctor. should be set here.
|
|
|
|
return EGL_FALSE;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2009-05-29 00:39:03 +00:00
|
|
|
// get our driver loader
|
2009-08-18 01:07:06 +00:00
|
|
|
Loader& loader(Loader::getInstance());
|
2011-05-13 23:21:08 +00:00
|
|
|
|
2012-02-14 01:09:30 +00:00
|
|
|
// dynamically load our EGL implementation
|
|
|
|
egl_connection_t* cnx = &gEGLImpl;
|
2009-03-04 03:31:44 +00:00
|
|
|
if (cnx->dso == 0) {
|
2012-02-14 04:06:08 +00:00
|
|
|
cnx->hooks[egl_connection_t::GLESv1_INDEX] =
|
|
|
|
&gHooks[egl_connection_t::GLESv1_INDEX];
|
|
|
|
cnx->hooks[egl_connection_t::GLESv2_INDEX] =
|
|
|
|
&gHooks[egl_connection_t::GLESv2_INDEX];
|
2012-02-14 01:09:30 +00:00
|
|
|
cnx->dso = loader.open(cnx);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 01:09:30 +00:00
|
|
|
return cnx->dso ? EGL_TRUE : EGL_FALSE;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
EGLBoolean egl_init_drivers() {
|
2009-08-18 01:07:06 +00:00
|
|
|
EGLBoolean res;
|
2011-05-13 23:21:08 +00:00
|
|
|
pthread_mutex_lock(&sInitDriverMutex);
|
2009-08-18 01:07:06 +00:00
|
|
|
res = egl_init_drivers_locked();
|
2011-05-13 23:21:08 +00:00
|
|
|
pthread_mutex_unlock(&sInitDriverMutex);
|
2009-08-18 01:07:06 +00:00
|
|
|
return res;
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2011-05-24 00:26:14 +00:00
|
|
|
void gl_unimplemented() {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("called unimplemented OpenGL ES API");
|
2011-05-24 00:26:14 +00:00
|
|
|
}
|
|
|
|
|
2012-01-29 05:44:00 +00:00
|
|
|
void gl_noop() {
|
|
|
|
}
|
|
|
|
|
2011-05-24 00:26:14 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void setGlThreadSpecific(gl_hooks_t const *value) {
|
|
|
|
gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
|
|
|
|
tls_hooks[TLS_SLOT_OPENGL_API] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// GL / EGL hooks
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#undef GL_ENTRY
|
|
|
|
#undef EGL_ENTRY
|
|
|
|
#define GL_ENTRY(_r, _api, ...) #_api,
|
|
|
|
#define EGL_ENTRY(_r, _api, ...) #_api,
|
|
|
|
|
|
|
|
char const * const gl_names[] = {
|
2013-04-05 06:17:56 +00:00
|
|
|
#include "../entries.in"
|
2011-05-24 00:26:14 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
char const * const egl_names[] = {
|
|
|
|
#include "egl_entries.in"
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef GL_ENTRY
|
|
|
|
#undef EGL_ENTRY
|
|
|
|
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|