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