blob: 8b314680875f4527bfafa60408d4fa430c26931d [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
24namespace android {
25
26class DbgContext;
27
28class egl_tls_t {
29 static pthread_key_t sKey;
30 static pthread_mutex_t sLockKey;
31
32 EGLint error;
33 EGLContext ctx;
34 EGLBoolean logCallWithNoContext;
35 DbgContext* dbg;
36
37 egl_tls_t();
38 static void validateTLSKey();
39 static void setErrorEtcImpl(const char* caller, int line, EGLint error);
40
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();
49 static const char *egl_strerror(EGLint err);
50
51 template<typename T>
52 static T setErrorEtc(const char* caller,
53 int line, EGLint error, T returnValue) {
54 setErrorEtcImpl(caller, line, error);
55 return returnValue;
56 }
57};
58
59#define setError(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
60
61}; // namespace android
62
63#endif // ANDROID_EGL_TLS_H