The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <ctype.h> |
Mathias Agopian | d8fb7b5 | 2009-05-17 18:50:16 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <string.h> |
| 20 | #include <errno.h> |
| 21 | #include <dlfcn.h> |
| 22 | |
| 23 | #include <sys/ioctl.h> |
| 24 | |
Kenny Root | af1cf07 | 2011-02-16 10:13:53 -0800 | [diff] [blame] | 25 | #ifdef HAVE_ANDROID_OS |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <linux/android_pmem.h> |
| 27 | #endif |
| 28 | |
| 29 | #include <EGL/egl.h> |
| 30 | #include <EGL/eglext.h> |
| 31 | #include <GLES/gl.h> |
| 32 | #include <GLES/glext.h> |
| 33 | |
| 34 | #include <cutils/log.h> |
| 35 | #include <cutils/atomic.h> |
| 36 | #include <cutils/properties.h> |
| 37 | #include <cutils/memory.h> |
| 38 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 39 | #include <utils/SortedVector.h> |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 40 | #include <utils/KeyedVector.h> |
| 41 | #include <utils/String8.h> |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 42 | |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 43 | #include <ui/egl/android_natives.h> |
| 44 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | #include "hooks.h" |
| 46 | #include "egl_impl.h" |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 47 | #include "Loader.h" |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 48 | #include "glesv2dbg.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | #define setError(_e, _r) setErrorEtc(__FUNCTION__, __LINE__, _e, _r) |
| 51 | |
| 52 | // ---------------------------------------------------------------------------- |
| 53 | namespace android { |
| 54 | // ---------------------------------------------------------------------------- |
| 55 | |
| 56 | #define VERSION_MAJOR 1 |
| 57 | #define VERSION_MINOR 4 |
| 58 | static char const * const gVendorString = "Android"; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 59 | static char const * const gVersionString = "1.4 Android META-EGL"; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | static char const * const gClientApiString = "OpenGL ES"; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 61 | static char const * const gExtensionString = |
| 62 | "EGL_KHR_image " |
Mathias Agopian | e6bf8b3 | 2009-05-06 23:47:08 -0700 | [diff] [blame] | 63 | "EGL_KHR_image_base " |
| 64 | "EGL_KHR_image_pixmap " |
Mathias Agopian | 8e4b5a3 | 2010-08-27 16:08:03 -0700 | [diff] [blame] | 65 | "EGL_KHR_gl_texture_2D_image " |
Michael I. Gold | ca41e36 | 2011-01-13 10:13:15 -0800 | [diff] [blame] | 66 | "EGL_KHR_gl_texture_cubemap_image " |
| 67 | "EGL_KHR_gl_renderbuffer_image " |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 68 | "EGL_KHR_fence_sync " |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 69 | "EGL_ANDROID_image_native_buffer " |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 70 | "EGL_ANDROID_swap_rectangle " |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 71 | ; |
| 72 | |
| 73 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 75 | class egl_object_t { |
| 76 | static SortedVector<egl_object_t*> sObjects; |
| 77 | static Mutex sLock; |
| 78 | |
| 79 | volatile int32_t terminated; |
| 80 | mutable volatile int32_t count; |
| 81 | |
| 82 | public: |
| 83 | egl_object_t() : terminated(0), count(1) { |
| 84 | Mutex::Autolock _l(sLock); |
| 85 | sObjects.add(this); |
| 86 | } |
| 87 | |
| 88 | inline bool isAlive() const { return !terminated; } |
| 89 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | private: |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 91 | bool get() { |
| 92 | Mutex::Autolock _l(sLock); |
| 93 | if (egl_object_t::sObjects.indexOf(this) >= 0) { |
| 94 | android_atomic_inc(&count); |
| 95 | return true; |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | bool put() { |
| 101 | Mutex::Autolock _l(sLock); |
| 102 | if (android_atomic_dec(&count) == 1) { |
| 103 | sObjects.remove(this); |
| 104 | return true; |
| 105 | } |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | public: |
| 110 | template <typename N, typename T> |
| 111 | struct LocalRef { |
| 112 | N* ref; |
| 113 | LocalRef(T o) : ref(0) { |
| 114 | N* native = reinterpret_cast<N*>(o); |
| 115 | if (o && native->get()) { |
| 116 | ref = native; |
| 117 | } |
| 118 | } |
| 119 | ~LocalRef() { |
| 120 | if (ref && ref->put()) { |
| 121 | delete ref; |
| 122 | } |
| 123 | } |
| 124 | inline N* get() { |
| 125 | return ref; |
| 126 | } |
| 127 | void acquire() const { |
| 128 | if (ref) { |
| 129 | android_atomic_inc(&ref->count); |
| 130 | } |
| 131 | } |
| 132 | void release() const { |
| 133 | if (ref) { |
| 134 | int32_t c = android_atomic_dec(&ref->count); |
| 135 | // ref->count cannot be 1 prior atomic_dec because we have |
| 136 | // a reference, and if we have one, it means there was |
| 137 | // already one before us. |
| 138 | LOGE_IF(c==1, "refcount is now 0 in release()"); |
| 139 | } |
| 140 | } |
| 141 | void terminate() { |
| 142 | if (ref) { |
| 143 | ref->terminated = 1; |
| 144 | release(); |
| 145 | } |
| 146 | } |
| 147 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 150 | SortedVector<egl_object_t*> egl_object_t::sObjects; |
| 151 | Mutex egl_object_t::sLock; |
| 152 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 153 | |
| 154 | struct egl_config_t { |
| 155 | egl_config_t() {} |
| 156 | egl_config_t(int impl, EGLConfig config) |
| 157 | : impl(impl), config(config), configId(0), implConfigId(0) { } |
| 158 | int impl; // the implementation this config is for |
| 159 | EGLConfig config; // the implementation's EGLConfig |
| 160 | EGLint configId; // our CONFIG_ID |
| 161 | EGLint implConfigId; // the implementation's CONFIG_ID |
| 162 | inline bool operator < (const egl_config_t& rhs) const { |
| 163 | if (impl < rhs.impl) return true; |
| 164 | if (impl > rhs.impl) return false; |
| 165 | return config < rhs.config; |
| 166 | } |
| 167 | }; |
| 168 | |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 169 | struct egl_display_t { |
| 170 | enum { NOT_INITIALIZED, INITIALIZED, TERMINATED }; |
| 171 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | struct strings_t { |
| 173 | char const * vendor; |
| 174 | char const * version; |
| 175 | char const * clientApi; |
| 176 | char const * extensions; |
| 177 | }; |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 178 | |
| 179 | struct DisplayImpl { |
| 180 | DisplayImpl() : dpy(EGL_NO_DISPLAY), config(0), |
| 181 | state(NOT_INITIALIZED), numConfigs(0) { } |
| 182 | EGLDisplay dpy; |
| 183 | EGLConfig* config; |
| 184 | EGLint state; |
| 185 | EGLint numConfigs; |
| 186 | strings_t queryString; |
| 187 | }; |
| 188 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 189 | uint32_t magic; |
| 190 | DisplayImpl disp[IMPL_NUM_IMPLEMENTATIONS]; |
| 191 | EGLint numTotalConfigs; |
| 192 | egl_config_t* configs; |
| 193 | uint32_t refs; |
| 194 | Mutex lock; |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 195 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 196 | egl_display_t() : magic('_dpy'), numTotalConfigs(0), configs(0) { } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 197 | ~egl_display_t() { magic = 0; } |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 198 | inline bool isReady() const { return (refs > 0); } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 199 | inline bool isValid() const { return magic == '_dpy'; } |
| 200 | inline bool isAlive() const { return isValid(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | }; |
| 202 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 203 | struct egl_surface_t : public egl_object_t |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 205 | typedef egl_object_t::LocalRef<egl_surface_t, EGLSurface> Ref; |
| 206 | |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 207 | egl_surface_t(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, |
| 208 | EGLSurface surface, int impl, egl_connection_t const* cnx) |
| 209 | : dpy(dpy), surface(surface), config(config), win(win), impl(impl), cnx(cnx) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | } |
| 211 | ~egl_surface_t() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } |
| 213 | EGLDisplay dpy; |
| 214 | EGLSurface surface; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 215 | EGLConfig config; |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 216 | sp<ANativeWindow> win; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | int impl; |
| 218 | egl_connection_t const* cnx; |
| 219 | }; |
| 220 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 221 | struct egl_context_t : public egl_object_t |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 223 | typedef egl_object_t::LocalRef<egl_context_t, EGLContext> Ref; |
| 224 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 225 | egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 226 | int impl, egl_connection_t const* cnx, int version) |
Mathias Agopian | c3ce880 | 2010-12-08 15:34:02 -0800 | [diff] [blame] | 227 | : dpy(dpy), context(context), config(config), read(0), draw(0), impl(impl), |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 228 | cnx(cnx), version(version), dbg(NULL) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | { |
| 230 | } |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 231 | ~egl_context_t() |
| 232 | { |
| 233 | if (dbg) |
| 234 | DestroyDbgContext(dbg); |
| 235 | dbg = NULL; |
| 236 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | EGLDisplay dpy; |
| 238 | EGLContext context; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 239 | EGLConfig config; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | EGLSurface read; |
| 241 | EGLSurface draw; |
| 242 | int impl; |
| 243 | egl_connection_t const* cnx; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 244 | int version; |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 245 | DbgContext * dbg; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 248 | struct egl_image_t : public egl_object_t |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 249 | { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 250 | typedef egl_object_t::LocalRef<egl_image_t, EGLImageKHR> Ref; |
| 251 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 252 | egl_image_t(EGLDisplay dpy, EGLContext context) |
| 253 | : dpy(dpy), context(context) |
| 254 | { |
| 255 | memset(images, 0, sizeof(images)); |
| 256 | } |
| 257 | EGLDisplay dpy; |
Mathias Agopian | 77fbf8d | 2010-09-09 11:12:54 -0700 | [diff] [blame] | 258 | EGLContext context; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 259 | EGLImageKHR images[IMPL_NUM_IMPLEMENTATIONS]; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 262 | struct egl_sync_t : public egl_object_t |
| 263 | { |
| 264 | typedef egl_object_t::LocalRef<egl_sync_t, EGLSyncKHR> Ref; |
| 265 | |
| 266 | egl_sync_t(EGLDisplay dpy, EGLContext context, EGLSyncKHR sync) |
| 267 | : dpy(dpy), context(context), sync(sync) |
| 268 | { |
| 269 | } |
| 270 | EGLDisplay dpy; |
| 271 | EGLContext context; |
| 272 | EGLSyncKHR sync; |
| 273 | }; |
| 274 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 275 | typedef egl_surface_t::Ref SurfaceRef; |
| 276 | typedef egl_context_t::Ref ContextRef; |
| 277 | typedef egl_image_t::Ref ImageRef; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 278 | typedef egl_sync_t::Ref SyncRef; |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 279 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | struct tls_t |
| 281 | { |
Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 282 | tls_t() : error(EGL_SUCCESS), ctx(0), logCallWithNoContext(EGL_TRUE) { } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | EGLint error; |
| 284 | EGLContext ctx; |
Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 285 | EGLBoolean logCallWithNoContext; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | }; |
| 287 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | |
| 289 | // ---------------------------------------------------------------------------- |
| 290 | |
Mathias Agopian | bf41b11 | 2010-04-09 13:37:34 -0700 | [diff] [blame] | 291 | static egl_connection_t gEGLImpl[IMPL_NUM_IMPLEMENTATIONS]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | static egl_display_t gDisplay[NUM_DISPLAYS]; |
| 293 | static pthread_mutex_t gThreadLocalStorageKeyMutex = PTHREAD_MUTEX_INITIALIZER; |
| 294 | static pthread_key_t gEGLThreadLocalStorageKey = -1; |
| 295 | |
| 296 | // ---------------------------------------------------------------------------- |
| 297 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 298 | EGLAPI gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS]; |
| 299 | EGLAPI gl_hooks_t gHooksNoContext; |
Mathias Agopian | eccc8cf | 2009-05-13 00:19:22 -0700 | [diff] [blame] | 300 | EGLAPI pthread_key_t gGLWrapperKey = -1; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 302 | #if EGL_TRACE |
| 303 | |
| 304 | EGLAPI pthread_key_t gGLTraceKey = -1; |
| 305 | |
| 306 | // ---------------------------------------------------------------------------- |
| 307 | |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 308 | static int gEGLTraceLevel, gEGLDebugLevel; |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 309 | static int gEGLApplicationTraceLevel; |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 310 | extern EGLAPI gl_hooks_t gHooksTrace, gHooksDebug; |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 311 | |
| 312 | static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { |
| 313 | pthread_setspecific(gGLTraceKey, value); |
| 314 | } |
| 315 | |
| 316 | gl_hooks_t const* getGLTraceThreadSpecific() { |
| 317 | return static_cast<gl_hooks_t*>(pthread_getspecific(gGLTraceKey)); |
| 318 | } |
| 319 | |
| 320 | static void initEglTraceLevel() { |
| 321 | char value[PROPERTY_VALUE_MAX]; |
| 322 | property_get("debug.egl.trace", value, "0"); |
| 323 | int propertyLevel = atoi(value); |
| 324 | int applicationLevel = gEGLApplicationTraceLevel; |
| 325 | gEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 326 | |
| 327 | property_get("debug.egl.debug_proc", value, ""); |
| 328 | long pid = getpid(); |
| 329 | char procPath[128] = {}; |
| 330 | sprintf(procPath, "/proc/%ld/cmdline", pid); |
| 331 | FILE * file = fopen(procPath, "r"); |
| 332 | if (file) |
| 333 | { |
| 334 | char cmdline[256] = {}; |
| 335 | if (fgets(cmdline, sizeof(cmdline) - 1, file)) |
| 336 | { |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 337 | if (!strcmp(value, cmdline)) |
| 338 | gEGLDebugLevel = 1; |
| 339 | } |
| 340 | fclose(file); |
| 341 | } |
| 342 | |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 343 | if (gEGLDebugLevel > 0) |
David Li | 85f33a7 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 344 | { |
| 345 | property_get("debug.egl.debug_port", value, "5039"); |
| 346 | StartDebugServer(atoi(value)); |
| 347 | } |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void setGLHooksThreadSpecific(gl_hooks_t const *value) { |
| 351 | if (gEGLTraceLevel > 0) { |
| 352 | setGlTraceThreadSpecific(value); |
| 353 | setGlThreadSpecific(&gHooksTrace); |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 354 | } else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) { |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 355 | setGlTraceThreadSpecific(value); |
| 356 | setGlThreadSpecific(&gHooksDebug); |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 357 | } else { |
| 358 | setGlThreadSpecific(value); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Global entry point to allow applications to modify their own trace level. |
| 364 | * The effective trace level is the max of this level and the value of debug.egl.trace. |
| 365 | */ |
| 366 | extern "C" |
| 367 | void setGLTraceLevel(int level) { |
| 368 | gEGLApplicationTraceLevel = level; |
| 369 | } |
| 370 | |
| 371 | #else |
| 372 | |
| 373 | static inline void setGLHooksThreadSpecific(gl_hooks_t const *value) { |
| 374 | setGlThreadSpecific(value); |
| 375 | } |
| 376 | |
| 377 | #endif |
| 378 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | // ---------------------------------------------------------------------------- |
| 380 | |
| 381 | static __attribute__((noinline)) |
| 382 | const char *egl_strerror(EGLint err) |
| 383 | { |
| 384 | switch (err){ |
| 385 | case EGL_SUCCESS: return "EGL_SUCCESS"; |
| 386 | case EGL_NOT_INITIALIZED: return "EGL_NOT_INITIALIZED"; |
| 387 | case EGL_BAD_ACCESS: return "EGL_BAD_ACCESS"; |
| 388 | case EGL_BAD_ALLOC: return "EGL_BAD_ALLOC"; |
| 389 | case EGL_BAD_ATTRIBUTE: return "EGL_BAD_ATTRIBUTE"; |
| 390 | case EGL_BAD_CONFIG: return "EGL_BAD_CONFIG"; |
| 391 | case EGL_BAD_CONTEXT: return "EGL_BAD_CONTEXT"; |
| 392 | case EGL_BAD_CURRENT_SURFACE: return "EGL_BAD_CURRENT_SURFACE"; |
| 393 | case EGL_BAD_DISPLAY: return "EGL_BAD_DISPLAY"; |
| 394 | case EGL_BAD_MATCH: return "EGL_BAD_MATCH"; |
| 395 | case EGL_BAD_NATIVE_PIXMAP: return "EGL_BAD_NATIVE_PIXMAP"; |
| 396 | case EGL_BAD_NATIVE_WINDOW: return "EGL_BAD_NATIVE_WINDOW"; |
| 397 | case EGL_BAD_PARAMETER: return "EGL_BAD_PARAMETER"; |
| 398 | case EGL_BAD_SURFACE: return "EGL_BAD_SURFACE"; |
| 399 | case EGL_CONTEXT_LOST: return "EGL_CONTEXT_LOST"; |
| 400 | default: return "UNKNOWN"; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | static __attribute__((noinline)) |
| 405 | void clearTLS() { |
| 406 | if (gEGLThreadLocalStorageKey != -1) { |
| 407 | tls_t* tls = (tls_t*)pthread_getspecific(gEGLThreadLocalStorageKey); |
| 408 | if (tls) { |
| 409 | delete tls; |
| 410 | pthread_setspecific(gEGLThreadLocalStorageKey, 0); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | static tls_t* getTLS() |
| 416 | { |
| 417 | tls_t* tls = (tls_t*)pthread_getspecific(gEGLThreadLocalStorageKey); |
| 418 | if (tls == 0) { |
| 419 | tls = new tls_t; |
| 420 | pthread_setspecific(gEGLThreadLocalStorageKey, tls); |
| 421 | } |
| 422 | return tls; |
| 423 | } |
| 424 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 425 | static inline void clearError() { |
Jamie Gennis | f1cde8e | 2011-01-30 16:50:04 -0800 | [diff] [blame] | 426 | // This must clear the error from all the underlying EGL implementations as |
| 427 | // well as the EGL wrapper layer. |
| 428 | eglGetError(); |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 429 | } |
| 430 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | template<typename T> |
| 432 | static __attribute__((noinline)) |
| 433 | T setErrorEtc(const char* caller, int line, EGLint error, T returnValue) { |
| 434 | if (gEGLThreadLocalStorageKey == -1) { |
| 435 | pthread_mutex_lock(&gThreadLocalStorageKeyMutex); |
| 436 | if (gEGLThreadLocalStorageKey == -1) |
| 437 | pthread_key_create(&gEGLThreadLocalStorageKey, NULL); |
| 438 | pthread_mutex_unlock(&gThreadLocalStorageKeyMutex); |
| 439 | } |
| 440 | tls_t* tls = getTLS(); |
| 441 | if (tls->error != error) { |
| 442 | LOGE("%s:%d error %x (%s)", caller, line, error, egl_strerror(error)); |
| 443 | tls->error = error; |
| 444 | } |
| 445 | return returnValue; |
| 446 | } |
| 447 | |
| 448 | static __attribute__((noinline)) |
| 449 | GLint getError() { |
| 450 | if (gEGLThreadLocalStorageKey == -1) |
| 451 | return EGL_SUCCESS; |
| 452 | tls_t* tls = (tls_t*)pthread_getspecific(gEGLThreadLocalStorageKey); |
| 453 | if (!tls) return EGL_SUCCESS; |
| 454 | GLint error = tls->error; |
| 455 | tls->error = EGL_SUCCESS; |
| 456 | return error; |
| 457 | } |
| 458 | |
| 459 | static __attribute__((noinline)) |
| 460 | void setContext(EGLContext ctx) { |
| 461 | if (gEGLThreadLocalStorageKey == -1) { |
| 462 | pthread_mutex_lock(&gThreadLocalStorageKeyMutex); |
| 463 | if (gEGLThreadLocalStorageKey == -1) |
| 464 | pthread_key_create(&gEGLThreadLocalStorageKey, NULL); |
| 465 | pthread_mutex_unlock(&gThreadLocalStorageKeyMutex); |
| 466 | } |
| 467 | tls_t* tls = getTLS(); |
| 468 | tls->ctx = ctx; |
| 469 | } |
| 470 | |
| 471 | static __attribute__((noinline)) |
| 472 | EGLContext getContext() { |
| 473 | if (gEGLThreadLocalStorageKey == -1) |
| 474 | return EGL_NO_CONTEXT; |
| 475 | tls_t* tls = (tls_t*)pthread_getspecific(gEGLThreadLocalStorageKey); |
| 476 | if (!tls) return EGL_NO_CONTEXT; |
| 477 | return tls->ctx; |
| 478 | } |
| 479 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | /*****************************************************************************/ |
| 481 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | template<typename T> |
| 483 | static __attribute__((noinline)) |
| 484 | int binarySearch( |
| 485 | T const sortedArray[], int first, int last, T key) |
| 486 | { |
| 487 | while (first <= last) { |
| 488 | int mid = (first + last) / 2; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 489 | if (sortedArray[mid] < key) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | first = mid + 1; |
| 491 | } else if (key < sortedArray[mid]) { |
| 492 | last = mid - 1; |
| 493 | } else { |
| 494 | return mid; |
| 495 | } |
| 496 | } |
| 497 | return -1; |
| 498 | } |
| 499 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | static int cmp_configs(const void* a, const void *b) |
| 501 | { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 502 | const egl_config_t& c0 = *(egl_config_t const *)a; |
| 503 | const egl_config_t& c1 = *(egl_config_t const *)b; |
| 504 | return c0<c1 ? -1 : (c1<c0 ? 1 : 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | struct extention_map_t { |
| 508 | const char* name; |
| 509 | __eglMustCastToProperFunctionPointerType address; |
| 510 | }; |
| 511 | |
| 512 | static const extention_map_t gExtentionMap[] = { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 513 | { "eglLockSurfaceKHR", |
| 514 | (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, |
| 515 | { "eglUnlockSurfaceKHR", |
| 516 | (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, |
| 517 | { "eglCreateImageKHR", |
| 518 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, |
| 519 | { "eglDestroyImageKHR", |
| 520 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, |
Mathias Agopian | 8d2e83b | 2009-06-24 22:37:39 -0700 | [diff] [blame] | 521 | { "eglSetSwapRectangleANDROID", |
| 522 | (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID }, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | }; |
| 524 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 525 | extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; |
| 526 | |
| 527 | // accesses protected by gInitDriverMutex |
| 528 | static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> gGLExtentionMap; |
| 529 | static int gGLExtentionSlot = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | |
| 531 | static void(*findProcAddress(const char* name, |
| 532 | const extention_map_t* map, size_t n))() |
| 533 | { |
| 534 | for (uint32_t i=0 ; i<n ; i++) { |
| 535 | if (!strcmp(name, map[i].name)) { |
| 536 | return map[i].address; |
| 537 | } |
| 538 | } |
| 539 | return NULL; |
| 540 | } |
| 541 | |
| 542 | // ---------------------------------------------------------------------------- |
| 543 | |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 544 | static int gl_no_context() { |
Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 545 | tls_t* tls = getTLS(); |
| 546 | if (tls->logCallWithNoContext == EGL_TRUE) { |
| 547 | tls->logCallWithNoContext = EGL_FALSE; |
| 548 | LOGE("call to OpenGL ES API with no current context " |
| 549 | "(logged once per thread)"); |
| 550 | } |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 551 | return 0; |
Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 552 | } |
| 553 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | static void early_egl_init(void) |
| 555 | { |
| 556 | #if !USE_FAST_TLS_KEY |
| 557 | pthread_key_create(&gGLWrapperKey, NULL); |
| 558 | #endif |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 559 | #if EGL_TRACE |
| 560 | pthread_key_create(&gGLTraceKey, NULL); |
| 561 | initEglTraceLevel(); |
| 562 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | uint32_t addr = (uint32_t)((void*)gl_no_context); |
| 564 | android_memset32( |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 565 | (uint32_t*)(void*)&gHooksNoContext, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | addr, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 567 | sizeof(gHooksNoContext)); |
Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 568 | |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 569 | setGLHooksThreadSpecific(&gHooksNoContext); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static pthread_once_t once_control = PTHREAD_ONCE_INIT; |
| 573 | static int sEarlyInitState = pthread_once(&once_control, &early_egl_init); |
| 574 | |
| 575 | |
| 576 | static inline |
| 577 | egl_display_t* get_display(EGLDisplay dpy) |
| 578 | { |
| 579 | uintptr_t index = uintptr_t(dpy)-1U; |
| 580 | return (index >= NUM_DISPLAYS) ? NULL : &gDisplay[index]; |
| 581 | } |
| 582 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 583 | template<typename NATIVE, typename EGL> |
| 584 | static inline NATIVE* egl_to_native_cast(EGL arg) { |
| 585 | return reinterpret_cast<NATIVE*>(arg); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static inline |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 589 | egl_surface_t* get_surface(EGLSurface surface) { |
| 590 | return egl_to_native_cast<egl_surface_t>(surface); |
| 591 | } |
| 592 | |
| 593 | static inline |
| 594 | egl_context_t* get_context(EGLContext context) { |
| 595 | return egl_to_native_cast<egl_context_t>(context); |
| 596 | } |
| 597 | |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 598 | DbgContext * getDbgContextThreadSpecific() |
| 599 | { |
| 600 | return get_context(getContext())->dbg; |
| 601 | } |
| 602 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 603 | static inline |
| 604 | egl_image_t* get_image(EGLImageKHR image) { |
| 605 | return egl_to_native_cast<egl_image_t>(image); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 608 | static inline |
| 609 | egl_sync_t* get_sync(EGLSyncKHR sync) { |
| 610 | return egl_to_native_cast<egl_sync_t>(sync); |
| 611 | } |
| 612 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 613 | static inline |
| 614 | egl_display_t* validate_display(EGLDisplay dpy) |
| 615 | { |
| 616 | egl_display_t * const dp = get_display(dpy); |
| 617 | if (!dp) return setError(EGL_BAD_DISPLAY, (egl_display_t*)NULL); |
| 618 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (egl_display_t*)NULL); |
| 619 | |
| 620 | return dp; |
| 621 | } |
| 622 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | static egl_connection_t* validate_display_config( |
| 624 | EGLDisplay dpy, EGLConfig config, |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 625 | egl_display_t const*& dp) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | { |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 627 | dp = validate_display(dpy); |
| 628 | if (!dp) return (egl_connection_t*) NULL; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 630 | if (intptr_t(config) >= dp->numTotalConfigs) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL); |
| 632 | } |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 633 | egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(config)].impl]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | if (cnx->dso == 0) { |
| 635 | return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL); |
| 636 | } |
| 637 | return cnx; |
| 638 | } |
| 639 | |
| 640 | static EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx) |
| 641 | { |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 642 | egl_display_t const * const dp = validate_display(dpy); |
| 643 | if (!dp) return EGL_FALSE; |
| 644 | if (!dp->isAlive()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 646 | if (!get_context(ctx)->isAlive()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 648 | return EGL_TRUE; |
| 649 | } |
| 650 | |
| 651 | static EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface) |
| 652 | { |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 653 | egl_display_t const * const dp = validate_display(dpy); |
| 654 | if (!dp) return EGL_FALSE; |
| 655 | if (!dp->isAlive()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 657 | if (!get_surface(surface)->isAlive()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 659 | return EGL_TRUE; |
| 660 | } |
| 661 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 662 | EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image) |
| 663 | { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 664 | ImageRef _i(image); |
| 665 | if (!_i.get()) return EGL_NO_IMAGE_KHR; |
| 666 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 667 | EGLContext context = getContext(); |
| 668 | if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR) |
| 669 | return EGL_NO_IMAGE_KHR; |
| 670 | |
| 671 | egl_context_t const * const c = get_context(context); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 672 | if (!c->isAlive()) |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 673 | return EGL_NO_IMAGE_KHR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 675 | egl_image_t const * const i = get_image(image); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 676 | return i->images[c->impl]; |
| 677 | } |
| 678 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 679 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 680 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 681 | // this mutex protects: |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 682 | // d->disp[] |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 683 | // egl_init_drivers_locked() |
| 684 | // |
| 685 | static pthread_mutex_t gInitDriverMutex = PTHREAD_MUTEX_INITIALIZER; |
| 686 | |
| 687 | EGLBoolean egl_init_drivers_locked() |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | { |
| 689 | if (sEarlyInitState) { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 690 | // initialized by static ctor. should be set here. |
| 691 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 694 | // get our driver loader |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 695 | Loader& loader(Loader::getInstance()); |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 696 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 697 | // dynamically load all our EGL implementations for all displays |
| 698 | // and retrieve the corresponding EGLDisplay |
| 699 | // if that fails, don't use this driver. |
| 700 | // TODO: currently we only deal with EGL_DEFAULT_DISPLAY |
| 701 | egl_connection_t* cnx; |
| 702 | egl_display_t* d = &gDisplay[0]; |
| 703 | |
| 704 | cnx = &gEGLImpl[IMPL_SOFTWARE]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | if (cnx->dso == 0) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 706 | cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_SOFTWARE]; |
| 707 | cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_SOFTWARE]; |
| 708 | cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 0, cnx); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 709 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 710 | EGLDisplay dpy = cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 711 | LOGE_IF(dpy==EGL_NO_DISPLAY, "No EGLDisplay for software EGL!"); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 712 | d->disp[IMPL_SOFTWARE].dpy = dpy; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 713 | if (dpy == EGL_NO_DISPLAY) { |
| 714 | loader.close(cnx->dso); |
| 715 | cnx->dso = NULL; |
| 716 | } |
| 717 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | cnx = &gEGLImpl[IMPL_HARDWARE]; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 721 | if (cnx->dso == 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | char value[PROPERTY_VALUE_MAX]; |
| 723 | property_get("debug.egl.hw", value, "1"); |
| 724 | if (atoi(value) != 0) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 725 | cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_HARDWARE]; |
| 726 | cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_HARDWARE]; |
| 727 | cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 1, cnx); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 728 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 729 | EGLDisplay dpy = cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 730 | LOGE_IF(dpy==EGL_NO_DISPLAY, "No EGLDisplay for hardware EGL!"); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 731 | d->disp[IMPL_HARDWARE].dpy = dpy; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 732 | if (dpy == EGL_NO_DISPLAY) { |
| 733 | loader.close(cnx->dso); |
| 734 | cnx->dso = NULL; |
| 735 | } |
| 736 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | } else { |
| 738 | LOGD("3D hardware acceleration is disabled"); |
| 739 | } |
| 740 | } |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 741 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 742 | if (!gEGLImpl[IMPL_SOFTWARE].dso && !gEGLImpl[IMPL_HARDWARE].dso) { |
| 743 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 746 | return EGL_TRUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 749 | EGLBoolean egl_init_drivers() |
| 750 | { |
| 751 | EGLBoolean res; |
| 752 | pthread_mutex_lock(&gInitDriverMutex); |
| 753 | res = egl_init_drivers_locked(); |
| 754 | pthread_mutex_unlock(&gInitDriverMutex); |
| 755 | return res; |
| 756 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 757 | |
| 758 | // ---------------------------------------------------------------------------- |
| 759 | }; // namespace android |
| 760 | // ---------------------------------------------------------------------------- |
| 761 | |
| 762 | using namespace android; |
| 763 | |
| 764 | EGLDisplay eglGetDisplay(NativeDisplayType display) |
| 765 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 766 | clearError(); |
| 767 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 768 | uint32_t index = uint32_t(display); |
| 769 | if (index >= NUM_DISPLAYS) { |
| 770 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 771 | } |
| 772 | |
| 773 | if (egl_init_drivers() == EGL_FALSE) { |
| 774 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 775 | } |
| 776 | |
| 777 | EGLDisplay dpy = EGLDisplay(uintptr_t(display) + 1LU); |
| 778 | return dpy; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 779 | } |
| 780 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | // ---------------------------------------------------------------------------- |
| 782 | // Initialization |
| 783 | // ---------------------------------------------------------------------------- |
| 784 | |
| 785 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 786 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 787 | clearError(); |
| 788 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | egl_display_t * const dp = get_display(dpy); |
| 790 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 791 | |
Mathias Agopian | 75bc278 | 2010-02-05 16:17:01 -0800 | [diff] [blame] | 792 | Mutex::Autolock _l(dp->lock); |
| 793 | |
| 794 | if (dp->refs > 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | if (major != NULL) *major = VERSION_MAJOR; |
| 796 | if (minor != NULL) *minor = VERSION_MINOR; |
Jack Palevich | 81cd084 | 2010-03-15 20:45:21 -0700 | [diff] [blame] | 797 | dp->refs++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | return EGL_TRUE; |
| 799 | } |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 800 | |
| 801 | #if EGL_TRACE |
| 802 | |
| 803 | // Called both at early_init time and at this time. (Early_init is pre-zygote, so |
| 804 | // the information from that call may be stale.) |
| 805 | initEglTraceLevel(); |
| 806 | |
| 807 | #endif |
| 808 | |
| 809 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 810 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | // initialize each EGL and |
| 812 | // build our own extension string first, based on the extension we know |
| 813 | // and the extension supported by our client implementation |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 814 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 816 | cnx->major = -1; |
| 817 | cnx->minor = -1; |
| 818 | if (!cnx->dso) |
| 819 | continue; |
| 820 | |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 821 | #if defined(ADRENO130) |
| 822 | #warning "Adreno-130 eglInitialize() workaround" |
| 823 | /* |
| 824 | * The ADRENO 130 driver returns a different EGLDisplay each time |
| 825 | * eglGetDisplay() is called, but also makes the EGLDisplay invalid |
| 826 | * after eglTerminate() has been called, so that eglInitialize() |
| 827 | * cannot be called again. Therefore, we need to make sure to call |
| 828 | * eglGetDisplay() before calling eglInitialize(); |
| 829 | */ |
| 830 | if (i == IMPL_HARDWARE) { |
| 831 | dp->disp[i].dpy = |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 832 | cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 833 | } |
| 834 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 836 | |
| 837 | EGLDisplay idpy = dp->disp[i].dpy; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 838 | if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | //LOGD("initialized %d dpy=%p, ver=%d.%d, cnx=%p", |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 840 | // i, idpy, cnx->major, cnx->minor, cnx); |
| 841 | |
| 842 | // display is now initialized |
| 843 | dp->disp[i].state = egl_display_t::INITIALIZED; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | |
| 845 | // get the query-strings for this display for each implementation |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 846 | dp->disp[i].queryString.vendor = |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 847 | cnx->egl.eglQueryString(idpy, EGL_VENDOR); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 848 | dp->disp[i].queryString.version = |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 849 | cnx->egl.eglQueryString(idpy, EGL_VERSION); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 850 | dp->disp[i].queryString.extensions = |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 851 | cnx->egl.eglQueryString(idpy, EGL_EXTENSIONS); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 852 | dp->disp[i].queryString.clientApi = |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 853 | cnx->egl.eglQueryString(idpy, EGL_CLIENT_APIS); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | |
| 855 | } else { |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 856 | LOGW("%d: eglInitialize(%p) failed (%s)", i, idpy, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 857 | egl_strerror(cnx->egl.eglGetError())); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | |
| 861 | EGLBoolean res = EGL_FALSE; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 862 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 864 | if (cnx->dso && cnx->major>=0 && cnx->minor>=0) { |
| 865 | EGLint n; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 866 | if (cnx->egl.eglGetConfigs(dp->disp[i].dpy, 0, 0, &n)) { |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 867 | dp->disp[i].config = (EGLConfig*)malloc(sizeof(EGLConfig)*n); |
| 868 | if (dp->disp[i].config) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 869 | if (cnx->egl.eglGetConfigs( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 870 | dp->disp[i].dpy, dp->disp[i].config, n, |
| 871 | &dp->disp[i].numConfigs)) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 872 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | dp->numTotalConfigs += n; |
| 874 | res = EGL_TRUE; |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | if (res == EGL_TRUE) { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 882 | dp->configs = new egl_config_t[ dp->numTotalConfigs ]; |
| 883 | for (int i=0, k=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
| 884 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 885 | if (cnx->dso && cnx->major>=0 && cnx->minor>=0) { |
| 886 | for (int j=0 ; j<dp->disp[i].numConfigs ; j++) { |
| 887 | dp->configs[k].impl = i; |
| 888 | dp->configs[k].config = dp->disp[i].config[j]; |
| 889 | dp->configs[k].configId = k + 1; // CONFIG_ID start at 1 |
| 890 | // store the implementation's CONFIG_ID |
| 891 | cnx->egl.eglGetConfigAttrib( |
| 892 | dp->disp[i].dpy, |
| 893 | dp->disp[i].config[j], |
| 894 | EGL_CONFIG_ID, |
| 895 | &dp->configs[k].implConfigId); |
| 896 | k++; |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | // sort our configurations so we can do binary-searches |
| 902 | qsort( dp->configs, |
| 903 | dp->numTotalConfigs, |
| 904 | sizeof(egl_config_t), cmp_configs); |
| 905 | |
Mathias Agopian | 75bc278 | 2010-02-05 16:17:01 -0800 | [diff] [blame] | 906 | dp->refs++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | if (major != NULL) *major = VERSION_MAJOR; |
| 908 | if (minor != NULL) *minor = VERSION_MINOR; |
| 909 | return EGL_TRUE; |
| 910 | } |
| 911 | return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 912 | } |
| 913 | |
| 914 | EGLBoolean eglTerminate(EGLDisplay dpy) |
| 915 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 916 | // NOTE: don't unload the drivers b/c some APIs can be called |
| 917 | // after eglTerminate() has been called. eglTerminate() only |
| 918 | // terminates an EGLDisplay, not a EGL itself. |
| 919 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 920 | clearError(); |
| 921 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | egl_display_t* const dp = get_display(dpy); |
| 923 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
Mathias Agopian | 75bc278 | 2010-02-05 16:17:01 -0800 | [diff] [blame] | 924 | |
| 925 | Mutex::Autolock _l(dp->lock); |
| 926 | |
| 927 | if (dp->refs == 0) { |
| 928 | return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 929 | } |
| 930 | |
| 931 | // this is specific to Android, display termination is ref-counted. |
Jack Palevich | 81cd084 | 2010-03-15 20:45:21 -0700 | [diff] [blame] | 932 | if (dp->refs > 1) { |
| 933 | dp->refs--; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | return EGL_TRUE; |
Jack Palevich | 81cd084 | 2010-03-15 20:45:21 -0700 | [diff] [blame] | 935 | } |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 936 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | EGLBoolean res = EGL_FALSE; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 938 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | egl_connection_t* const cnx = &gEGLImpl[i]; |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 940 | if (cnx->dso && dp->disp[i].state == egl_display_t::INITIALIZED) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 941 | if (cnx->egl.eglTerminate(dp->disp[i].dpy) == EGL_FALSE) { |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 942 | LOGW("%d: eglTerminate(%p) failed (%s)", i, dp->disp[i].dpy, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 943 | egl_strerror(cnx->egl.eglGetError())); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 944 | } |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 945 | // REVISIT: it's unclear what to do if eglTerminate() fails |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 946 | free(dp->disp[i].config); |
| 947 | |
| 948 | dp->disp[i].numConfigs = 0; |
| 949 | dp->disp[i].config = 0; |
| 950 | dp->disp[i].state = egl_display_t::TERMINATED; |
| 951 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | res = EGL_TRUE; |
| 953 | } |
| 954 | } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 955 | |
| 956 | // TODO: all egl_object_t should be marked for termination |
| 957 | |
Mathias Agopian | 75bc278 | 2010-02-05 16:17:01 -0800 | [diff] [blame] | 958 | dp->refs--; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | dp->numTotalConfigs = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 960 | delete [] dp->configs; |
Michael I. Gold | 0c3ce2a | 2010-12-23 13:51:36 -0800 | [diff] [blame] | 961 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | return res; |
| 963 | } |
| 964 | |
| 965 | // ---------------------------------------------------------------------------- |
| 966 | // configuration |
| 967 | // ---------------------------------------------------------------------------- |
| 968 | |
| 969 | EGLBoolean eglGetConfigs( EGLDisplay dpy, |
| 970 | EGLConfig *configs, |
| 971 | EGLint config_size, EGLint *num_config) |
| 972 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 973 | clearError(); |
| 974 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 975 | egl_display_t const * const dp = validate_display(dpy); |
| 976 | if (!dp) return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | |
| 978 | GLint numConfigs = dp->numTotalConfigs; |
| 979 | if (!configs) { |
| 980 | *num_config = numConfigs; |
| 981 | return EGL_TRUE; |
| 982 | } |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 983 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | GLint n = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 985 | for (intptr_t i=0 ; i<dp->numTotalConfigs && config_size ; i++) { |
| 986 | *configs++ = EGLConfig(i); |
| 987 | config_size--; |
| 988 | n++; |
| 989 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | |
| 991 | *num_config = n; |
| 992 | return EGL_TRUE; |
| 993 | } |
| 994 | |
| 995 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, |
| 996 | EGLConfig *configs, EGLint config_size, |
| 997 | EGLint *num_config) |
| 998 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 999 | clearError(); |
| 1000 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1001 | egl_display_t const * const dp = validate_display(dpy); |
| 1002 | if (!dp) return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1004 | if (num_config==0) { |
| 1005 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | EGLint n; |
| 1009 | EGLBoolean res = EGL_FALSE; |
| 1010 | *num_config = 0; |
| 1011 | |
| 1012 | |
| 1013 | // It is unfortunate, but we need to remap the EGL_CONFIG_IDs, |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1014 | // to do this, we have to go through the attrib_list array once |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | // to figure out both its size and if it contains an EGL_CONFIG_ID |
| 1016 | // key. If so, the full array is copied and patched. |
| 1017 | // NOTE: we assume that there can be only one occurrence |
| 1018 | // of EGL_CONFIG_ID. |
| 1019 | |
| 1020 | EGLint patch_index = -1; |
| 1021 | GLint attr; |
| 1022 | size_t size = 0; |
Mathias Agopian | 04aed21 | 2010-05-17 14:45:43 -0700 | [diff] [blame] | 1023 | if (attrib_list) { |
| 1024 | while ((attr=attrib_list[size]) != EGL_NONE) { |
| 1025 | if (attr == EGL_CONFIG_ID) |
| 1026 | patch_index = size; |
| 1027 | size += 2; |
| 1028 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | } |
| 1030 | if (patch_index >= 0) { |
| 1031 | size += 2; // we need copy the sentinel as well |
| 1032 | EGLint* new_list = (EGLint*)malloc(size*sizeof(EGLint)); |
| 1033 | if (new_list == 0) |
| 1034 | return setError(EGL_BAD_ALLOC, EGL_FALSE); |
| 1035 | memcpy(new_list, attrib_list, size*sizeof(EGLint)); |
| 1036 | |
| 1037 | // patch the requested EGL_CONFIG_ID |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1038 | bool found = false; |
| 1039 | EGLConfig ourConfig(0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | EGLint& configId(new_list[patch_index+1]); |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1041 | for (intptr_t i=0 ; i<dp->numTotalConfigs ; i++) { |
| 1042 | if (dp->configs[i].configId == configId) { |
| 1043 | ourConfig = EGLConfig(i); |
| 1044 | configId = dp->configs[i].implConfigId; |
| 1045 | found = true; |
| 1046 | break; |
| 1047 | } |
| 1048 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1050 | egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(ourConfig)].impl]; |
| 1051 | if (found && cnx->dso) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | // and switch to the new list |
| 1053 | attrib_list = const_cast<const EGLint *>(new_list); |
| 1054 | |
| 1055 | // At this point, the only configuration that can match is |
| 1056 | // dp->configs[i][index], however, we don't know if it would be |
| 1057 | // rejected because of the other attributes, so we do have to call |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1058 | // cnx->egl.eglChooseConfig() -- but we don't have to loop |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | // through all the EGLimpl[]. |
| 1060 | // We also know we can only get a single config back, and we know |
| 1061 | // which one. |
| 1062 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1063 | res = cnx->egl.eglChooseConfig( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1064 | dp->disp[ dp->configs[intptr_t(ourConfig)].impl ].dpy, |
| 1065 | attrib_list, configs, config_size, &n); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | if (res && n>0) { |
| 1067 | // n has to be 0 or 1, by construction, and we already know |
| 1068 | // which config it will return (since there can be only one). |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1069 | if (configs) { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1070 | configs[0] = ourConfig; |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1071 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | *num_config = 1; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | free(const_cast<EGLint *>(attrib_list)); |
| 1077 | return res; |
| 1078 | } |
| 1079 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1080 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1081 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1083 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1084 | if (cnx->egl.eglChooseConfig( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1085 | dp->disp[i].dpy, attrib_list, configs, config_size, &n)) { |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1086 | if (configs) { |
| 1087 | // now we need to convert these client EGLConfig to our |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1088 | // internal EGLConfig format. |
| 1089 | // This is done in O(n Log(n)) time. |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1090 | for (int j=0 ; j<n ; j++) { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1091 | egl_config_t key(i, configs[j]); |
| 1092 | intptr_t index = binarySearch<egl_config_t>( |
| 1093 | dp->configs, 0, dp->numTotalConfigs, key); |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1094 | if (index >= 0) { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1095 | configs[j] = EGLConfig(index); |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1096 | } else { |
| 1097 | return setError(EGL_BAD_CONFIG, EGL_FALSE); |
| 1098 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | } |
Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1100 | configs += n; |
| 1101 | config_size -= n; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | *num_config += n; |
| 1104 | res = EGL_TRUE; |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | return res; |
| 1109 | } |
| 1110 | |
| 1111 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 1112 | EGLint attribute, EGLint *value) |
| 1113 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1114 | clearError(); |
| 1115 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1117 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | if (!cnx) return EGL_FALSE; |
| 1119 | |
| 1120 | if (attribute == EGL_CONFIG_ID) { |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1121 | *value = dp->configs[intptr_t(config)].configId; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | return EGL_TRUE; |
| 1123 | } |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1124 | return cnx->egl.eglGetConfigAttrib( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1125 | dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, |
| 1126 | dp->configs[intptr_t(config)].config, attribute, value); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | // ---------------------------------------------------------------------------- |
| 1130 | // surfaces |
| 1131 | // ---------------------------------------------------------------------------- |
| 1132 | |
| 1133 | EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, |
| 1134 | NativeWindowType window, |
| 1135 | const EGLint *attrib_list) |
| 1136 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1137 | clearError(); |
| 1138 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1140 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | if (cnx) { |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1142 | EGLDisplay iDpy = dp->disp[ dp->configs[intptr_t(config)].impl ].dpy; |
| 1143 | EGLConfig iConfig = dp->configs[intptr_t(config)].config; |
| 1144 | EGLint format; |
| 1145 | |
Jamie Gennis | 5c0c93a | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 1146 | // for now fail if the window is not a Surface. |
| 1147 | int type = -1; |
| 1148 | ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); |
| 1149 | if ((anw->query(window, NATIVE_WINDOW_CONCRETE_TYPE, &type) != 0) || |
| 1150 | (type == NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT)) { |
| 1151 | LOGE("native window is a SurfaceTextureClient (currently " |
| 1152 | "unsupported)"); |
| 1153 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 1154 | } |
| 1155 | |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1156 | // set the native window's buffers format to match this config |
| 1157 | if (cnx->egl.eglGetConfigAttrib(iDpy, |
| 1158 | iConfig, EGL_NATIVE_VISUAL_ID, &format)) { |
| 1159 | if (format != 0) { |
| 1160 | native_window_set_buffers_geometry(window, 0, 0, format); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1164 | EGLSurface surface = cnx->egl.eglCreateWindowSurface( |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1165 | iDpy, iConfig, window, attrib_list); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | if (surface != EGL_NO_SURFACE) { |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1167 | egl_surface_t* s = new egl_surface_t(dpy, config, window, surface, |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1168 | dp->configs[intptr_t(config)].impl, cnx); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | return s; |
| 1170 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | } |
| 1172 | return EGL_NO_SURFACE; |
| 1173 | } |
| 1174 | |
| 1175 | EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, |
| 1176 | NativePixmapType pixmap, |
| 1177 | const EGLint *attrib_list) |
| 1178 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1179 | clearError(); |
| 1180 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1182 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | if (cnx) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1184 | EGLSurface surface = cnx->egl.eglCreatePixmapSurface( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1185 | dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, |
| 1186 | dp->configs[intptr_t(config)].config, pixmap, attrib_list); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | if (surface != EGL_NO_SURFACE) { |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1188 | egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1189 | dp->configs[intptr_t(config)].impl, cnx); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | return s; |
| 1191 | } |
| 1192 | } |
| 1193 | return EGL_NO_SURFACE; |
| 1194 | } |
| 1195 | |
| 1196 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, |
| 1197 | const EGLint *attrib_list) |
| 1198 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1199 | clearError(); |
| 1200 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1202 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | if (cnx) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1204 | EGLSurface surface = cnx->egl.eglCreatePbufferSurface( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1205 | dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, |
| 1206 | dp->configs[intptr_t(config)].config, attrib_list); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | if (surface != EGL_NO_SURFACE) { |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1208 | egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1209 | dp->configs[intptr_t(config)].impl, cnx); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | return s; |
| 1211 | } |
| 1212 | } |
| 1213 | return EGL_NO_SURFACE; |
| 1214 | } |
| 1215 | |
| 1216 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 1217 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1218 | clearError(); |
| 1219 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1220 | egl_display_t const * const dp = validate_display(dpy); |
| 1221 | if (!dp) return EGL_FALSE; |
| 1222 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1223 | SurfaceRef _s(surface); |
| 1224 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1225 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | if (!validate_display_surface(dpy, surface)) |
| 1227 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1229 | egl_surface_t * const s = get_surface(surface); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1230 | EGLBoolean result = s->cnx->egl.eglDestroySurface( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1231 | dp->disp[s->impl].dpy, s->surface); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1232 | if (result == EGL_TRUE) { |
Mathias Agopian | 644bb2a | 2010-11-24 15:59:35 -0800 | [diff] [blame] | 1233 | if (s->win != NULL) { |
| 1234 | native_window_set_buffers_geometry(s->win.get(), 0, 0, 0); |
| 1235 | } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1236 | _s.terminate(); |
| 1237 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | return result; |
| 1239 | } |
| 1240 | |
| 1241 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, |
| 1242 | EGLint attribute, EGLint *value) |
| 1243 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1244 | clearError(); |
| 1245 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1246 | egl_display_t const * const dp = validate_display(dpy); |
| 1247 | if (!dp) return EGL_FALSE; |
| 1248 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1249 | SurfaceRef _s(surface); |
| 1250 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1251 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | if (!validate_display_surface(dpy, surface)) |
| 1253 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | egl_surface_t const * const s = get_surface(surface); |
| 1255 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1256 | EGLBoolean result(EGL_TRUE); |
| 1257 | if (attribute == EGL_CONFIG_ID) { |
| 1258 | // We need to remap EGL_CONFIG_IDs |
| 1259 | *value = dp->configs[intptr_t(s->config)].configId; |
| 1260 | } else { |
| 1261 | result = s->cnx->egl.eglQuerySurface( |
| 1262 | dp->disp[s->impl].dpy, s->surface, attribute, value); |
| 1263 | } |
| 1264 | |
| 1265 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | // ---------------------------------------------------------------------------- |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1269 | // Contexts |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | // ---------------------------------------------------------------------------- |
| 1271 | |
| 1272 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, |
| 1273 | EGLContext share_list, const EGLint *attrib_list) |
| 1274 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1275 | clearError(); |
| 1276 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1278 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | if (cnx) { |
Jamie Gennis | 4c39f8f | 2010-07-02 11:39:12 -0700 | [diff] [blame] | 1280 | if (share_list != EGL_NO_CONTEXT) { |
| 1281 | egl_context_t* const c = get_context(share_list); |
| 1282 | share_list = c->context; |
| 1283 | } |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1284 | EGLContext context = cnx->egl.eglCreateContext( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1285 | dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, |
| 1286 | dp->configs[intptr_t(config)].config, |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1287 | share_list, attrib_list); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | if (context != EGL_NO_CONTEXT) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1289 | // figure out if it's a GLESv1 or GLESv2 |
| 1290 | int version = 0; |
| 1291 | if (attrib_list) { |
| 1292 | while (*attrib_list != EGL_NONE) { |
| 1293 | GLint attr = *attrib_list++; |
| 1294 | GLint value = *attrib_list++; |
| 1295 | if (attr == EGL_CONTEXT_CLIENT_VERSION) { |
| 1296 | if (value == 1) { |
| 1297 | version = GLESv1_INDEX; |
| 1298 | } else if (value == 2) { |
| 1299 | version = GLESv2_INDEX; |
| 1300 | } |
| 1301 | } |
| 1302 | }; |
| 1303 | } |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1304 | egl_context_t* c = new egl_context_t(dpy, context, config, |
| 1305 | dp->configs[intptr_t(config)].impl, cnx, version); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | return c; |
| 1307 | } |
| 1308 | } |
| 1309 | return EGL_NO_CONTEXT; |
| 1310 | } |
| 1311 | |
| 1312 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 1313 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1314 | clearError(); |
| 1315 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1316 | egl_display_t const * const dp = validate_display(dpy); |
| 1317 | if (!dp) return EGL_FALSE; |
| 1318 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1319 | ContextRef _c(ctx); |
| 1320 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1321 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | if (!validate_display_context(dpy, ctx)) |
| 1323 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1325 | EGLBoolean result = c->cnx->egl.eglDestroyContext( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1326 | dp->disp[c->impl].dpy, c->context); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1327 | if (result == EGL_TRUE) { |
| 1328 | _c.terminate(); |
| 1329 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | return result; |
| 1331 | } |
| 1332 | |
Michael I. Gold | 0c3ce2a | 2010-12-23 13:51:36 -0800 | [diff] [blame] | 1333 | static void loseCurrent(egl_context_t * cur_c) |
| 1334 | { |
| 1335 | if (cur_c) { |
| 1336 | egl_surface_t * cur_r = get_surface(cur_c->read); |
| 1337 | egl_surface_t * cur_d = get_surface(cur_c->draw); |
| 1338 | |
| 1339 | // by construction, these are either 0 or valid (possibly terminated) |
| 1340 | // it should be impossible for these to be invalid |
| 1341 | ContextRef _cur_c(cur_c); |
| 1342 | SurfaceRef _cur_r(cur_r); |
| 1343 | SurfaceRef _cur_d(cur_d); |
| 1344 | |
| 1345 | cur_c->read = NULL; |
| 1346 | cur_c->draw = NULL; |
| 1347 | |
| 1348 | _cur_c.release(); |
| 1349 | _cur_r.release(); |
| 1350 | _cur_d.release(); |
| 1351 | } |
| 1352 | } |
| 1353 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, |
| 1355 | EGLSurface read, EGLContext ctx) |
| 1356 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1357 | clearError(); |
| 1358 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1359 | egl_display_t const * const dp = get_display(dpy); |
| 1360 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1361 | |
| 1362 | /* If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not |
| 1363 | EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is |
| 1364 | a valid but uninitialized display. */ |
| 1365 | if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || |
| 1366 | (draw != EGL_NO_SURFACE) ) { |
| 1367 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 1368 | } |
| 1369 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1370 | // get a reference to the object passed in |
| 1371 | ContextRef _c(ctx); |
| 1372 | SurfaceRef _d(draw); |
| 1373 | SurfaceRef _r(read); |
| 1374 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1375 | // validate the context (if not EGL_NO_CONTEXT) |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1376 | if ((ctx != EGL_NO_CONTEXT) && (!validate_display_context(dpy, ctx))) { |
| 1377 | // EGL_NO_CONTEXT is valid |
| 1378 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1381 | // these are the underlying implementation's object |
| 1382 | EGLContext impl_ctx = EGL_NO_CONTEXT; |
Mathias Agopian | af74213 | 2009-06-25 00:01:11 -0700 | [diff] [blame] | 1383 | EGLSurface impl_draw = EGL_NO_SURFACE; |
| 1384 | EGLSurface impl_read = EGL_NO_SURFACE; |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1385 | |
| 1386 | // these are our objects structs passed in |
| 1387 | egl_context_t * c = NULL; |
| 1388 | egl_surface_t const * d = NULL; |
| 1389 | egl_surface_t const * r = NULL; |
| 1390 | |
| 1391 | // these are the current objects structs |
| 1392 | egl_context_t * cur_c = get_context(getContext()); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1393 | |
| 1394 | if (ctx != EGL_NO_CONTEXT) { |
| 1395 | c = get_context(ctx); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1396 | impl_ctx = c->context; |
| 1397 | } else { |
| 1398 | // no context given, use the implementation of the current context |
| 1399 | if (cur_c == NULL) { |
| 1400 | // no current context |
| 1401 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { |
Mathias Agopian | 8063c3a | 2010-01-25 11:30:11 -0800 | [diff] [blame] | 1402 | // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); |
| 1403 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1404 | } |
Mathias Agopian | 8063c3a | 2010-01-25 11:30:11 -0800 | [diff] [blame] | 1405 | // not an error, there is just no current context. |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1406 | return EGL_TRUE; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | // retrieve the underlying implementation's draw EGLSurface |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | if (draw != EGL_NO_SURFACE) { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1412 | d = get_surface(draw); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1413 | // make sure the EGLContext and EGLSurface passed in are for |
| 1414 | // the same driver |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1415 | if (c && d->impl != c->impl) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
Mathias Agopian | af74213 | 2009-06-25 00:01:11 -0700 | [diff] [blame] | 1417 | impl_draw = d->surface; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1419 | |
| 1420 | // retrieve the underlying implementation's read EGLSurface |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | if (read != EGL_NO_SURFACE) { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1422 | r = get_surface(read); |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1423 | // make sure the EGLContext and EGLSurface passed in are for |
| 1424 | // the same driver |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1425 | if (c && r->impl != c->impl) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
Mathias Agopian | af74213 | 2009-06-25 00:01:11 -0700 | [diff] [blame] | 1427 | impl_read = r->surface; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | } |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1429 | |
| 1430 | EGLBoolean result; |
| 1431 | |
| 1432 | if (c) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1433 | result = c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1434 | dp->disp[c->impl].dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1435 | } else { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1436 | result = cur_c->cnx->egl.eglMakeCurrent( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1437 | dp->disp[cur_c->impl].dpy, impl_draw, impl_read, impl_ctx); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1438 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | |
| 1440 | if (result == EGL_TRUE) { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1441 | |
Michael I. Gold | 0c3ce2a | 2010-12-23 13:51:36 -0800 | [diff] [blame] | 1442 | loseCurrent(cur_c); |
| 1443 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1444 | if (ctx != EGL_NO_CONTEXT) { |
David Li | 65948aa | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 1445 | if (!c->dbg && gEGLDebugLevel > 0) |
| 1446 | c->dbg = CreateDbgContext(c->version, c->cnx->hooks[c->version]); |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 1447 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1448 | setContext(ctx); |
| 1449 | _c.acquire(); |
Michael I. Gold | 0c3ce2a | 2010-12-23 13:51:36 -0800 | [diff] [blame] | 1450 | _r.acquire(); |
| 1451 | _d.acquire(); |
| 1452 | c->read = read; |
| 1453 | c->draw = draw; |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1454 | } else { |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 1455 | setGLHooksThreadSpecific(&gHooksNoContext); |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1456 | setContext(EGL_NO_CONTEXT); |
| 1457 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | } |
| 1459 | return result; |
| 1460 | } |
| 1461 | |
| 1462 | |
| 1463 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, |
| 1464 | EGLint attribute, EGLint *value) |
| 1465 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1466 | clearError(); |
| 1467 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1468 | egl_display_t const * const dp = validate_display(dpy); |
| 1469 | if (!dp) return EGL_FALSE; |
| 1470 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1471 | ContextRef _c(ctx); |
| 1472 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1473 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | if (!validate_display_context(dpy, ctx)) |
| 1475 | return EGL_FALSE; |
| 1476 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | egl_context_t * const c = get_context(ctx); |
| 1478 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1479 | EGLBoolean result(EGL_TRUE); |
| 1480 | if (attribute == EGL_CONFIG_ID) { |
| 1481 | *value = dp->configs[intptr_t(c->config)].configId; |
| 1482 | } else { |
| 1483 | // We need to remap EGL_CONFIG_IDs |
| 1484 | result = c->cnx->egl.eglQueryContext( |
| 1485 | dp->disp[c->impl].dpy, c->context, attribute, value); |
| 1486 | } |
| 1487 | |
| 1488 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | EGLContext eglGetCurrentContext(void) |
| 1492 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1493 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1494 | // then, and this function would correctly return EGL_NO_CONTEXT. |
| 1495 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1496 | clearError(); |
| 1497 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | EGLContext ctx = getContext(); |
| 1499 | return ctx; |
| 1500 | } |
| 1501 | |
| 1502 | EGLSurface eglGetCurrentSurface(EGLint readdraw) |
| 1503 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1504 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1505 | // then, and this function would correctly return EGL_NO_SURFACE. |
| 1506 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1507 | clearError(); |
| 1508 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | EGLContext ctx = getContext(); |
| 1510 | if (ctx) { |
| 1511 | egl_context_t const * const c = get_context(ctx); |
| 1512 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 1513 | switch (readdraw) { |
| 1514 | case EGL_READ: return c->read; |
| 1515 | case EGL_DRAW: return c->draw; |
| 1516 | default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
| 1517 | } |
| 1518 | } |
| 1519 | return EGL_NO_SURFACE; |
| 1520 | } |
| 1521 | |
| 1522 | EGLDisplay eglGetCurrentDisplay(void) |
| 1523 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1524 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1525 | // then, and this function would correctly return EGL_NO_DISPLAY. |
| 1526 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1527 | clearError(); |
| 1528 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | EGLContext ctx = getContext(); |
| 1530 | if (ctx) { |
| 1531 | egl_context_t const * const c = get_context(ctx); |
| 1532 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 1533 | return c->dpy; |
| 1534 | } |
| 1535 | return EGL_NO_DISPLAY; |
| 1536 | } |
| 1537 | |
| 1538 | EGLBoolean eglWaitGL(void) |
| 1539 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1540 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1541 | // then, and this function would return GL_TRUE, which isn't wrong. |
| 1542 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1543 | clearError(); |
| 1544 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | EGLBoolean res = EGL_TRUE; |
| 1546 | EGLContext ctx = getContext(); |
| 1547 | if (ctx) { |
| 1548 | egl_context_t const * const c = get_context(ctx); |
| 1549 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1550 | if (uint32_t(c->impl)>=2) |
| 1551 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1552 | egl_connection_t* const cnx = &gEGLImpl[c->impl]; |
| 1553 | if (!cnx->dso) |
| 1554 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1555 | res = cnx->egl.eglWaitGL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | } |
| 1557 | return res; |
| 1558 | } |
| 1559 | |
| 1560 | EGLBoolean eglWaitNative(EGLint engine) |
| 1561 | { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1562 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1563 | // then, and this function would return GL_TRUE, which isn't wrong. |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1564 | |
| 1565 | clearError(); |
| 1566 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | EGLBoolean res = EGL_TRUE; |
| 1568 | EGLContext ctx = getContext(); |
| 1569 | if (ctx) { |
| 1570 | egl_context_t const * const c = get_context(ctx); |
| 1571 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1572 | if (uint32_t(c->impl)>=2) |
| 1573 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1574 | egl_connection_t* const cnx = &gEGLImpl[c->impl]; |
| 1575 | if (!cnx->dso) |
| 1576 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1577 | res = cnx->egl.eglWaitNative(engine); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | } |
| 1579 | return res; |
| 1580 | } |
| 1581 | |
| 1582 | EGLint eglGetError(void) |
| 1583 | { |
| 1584 | EGLint result = EGL_SUCCESS; |
Mathias Agopian | 02dafb5 | 2010-09-21 15:43:59 -0700 | [diff] [blame] | 1585 | EGLint err; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1586 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
Mathias Agopian | 02dafb5 | 2010-09-21 15:43:59 -0700 | [diff] [blame] | 1587 | err = EGL_SUCCESS; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1589 | if (cnx->dso) |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1590 | err = cnx->egl.eglGetError(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | if (err!=EGL_SUCCESS && result==EGL_SUCCESS) |
| 1592 | result = err; |
| 1593 | } |
Mathias Agopian | 02dafb5 | 2010-09-21 15:43:59 -0700 | [diff] [blame] | 1594 | err = getError(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (result == EGL_SUCCESS) |
Mathias Agopian | 02dafb5 | 2010-09-21 15:43:59 -0700 | [diff] [blame] | 1596 | result = err; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | return result; |
| 1598 | } |
| 1599 | |
Michael I. Gold | 609bb4d | 2011-01-04 01:16:59 -0800 | [diff] [blame] | 1600 | // Note: Similar implementations of these functions also exist in |
| 1601 | // gl2.cpp and gl.cpp, and are used by applications that call the |
| 1602 | // exported entry points directly. |
| 1603 | typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); |
| 1604 | typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image); |
| 1605 | |
| 1606 | static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES_impl = NULL; |
| 1607 | static PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES_impl = NULL; |
| 1608 | |
| 1609 | static void glEGLImageTargetTexture2DOES_wrapper(GLenum target, GLeglImageOES image) |
| 1610 | { |
| 1611 | GLeglImageOES implImage = |
| 1612 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); |
| 1613 | glEGLImageTargetTexture2DOES_impl(target, implImage); |
| 1614 | } |
| 1615 | |
| 1616 | static void glEGLImageTargetRenderbufferStorageOES_wrapper(GLenum target, GLeglImageOES image) |
| 1617 | { |
| 1618 | GLeglImageOES implImage = |
| 1619 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); |
| 1620 | glEGLImageTargetRenderbufferStorageOES_impl(target, implImage); |
| 1621 | } |
| 1622 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1623 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1625 | // eglGetProcAddress() could be the very first function called |
| 1626 | // in which case we must make sure we've initialized ourselves, this |
| 1627 | // happens the first time egl_get_display() is called. |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1628 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1629 | clearError(); |
| 1630 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1631 | if (egl_init_drivers() == EGL_FALSE) { |
| 1632 | setError(EGL_BAD_PARAMETER, NULL); |
| 1633 | return NULL; |
| 1634 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1635 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | __eglMustCastToProperFunctionPointerType addr; |
| 1637 | addr = findProcAddress(procname, gExtentionMap, NELEM(gExtentionMap)); |
| 1638 | if (addr) return addr; |
| 1639 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1640 | // this protects accesses to gGLExtentionMap and gGLExtentionSlot |
| 1641 | pthread_mutex_lock(&gInitDriverMutex); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1643 | /* |
| 1644 | * Since eglGetProcAddress() is not associated to anything, it needs |
| 1645 | * to return a function pointer that "works" regardless of what |
| 1646 | * the current context is. |
| 1647 | * |
| 1648 | * For this reason, we return a "forwarder", a small stub that takes |
| 1649 | * care of calling the function associated with the context |
| 1650 | * currently bound. |
| 1651 | * |
| 1652 | * We first look for extensions we've already resolved, if we're seeing |
| 1653 | * this extension for the first time, we go through all our |
| 1654 | * implementations and call eglGetProcAddress() and record the |
| 1655 | * result in the appropriate implementation hooks and return the |
| 1656 | * address of the forwarder corresponding to that hook set. |
| 1657 | * |
| 1658 | */ |
| 1659 | |
| 1660 | const String8 name(procname); |
| 1661 | addr = gGLExtentionMap.valueFor(name); |
| 1662 | const int slot = gGLExtentionSlot; |
| 1663 | |
| 1664 | LOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, |
| 1665 | "no more slots for eglGetProcAddress(\"%s\")", |
| 1666 | procname); |
| 1667 | |
| 1668 | if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { |
| 1669 | bool found = false; |
| 1670 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
| 1671 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1672 | if (cnx->dso && cnx->egl.eglGetProcAddress) { |
| 1673 | found = true; |
Mathias Agopian | 4a88b52 | 2010-08-13 12:19:04 -0700 | [diff] [blame] | 1674 | // Extensions are independent of the bound context |
| 1675 | cnx->hooks[GLESv1_INDEX]->ext.extensions[slot] = |
| 1676 | cnx->hooks[GLESv2_INDEX]->ext.extensions[slot] = |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 1677 | #if EGL_TRACE |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 1678 | gHooksDebug.ext.extensions[slot] = gHooksTrace.ext.extensions[slot] = |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 1679 | #endif |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1680 | cnx->egl.eglGetProcAddress(procname); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | } |
| 1682 | } |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1683 | if (found) { |
| 1684 | addr = gExtensionForwarders[slot]; |
Michael I. Gold | 609bb4d | 2011-01-04 01:16:59 -0800 | [diff] [blame] | 1685 | |
| 1686 | if (!strcmp(procname, "glEGLImageTargetTexture2DOES")) { |
| 1687 | glEGLImageTargetTexture2DOES_impl = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)addr; |
| 1688 | addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES_wrapper; |
| 1689 | } |
| 1690 | if (!strcmp(procname, "glEGLImageTargetRenderbufferStorageOES")) { |
| 1691 | glEGLImageTargetRenderbufferStorageOES_impl = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC)addr; |
| 1692 | addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES_wrapper; |
| 1693 | } |
| 1694 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1695 | gGLExtentionMap.add(name, addr); |
| 1696 | gGLExtentionSlot++; |
| 1697 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1700 | pthread_mutex_unlock(&gInitDriverMutex); |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 1701 | return addr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) |
| 1705 | { |
David Li | b33d5cf | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 1706 | EGLBoolean Debug_eglSwapBuffers(EGLDisplay dpy, EGLSurface draw); |
| 1707 | if (gEGLDebugLevel > 0) |
| 1708 | Debug_eglSwapBuffers(dpy, draw); |
| 1709 | |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1710 | clearError(); |
| 1711 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1712 | egl_display_t const * const dp = validate_display(dpy); |
| 1713 | if (!dp) return EGL_FALSE; |
| 1714 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1715 | SurfaceRef _s(draw); |
| 1716 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1717 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | if (!validate_display_surface(dpy, draw)) |
| 1719 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | egl_surface_t const * const s = get_surface(draw); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1721 | return s->cnx->egl.eglSwapBuffers(dp->disp[s->impl].dpy, s->surface); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, |
| 1725 | NativePixmapType target) |
| 1726 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1727 | clearError(); |
| 1728 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1729 | egl_display_t const * const dp = validate_display(dpy); |
| 1730 | if (!dp) return EGL_FALSE; |
| 1731 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1732 | SurfaceRef _s(surface); |
| 1733 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1734 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | if (!validate_display_surface(dpy, surface)) |
| 1736 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1738 | return s->cnx->egl.eglCopyBuffers( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1739 | dp->disp[s->impl].dpy, s->surface, target); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | const char* eglQueryString(EGLDisplay dpy, EGLint name) |
| 1743 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1744 | clearError(); |
| 1745 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1746 | egl_display_t const * const dp = validate_display(dpy); |
| 1747 | if (!dp) return (const char *) NULL; |
| 1748 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | switch (name) { |
| 1750 | case EGL_VENDOR: |
| 1751 | return gVendorString; |
| 1752 | case EGL_VERSION: |
| 1753 | return gVersionString; |
| 1754 | case EGL_EXTENSIONS: |
| 1755 | return gExtensionString; |
| 1756 | case EGL_CLIENT_APIS: |
| 1757 | return gClientApiString; |
| 1758 | } |
| 1759 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | // ---------------------------------------------------------------------------- |
| 1764 | // EGL 1.1 |
| 1765 | // ---------------------------------------------------------------------------- |
| 1766 | |
| 1767 | EGLBoolean eglSurfaceAttrib( |
| 1768 | EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) |
| 1769 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1770 | clearError(); |
| 1771 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1772 | egl_display_t const * const dp = validate_display(dpy); |
| 1773 | if (!dp) return EGL_FALSE; |
| 1774 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1775 | SurfaceRef _s(surface); |
| 1776 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1777 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | if (!validate_display_surface(dpy, surface)) |
| 1779 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1781 | if (s->cnx->egl.eglSurfaceAttrib) { |
| 1782 | return s->cnx->egl.eglSurfaceAttrib( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1783 | dp->disp[s->impl].dpy, s->surface, attribute, value); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | } |
| 1785 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1786 | } |
| 1787 | |
| 1788 | EGLBoolean eglBindTexImage( |
| 1789 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1790 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1791 | clearError(); |
| 1792 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1793 | egl_display_t const * const dp = validate_display(dpy); |
| 1794 | if (!dp) return EGL_FALSE; |
| 1795 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1796 | SurfaceRef _s(surface); |
| 1797 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1798 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | if (!validate_display_surface(dpy, surface)) |
| 1800 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1802 | if (s->cnx->egl.eglBindTexImage) { |
| 1803 | return s->cnx->egl.eglBindTexImage( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1804 | dp->disp[s->impl].dpy, s->surface, buffer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | } |
| 1806 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1807 | } |
| 1808 | |
| 1809 | EGLBoolean eglReleaseTexImage( |
| 1810 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1811 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1812 | clearError(); |
| 1813 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1814 | egl_display_t const * const dp = validate_display(dpy); |
| 1815 | if (!dp) return EGL_FALSE; |
| 1816 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1817 | SurfaceRef _s(surface); |
| 1818 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1819 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | if (!validate_display_surface(dpy, surface)) |
| 1821 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1822 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1823 | if (s->cnx->egl.eglReleaseTexImage) { |
| 1824 | return s->cnx->egl.eglReleaseTexImage( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1825 | dp->disp[s->impl].dpy, s->surface, buffer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1826 | } |
| 1827 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1828 | } |
| 1829 | |
| 1830 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 1831 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1832 | clearError(); |
| 1833 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1834 | egl_display_t const * const dp = validate_display(dpy); |
| 1835 | if (!dp) return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | |
| 1837 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1838 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1840 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1841 | if (cnx->egl.eglSwapInterval) { |
| 1842 | if (cnx->egl.eglSwapInterval( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1843 | dp->disp[i].dpy, interval) == EGL_FALSE) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | res = EGL_FALSE; |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | } |
| 1849 | return res; |
| 1850 | } |
| 1851 | |
| 1852 | |
| 1853 | // ---------------------------------------------------------------------------- |
| 1854 | // EGL 1.2 |
| 1855 | // ---------------------------------------------------------------------------- |
| 1856 | |
| 1857 | EGLBoolean eglWaitClient(void) |
| 1858 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1859 | clearError(); |
| 1860 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1861 | // could be called before eglInitialize(), but we wouldn't have a context |
| 1862 | // then, and this function would return GL_TRUE, which isn't wrong. |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | EGLBoolean res = EGL_TRUE; |
| 1864 | EGLContext ctx = getContext(); |
| 1865 | if (ctx) { |
| 1866 | egl_context_t const * const c = get_context(ctx); |
| 1867 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1868 | if (uint32_t(c->impl)>=2) |
| 1869 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1870 | egl_connection_t* const cnx = &gEGLImpl[c->impl]; |
| 1871 | if (!cnx->dso) |
| 1872 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1873 | if (cnx->egl.eglWaitClient) { |
| 1874 | res = cnx->egl.eglWaitClient(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | } else { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1876 | res = cnx->egl.eglWaitGL(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | return res; |
| 1880 | } |
| 1881 | |
| 1882 | EGLBoolean eglBindAPI(EGLenum api) |
| 1883 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1884 | clearError(); |
| 1885 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1886 | if (egl_init_drivers() == EGL_FALSE) { |
| 1887 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1888 | } |
| 1889 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | // bind this API on all EGLs |
| 1891 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1892 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1894 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1895 | if (cnx->egl.eglBindAPI) { |
| 1896 | if (cnx->egl.eglBindAPI(api) == EGL_FALSE) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1897 | res = EGL_FALSE; |
| 1898 | } |
| 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | return res; |
| 1903 | } |
| 1904 | |
| 1905 | EGLenum eglQueryAPI(void) |
| 1906 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1907 | clearError(); |
| 1908 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 1909 | if (egl_init_drivers() == EGL_FALSE) { |
| 1910 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1911 | } |
| 1912 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1913 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1915 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1916 | if (cnx->egl.eglQueryAPI) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | // the first one we find is okay, because they all |
| 1918 | // should be the same |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1919 | return cnx->egl.eglQueryAPI(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | // or, it can only be OpenGL ES |
| 1924 | return EGL_OPENGL_ES_API; |
| 1925 | } |
| 1926 | |
| 1927 | EGLBoolean eglReleaseThread(void) |
| 1928 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1929 | clearError(); |
| 1930 | |
Michael I. Gold | 0c3ce2a | 2010-12-23 13:51:36 -0800 | [diff] [blame] | 1931 | // If there is context bound to the thread, release it |
| 1932 | loseCurrent(get_context(getContext())); |
| 1933 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1934 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 1936 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1937 | if (cnx->egl.eglReleaseThread) { |
| 1938 | cnx->egl.eglReleaseThread(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | clearTLS(); |
| 1943 | return EGL_TRUE; |
| 1944 | } |
| 1945 | |
| 1946 | EGLSurface eglCreatePbufferFromClientBuffer( |
| 1947 | EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, |
| 1948 | EGLConfig config, const EGLint *attrib_list) |
| 1949 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1950 | clearError(); |
| 1951 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | egl_display_t const* dp = 0; |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1953 | egl_connection_t* cnx = validate_display_config(dpy, config, dp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1954 | if (!cnx) return EGL_FALSE; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1955 | if (cnx->egl.eglCreatePbufferFromClientBuffer) { |
| 1956 | return cnx->egl.eglCreatePbufferFromClientBuffer( |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 1957 | dp->disp[ dp->configs[intptr_t(config)].impl ].dpy, |
| 1958 | buftype, buffer, |
| 1959 | dp->configs[intptr_t(config)].config, attrib_list); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | } |
| 1961 | return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); |
| 1962 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1963 | |
| 1964 | // ---------------------------------------------------------------------------- |
| 1965 | // EGL_EGLEXT_VERSION 3 |
| 1966 | // ---------------------------------------------------------------------------- |
| 1967 | |
| 1968 | EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, |
| 1969 | const EGLint *attrib_list) |
| 1970 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1971 | clearError(); |
| 1972 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1973 | egl_display_t const * const dp = validate_display(dpy); |
| 1974 | if (!dp) return EGL_FALSE; |
| 1975 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1976 | SurfaceRef _s(surface); |
| 1977 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1978 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1979 | if (!validate_display_surface(dpy, surface)) |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 1980 | return EGL_FALSE; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1981 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1982 | egl_surface_t const * const s = get_surface(surface); |
| 1983 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 1984 | if (s->cnx->egl.eglLockSurfaceKHR) { |
| 1985 | return s->cnx->egl.eglLockSurfaceKHR( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 1986 | dp->disp[s->impl].dpy, s->surface, attrib_list); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1987 | } |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 1988 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) |
| 1992 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 1993 | clearError(); |
| 1994 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 1995 | egl_display_t const * const dp = validate_display(dpy); |
| 1996 | if (!dp) return EGL_FALSE; |
| 1997 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 1998 | SurfaceRef _s(surface); |
| 1999 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 2000 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2001 | if (!validate_display_surface(dpy, surface)) |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 2002 | return EGL_FALSE; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2003 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2004 | egl_surface_t const * const s = get_surface(surface); |
| 2005 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2006 | if (s->cnx->egl.eglUnlockSurfaceKHR) { |
| 2007 | return s->cnx->egl.eglUnlockSurfaceKHR( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 2008 | dp->disp[s->impl].dpy, s->surface); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2009 | } |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 2010 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 2014 | EGLClientBuffer buffer, const EGLint *attrib_list) |
| 2015 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2016 | clearError(); |
| 2017 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2018 | egl_display_t const * const dp = validate_display(dpy); |
| 2019 | if (!dp) return EGL_NO_IMAGE_KHR; |
| 2020 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2021 | if (ctx != EGL_NO_CONTEXT) { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 2022 | ContextRef _c(ctx); |
| 2023 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2024 | if (!validate_display_context(dpy, ctx)) |
| 2025 | return EGL_NO_IMAGE_KHR; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2026 | egl_context_t * const c = get_context(ctx); |
| 2027 | // since we have an EGLContext, we know which implementation to use |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2028 | EGLImageKHR image = c->cnx->egl.eglCreateImageKHR( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 2029 | dp->disp[c->impl].dpy, c->context, target, buffer, attrib_list); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2030 | if (image == EGL_NO_IMAGE_KHR) |
| 2031 | return image; |
| 2032 | |
| 2033 | egl_image_t* result = new egl_image_t(dpy, ctx); |
| 2034 | result->images[c->impl] = image; |
| 2035 | return (EGLImageKHR)result; |
| 2036 | } else { |
| 2037 | // EGL_NO_CONTEXT is a valid parameter |
Mathias Agopian | df2d929 | 2009-10-28 21:00:29 -0700 | [diff] [blame] | 2038 | |
| 2039 | /* Since we don't have a way to know which implementation to call, |
| 2040 | * we're calling all of them. If at least one of the implementation |
| 2041 | * succeeded, this is a success. |
| 2042 | */ |
| 2043 | |
| 2044 | EGLint currentError = eglGetError(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2045 | |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2046 | EGLImageKHR implImages[IMPL_NUM_IMPLEMENTATIONS]; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2047 | bool success = false; |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2048 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2049 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 2050 | implImages[i] = EGL_NO_IMAGE_KHR; |
| 2051 | if (cnx->dso) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2052 | if (cnx->egl.eglCreateImageKHR) { |
| 2053 | implImages[i] = cnx->egl.eglCreateImageKHR( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 2054 | dp->disp[i].dpy, ctx, target, buffer, attrib_list); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2055 | if (implImages[i] != EGL_NO_IMAGE_KHR) { |
| 2056 | success = true; |
| 2057 | } |
| 2058 | } |
| 2059 | } |
| 2060 | } |
Mathias Agopian | df2d929 | 2009-10-28 21:00:29 -0700 | [diff] [blame] | 2061 | |
| 2062 | if (!success) { |
| 2063 | // failure, if there was an error when we entered this function, |
| 2064 | // the error flag must not be updated. |
| 2065 | // Otherwise, the error is whatever happened in the implementation |
| 2066 | // that faulted. |
| 2067 | if (currentError != EGL_SUCCESS) { |
| 2068 | setError(currentError, EGL_NO_IMAGE_KHR); |
| 2069 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2070 | return EGL_NO_IMAGE_KHR; |
Mathias Agopian | df2d929 | 2009-10-28 21:00:29 -0700 | [diff] [blame] | 2071 | } else { |
| 2072 | // In case of success, we need to clear all error flags |
| 2073 | // (especially those caused by the implementation that didn't |
Mathias Agopian | 863e5fd | 2009-10-29 18:29:30 -0700 | [diff] [blame] | 2074 | // succeed). TODO: we could avoid this if we knew this was |
Mathias Agopian | df2d929 | 2009-10-28 21:00:29 -0700 | [diff] [blame] | 2075 | // a "full" success (all implementation succeeded). |
| 2076 | eglGetError(); |
| 2077 | } |
| 2078 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2079 | egl_image_t* result = new egl_image_t(dpy, ctx); |
| 2080 | memcpy(result->images, implImages, sizeof(implImages)); |
| 2081 | return (EGLImageKHR)result; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) |
| 2086 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2087 | clearError(); |
| 2088 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2089 | egl_display_t const * const dp = validate_display(dpy); |
| 2090 | if (!dp) return EGL_FALSE; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2091 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2092 | ImageRef _i(img); |
| 2093 | if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2094 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2095 | egl_image_t* image = get_image(img); |
| 2096 | bool success = false; |
| 2097 | for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) { |
| 2098 | egl_connection_t* const cnx = &gEGLImpl[i]; |
| 2099 | if (image->images[i] != EGL_NO_IMAGE_KHR) { |
| 2100 | if (cnx->dso) { |
| 2101 | if (cnx->egl.eglDestroyImageKHR) { |
| 2102 | if (cnx->egl.eglDestroyImageKHR( |
| 2103 | dp->disp[i].dpy, image->images[i])) { |
| 2104 | success = true; |
| 2105 | } |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | if (!success) |
| 2111 | return EGL_FALSE; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2112 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2113 | _i.terminate(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2114 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2115 | return EGL_TRUE; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2116 | } |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2117 | |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2118 | // ---------------------------------------------------------------------------- |
| 2119 | // EGL_EGLEXT_VERSION 5 |
| 2120 | // ---------------------------------------------------------------------------- |
| 2121 | |
| 2122 | |
| 2123 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) |
| 2124 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2125 | clearError(); |
| 2126 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2127 | egl_display_t const * const dp = validate_display(dpy); |
| 2128 | if (!dp) return EGL_NO_SYNC_KHR; |
| 2129 | |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2130 | EGLContext ctx = eglGetCurrentContext(); |
| 2131 | ContextRef _c(ctx); |
Mathias Agopian | a93b957 | 2010-09-21 16:22:10 -0700 | [diff] [blame] | 2132 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_NO_SYNC_KHR); |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2133 | if (!validate_display_context(dpy, ctx)) |
Mathias Agopian | a93b957 | 2010-09-21 16:22:10 -0700 | [diff] [blame] | 2134 | return EGL_NO_SYNC_KHR; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2135 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | a93b957 | 2010-09-21 16:22:10 -0700 | [diff] [blame] | 2136 | EGLSyncKHR result = EGL_NO_SYNC_KHR; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2137 | if (c->cnx->egl.eglCreateSyncKHR) { |
| 2138 | EGLSyncKHR sync = c->cnx->egl.eglCreateSyncKHR( |
| 2139 | dp->disp[c->impl].dpy, type, attrib_list); |
Mathias Agopian | a93b957 | 2010-09-21 16:22:10 -0700 | [diff] [blame] | 2140 | if (sync == EGL_NO_SYNC_KHR) |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2141 | return sync; |
| 2142 | result = (egl_sync_t*)new egl_sync_t(dpy, ctx, sync); |
| 2143 | } |
| 2144 | return (EGLSyncKHR)result; |
| 2145 | } |
| 2146 | |
| 2147 | EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) |
| 2148 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2149 | clearError(); |
| 2150 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2151 | egl_display_t const * const dp = validate_display(dpy); |
| 2152 | if (!dp) return EGL_FALSE; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2153 | |
| 2154 | SyncRef _s(sync); |
| 2155 | if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 2156 | egl_sync_t* syncObject = get_sync(sync); |
| 2157 | |
| 2158 | EGLContext ctx = syncObject->context; |
| 2159 | ContextRef _c(ctx); |
| 2160 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 2161 | if (!validate_display_context(dpy, ctx)) |
| 2162 | return EGL_FALSE; |
| 2163 | |
Mathias Agopian | 36bdf14 | 2011-03-16 14:19:03 -0700 | [diff] [blame] | 2164 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2165 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2166 | if (c->cnx->egl.eglDestroySyncKHR) { |
Mathias Agopian | 36bdf14 | 2011-03-16 14:19:03 -0700 | [diff] [blame] | 2167 | result = c->cnx->egl.eglDestroySyncKHR( |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2168 | dp->disp[c->impl].dpy, syncObject->sync); |
Mathias Agopian | 36bdf14 | 2011-03-16 14:19:03 -0700 | [diff] [blame] | 2169 | if (result) |
| 2170 | _s.terminate(); |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2171 | } |
Mathias Agopian | 36bdf14 | 2011-03-16 14:19:03 -0700 | [diff] [blame] | 2172 | return result; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) |
| 2176 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2177 | clearError(); |
| 2178 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2179 | egl_display_t const * const dp = validate_display(dpy); |
| 2180 | if (!dp) return EGL_FALSE; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2181 | |
| 2182 | SyncRef _s(sync); |
| 2183 | if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 2184 | egl_sync_t* syncObject = get_sync(sync); |
| 2185 | |
| 2186 | EGLContext ctx = syncObject->context; |
| 2187 | ContextRef _c(ctx); |
| 2188 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 2189 | if (!validate_display_context(dpy, ctx)) |
| 2190 | return EGL_FALSE; |
| 2191 | |
| 2192 | egl_context_t * const c = get_context(ctx); |
| 2193 | |
| 2194 | if (c->cnx->egl.eglClientWaitSyncKHR) { |
| 2195 | return c->cnx->egl.eglClientWaitSyncKHR( |
| 2196 | dp->disp[c->impl].dpy, syncObject->sync, flags, timeout); |
| 2197 | } |
| 2198 | |
| 2199 | return EGL_FALSE; |
| 2200 | } |
| 2201 | |
| 2202 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) |
| 2203 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2204 | clearError(); |
| 2205 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2206 | egl_display_t const * const dp = validate_display(dpy); |
| 2207 | if (!dp) return EGL_FALSE; |
Mathias Agopian | c291f585 | 2010-08-27 16:48:56 -0700 | [diff] [blame] | 2208 | |
| 2209 | SyncRef _s(sync); |
| 2210 | if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 2211 | egl_sync_t* syncObject = get_sync(sync); |
| 2212 | |
| 2213 | EGLContext ctx = syncObject->context; |
| 2214 | ContextRef _c(ctx); |
| 2215 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 2216 | if (!validate_display_context(dpy, ctx)) |
| 2217 | return EGL_FALSE; |
| 2218 | |
| 2219 | egl_context_t * const c = get_context(ctx); |
| 2220 | |
| 2221 | if (c->cnx->egl.eglGetSyncAttribKHR) { |
| 2222 | return c->cnx->egl.eglGetSyncAttribKHR( |
| 2223 | dp->disp[c->impl].dpy, syncObject->sync, attribute, value); |
| 2224 | } |
| 2225 | |
| 2226 | return EGL_FALSE; |
| 2227 | } |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2228 | |
| 2229 | // ---------------------------------------------------------------------------- |
| 2230 | // ANDROID extensions |
| 2231 | // ---------------------------------------------------------------------------- |
| 2232 | |
| 2233 | EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, |
| 2234 | EGLint left, EGLint top, EGLint width, EGLint height) |
| 2235 | { |
Michael I. Gold | 4aea6bf | 2011-01-21 15:39:38 -0800 | [diff] [blame] | 2236 | clearError(); |
| 2237 | |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame^] | 2238 | egl_display_t const * const dp = validate_display(dpy); |
| 2239 | if (!dp) return EGL_FALSE; |
| 2240 | |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 2241 | SurfaceRef _s(draw); |
| 2242 | if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 2243 | |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2244 | if (!validate_display_surface(dpy, draw)) |
| 2245 | return EGL_FALSE; |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2246 | egl_surface_t const * const s = get_surface(draw); |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 2247 | if (s->cnx->egl.eglSetSwapRectangleANDROID) { |
| 2248 | return s->cnx->egl.eglSetSwapRectangleANDROID( |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 2249 | dp->disp[s->impl].dpy, s->surface, left, top, width, height); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2250 | } |
Mathias Agopian | 24e5f52 | 2009-08-12 21:18:15 -0700 | [diff] [blame] | 2251 | return setError(EGL_BAD_DISPLAY, NULL); |
Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2252 | } |