2011-05-13 23:21:08 +00:00
|
|
|
/*
|
|
|
|
** Copyright 2011, 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.
|
|
|
|
*/
|
|
|
|
|
2011-09-07 00:24:05 +00:00
|
|
|
#include <stdlib.h>
|
2011-05-13 23:21:08 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include <cutils/log.h>
|
2011-09-07 00:24:05 +00:00
|
|
|
#include <cutils/properties.h>
|
|
|
|
|
|
|
|
#include <utils/CallStack.h>
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
|
|
|
|
#include "egl_tls.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2013-05-30 23:07:36 +00:00
|
|
|
pthread_key_t egl_tls_t::sKey = TLS_KEY_NOT_INITIALIZED;
|
|
|
|
pthread_once_t egl_tls_t::sOnceKey = PTHREAD_ONCE_INIT;
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
egl_tls_t::egl_tls_t()
|
2011-11-30 23:05:37 +00:00
|
|
|
: error(EGL_SUCCESS), ctx(0), logCallWithNoContext(EGL_TRUE) {
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *egl_tls_t::egl_strerror(EGLint err) {
|
|
|
|
switch (err) {
|
|
|
|
case EGL_SUCCESS: return "EGL_SUCCESS";
|
|
|
|
case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED";
|
|
|
|
case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS";
|
|
|
|
case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC";
|
|
|
|
case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE";
|
|
|
|
case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG";
|
|
|
|
case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT";
|
|
|
|
case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE";
|
|
|
|
case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY";
|
|
|
|
case EGL_BAD_MATCH: return "EGL_BAD_MATCH";
|
|
|
|
case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP";
|
|
|
|
case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW";
|
|
|
|
case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER";
|
|
|
|
case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE";
|
|
|
|
case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST";
|
|
|
|
default: return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_tls_t::validateTLSKey()
|
|
|
|
{
|
2013-05-30 23:07:36 +00:00
|
|
|
struct TlsKeyInitializer {
|
|
|
|
static void create() {
|
|
|
|
pthread_key_create(&sKey, (void (*)(void*))&eglReleaseThread);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
pthread_once(&sOnceKey, TlsKeyInitializer::create);
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 02:15:05 +00:00
|
|
|
void egl_tls_t::setErrorEtcImpl(
|
|
|
|
const char* caller, int line, EGLint error, bool quiet) {
|
2011-05-13 23:21:08 +00:00
|
|
|
validateTLSKey();
|
|
|
|
egl_tls_t* tls = getTLS();
|
|
|
|
if (tls->error != error) {
|
2011-10-06 02:15:05 +00:00
|
|
|
if (!quiet) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("%s:%d error %x (%s)",
|
2011-10-06 02:15:05 +00:00
|
|
|
caller, line, error, egl_strerror(error));
|
|
|
|
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-10-06 02:15:05 +00:00
|
|
|
}
|
2011-09-07 00:24:05 +00:00
|
|
|
}
|
2011-10-06 02:15:05 +00:00
|
|
|
tls->error = error;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool egl_tls_t::logNoContextCall() {
|
|
|
|
egl_tls_t* tls = getTLS();
|
|
|
|
if (tls->logCallWithNoContext == true) {
|
|
|
|
tls->logCallWithNoContext = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_tls_t* egl_tls_t::getTLS() {
|
|
|
|
egl_tls_t* tls = (egl_tls_t*)pthread_getspecific(sKey);
|
|
|
|
if (tls == 0) {
|
|
|
|
tls = new egl_tls_t;
|
|
|
|
pthread_setspecific(sKey, tls);
|
|
|
|
}
|
|
|
|
return tls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_tls_t::clearTLS() {
|
2013-05-30 23:07:36 +00:00
|
|
|
if (sKey != TLS_KEY_NOT_INITIALIZED) {
|
2011-05-13 23:21:08 +00:00
|
|
|
egl_tls_t* tls = (egl_tls_t*)pthread_getspecific(sKey);
|
|
|
|
if (tls) {
|
|
|
|
pthread_setspecific(sKey, 0);
|
2013-05-30 23:07:36 +00:00
|
|
|
delete tls;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_tls_t::clearError() {
|
|
|
|
// This must clear the error from all the underlying EGL implementations as
|
|
|
|
// well as the EGL wrapper layer.
|
|
|
|
eglGetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLint egl_tls_t::getError() {
|
2013-05-30 23:07:36 +00:00
|
|
|
if (sKey == TLS_KEY_NOT_INITIALIZED) {
|
2011-05-13 23:21:08 +00:00
|
|
|
return EGL_SUCCESS;
|
2013-05-30 23:07:36 +00:00
|
|
|
}
|
2011-05-13 23:21:08 +00:00
|
|
|
egl_tls_t* tls = (egl_tls_t*)pthread_getspecific(sKey);
|
2013-05-30 23:07:36 +00:00
|
|
|
if (!tls) {
|
|
|
|
return EGL_SUCCESS;
|
|
|
|
}
|
2011-05-13 23:21:08 +00:00
|
|
|
EGLint error = tls->error;
|
|
|
|
tls->error = EGL_SUCCESS;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_tls_t::setContext(EGLContext ctx) {
|
|
|
|
validateTLSKey();
|
|
|
|
getTLS()->ctx = ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLContext egl_tls_t::getContext() {
|
2013-05-30 23:07:36 +00:00
|
|
|
if (sKey == TLS_KEY_NOT_INITIALIZED) {
|
2011-05-13 23:21:08 +00:00
|
|
|
return EGL_NO_CONTEXT;
|
2013-05-30 23:07:36 +00:00
|
|
|
}
|
2011-05-13 23:21:08 +00:00
|
|
|
egl_tls_t* tls = (egl_tls_t *)pthread_getspecific(sKey);
|
|
|
|
if (!tls) return EGL_NO_CONTEXT;
|
|
|
|
return tls->ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace android
|