blob: 56c5dba37d5296c75b43d249a733028359a935f1 [file] [log] [blame]
Mathias Agopian518ec112011-05-13 16:21:08 -07001/*
2 ** Copyright 2011, The Android Open Source Project
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17#ifndef ANDROID_EGL_TLS_H
18#define ANDROID_EGL_TLS_H
19
20#include <pthread.h>
21
22#include <EGL/egl.h>
23
Mathias Agopian1cadb252011-05-23 17:26:14 -070024#include "egldefs.h"
Mathias Agopian1cadb252011-05-23 17:26:14 -070025
26// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070027namespace android {
Mathias Agopian1cadb252011-05-23 17:26:14 -070028// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070029
30class DbgContext;
31
32class egl_tls_t {
33 static pthread_key_t sKey;
34 static pthread_mutex_t sLockKey;
35
36 EGLint error;
37 EGLContext ctx;
38 EGLBoolean logCallWithNoContext;
Mathias Agopian518ec112011-05-13 16:21:08 -070039
40 egl_tls_t();
41 static void validateTLSKey();
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070042 static void setErrorEtcImpl(
43 const char* caller, int line, EGLint error, bool quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070044
45public:
46 static egl_tls_t* getTLS();
47 static void clearTLS();
48 static void clearError();
49 static EGLint getError();
50 static void setContext(EGLContext ctx);
51 static EGLContext getContext();
52 static bool logNoContextCall();
53 static const char *egl_strerror(EGLint err);
54
55 template<typename T>
56 static T setErrorEtc(const char* caller,
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070057 int line, EGLint error, T returnValue, bool quiet = false) {
58 setErrorEtcImpl(caller, line, error, quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070059 return returnValue;
60 }
61};
62
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070063#define setError(_e, _r) \
64 egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
65
66#define setErrorQuiet(_e, _r) \
67 egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true)
Mathias Agopian518ec112011-05-13 16:21:08 -070068
Mathias Agopian1cadb252011-05-23 17:26:14 -070069// ----------------------------------------------------------------------------
70
71#if EGL_TRACE
72
73extern gl_hooks_t const* getGLTraceThreadSpecific();
74
75#endif
76
77// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070078}; // namespace android
Mathias Agopian1cadb252011-05-23 17:26:14 -070079// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070080
81#endif // ANDROID_EGL_TLS_H