blob: a7989ef965846430af6ff0a9a663541dcc5a6f0c [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
Mathias Agopian1cadb252011-05-23 17:26:14 -070024#include "egldefs.h"
25#include "hooks.h"
26
27// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070028namespace android {
Mathias Agopian1cadb252011-05-23 17:26:14 -070029// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070030
31class DbgContext;
32
33class 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();
44 static void setErrorEtcImpl(const char* caller, int line, EGLint error);
45
46public:
47 static egl_tls_t* getTLS();
48 static void clearTLS();
49 static void clearError();
50 static EGLint getError();
51 static void setContext(EGLContext ctx);
52 static EGLContext getContext();
53 static bool logNoContextCall();
54 static const char *egl_strerror(EGLint err);
55
56 template<typename T>
57 static T setErrorEtc(const char* caller,
58 int line, EGLint error, T returnValue) {
59 setErrorEtcImpl(caller, line, error);
60 return returnValue;
61 }
62};
63
64#define setError(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
65
Mathias Agopian1cadb252011-05-23 17:26:14 -070066// ----------------------------------------------------------------------------
67
68#if EGL_TRACE
69
70extern gl_hooks_t const* getGLTraceThreadSpecific();
71
72#endif
73
74// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070075}; // namespace android
Mathias Agopian1cadb252011-05-23 17:26:14 -070076// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -070077
78#endif // ANDROID_EGL_TLS_H