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