hooks.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Copyright 2007, 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_GLES_CM_HOOKS_H
  17. #define ANDROID_GLES_CM_HOOKS_H
  18. #include <ctype.h>
  19. #include <string.h>
  20. #include <errno.h>
  21. #include <pthread.h>
  22. #include <EGL/egl.h>
  23. #include <EGL/eglext.h>
  24. #include <GLES/gl.h>
  25. #include <GLES/glext.h>
  26. #include <GLES2/gl2.h>
  27. #include <GLES2/gl2ext.h>
  28. #include <GLES3/gl3.h>
  29. #include <GLES3/gl31.h>
  30. #include <GLES3/gl32.h>
  31. // set to 1 for debugging
  32. #define USE_SLOW_BINDING 0
  33. #undef NELEM
  34. #define NELEM(x) (sizeof(x)/sizeof(*(x)))
  35. // maximum number of GL extensions that can be used simultaneously in
  36. // a given process. this limitation exists because we need to have
  37. // a static function for each extension and currently these static functions
  38. // are generated at compile time.
  39. #define MAX_NUMBER_OF_GL_EXTENSIONS 256
  40. #include <bionic_tls.h> /* special private C library header */
  41. // ----------------------------------------------------------------------------
  42. namespace android {
  43. // ----------------------------------------------------------------------------
  44. // GL / EGL hooks
  45. #undef GL_ENTRY
  46. #undef EGL_ENTRY
  47. #define GL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__);
  48. #define EGL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__);
  49. struct platform_impl_t {
  50. #include "platform_entries.in"
  51. };
  52. struct egl_t {
  53. #include "EGL/egl_entries.in"
  54. };
  55. struct gl_hooks_t {
  56. struct gl_t {
  57. #include "entries.in"
  58. } gl;
  59. struct gl_ext_t {
  60. __eglMustCastToProperFunctionPointerType extensions[MAX_NUMBER_OF_GL_EXTENSIONS];
  61. } ext;
  62. };
  63. #undef GL_ENTRY
  64. #undef EGL_ENTRY
  65. EGLAPI void setGlThreadSpecific(gl_hooks_t const *value);
  66. // We have a dedicated TLS slot in bionic
  67. inline gl_hooks_t const * volatile * get_tls_hooks() {
  68. volatile void *tls_base = __get_tls();
  69. gl_hooks_t const * volatile * tls_hooks =
  70. reinterpret_cast<gl_hooks_t const * volatile *>(tls_base);
  71. return tls_hooks;
  72. }
  73. inline EGLAPI gl_hooks_t const* getGlThreadSpecific() {
  74. gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
  75. gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API];
  76. return hooks;
  77. }
  78. // ----------------------------------------------------------------------------
  79. }; // namespace android
  80. // ----------------------------------------------------------------------------
  81. #endif /* ANDROID_GLES_CM_HOOKS_H */