egl_tls.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef ANDROID_EGL_TLS_H
  17. #define ANDROID_EGL_TLS_H
  18. #include <pthread.h>
  19. #include <EGL/egl.h>
  20. #include "egldefs.h"
  21. // ----------------------------------------------------------------------------
  22. namespace android {
  23. // ----------------------------------------------------------------------------
  24. class DbgContext;
  25. class egl_tls_t {
  26. enum { TLS_KEY_NOT_INITIALIZED = -1 };
  27. static pthread_key_t sKey;
  28. static pthread_once_t sOnceKey;
  29. EGLint error;
  30. EGLContext ctx;
  31. EGLBoolean logCallWithNoContext;
  32. egl_tls_t();
  33. static void validateTLSKey();
  34. static void setErrorEtcImpl(
  35. const char* caller, int line, EGLint error, bool quiet);
  36. public:
  37. static egl_tls_t* getTLS();
  38. static void clearTLS();
  39. static void clearError();
  40. static EGLint getError();
  41. static void setContext(EGLContext ctx);
  42. static EGLContext getContext();
  43. static bool logNoContextCall();
  44. static const char *egl_strerror(EGLint err);
  45. template<typename T>
  46. static T setErrorEtc(const char* caller,
  47. int line, EGLint error, T returnValue, bool quiet = false) {
  48. setErrorEtcImpl(caller, line, error, quiet);
  49. return returnValue;
  50. }
  51. };
  52. #define setError(_e, _r) \
  53. egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r)
  54. #define setErrorQuiet(_e, _r) \
  55. egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true)
  56. // ----------------------------------------------------------------------------
  57. #if EGL_TRACE
  58. extern gl_hooks_t const* getGLTraceThreadSpecific();
  59. #endif
  60. // ----------------------------------------------------------------------------
  61. }; // namespace android
  62. // ----------------------------------------------------------------------------
  63. #endif // ANDROID_EGL_TLS_H