| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 20 | #include <EGL/egl.h> | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 21 | #include <pthread.h> | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 22 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 23 | namespace android { | 
 | 24 |  | 
 | 25 | class DbgContext; | 
 | 26 |  | 
 | 27 | class egl_tls_t { | 
| Mathias Agopian | 4e620dd | 2013-05-30 16:07:36 -0700 | [diff] [blame] | 28 |     enum { TLS_KEY_NOT_INITIALIZED = -1 }; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 29 |     static pthread_key_t sKey; | 
| Mathias Agopian | 4e620dd | 2013-05-30 16:07:36 -0700 | [diff] [blame] | 30 |     static pthread_once_t sOnceKey; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 31 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 32 |     EGLint error; | 
 | 33 |     EGLContext ctx; | 
 | 34 |     bool logCallWithNoContext; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 35 |  | 
 | 36 |     egl_tls_t(); | 
 | 37 |     static void validateTLSKey(); | 
| Jesse Hall | 6b0aee3 | 2018-06-15 16:44:27 -0700 | [diff] [blame] | 38 |     static void destructTLSData(void* data); | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 39 |     static void setErrorEtcImpl(const char* caller, int line, EGLint error, bool quiet); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 40 |  | 
 | 41 | public: | 
 | 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 Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 49 |     static const char* egl_strerror(EGLint err); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 50 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 51 |     template <typename T> | 
 | 52 |     static T setErrorEtc(const char* caller, int line, EGLint error, T returnValue, | 
 | 53 |                          bool quiet = false) { | 
| Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 54 |         setErrorEtcImpl(caller, line, error, quiet); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 55 |         return returnValue; | 
 | 56 |     } | 
 | 57 | }; | 
 | 58 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 59 | #define setError(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r) | 
| Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 60 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 61 | #define setErrorQuiet(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true) | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 62 |  | 
 | 63 | }; // namespace android | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 64 |  | 
 | 65 | #endif // ANDROID_EGL_TLS_H |