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