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 | |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 17 | #include "egl_object.h" |
| 18 | |
Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 19 | #include <sstream> |
| 20 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 21 | |
| 22 | // ---------------------------------------------------------------------------- |
| 23 | namespace android { |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | |
| 26 | egl_object_t::egl_object_t(egl_display_t* disp) : |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 27 | display(disp), count(1) { |
| 28 | // NOTE: this does an implicit incRef |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 29 | display->addObject(this); |
| 30 | } |
| 31 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 32 | egl_object_t::~egl_object_t() { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 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 |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 40 | ALOGE("egl_object_t::terminate() removed the last reference!"); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | void egl_object_t::destroy() { |
| 45 | if (decRef() == 1) { |
| 46 | delete this; |
| 47 | } |
| 48 | } |
| 49 | |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 50 | 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] | 51 | // used by LocalRef, this does an incRef() atomically with |
| 52 | // checking that the object is valid. |
Mathias Agopian | f0480de | 2011-11-13 20:50:07 -0800 | [diff] [blame] | 53 | return display->getObject(object); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 57 | |
Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame^] | 58 | egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWindowType win, |
| 59 | EGLSurface surface, EGLint colorSpace, egl_connection_t const* cnx) |
| 60 | : egl_object_t(dpy), |
| 61 | surface(surface), |
| 62 | config(config), |
| 63 | win(win), |
| 64 | cnx(cnx), |
| 65 | connected(true), |
| 66 | colorSpace(colorSpace) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 67 | if (win) { |
| 68 | win->incStrong(this); |
| 69 | } |
| 70 | } |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 71 | |
| 72 | egl_surface_t::~egl_surface_t() { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 73 | if (win != NULL) { |
Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 74 | disconnect(); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 75 | win->decStrong(this); |
Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | void egl_surface_t::disconnect() { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 80 | if (win != NULL && connected) { |
| 81 | native_window_set_buffers_format(win, 0); |
| 82 | if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) { |
| 83 | ALOGW("EGLNativeWindowType %p disconnect failed", win); |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 84 | } |
Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 85 | connected = false; |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Pablo Ceballos | ae8cf0b | 2016-05-02 11:24:13 -0700 | [diff] [blame] | 89 | void egl_surface_t::terminate() { |
| 90 | disconnect(); |
| 91 | egl_object_t::terminate(); |
| 92 | } |
| 93 | |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 94 | // ---------------------------------------------------------------------------- |
| 95 | |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 96 | egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 97 | egl_connection_t const* cnx, int version) : |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 98 | egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context), |
| 99 | config(config), read(0), draw(0), cnx(cnx), version(version) { |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void egl_context_t::onLooseCurrent() { |
| 103 | read = NULL; |
| 104 | draw = NULL; |
| 105 | } |
| 106 | |
| 107 | void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) { |
| 108 | this->read = read; |
| 109 | this->draw = draw; |
| 110 | |
| 111 | /* |
| 112 | * Here we cache the GL_EXTENSIONS string for this context and we |
| 113 | * add the extensions always handled by the wrapper |
| 114 | */ |
| 115 | |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 116 | if (gl_extensions.empty()) { |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 117 | // call the implementation's glGetString(GL_EXTENSIONS) |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 118 | const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 119 | gl_extensions = exts; |
Pyry Haulos | f15219b | 2017-04-03 18:22:58 -0700 | [diff] [blame] | 120 | if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 121 | gl_extensions.insert(0, "GL_EXT_debug_marker "); |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 122 | } |
Alistair Strachan | 89301ea | 2015-05-22 14:10:09 -0700 | [diff] [blame] | 123 | |
| 124 | // tokenize the supported extensions for the glGetStringi() wrapper |
Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 125 | std::stringstream ss; |
| 126 | std::string str; |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 127 | ss << gl_extensions; |
Michael Lentine | e2fc6f8 | 2015-07-28 16:30:10 -0700 | [diff] [blame] | 128 | while (ss >> str) { |
Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 129 | tokenized_gl_extensions.push_back(str); |
Alistair Strachan | 89301ea | 2015-05-22 14:10:09 -0700 | [diff] [blame] | 130 | } |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
| 134 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 135 | }; // namespace android |
| 136 | // ---------------------------------------------------------------------------- |