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