| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1 | /* | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project | 
|  | 3 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 7 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 8 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 9 | ** | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 14 | ** limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 17 | #include <string> | 
|  | 18 | #include <sstream> | 
|  | 19 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 20 | #include <ctype.h> | 
|  | 21 | #include <stdint.h> | 
|  | 22 | #include <stdlib.h> | 
|  | 23 |  | 
|  | 24 | #include <EGL/egl.h> | 
|  | 25 | #include <EGL/eglext.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | #include <utils/threads.h> | 
|  | 28 |  | 
|  | 29 | #include "egl_object.h" | 
|  | 30 |  | 
|  | 31 | // ---------------------------------------------------------------------------- | 
|  | 32 | namespace android { | 
|  | 33 | // ---------------------------------------------------------------------------- | 
|  | 34 |  | 
|  | 35 | egl_object_t::egl_object_t(egl_display_t* disp) : | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 36 | display(disp), count(1) { | 
|  | 37 | // NOTE: this does an implicit incRef | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 38 | display->addObject(this); | 
|  | 39 | } | 
|  | 40 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 41 | egl_object_t::~egl_object_t() { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 44 | void egl_object_t::terminate() { | 
|  | 45 | // this marks the object as "terminated" | 
|  | 46 | display->removeObject(this); | 
|  | 47 | if (decRef() == 1) { | 
|  | 48 | // shouldn't happen because this is called from LocalRef | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 49 | ALOGE("egl_object_t::terminate() removed the last reference!"); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 50 | } | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | void egl_object_t::destroy() { | 
|  | 54 | if (decRef() == 1) { | 
|  | 55 | delete this; | 
|  | 56 | } | 
|  | 57 | } | 
|  | 58 |  | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 59 | 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] | 60 | // used by LocalRef, this does an incRef() atomically with | 
|  | 61 | // checking that the object is valid. | 
| Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 62 | return display->getObject(object); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
|  | 65 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 66 |  | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 67 | egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, | 
|  | 68 | EGLNativeWindowType win, EGLSurface surface, | 
|  | 69 | egl_connection_t const* cnx) : | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 70 | egl_object_t(dpy), surface(surface), config(config), win(win), cnx(cnx), | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 71 | enableTimestamps(false), connected(true) | 
| Dan Willemsen | e9cbb65 | 2016-10-11 12:46:38 -0700 | [diff] [blame] | 72 | {} | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | egl_surface_t::~egl_surface_t() { | 
|  | 75 | ANativeWindow* const window = win.get(); | 
|  | 76 | if (window != NULL) { | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 77 | disconnect(); | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 78 | } | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | void egl_surface_t::disconnect() { | 
|  | 82 | ANativeWindow* const window = win.get(); | 
|  | 83 | if (window != NULL && connected) { | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 84 | native_window_set_buffers_format(window, 0); | 
|  | 85 | if (native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL)) { | 
|  | 86 | ALOGW("EGLNativeWindowType %p disconnect failed", window); | 
|  | 87 | } | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 88 | connected = false; | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 89 | } | 
|  | 90 | } | 
|  | 91 |  | 
| Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 92 | void egl_surface_t::terminate() { | 
|  | 93 | disconnect(); | 
|  | 94 | egl_object_t::terminate(); | 
|  | 95 | } | 
|  | 96 |  | 
| Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 97 | // ---------------------------------------------------------------------------- | 
|  | 98 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 99 | egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 100 | egl_connection_t const* cnx, int version) : | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 101 | egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context), | 
|  | 102 | config(config), read(0), draw(0), cnx(cnx), version(version) { | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
|  | 105 | void egl_context_t::onLooseCurrent() { | 
|  | 106 | read = NULL; | 
|  | 107 | draw = NULL; | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) { | 
|  | 111 | this->read = read; | 
|  | 112 | this->draw = draw; | 
|  | 113 |  | 
|  | 114 | /* | 
|  | 115 | * Here we cache the GL_EXTENSIONS string for this context and we | 
|  | 116 | * add the extensions always handled by the wrapper | 
|  | 117 | */ | 
|  | 118 |  | 
|  | 119 | if (gl_extensions.isEmpty()) { | 
|  | 120 | // call the implementation's glGetString(GL_EXTENSIONS) | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 121 | const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 122 | gl_extensions.setTo(exts); | 
|  | 123 | if (gl_extensions.find("GL_EXT_debug_marker") < 0) { | 
|  | 124 | String8 temp("GL_EXT_debug_marker "); | 
|  | 125 | temp.append(gl_extensions); | 
|  | 126 | gl_extensions.setTo(temp); | 
|  | 127 | } | 
| Alistair Strachan | 89301ea | 2015-05-22 14:10:09 -0700 | [diff] [blame] | 128 |  | 
|  | 129 | // tokenize the supported extensions for the glGetStringi() wrapper | 
| Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 130 | std::stringstream ss; | 
|  | 131 | std::string str; | 
|  | 132 | ss << gl_extensions.string(); | 
|  | 133 | while (ss >> str) { | 
|  | 134 | tokenized_gl_extensions.push(String8(str.c_str())); | 
| Alistair Strachan | 89301ea | 2015-05-22 14:10:09 -0700 | [diff] [blame] | 135 | } | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 136 | } | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 140 | }; // namespace android | 
|  | 141 | // ---------------------------------------------------------------------------- |