blob: 9feae681bde0447c42792f0a56366941316ea7cb [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
Mathias Agopian518ec112011-05-13 16:21:08 -070020#include <EGL/egl.h>
21
Mathias Agopian311b4792017-02-28 15:00:49 -080022#include <pthread.h>
Mathias Agopian1cadb252011-05-23 17:26:14 -070023
24// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070025namespace android {
Mathias Agopian1cadb252011-05-23 17:26:14 -070026// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070027
28class DbgContext;
29
30class egl_tls_t {
Mathias Agopian4e620dd2013-05-30 16:07:36 -070031 enum { TLS_KEY_NOT_INITIALIZED = -1 };
Mathias Agopian518ec112011-05-13 16:21:08 -070032 static pthread_key_t sKey;
Mathias Agopian4e620dd2013-05-30 16:07:36 -070033 static pthread_once_t sOnceKey;
Mathias Agopian518ec112011-05-13 16:21:08 -070034
35 EGLint error;
36 EGLContext ctx;
Mathias Agopian311b4792017-02-28 15:00:49 -080037 bool logCallWithNoContext;
Mathias Agopian518ec112011-05-13 16:21:08 -070038
39 egl_tls_t();
40 static void validateTLSKey();
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070041 static void setErrorEtcImpl(
42 const char* caller, int line, EGLint error, bool quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070043
44public:
45 static egl_tls_t* getTLS();
46 static void clearTLS();
47 static void clearError();
48 static EGLint getError();
49 static void setContext(EGLContext ctx);
50 static EGLContext getContext();
51 static bool logNoContextCall();
52 static const char *egl_strerror(EGLint err);
53
54 template<typename T>
55 static T setErrorEtc(const char* caller,
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070056 int line, EGLint error, T returnValue, bool quiet = false) {
57 setErrorEtcImpl(caller, line, error, quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070058 return returnValue;
59 }
60};
61
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070062#define setError(_e, _r) \
63 egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
64
65#define setErrorQuiet(_e, _r) \
66 egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true)
Mathias Agopian518ec112011-05-13 16:21:08 -070067
Mathias Agopian1cadb252011-05-23 17:26:14 -070068// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070069}; // namespace android
Mathias Agopian1cadb252011-05-23 17:26:14 -070070// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070071
72#endif // ANDROID_EGL_TLS_H