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 | |
| 20 | #include <pthread.h> |
| 21 | |
| 22 | #include <EGL/egl.h> |
| 23 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 24 | #include "egldefs.h" |
| 25 | #include "hooks.h" |
| 26 | |
| 27 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 28 | namespace android { |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 29 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 30 | |
| 31 | class DbgContext; |
| 32 | |
| 33 | class egl_tls_t { |
| 34 | static pthread_key_t sKey; |
| 35 | static pthread_mutex_t sLockKey; |
| 36 | |
| 37 | EGLint error; |
| 38 | EGLContext ctx; |
| 39 | EGLBoolean logCallWithNoContext; |
| 40 | DbgContext* dbg; |
| 41 | |
| 42 | egl_tls_t(); |
| 43 | static void validateTLSKey(); |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 44 | static void setErrorEtcImpl( |
| 45 | const char* caller, int line, EGLint error, bool quiet); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 46 | |
| 47 | public: |
| 48 | static egl_tls_t* getTLS(); |
| 49 | static void clearTLS(); |
| 50 | static void clearError(); |
| 51 | static EGLint getError(); |
| 52 | static void setContext(EGLContext ctx); |
| 53 | static EGLContext getContext(); |
| 54 | static bool logNoContextCall(); |
| 55 | static const char *egl_strerror(EGLint err); |
| 56 | |
| 57 | template<typename T> |
| 58 | static T setErrorEtc(const char* caller, |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 59 | int line, EGLint error, T returnValue, bool quiet = false) { |
| 60 | setErrorEtcImpl(caller, line, error, quiet); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 61 | return returnValue; |
| 62 | } |
| 63 | }; |
| 64 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 65 | #define setError(_e, _r) \ |
| 66 | egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r) |
| 67 | |
| 68 | #define setErrorQuiet(_e, _r) \ |
| 69 | egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 70 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 71 | // ---------------------------------------------------------------------------- |
| 72 | |
| 73 | #if EGL_TRACE |
| 74 | |
| 75 | extern gl_hooks_t const* getGLTraceThreadSpecific(); |
| 76 | |
| 77 | #endif |
| 78 | |
| 79 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 80 | }; // namespace android |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 81 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 82 | |
| 83 | #endif // ANDROID_EGL_TLS_H |