blob: b5fcc1a80557df716c273aac987b36a039db87d4 [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>
Mathias Agopian311b4792017-02-28 15:00:49 -080021#include <pthread.h>
Mathias Agopian1cadb252011-05-23 17:26:14 -070022
Mathias Agopian518ec112011-05-13 16:21:08 -070023namespace android {
24
25class DbgContext;
26
27class egl_tls_t {
Mathias Agopian4e620dd2013-05-30 16:07:36 -070028 enum { TLS_KEY_NOT_INITIALIZED = -1 };
Mathias Agopian518ec112011-05-13 16:21:08 -070029 static pthread_key_t sKey;
Mathias Agopian4e620dd2013-05-30 16:07:36 -070030 static pthread_once_t sOnceKey;
Mathias Agopian518ec112011-05-13 16:21:08 -070031
Yiwei Zhang8af03062020-08-12 21:28:15 -070032 EGLint error;
33 EGLContext ctx;
34 bool logCallWithNoContext;
Mathias Agopian518ec112011-05-13 16:21:08 -070035
36 egl_tls_t();
37 static void validateTLSKey();
Jesse Hall6b0aee32018-06-15 16:44:27 -070038 static void destructTLSData(void* data);
Yiwei Zhang8af03062020-08-12 21:28:15 -070039 static void setErrorEtcImpl(const char* caller, int line, EGLint error, bool quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070040
41public:
42 static egl_tls_t* getTLS();
43 static void clearTLS();
44 static void clearError();
45 static EGLint getError();
46 static void setContext(EGLContext ctx);
47 static EGLContext getContext();
48 static bool logNoContextCall();
Yiwei Zhang8af03062020-08-12 21:28:15 -070049 static const char* egl_strerror(EGLint err);
Mathias Agopian518ec112011-05-13 16:21:08 -070050
Yiwei Zhang8af03062020-08-12 21:28:15 -070051 template <typename T>
52 static T setErrorEtc(const char* caller, int line, EGLint error, T returnValue,
53 bool quiet = false) {
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070054 setErrorEtcImpl(caller, line, error, quiet);
Mathias Agopian518ec112011-05-13 16:21:08 -070055 return returnValue;
56 }
57};
58
Yiwei Zhang8af03062020-08-12 21:28:15 -070059#define setError(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
Mathias Agopian0e8bbee2011-10-05 19:15:05 -070060
Yiwei Zhang8af03062020-08-12 21:28:15 -070061#define setErrorQuiet(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true)
Mathias Agopian518ec112011-05-13 16:21:08 -070062
63}; // namespace android
Mathias Agopian518ec112011-05-13 16:21:08 -070064
65#endif // ANDROID_EGL_TLS_H