| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 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 |  | 
|  | 17 | #include <ctype.h> | 
|  | 18 | #include <stdint.h> | 
|  | 19 | #include <stdlib.h> | 
|  | 20 |  | 
|  | 21 | #include <EGL/egl.h> | 
|  | 22 | #include <EGL/eglext.h> | 
|  | 23 | #include <GLES/gl.h> | 
|  | 24 | #include <GLES/glext.h> | 
|  | 25 |  | 
|  | 26 | #include <utils/threads.h> | 
|  | 27 |  | 
|  | 28 | #include "egl_object.h" | 
|  | 29 |  | 
|  | 30 | // ---------------------------------------------------------------------------- | 
|  | 31 | namespace android { | 
|  | 32 | // ---------------------------------------------------------------------------- | 
|  | 33 |  | 
|  | 34 | egl_object_t::egl_object_t(egl_display_t* disp) : | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 35 | display(disp), count(1) { | 
|  | 36 | // NOTE: this does an implicit incRef | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 37 | display->addObject(this); | 
|  | 38 | } | 
|  | 39 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 40 | egl_object_t::~egl_object_t() { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 41 | } | 
|  | 42 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 43 | void egl_object_t::terminate() { | 
|  | 44 | // this marks the object as "terminated" | 
|  | 45 | display->removeObject(this); | 
|  | 46 | if (decRef() == 1) { | 
|  | 47 | // shouldn't happen because this is called from LocalRef | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 48 | ALOGE("egl_object_t::terminate() removed the last reference!"); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 49 | } | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | void egl_object_t::destroy() { | 
|  | 53 | if (decRef() == 1) { | 
|  | 54 | delete this; | 
|  | 55 | } | 
|  | 56 | } | 
|  | 57 |  | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 58 | bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) { | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 59 | // used by LocalRef, this does an incRef() atomically with | 
|  | 60 | // checking that the object is valid. | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 61 | return display->getObject(object); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 65 |  | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 66 | egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, | 
|  | 67 | EGLNativeWindowType win, EGLSurface surface, | 
|  | 68 | egl_connection_t const* cnx) : | 
|  | 69 | egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx) | 
|  | 70 | { | 
|  | 71 | if (win) { | 
|  | 72 | getDisplay()->onWindowSurfaceCreated(); | 
|  | 73 | } | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | egl_surface_t::~egl_surface_t() { | 
|  | 77 | ANativeWindow* const window = win.get(); | 
|  | 78 | if (window != NULL) { | 
|  | 79 | native_window_set_buffers_format(window, 0); | 
|  | 80 | if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) { | 
|  | 81 | ALOGW("EGLNativeWindowType %p disconnect failed", window); | 
|  | 82 | } | 
|  | 83 | getDisplay()->onWindowSurfaceDestroyed(); | 
|  | 84 | } | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | // ---------------------------------------------------------------------------- | 
|  | 88 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 89 | egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 90 | egl_connection_t const* cnx, int version) : | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 91 | egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context), | 
|  | 92 | config(config), read(0), draw(0), cnx(cnx), version(version) { | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 93 | } | 
|  | 94 |  | 
|  | 95 | void egl_context_t::onLooseCurrent() { | 
|  | 96 | read = NULL; | 
|  | 97 | draw = NULL; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) { | 
|  | 101 | this->read = read; | 
|  | 102 | this->draw = draw; | 
|  | 103 |  | 
|  | 104 | /* | 
|  | 105 | * Here we cache the GL_EXTENSIONS string for this context and we | 
|  | 106 | * add the extensions always handled by the wrapper | 
|  | 107 | */ | 
|  | 108 |  | 
|  | 109 | if (gl_extensions.isEmpty()) { | 
|  | 110 | // call the implementation's glGetString(GL_EXTENSIONS) | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 111 | const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 112 | gl_extensions.setTo(exts); | 
|  | 113 | if (gl_extensions.find("GL_EXT_debug_marker") < 0) { | 
|  | 114 | String8 temp("GL_EXT_debug_marker "); | 
|  | 115 | temp.append(gl_extensions); | 
|  | 116 | gl_extensions.setTo(temp); | 
|  | 117 | } | 
|  | 118 | } | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 122 | }; // namespace android | 
|  | 123 | // ---------------------------------------------------------------------------- |