egl_object.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include <string>
  17. #include <sstream>
  18. #include <ctype.h>
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <EGL/egl.h>
  22. #include <EGL/eglext.h>
  23. #include <utils/threads.h>
  24. #include "egl_object.h"
  25. // ----------------------------------------------------------------------------
  26. namespace android {
  27. // ----------------------------------------------------------------------------
  28. egl_object_t::egl_object_t(egl_display_t* disp) :
  29. display(disp), count(1) {
  30. // NOTE: this does an implicit incRef
  31. display->addObject(this);
  32. }
  33. egl_object_t::~egl_object_t() {
  34. }
  35. void egl_object_t::terminate() {
  36. // this marks the object as "terminated"
  37. display->removeObject(this);
  38. if (decRef() == 1) {
  39. // shouldn't happen because this is called from LocalRef
  40. ALOGE("egl_object_t::terminate() removed the last reference!");
  41. }
  42. }
  43. void egl_object_t::destroy() {
  44. if (decRef() == 1) {
  45. delete this;
  46. }
  47. }
  48. bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {
  49. // used by LocalRef, this does an incRef() atomically with
  50. // checking that the object is valid.
  51. return display->getObject(object);
  52. }
  53. // ----------------------------------------------------------------------------
  54. egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config,
  55. EGLNativeWindowType win, EGLSurface surface,
  56. egl_connection_t const* cnx) :
  57. egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx)
  58. {
  59. if (win) {
  60. getDisplay()->onWindowSurfaceCreated();
  61. }
  62. }
  63. egl_surface_t::~egl_surface_t() {
  64. ANativeWindow* const window = win.get();
  65. if (window != NULL) {
  66. native_window_set_buffers_format(window, 0);
  67. if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) {
  68. ALOGW("EGLNativeWindowType %p disconnect failed", window);
  69. }
  70. getDisplay()->onWindowSurfaceDestroyed();
  71. }
  72. }
  73. // ----------------------------------------------------------------------------
  74. egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config,
  75. egl_connection_t const* cnx, int version) :
  76. egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context),
  77. config(config), read(0), draw(0), cnx(cnx), version(version) {
  78. }
  79. void egl_context_t::onLooseCurrent() {
  80. read = NULL;
  81. draw = NULL;
  82. }
  83. void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {
  84. this->read = read;
  85. this->draw = draw;
  86. /*
  87. * Here we cache the GL_EXTENSIONS string for this context and we
  88. * add the extensions always handled by the wrapper
  89. */
  90. if (gl_extensions.isEmpty()) {
  91. // call the implementation's glGetString(GL_EXTENSIONS)
  92. const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS);
  93. gl_extensions.setTo(exts);
  94. if (gl_extensions.find("GL_EXT_debug_marker") < 0) {
  95. String8 temp("GL_EXT_debug_marker ");
  96. temp.append(gl_extensions);
  97. gl_extensions.setTo(temp);
  98. }
  99. // tokenize the supported extensions for the glGetStringi() wrapper
  100. std::stringstream ss;
  101. std::string str;
  102. ss << gl_extensions.string();
  103. while (ss >> str) {
  104. tokenized_gl_extensions.push(String8(str.c_str()));
  105. }
  106. }
  107. }
  108. // ----------------------------------------------------------------------------
  109. }; // namespace android
  110. // ----------------------------------------------------------------------------