2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
** Copyright 2007, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** 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
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** 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
|
|
|
|
** 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 <GLES/gl.h>
|
|
|
|
#include <GLES/glext.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
|
|
|
|
2011-05-24 00:26:14 +00:00
|
|
|
#include "egldefs.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "egl_impl.h"
|
2011-03-28 17:39:28 +00:00
|
|
|
#include "egl_tls.h"
|
2011-05-13 23:21:08 +00:00
|
|
|
#include "glesv2dbg.h"
|
|
|
|
#include "hooks.h"
|
|
|
|
#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 {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
egl_connection_t gEGLImpl[IMPL_NUM_IMPLEMENTATIONS];
|
|
|
|
gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS];
|
|
|
|
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;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
int gEGLDebugLevel;
|
|
|
|
|
|
|
|
static int sEGLTraceLevel;
|
|
|
|
static int sEGLApplicationTraceLevel;
|
|
|
|
|
|
|
|
extern gl_hooks_t gHooksTrace;
|
|
|
|
extern gl_hooks_t gHooksDebug;
|
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");
|
|
|
|
int propertyLevel = atoi(value);
|
2011-05-13 23:21:08 +00:00
|
|
|
int applicationLevel = sEGLApplicationTraceLevel;
|
|
|
|
sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel;
|
2011-04-09 01:43:16 +00:00
|
|
|
|
2011-03-02 00:08:10 +00:00
|
|
|
property_get("debug.egl.debug_proc", value, "");
|
|
|
|
long pid = getpid();
|
|
|
|
char procPath[128] = {};
|
|
|
|
sprintf(procPath, "/proc/%ld/cmdline", pid);
|
|
|
|
FILE * file = fopen(procPath, "r");
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
char cmdline[256] = {};
|
|
|
|
if (fgets(cmdline, sizeof(cmdline) - 1, file))
|
|
|
|
{
|
|
|
|
if (!strcmp(value, cmdline))
|
2011-09-01 21:55:00 +00:00
|
|
|
gEGLDebugLevel = 1;
|
2011-04-09 01:43:16 +00:00
|
|
|
}
|
2011-03-02 00:08:10 +00:00
|
|
|
fclose(file);
|
|
|
|
}
|
2011-04-09 01:43:16 +00:00
|
|
|
|
2011-09-01 21:55:00 +00:00
|
|
|
if (gEGLDebugLevel > 0)
|
2011-03-11 03:07:42 +00:00
|
|
|
{
|
|
|
|
property_get("debug.egl.debug_port", value, "5039");
|
2011-04-09 01:43:16 +00:00
|
|
|
const unsigned short port = (unsigned short)atoi(value);
|
|
|
|
property_get("debug.egl.debug_forceUseFile", value, "0");
|
|
|
|
const bool forceUseFile = (bool)atoi(value);
|
|
|
|
property_get("debug.egl.debug_maxFileSize", value, "8");
|
|
|
|
const unsigned int maxFileSize = atoi(value) << 20;
|
|
|
|
property_get("debug.egl.debug_filePath", value, "/data/local/tmp/dump.gles2dbg");
|
|
|
|
StartDebugServer(port, forceUseFile, maxFileSize, value);
|
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) {
|
|
|
|
if (sEGLTraceLevel > 0) {
|
2010-10-26 22:21:24 +00:00
|
|
|
setGlTraceThreadSpecific(value);
|
|
|
|
setGlThreadSpecific(&gHooksTrace);
|
2011-09-01 21:55:00 +00:00
|
|
|
} else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) {
|
2011-03-02 00:08:10 +00:00
|
|
|
setGlTraceThreadSpecific(value);
|
|
|
|
setGlThreadSpecific(&gHooksDebug);
|
2010-10-26 22:21:24 +00:00
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#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()) {
|
2009-07-31 23:21:17 +00:00
|
|
|
LOGE("call to OpenGL ES API with no current context "
|
|
|
|
"(logged once per thread)");
|
2011-09-07 00:24:05 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.egl.callstack", value, "0");
|
|
|
|
if (atoi(value)) {
|
|
|
|
CallStack stack;
|
|
|
|
stack.update();
|
|
|
|
stack.dump();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
static void early_egl_init(void)
|
|
|
|
{
|
|
|
|
#if !USE_FAST_TLS_KEY
|
|
|
|
pthread_key_create(&gGLWrapperKey, NULL);
|
2010-10-26 22:21:24 +00:00
|
|
|
#endif
|
|
|
|
#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(
|
2009-10-14 09:06:37 +00:00
|
|
|
(uint32_t*)(void*)&gHooksNoContext,
|
2009-03-04 03:31:44 +00:00
|
|
|
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
|
|
|
|
2011-05-17 01:58:55 +00:00
|
|
|
egl_display_t* validate_display(EGLDisplay dpy) {
|
2011-03-23 22:59:00 +00:00
|
|
|
egl_display_t * const dp = get_display(dpy);
|
2011-05-17 01:58:55 +00:00
|
|
|
if (!dp)
|
|
|
|
return setError(EGL_BAD_DISPLAY, (egl_display_t*)NULL);
|
|
|
|
if (!dp->isReady())
|
|
|
|
return setError(EGL_NOT_INITIALIZED, (egl_display_t*)NULL);
|
2011-03-23 22:59:00 +00:00
|
|
|
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2011-05-17 01:58:55 +00:00
|
|
|
egl_connection_t* validate_display_config(EGLDisplay dpy, EGLConfig config,
|
|
|
|
egl_display_t const*& dp) {
|
2011-03-23 22:59:00 +00:00
|
|
|
dp = validate_display(dpy);
|
2011-05-17 01:58:55 +00:00
|
|
|
if (!dp)
|
|
|
|
return (egl_connection_t*) NULL;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-07-27 04:14:59 +00:00
|
|
|
if (intptr_t(config) >= dp->numTotalConfigs) {
|
2009-03-04 03:31:44 +00:00
|
|
|
return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
|
|
|
|
}
|
2010-07-27 04:14:59 +00:00
|
|
|
egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(config)].impl];
|
2009-03-04 03:31:44 +00:00
|
|
|
if (cnx->dso == 0) {
|
|
|
|
return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL);
|
|
|
|
}
|
|
|
|
return cnx;
|
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image)
|
|
|
|
{
|
2011-05-13 23:21:08 +00:00
|
|
|
EGLContext context = egl_tls_t::getContext();
|
2009-04-10 21:24:30 +00:00
|
|
|
if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR)
|
|
|
|
return EGL_NO_IMAGE_KHR;
|
2011-05-17 01:58:55 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
egl_context_t const * const c = get_context(context);
|
2011-11-14 04:50:07 +00:00
|
|
|
if (c == NULL) // this should never happen, by construction
|
|
|
|
return EGL_NO_IMAGE_KHR;
|
|
|
|
|
|
|
|
egl_display_t* display = egl_display_t::get(c->dpy);
|
|
|
|
if (display == NULL) // this should never happen, by construction
|
|
|
|
return EGL_NO_IMAGE_KHR;
|
|
|
|
|
|
|
|
ImageRef _i(display, image);
|
|
|
|
if (!_i.get())
|
2009-04-10 21:24:30 +00:00
|
|
|
return EGL_NO_IMAGE_KHR;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2011-05-17 01:58:55 +00:00
|
|
|
// here we don't validate the context because if it's been marked for
|
|
|
|
// termination, this call should still succeed since it's internal to
|
|
|
|
// EGL.
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
egl_image_t const * const i = get_image(image);
|
|
|
|
return i->images[c->impl];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// dynamically load all our EGL implementations
|
2009-08-18 01:07:06 +00:00
|
|
|
egl_connection_t* cnx;
|
|
|
|
|
|
|
|
cnx = &gEGLImpl[IMPL_SOFTWARE];
|
2009-03-04 03:31:44 +00:00
|
|
|
if (cnx->dso == 0) {
|
2009-10-14 09:06:37 +00:00
|
|
|
cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_SOFTWARE];
|
|
|
|
cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_SOFTWARE];
|
|
|
|
cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 0, cnx);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cnx = &gEGLImpl[IMPL_HARDWARE];
|
2009-08-18 01:07:06 +00:00
|
|
|
if (cnx->dso == 0) {
|
2009-03-04 03:31:44 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.egl.hw", value, "1");
|
|
|
|
if (atoi(value) != 0) {
|
2009-10-14 09:06:37 +00:00
|
|
|
cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_HARDWARE];
|
|
|
|
cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_HARDWARE];
|
|
|
|
cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 1, cnx);
|
2009-03-04 03:31:44 +00:00
|
|
|
} else {
|
2011-12-20 16:23:08 +00:00
|
|
|
ALOGD("3D hardware acceleration is disabled");
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-25 04:47:13 +00:00
|
|
|
|
2009-08-18 01:07:06 +00:00
|
|
|
if (!gEGLImpl[IMPL_SOFTWARE].dso && !gEGLImpl[IMPL_HARDWARE].dso) {
|
|
|
|
return EGL_FALSE;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 01:07:06 +00:00
|
|
|
return EGL_TRUE;
|
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() {
|
|
|
|
LOGE("called unimplemented OpenGL ES API");
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#if USE_FAST_TLS_KEY
|
|
|
|
|
|
|
|
// We have a dedicated TLS slot in bionic
|
|
|
|
static inline gl_hooks_t const * volatile * get_tls_hooks() {
|
|
|
|
volatile void *tls_base = __get_tls();
|
|
|
|
gl_hooks_t const * volatile * tls_hooks =
|
|
|
|
reinterpret_cast<gl_hooks_t const * volatile *>(tls_base);
|
|
|
|
return tls_hooks;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_hooks_t const* getGlThreadSpecific() {
|
|
|
|
gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
|
|
|
|
gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API];
|
|
|
|
if (hooks) return hooks;
|
|
|
|
return &gHooksNoContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void setGlThreadSpecific(gl_hooks_t const *value) {
|
|
|
|
pthread_setspecific(gGLWrapperKey, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_hooks_t const* getGlThreadSpecific() {
|
|
|
|
gl_hooks_t const* hooks = static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey));
|
|
|
|
if (hooks) return hooks;
|
|
|
|
return &gHooksNoContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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[] = {
|
|
|
|
#include "entries.in"
|
|
|
|
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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|