Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 7 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 9 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 19 | #include <dlfcn.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 20 | #include <ctype.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <hardware/gralloc.h> |
| 25 | #include <system/window.h> |
| 26 | |
| 27 | #include <EGL/egl.h> |
| 28 | #include <EGL/eglext.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 29 | |
| 30 | #include <cutils/log.h> |
| 31 | #include <cutils/atomic.h> |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 32 | #include <cutils/compiler.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 33 | #include <cutils/properties.h> |
| 34 | #include <cutils/memory.h> |
| 35 | |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 36 | #include <ui/GraphicBuffer.h> |
| 37 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 38 | #include <utils/KeyedVector.h> |
| 39 | #include <utils/SortedVector.h> |
| 40 | #include <utils/String8.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 41 | #include <utils/Trace.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 42 | |
Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 43 | #include "../egl_impl.h" |
Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 44 | #include "../hooks.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 45 | |
| 46 | #include "egl_display.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 47 | #include "egl_object.h" |
| 48 | #include "egl_tls.h" |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 49 | #include "egldefs.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 50 | |
| 51 | using namespace android; |
| 52 | |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 53 | // This extension has not been ratified yet, so can't be shipped. |
| 54 | // Implementation is incomplete and untested. |
| 55 | #define ENABLE_EGL_KHR_GL_COLORSPACE 0 |
| 56 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 57 | // ---------------------------------------------------------------------------- |
| 58 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 59 | namespace android { |
| 60 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 61 | struct extention_map_t { |
| 62 | const char* name; |
| 63 | __eglMustCastToProperFunctionPointerType address; |
| 64 | }; |
| 65 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 66 | /* |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 67 | * This is the list of EGL extensions exposed to applications. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 68 | * |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 69 | * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL |
| 70 | * wrapper and are always available. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 71 | * |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 72 | * The rest (gExtensionString) depend on support in the EGL driver, and are |
| 73 | * only available if the driver supports them. However, some of these must be |
| 74 | * supported because they are used by the Android system itself; these are |
Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 75 | * listed as mandatory below and are required by the CDD. The system *assumes* |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 76 | * the mandatory extensions are present and may not function properly if some |
| 77 | * are missing. |
| 78 | * |
| 79 | * NOTE: Both strings MUST have a single space as the last character. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 80 | */ |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 81 | extern char const * const gBuiltinExtensionString = |
| 82 | "EGL_KHR_get_all_proc_addresses " |
| 83 | "EGL_ANDROID_presentation_time " |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 84 | "EGL_KHR_swap_buffers_with_damage " |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 85 | "EGL_ANDROID_create_native_client_buffer " |
Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 86 | "EGL_ANDROID_front_buffer_auto_refresh " |
Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 87 | "EGL_ANDROID_get_frame_timestamps " |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 88 | ; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 89 | extern char const * const gExtensionString = |
| 90 | "EGL_KHR_image " // mandatory |
| 91 | "EGL_KHR_image_base " // mandatory |
| 92 | "EGL_KHR_image_pixmap " |
| 93 | "EGL_KHR_lock_surface " |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 94 | #if (ENABLE_EGL_KHR_GL_COLORSPACE != 0) |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 95 | "EGL_KHR_gl_colorspace " |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 96 | #endif |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 97 | "EGL_KHR_gl_texture_2D_image " |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 98 | "EGL_KHR_gl_texture_3D_image " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 99 | "EGL_KHR_gl_texture_cubemap_image " |
| 100 | "EGL_KHR_gl_renderbuffer_image " |
| 101 | "EGL_KHR_reusable_sync " |
| 102 | "EGL_KHR_fence_sync " |
Jamie Gennis | f6d1c39 | 2013-04-25 18:48:41 -0700 | [diff] [blame] | 103 | "EGL_KHR_create_context " |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 104 | "EGL_KHR_config_attribs " |
| 105 | "EGL_KHR_surfaceless_context " |
| 106 | "EGL_KHR_stream " |
| 107 | "EGL_KHR_stream_fifo " |
| 108 | "EGL_KHR_stream_producer_eglsurface " |
| 109 | "EGL_KHR_stream_consumer_gltexture " |
| 110 | "EGL_KHR_stream_cross_process_fd " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 111 | "EGL_EXT_create_context_robustness " |
| 112 | "EGL_NV_system_time " |
| 113 | "EGL_ANDROID_image_native_buffer " // mandatory |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 114 | "EGL_KHR_wait_sync " // strongly recommended |
Jamie Gennis | dbe9245 | 2013-09-23 17:22:10 -0700 | [diff] [blame] | 115 | "EGL_ANDROID_recordable " // mandatory |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 116 | "EGL_KHR_partial_update " // strongly recommended |
| 117 | "EGL_EXT_buffer_age " // strongly recommended with partial_update |
Jesse Hall | 408e59f | 2015-04-24 01:40:42 -0700 | [diff] [blame] | 118 | "EGL_KHR_create_context_no_error " |
Pablo Ceballos | ceb9ee7 | 2016-04-13 11:17:32 -0700 | [diff] [blame] | 119 | "EGL_KHR_mutable_render_buffer " |
Mika Isojärvi | f37864b | 2016-04-15 11:58:56 -0700 | [diff] [blame] | 120 | "EGL_EXT_yuv_surface " |
Craig Donner | aec8697 | 2016-04-28 18:09:40 -0700 | [diff] [blame] | 121 | "EGL_EXT_protected_content " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 122 | ; |
| 123 | |
| 124 | // extensions not exposed to applications but used by the ANDROID system |
| 125 | // "EGL_ANDROID_blob_cache " // strongly recommended |
| 126 | // "EGL_IMG_hibernate_process " // optional |
| 127 | // "EGL_ANDROID_native_fence_sync " // strongly recommended |
| 128 | // "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 |
Jamie Gennis | dbe9245 | 2013-09-23 17:22:10 -0700 | [diff] [blame] | 129 | // "EGL_ANDROID_image_crop " // optional |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * EGL Extensions entry-points exposed to 3rd party applications |
| 133 | * (keep in sync with gExtensionString above) |
| 134 | * |
| 135 | */ |
| 136 | static const extention_map_t sExtensionMap[] = { |
| 137 | // EGL_KHR_lock_surface |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 138 | { "eglLockSurfaceKHR", |
| 139 | (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, |
| 140 | { "eglUnlockSurfaceKHR", |
| 141 | (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 142 | |
| 143 | // EGL_KHR_image, EGL_KHR_image_base |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 144 | { "eglCreateImageKHR", |
| 145 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, |
| 146 | { "eglDestroyImageKHR", |
| 147 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 148 | |
| 149 | // EGL_KHR_reusable_sync, EGL_KHR_fence_sync |
| 150 | { "eglCreateSyncKHR", |
| 151 | (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, |
| 152 | { "eglDestroySyncKHR", |
| 153 | (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, |
| 154 | { "eglClientWaitSyncKHR", |
| 155 | (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, |
| 156 | { "eglSignalSyncKHR", |
| 157 | (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, |
| 158 | { "eglGetSyncAttribKHR", |
| 159 | (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, |
| 160 | |
| 161 | // EGL_NV_system_time |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 162 | { "eglGetSystemTimeFrequencyNV", |
| 163 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, |
| 164 | { "eglGetSystemTimeNV", |
| 165 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 166 | |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 167 | // EGL_KHR_wait_sync |
| 168 | { "eglWaitSyncKHR", |
| 169 | (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 170 | |
| 171 | // EGL_ANDROID_presentation_time |
| 172 | { "eglPresentationTimeANDROID", |
| 173 | (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 174 | |
| 175 | // EGL_KHR_swap_buffers_with_damage |
| 176 | { "eglSwapBuffersWithDamageKHR", |
| 177 | (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR }, |
| 178 | |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 179 | // EGL_ANDROID_native_client_buffer |
| 180 | { "eglCreateNativeClientBufferANDROID", |
| 181 | (__eglMustCastToProperFunctionPointerType)&eglCreateNativeClientBufferANDROID }, |
| 182 | |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 183 | // EGL_KHR_partial_update |
| 184 | { "eglSetDamageRegionKHR", |
| 185 | (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 186 | |
| 187 | { "eglCreateStreamKHR", |
| 188 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR }, |
| 189 | { "eglDestroyStreamKHR", |
| 190 | (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR }, |
| 191 | { "eglStreamAttribKHR", |
| 192 | (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR }, |
| 193 | { "eglQueryStreamKHR", |
| 194 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR }, |
| 195 | { "eglQueryStreamu64KHR", |
| 196 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR }, |
| 197 | { "eglQueryStreamTimeKHR", |
| 198 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR }, |
| 199 | { "eglCreateStreamProducerSurfaceKHR", |
| 200 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR }, |
| 201 | { "eglStreamConsumerGLTextureExternalKHR", |
| 202 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR }, |
| 203 | { "eglStreamConsumerAcquireKHR", |
| 204 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR }, |
| 205 | { "eglStreamConsumerReleaseKHR", |
| 206 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR }, |
| 207 | { "eglGetStreamFileDescriptorKHR", |
| 208 | (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR }, |
| 209 | { "eglCreateStreamFromFileDescriptorKHR", |
| 210 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR }, |
Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 211 | |
| 212 | // EGL_ANDROID_get_frame_timestamps |
| 213 | { "eglGetFrameTimestampsANDROID", |
| 214 | (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID }, |
| 215 | { "eglQueryTimestampSupportedANDROID", |
| 216 | (__eglMustCastToProperFunctionPointerType)&eglQueryTimestampSupportedANDROID }, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 219 | /* |
| 220 | * These extensions entry-points should not be exposed to applications. |
| 221 | * They're used internally by the Android EGL layer. |
| 222 | */ |
| 223 | #define FILTER_EXTENSIONS(procname) \ |
| 224 | (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ |
| 225 | !strcmp((procname), "eglHibernateProcessIMG") || \ |
| 226 | !strcmp((procname), "eglAwakenProcessIMG") || \ |
| 227 | !strcmp((procname), "eglDupNativeFenceFDANDROID")) |
| 228 | |
| 229 | |
| 230 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 231 | // accesses protected by sExtensionMapMutex |
| 232 | static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; |
| 233 | static int sGLExtentionSlot = 0; |
| 234 | static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; |
| 235 | |
| 236 | static void(*findProcAddress(const char* name, |
| 237 | const extention_map_t* map, size_t n))() { |
| 238 | for (uint32_t i=0 ; i<n ; i++) { |
| 239 | if (!strcmp(name, map[i].name)) { |
| 240 | return map[i].address; |
| 241 | } |
| 242 | } |
| 243 | return NULL; |
| 244 | } |
| 245 | |
| 246 | // ---------------------------------------------------------------------------- |
| 247 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 248 | extern void setGLHooksThreadSpecific(gl_hooks_t const *value); |
| 249 | extern EGLBoolean egl_init_drivers(); |
| 250 | extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 251 | extern gl_hooks_t gHooksTrace; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 252 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 253 | } // namespace android; |
| 254 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 255 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 256 | // ---------------------------------------------------------------------------- |
| 257 | |
| 258 | static inline void clearError() { egl_tls_t::clearError(); } |
| 259 | static inline EGLContext getContext() { return egl_tls_t::getContext(); } |
| 260 | |
| 261 | // ---------------------------------------------------------------------------- |
| 262 | |
| 263 | EGLDisplay eglGetDisplay(EGLNativeDisplayType display) |
| 264 | { |
| 265 | clearError(); |
| 266 | |
Dan Stoza | c3289c4 | 2014-01-17 11:38:34 -0800 | [diff] [blame] | 267 | uintptr_t index = reinterpret_cast<uintptr_t>(display); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 268 | if (index >= NUM_DISPLAYS) { |
| 269 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 270 | } |
| 271 | |
| 272 | if (egl_init_drivers() == EGL_FALSE) { |
| 273 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 274 | } |
| 275 | |
| 276 | EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); |
| 277 | return dpy; |
| 278 | } |
| 279 | |
| 280 | // ---------------------------------------------------------------------------- |
| 281 | // Initialization |
| 282 | // ---------------------------------------------------------------------------- |
| 283 | |
| 284 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 285 | { |
| 286 | clearError(); |
| 287 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 288 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 289 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 290 | |
| 291 | EGLBoolean res = dp->initialize(major, minor); |
| 292 | |
| 293 | return res; |
| 294 | } |
| 295 | |
| 296 | EGLBoolean eglTerminate(EGLDisplay dpy) |
| 297 | { |
| 298 | // NOTE: don't unload the drivers b/c some APIs can be called |
| 299 | // after eglTerminate() has been called. eglTerminate() only |
| 300 | // terminates an EGLDisplay, not a EGL itself. |
| 301 | |
| 302 | clearError(); |
| 303 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 304 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 305 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 306 | |
| 307 | EGLBoolean res = dp->terminate(); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 308 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 309 | return res; |
| 310 | } |
| 311 | |
| 312 | // ---------------------------------------------------------------------------- |
| 313 | // configuration |
| 314 | // ---------------------------------------------------------------------------- |
| 315 | |
| 316 | EGLBoolean eglGetConfigs( EGLDisplay dpy, |
| 317 | EGLConfig *configs, |
| 318 | EGLint config_size, EGLint *num_config) |
| 319 | { |
| 320 | clearError(); |
| 321 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 322 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 323 | if (!dp) return EGL_FALSE; |
| 324 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 325 | if (num_config==0) { |
| 326 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 329 | EGLBoolean res = EGL_FALSE; |
| 330 | *num_config = 0; |
| 331 | |
| 332 | egl_connection_t* const cnx = &gEGLImpl; |
| 333 | if (cnx->dso) { |
| 334 | res = cnx->egl.eglGetConfigs( |
| 335 | dp->disp.dpy, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 336 | } |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 337 | |
| 338 | return res; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, |
| 342 | EGLConfig *configs, EGLint config_size, |
| 343 | EGLint *num_config) |
| 344 | { |
| 345 | clearError(); |
| 346 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 347 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 348 | if (!dp) return EGL_FALSE; |
| 349 | |
| 350 | if (num_config==0) { |
| 351 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 352 | } |
| 353 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 354 | EGLBoolean res = EGL_FALSE; |
| 355 | *num_config = 0; |
| 356 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 357 | egl_connection_t* const cnx = &gEGLImpl; |
| 358 | if (cnx->dso) { |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 359 | if (attrib_list) { |
| 360 | char value[PROPERTY_VALUE_MAX]; |
| 361 | property_get("debug.egl.force_msaa", value, "false"); |
| 362 | |
| 363 | if (!strcmp(value, "true")) { |
| 364 | size_t attribCount = 0; |
| 365 | EGLint attrib = attrib_list[0]; |
| 366 | |
| 367 | // Only enable MSAA if the context is OpenGL ES 2.0 and |
Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 368 | // if no caveat is requested |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 369 | const EGLint *attribRendererable = NULL; |
| 370 | const EGLint *attribCaveat = NULL; |
| 371 | |
| 372 | // Count the number of attributes and look for |
Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 373 | // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 374 | while (attrib != EGL_NONE) { |
| 375 | attrib = attrib_list[attribCount]; |
| 376 | switch (attrib) { |
| 377 | case EGL_RENDERABLE_TYPE: |
| 378 | attribRendererable = &attrib_list[attribCount]; |
| 379 | break; |
| 380 | case EGL_CONFIG_CAVEAT: |
| 381 | attribCaveat = &attrib_list[attribCount]; |
| 382 | break; |
| 383 | } |
| 384 | attribCount++; |
| 385 | } |
| 386 | |
| 387 | if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && |
| 388 | (!attribCaveat || attribCaveat[1] != EGL_NONE)) { |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 389 | |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 390 | // Insert 2 extra attributes to force-enable MSAA 4x |
| 391 | EGLint aaAttribs[attribCount + 4]; |
| 392 | aaAttribs[0] = EGL_SAMPLE_BUFFERS; |
| 393 | aaAttribs[1] = 1; |
| 394 | aaAttribs[2] = EGL_SAMPLES; |
| 395 | aaAttribs[3] = 4; |
| 396 | |
| 397 | memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); |
| 398 | |
| 399 | EGLint numConfigAA; |
| 400 | EGLBoolean resAA = cnx->egl.eglChooseConfig( |
| 401 | dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); |
| 402 | |
| 403 | if (resAA == EGL_TRUE && numConfigAA > 0) { |
| 404 | ALOGD("Enabling MSAA 4x"); |
| 405 | *num_config = numConfigAA; |
| 406 | return resAA; |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 412 | res = cnx->egl.eglChooseConfig( |
| 413 | dp->disp.dpy, attrib_list, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 414 | } |
| 415 | return res; |
| 416 | } |
| 417 | |
| 418 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 419 | EGLint attribute, EGLint *value) |
| 420 | { |
| 421 | clearError(); |
| 422 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 423 | egl_connection_t* cnx = NULL; |
| 424 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 425 | if (!dp) return EGL_FALSE; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 426 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 427 | return cnx->egl.eglGetConfigAttrib( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 428 | dp->disp.dpy, config, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | // ---------------------------------------------------------------------------- |
| 432 | // surfaces |
| 433 | // ---------------------------------------------------------------------------- |
| 434 | |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 435 | // The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 436 | // been added to the Khronos egl.h. |
| 437 | #define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE |
| 438 | #define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB |
| 439 | #define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR |
| 440 | |
| 441 | // Turn linear formats into corresponding sRGB formats when colorspace is |
| 442 | // EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear |
| 443 | // formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 444 | // the modification isn't possible, the original dataSpace is returned. |
| 445 | static android_dataspace modifyBufferDataspace( android_dataspace dataSpace, |
| 446 | EGLint colorspace) { |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 447 | if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 448 | return HAL_DATASPACE_SRGB_LINEAR; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 449 | } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 450 | return HAL_DATASPACE_SRGB; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 451 | } |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 452 | return dataSpace; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 455 | EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, |
| 456 | NativeWindowType window, |
| 457 | const EGLint *attrib_list) |
| 458 | { |
| 459 | clearError(); |
| 460 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 461 | egl_connection_t* cnx = NULL; |
| 462 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 463 | if (dp) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 464 | EGLDisplay iDpy = dp->disp.dpy; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 465 | |
Andy McFadden | d566ce3 | 2014-01-07 15:54:17 -0800 | [diff] [blame] | 466 | int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); |
| 467 | if (result != OK) { |
| 468 | ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) " |
| 469 | "failed (%#x) (already connected to another API?)", |
| 470 | window, result); |
Jonathan Hamilton | 77a9b4a | 2013-07-17 09:41:42 -0700 | [diff] [blame] | 471 | return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 474 | // Set the native window's buffers format to match what this config requests. |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 475 | // Whether to use sRGB gamma is not part of the EGLconfig, but is part |
| 476 | // of our native format. So if sRGB gamma is requested, we have to |
| 477 | // modify the EGLconfig's format before setting the native window's |
| 478 | // format. |
Alistair Strachan | 733a807 | 2015-02-12 12:33:25 -0800 | [diff] [blame] | 479 | |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 480 | // by default, just pick RGBA_8888 |
| 481 | EGLint format = HAL_PIXEL_FORMAT_RGBA_8888; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 482 | android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN; |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 483 | |
| 484 | EGLint a = 0; |
| 485 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a); |
| 486 | if (a > 0) { |
| 487 | // alpha-channel requested, there's really only one suitable format |
| 488 | format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 489 | } else { |
| 490 | EGLint r, g, b; |
| 491 | r = g = b = 0; |
| 492 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r); |
| 493 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g); |
| 494 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b); |
| 495 | EGLint colorDepth = r + g + b; |
| 496 | if (colorDepth <= 16) { |
| 497 | format = HAL_PIXEL_FORMAT_RGB_565; |
| 498 | } else { |
| 499 | format = HAL_PIXEL_FORMAT_RGBX_8888; |
| 500 | } |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 501 | } |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 502 | |
| 503 | // now select a corresponding sRGB format if needed |
| 504 | if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { |
| 505 | for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { |
| 506 | if (*attr == EGL_GL_COLORSPACE_KHR) { |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 507 | if (ENABLE_EGL_KHR_GL_COLORSPACE) { |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 508 | dataSpace = modifyBufferDataspace(dataSpace, *(attr+1)); |
Jesse Hall | a2ba428 | 2013-09-14 21:00:14 -0700 | [diff] [blame] | 509 | } else { |
| 510 | // Normally we'd pass through unhandled attributes to |
| 511 | // the driver. But in case the driver implements this |
| 512 | // extension but we're disabling it, we want to prevent |
| 513 | // it getting through -- support will be broken without |
| 514 | // our help. |
| 515 | ALOGE("sRGB window surfaces not supported"); |
| 516 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); |
| 517 | } |
Jamie Gennis | bee205f | 2011-07-01 13:12:07 -0700 | [diff] [blame] | 518 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
Alistair Strachan | 733a807 | 2015-02-12 12:33:25 -0800 | [diff] [blame] | 521 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 522 | if (format != 0) { |
| 523 | int err = native_window_set_buffers_format(window, format); |
| 524 | if (err != 0) { |
| 525 | ALOGE("error setting native window pixel format: %s (%d)", |
| 526 | strerror(-err), err); |
| 527 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
| 528 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 529 | } |
| 530 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 531 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 532 | if (dataSpace != 0) { |
| 533 | int err = native_window_set_buffers_data_space(window, dataSpace); |
| 534 | if (err != 0) { |
| 535 | ALOGE("error setting native window pixel dataSpace: %s (%d)", |
| 536 | strerror(-err), err); |
| 537 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
| 538 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 539 | } |
| 540 | } |
| 541 | |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 542 | // the EGL spec requires that a new EGLSurface default to swap interval |
| 543 | // 1, so explicitly set that on the window here. |
| 544 | ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); |
| 545 | anw->setSwapInterval(anw, 1); |
| 546 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 547 | EGLSurface surface = cnx->egl.eglCreateWindowSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 548 | iDpy, config, window, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 549 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 550 | egl_surface_t* s = new egl_surface_t(dp.get(), config, window, |
| 551 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 552 | return s; |
| 553 | } |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 554 | |
| 555 | // EGLSurface creation failed |
| 556 | native_window_set_buffers_format(window, 0); |
| 557 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 558 | } |
| 559 | return EGL_NO_SURFACE; |
| 560 | } |
| 561 | |
| 562 | EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, |
| 563 | NativePixmapType pixmap, |
| 564 | const EGLint *attrib_list) |
| 565 | { |
| 566 | clearError(); |
| 567 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 568 | egl_connection_t* cnx = NULL; |
| 569 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 570 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 571 | EGLSurface surface = cnx->egl.eglCreatePixmapSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 572 | dp->disp.dpy, config, pixmap, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 573 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 574 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 575 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 576 | return s; |
| 577 | } |
| 578 | } |
| 579 | return EGL_NO_SURFACE; |
| 580 | } |
| 581 | |
| 582 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, |
| 583 | const EGLint *attrib_list) |
| 584 | { |
| 585 | clearError(); |
| 586 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 587 | egl_connection_t* cnx = NULL; |
| 588 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 589 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 590 | EGLSurface surface = cnx->egl.eglCreatePbufferSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 591 | dp->disp.dpy, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 592 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 593 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 594 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 595 | return s; |
| 596 | } |
| 597 | } |
| 598 | return EGL_NO_SURFACE; |
| 599 | } |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 600 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 601 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 602 | { |
| 603 | clearError(); |
| 604 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 605 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 606 | if (!dp) return EGL_FALSE; |
| 607 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 608 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 609 | if (!_s.get()) |
| 610 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 611 | |
| 612 | egl_surface_t * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 613 | EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 614 | if (result == EGL_TRUE) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 615 | _s.terminate(); |
| 616 | } |
| 617 | return result; |
| 618 | } |
| 619 | |
| 620 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, |
| 621 | EGLint attribute, EGLint *value) |
| 622 | { |
| 623 | clearError(); |
| 624 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 625 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 626 | if (!dp) return EGL_FALSE; |
| 627 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 628 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 629 | if (!_s.get()) |
| 630 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 631 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 632 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 633 | return s->cnx->egl.eglQuerySurface( |
| 634 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 637 | void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 638 | ATRACE_CALL(); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 639 | clearError(); |
| 640 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 641 | const egl_display_ptr dp = validate_display(dpy); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 642 | if (!dp) { |
| 643 | return; |
| 644 | } |
| 645 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 646 | SurfaceRef _s(dp.get(), surface); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 647 | if (!_s.get()) { |
| 648 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 649 | return; |
| 650 | } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 653 | // ---------------------------------------------------------------------------- |
| 654 | // Contexts |
| 655 | // ---------------------------------------------------------------------------- |
| 656 | |
| 657 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, |
| 658 | EGLContext share_list, const EGLint *attrib_list) |
| 659 | { |
| 660 | clearError(); |
| 661 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 662 | egl_connection_t* cnx = NULL; |
| 663 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 664 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 665 | if (share_list != EGL_NO_CONTEXT) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 666 | if (!ContextRef(dp.get(), share_list).get()) { |
| 667 | return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); |
| 668 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 669 | egl_context_t* const c = get_context(share_list); |
| 670 | share_list = c->context; |
| 671 | } |
| 672 | EGLContext context = cnx->egl.eglCreateContext( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 673 | dp->disp.dpy, config, share_list, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 674 | if (context != EGL_NO_CONTEXT) { |
| 675 | // figure out if it's a GLESv1 or GLESv2 |
| 676 | int version = 0; |
| 677 | if (attrib_list) { |
| 678 | while (*attrib_list != EGL_NONE) { |
| 679 | GLint attr = *attrib_list++; |
| 680 | GLint value = *attrib_list++; |
| 681 | if (attr == EGL_CONTEXT_CLIENT_VERSION) { |
| 682 | if (value == 1) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 683 | version = egl_connection_t::GLESv1_INDEX; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 684 | } else if (value == 2 || value == 3) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 685 | version = egl_connection_t::GLESv2_INDEX; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | }; |
| 689 | } |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 690 | egl_context_t* c = new egl_context_t(dpy, context, config, cnx, |
| 691 | version); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 692 | return c; |
| 693 | } |
| 694 | } |
| 695 | return EGL_NO_CONTEXT; |
| 696 | } |
| 697 | |
| 698 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 699 | { |
| 700 | clearError(); |
| 701 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 702 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 703 | if (!dp) |
| 704 | return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 705 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 706 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 707 | if (!_c.get()) |
| 708 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 709 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 710 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 711 | EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 712 | if (result == EGL_TRUE) { |
| 713 | _c.terminate(); |
| 714 | } |
| 715 | return result; |
| 716 | } |
| 717 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 718 | EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, |
| 719 | EGLSurface read, EGLContext ctx) |
| 720 | { |
| 721 | clearError(); |
| 722 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 723 | egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 724 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 725 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 726 | // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not |
| 727 | // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is |
| 728 | // a valid but uninitialized display. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 729 | if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || |
| 730 | (draw != EGL_NO_SURFACE) ) { |
| 731 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 732 | } |
| 733 | |
| 734 | // get a reference to the object passed in |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 735 | ContextRef _c(dp.get(), ctx); |
| 736 | SurfaceRef _d(dp.get(), draw); |
| 737 | SurfaceRef _r(dp.get(), read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 738 | |
| 739 | // validate the context (if not EGL_NO_CONTEXT) |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 740 | if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 741 | // EGL_NO_CONTEXT is valid |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 742 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // these are the underlying implementation's object |
| 746 | EGLContext impl_ctx = EGL_NO_CONTEXT; |
| 747 | EGLSurface impl_draw = EGL_NO_SURFACE; |
| 748 | EGLSurface impl_read = EGL_NO_SURFACE; |
| 749 | |
| 750 | // these are our objects structs passed in |
| 751 | egl_context_t * c = NULL; |
| 752 | egl_surface_t const * d = NULL; |
| 753 | egl_surface_t const * r = NULL; |
| 754 | |
| 755 | // these are the current objects structs |
| 756 | egl_context_t * cur_c = get_context(getContext()); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 757 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 758 | if (ctx != EGL_NO_CONTEXT) { |
| 759 | c = get_context(ctx); |
| 760 | impl_ctx = c->context; |
| 761 | } else { |
| 762 | // no context given, use the implementation of the current context |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 763 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { |
| 764 | // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); |
| 765 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
| 766 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 767 | if (cur_c == NULL) { |
| 768 | // no current context |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 769 | // not an error, there is just no current context. |
| 770 | return EGL_TRUE; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | // retrieve the underlying implementation's draw EGLSurface |
| 775 | if (draw != EGL_NO_SURFACE) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 776 | if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 777 | d = get_surface(draw); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 778 | impl_draw = d->surface; |
| 779 | } |
| 780 | |
| 781 | // retrieve the underlying implementation's read EGLSurface |
| 782 | if (read != EGL_NO_SURFACE) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 783 | if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 784 | r = get_surface(read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 785 | impl_read = r->surface; |
| 786 | } |
| 787 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 788 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 789 | EGLBoolean result = dp->makeCurrent(c, cur_c, |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 790 | draw, read, ctx, |
| 791 | impl_draw, impl_read, impl_ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 792 | |
| 793 | if (result == EGL_TRUE) { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 794 | if (c) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 795 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
| 796 | egl_tls_t::setContext(ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 797 | _c.acquire(); |
| 798 | _r.acquire(); |
| 799 | _d.acquire(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 800 | } else { |
| 801 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 802 | egl_tls_t::setContext(EGL_NO_CONTEXT); |
| 803 | } |
Mathias Agopian | 5fecea7 | 2011-08-25 18:38:24 -0700 | [diff] [blame] | 804 | } else { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 805 | // this will ALOGE the error |
Mathias Agopian | 63108c3 | 2013-09-06 13:36:49 -0700 | [diff] [blame] | 806 | egl_connection_t* const cnx = &gEGLImpl; |
| 807 | result = setError(cnx->egl.eglGetError(), EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 808 | } |
| 809 | return result; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, |
| 814 | EGLint attribute, EGLint *value) |
| 815 | { |
| 816 | clearError(); |
| 817 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 818 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 819 | if (!dp) return EGL_FALSE; |
| 820 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 821 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 822 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 823 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 824 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 825 | return c->cnx->egl.eglQueryContext( |
| 826 | dp->disp.dpy, c->context, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 827 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | EGLContext eglGetCurrentContext(void) |
| 831 | { |
| 832 | // could be called before eglInitialize(), but we wouldn't have a context |
| 833 | // then, and this function would correctly return EGL_NO_CONTEXT. |
| 834 | |
| 835 | clearError(); |
| 836 | |
| 837 | EGLContext ctx = getContext(); |
| 838 | return ctx; |
| 839 | } |
| 840 | |
| 841 | EGLSurface eglGetCurrentSurface(EGLint readdraw) |
| 842 | { |
| 843 | // could be called before eglInitialize(), but we wouldn't have a context |
| 844 | // then, and this function would correctly return EGL_NO_SURFACE. |
| 845 | |
| 846 | clearError(); |
| 847 | |
| 848 | EGLContext ctx = getContext(); |
| 849 | if (ctx) { |
| 850 | egl_context_t const * const c = get_context(ctx); |
| 851 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 852 | switch (readdraw) { |
| 853 | case EGL_READ: return c->read; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 854 | case EGL_DRAW: return c->draw; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 855 | default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
| 856 | } |
| 857 | } |
| 858 | return EGL_NO_SURFACE; |
| 859 | } |
| 860 | |
| 861 | EGLDisplay eglGetCurrentDisplay(void) |
| 862 | { |
| 863 | // could be called before eglInitialize(), but we wouldn't have a context |
| 864 | // then, and this function would correctly return EGL_NO_DISPLAY. |
| 865 | |
| 866 | clearError(); |
| 867 | |
| 868 | EGLContext ctx = getContext(); |
| 869 | if (ctx) { |
| 870 | egl_context_t const * const c = get_context(ctx); |
| 871 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 872 | return c->dpy; |
| 873 | } |
| 874 | return EGL_NO_DISPLAY; |
| 875 | } |
| 876 | |
| 877 | EGLBoolean eglWaitGL(void) |
| 878 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 879 | clearError(); |
| 880 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 881 | egl_connection_t* const cnx = &gEGLImpl; |
| 882 | if (!cnx->dso) |
| 883 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 884 | |
| 885 | return cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | EGLBoolean eglWaitNative(EGLint engine) |
| 889 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 890 | clearError(); |
| 891 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 892 | egl_connection_t* const cnx = &gEGLImpl; |
| 893 | if (!cnx->dso) |
| 894 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 895 | |
| 896 | return cnx->egl.eglWaitNative(engine); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | EGLint eglGetError(void) |
| 900 | { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 901 | EGLint err = EGL_SUCCESS; |
| 902 | egl_connection_t* const cnx = &gEGLImpl; |
| 903 | if (cnx->dso) { |
| 904 | err = cnx->egl.eglGetError(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 905 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 906 | if (err == EGL_SUCCESS) { |
| 907 | err = egl_tls_t::getError(); |
| 908 | } |
| 909 | return err; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 912 | static __eglMustCastToProperFunctionPointerType findBuiltinWrapper( |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 913 | const char* procname) { |
| 914 | const egl_connection_t* cnx = &gEGLImpl; |
| 915 | void* proc = NULL; |
| 916 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 917 | proc = dlsym(cnx->libEgl, procname); |
| 918 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 919 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 920 | proc = dlsym(cnx->libGles2, procname); |
| 921 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 922 | |
| 923 | proc = dlsym(cnx->libGles1, procname); |
| 924 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 925 | |
| 926 | return NULL; |
| 927 | } |
| 928 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 929 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) |
| 930 | { |
| 931 | // eglGetProcAddress() could be the very first function called |
| 932 | // in which case we must make sure we've initialized ourselves, this |
| 933 | // happens the first time egl_get_display() is called. |
| 934 | |
| 935 | clearError(); |
| 936 | |
| 937 | if (egl_init_drivers() == EGL_FALSE) { |
| 938 | setError(EGL_BAD_PARAMETER, NULL); |
| 939 | return NULL; |
| 940 | } |
| 941 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 942 | if (FILTER_EXTENSIONS(procname)) { |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 943 | return NULL; |
| 944 | } |
| 945 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 946 | __eglMustCastToProperFunctionPointerType addr; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 947 | addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 948 | if (addr) return addr; |
| 949 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 950 | addr = findBuiltinWrapper(procname); |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 951 | if (addr) return addr; |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 952 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 953 | // this protects accesses to sGLExtentionMap and sGLExtentionSlot |
| 954 | pthread_mutex_lock(&sExtensionMapMutex); |
| 955 | |
| 956 | /* |
| 957 | * Since eglGetProcAddress() is not associated to anything, it needs |
| 958 | * to return a function pointer that "works" regardless of what |
| 959 | * the current context is. |
| 960 | * |
| 961 | * For this reason, we return a "forwarder", a small stub that takes |
| 962 | * care of calling the function associated with the context |
| 963 | * currently bound. |
| 964 | * |
| 965 | * We first look for extensions we've already resolved, if we're seeing |
| 966 | * this extension for the first time, we go through all our |
| 967 | * implementations and call eglGetProcAddress() and record the |
| 968 | * result in the appropriate implementation hooks and return the |
| 969 | * address of the forwarder corresponding to that hook set. |
| 970 | * |
| 971 | */ |
| 972 | |
| 973 | const String8 name(procname); |
| 974 | addr = sGLExtentionMap.valueFor(name); |
| 975 | const int slot = sGLExtentionSlot; |
| 976 | |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 977 | ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 978 | "no more slots for eglGetProcAddress(\"%s\")", |
| 979 | procname); |
| 980 | |
| 981 | if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { |
| 982 | bool found = false; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 983 | |
| 984 | egl_connection_t* const cnx = &gEGLImpl; |
| 985 | if (cnx->dso && cnx->egl.eglGetProcAddress) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 986 | // Extensions are independent of the bound context |
luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 987 | addr = |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 988 | cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = |
| 989 | cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 990 | cnx->egl.eglGetProcAddress(procname); |
luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 991 | if (addr) found = true; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 992 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 993 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 994 | if (found) { |
| 995 | addr = gExtensionForwarders[slot]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 996 | sGLExtentionMap.add(name, addr); |
| 997 | sGLExtentionSlot++; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | pthread_mutex_unlock(&sExtensionMapMutex); |
| 1002 | return addr; |
| 1003 | } |
| 1004 | |
Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1005 | class FrameCompletionThread : public Thread { |
| 1006 | public: |
| 1007 | |
| 1008 | static void queueSync(EGLSyncKHR sync) { |
| 1009 | static sp<FrameCompletionThread> thread(new FrameCompletionThread); |
| 1010 | static bool running = false; |
| 1011 | if (!running) { |
| 1012 | thread->run("GPUFrameCompletion"); |
| 1013 | running = true; |
| 1014 | } |
| 1015 | { |
| 1016 | Mutex::Autolock lock(thread->mMutex); |
| 1017 | ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", |
| 1018 | thread->mFramesQueued).string()); |
| 1019 | thread->mQueue.push_back(sync); |
| 1020 | thread->mCondition.signal(); |
| 1021 | thread->mFramesQueued++; |
| 1022 | ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | private: |
| 1027 | FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} |
| 1028 | |
| 1029 | virtual bool threadLoop() { |
| 1030 | EGLSyncKHR sync; |
| 1031 | uint32_t frameNum; |
| 1032 | { |
| 1033 | Mutex::Autolock lock(mMutex); |
| 1034 | while (mQueue.isEmpty()) { |
| 1035 | mCondition.wait(mMutex); |
| 1036 | } |
| 1037 | sync = mQueue[0]; |
| 1038 | frameNum = mFramesCompleted; |
| 1039 | } |
| 1040 | EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 1041 | { |
| 1042 | ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", |
| 1043 | frameNum).string()); |
| 1044 | EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); |
| 1045 | if (result == EGL_FALSE) { |
| 1046 | ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); |
| 1047 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { |
| 1048 | ALOGE("FrameCompletion: timeout waiting for fence"); |
| 1049 | } |
| 1050 | eglDestroySyncKHR(dpy, sync); |
| 1051 | } |
| 1052 | { |
| 1053 | Mutex::Autolock lock(mMutex); |
| 1054 | mQueue.removeAt(0); |
| 1055 | mFramesCompleted++; |
| 1056 | ATRACE_INT("GPU Frames Outstanding", mQueue.size()); |
| 1057 | } |
| 1058 | return true; |
| 1059 | } |
| 1060 | |
| 1061 | uint32_t mFramesQueued; |
| 1062 | uint32_t mFramesCompleted; |
| 1063 | Vector<EGLSyncKHR> mQueue; |
| 1064 | Condition mCondition; |
| 1065 | Mutex mMutex; |
| 1066 | }; |
| 1067 | |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1068 | EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, |
| 1069 | EGLint *rects, EGLint n_rects) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1070 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1071 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1072 | clearError(); |
| 1073 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1074 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1075 | if (!dp) return EGL_FALSE; |
| 1076 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1077 | SurfaceRef _s(dp.get(), draw); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1078 | if (!_s.get()) |
| 1079 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1080 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1081 | egl_surface_t const * const s = get_surface(draw); |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1082 | |
Mathias Agopian | ed6d08b | 2013-04-16 16:39:46 -0700 | [diff] [blame] | 1083 | if (CC_UNLIKELY(dp->traceGpuCompletion)) { |
| 1084 | EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); |
| 1085 | if (sync != EGL_NO_SYNC_KHR) { |
| 1086 | FrameCompletionThread::queueSync(sync); |
| 1087 | } |
| 1088 | } |
| 1089 | |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1090 | if (CC_UNLIKELY(dp->finishOnSwap)) { |
| 1091 | uint32_t pixel; |
| 1092 | egl_context_t * const c = get_context( egl_tls_t::getContext() ); |
| 1093 | if (c) { |
| 1094 | // glReadPixels() ensures that the frame is complete |
| 1095 | s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, |
| 1096 | GL_RGBA,GL_UNSIGNED_BYTE,&pixel); |
| 1097 | } |
| 1098 | } |
| 1099 | |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1100 | if (n_rects == 0) { |
| 1101 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); |
| 1102 | } |
| 1103 | |
| 1104 | Vector<android_native_rect_t> androidRects; |
| 1105 | for (int r = 0; r < n_rects; ++r) { |
| 1106 | int offset = r * 4; |
| 1107 | int x = rects[offset]; |
| 1108 | int y = rects[offset + 1]; |
| 1109 | int width = rects[offset + 2]; |
| 1110 | int height = rects[offset + 3]; |
| 1111 | android_native_rect_t androidRect; |
| 1112 | androidRect.left = x; |
| 1113 | androidRect.top = y + height; |
| 1114 | androidRect.right = x + width; |
| 1115 | androidRect.bottom = y; |
| 1116 | androidRects.push_back(androidRect); |
| 1117 | } |
| 1118 | native_window_set_surface_damage(s->win.get(), androidRects.array(), |
| 1119 | androidRects.size()); |
| 1120 | |
| 1121 | if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { |
| 1122 | return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, |
| 1123 | rects, n_rects); |
| 1124 | } else { |
| 1125 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) |
| 1130 | { |
| 1131 | return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, |
| 1135 | NativePixmapType target) |
| 1136 | { |
| 1137 | clearError(); |
| 1138 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1139 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1140 | if (!dp) return EGL_FALSE; |
| 1141 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1142 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1143 | if (!_s.get()) |
| 1144 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1145 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1146 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1147 | return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | const char* eglQueryString(EGLDisplay dpy, EGLint name) |
| 1151 | { |
| 1152 | clearError(); |
| 1153 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1154 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1155 | if (!dp) return (const char *) NULL; |
| 1156 | |
| 1157 | switch (name) { |
| 1158 | case EGL_VENDOR: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1159 | return dp->getVendorString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1160 | case EGL_VERSION: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1161 | return dp->getVersionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1162 | case EGL_EXTENSIONS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1163 | return dp->getExtensionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1164 | case EGL_CLIENT_APIS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1165 | return dp->getClientApiString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1166 | } |
| 1167 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 1168 | } |
| 1169 | |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 1170 | EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) |
| 1171 | { |
| 1172 | clearError(); |
| 1173 | |
| 1174 | const egl_display_ptr dp = validate_display(dpy); |
| 1175 | if (!dp) return (const char *) NULL; |
| 1176 | |
| 1177 | switch (name) { |
| 1178 | case EGL_VENDOR: |
| 1179 | return dp->disp.queryString.vendor; |
| 1180 | case EGL_VERSION: |
| 1181 | return dp->disp.queryString.version; |
| 1182 | case EGL_EXTENSIONS: |
| 1183 | return dp->disp.queryString.extensions; |
| 1184 | case EGL_CLIENT_APIS: |
| 1185 | return dp->disp.queryString.clientApi; |
| 1186 | } |
| 1187 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 1188 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1189 | |
| 1190 | // ---------------------------------------------------------------------------- |
| 1191 | // EGL 1.1 |
| 1192 | // ---------------------------------------------------------------------------- |
| 1193 | |
| 1194 | EGLBoolean eglSurfaceAttrib( |
| 1195 | EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) |
| 1196 | { |
| 1197 | clearError(); |
| 1198 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1199 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1200 | if (!dp) return EGL_FALSE; |
| 1201 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1202 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1203 | if (!_s.get()) |
| 1204 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1205 | |
Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1206 | egl_surface_t * const s = get_surface(surface); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1207 | |
Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 1208 | if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) { |
Pablo Ceballos | f051ade | 2016-03-15 18:27:20 -0700 | [diff] [blame] | 1209 | int err = native_window_set_auto_refresh(s->win.get(), |
| 1210 | value ? true : false); |
| 1211 | return (err == NO_ERROR) ? EGL_TRUE : |
| 1212 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1215 | if (attribute == EGL_TIMESTAMPS_ANDROID) { |
| 1216 | s->enableTimestamps = value; |
| 1217 | return EGL_TRUE; |
| 1218 | } |
| 1219 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1220 | if (s->cnx->egl.eglSurfaceAttrib) { |
| 1221 | return s->cnx->egl.eglSurfaceAttrib( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1222 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1223 | } |
| 1224 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1225 | } |
| 1226 | |
| 1227 | EGLBoolean eglBindTexImage( |
| 1228 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1229 | { |
| 1230 | clearError(); |
| 1231 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1232 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1233 | if (!dp) return EGL_FALSE; |
| 1234 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1235 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1236 | if (!_s.get()) |
| 1237 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1238 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1239 | egl_surface_t const * const s = get_surface(surface); |
| 1240 | if (s->cnx->egl.eglBindTexImage) { |
| 1241 | return s->cnx->egl.eglBindTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1242 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1243 | } |
| 1244 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1245 | } |
| 1246 | |
| 1247 | EGLBoolean eglReleaseTexImage( |
| 1248 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1249 | { |
| 1250 | clearError(); |
| 1251 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1252 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1253 | if (!dp) return EGL_FALSE; |
| 1254 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1255 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1256 | if (!_s.get()) |
| 1257 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1258 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1259 | egl_surface_t const * const s = get_surface(surface); |
| 1260 | if (s->cnx->egl.eglReleaseTexImage) { |
| 1261 | return s->cnx->egl.eglReleaseTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1262 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1263 | } |
| 1264 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1265 | } |
| 1266 | |
| 1267 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 1268 | { |
| 1269 | clearError(); |
| 1270 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1271 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1272 | if (!dp) return EGL_FALSE; |
| 1273 | |
| 1274 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1275 | egl_connection_t* const cnx = &gEGLImpl; |
| 1276 | if (cnx->dso && cnx->egl.eglSwapInterval) { |
| 1277 | res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1278 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1279 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1280 | return res; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | // ---------------------------------------------------------------------------- |
| 1285 | // EGL 1.2 |
| 1286 | // ---------------------------------------------------------------------------- |
| 1287 | |
| 1288 | EGLBoolean eglWaitClient(void) |
| 1289 | { |
| 1290 | clearError(); |
| 1291 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1292 | egl_connection_t* const cnx = &gEGLImpl; |
| 1293 | if (!cnx->dso) |
| 1294 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1295 | |
| 1296 | EGLBoolean res; |
| 1297 | if (cnx->egl.eglWaitClient) { |
| 1298 | res = cnx->egl.eglWaitClient(); |
| 1299 | } else { |
| 1300 | res = cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1301 | } |
| 1302 | return res; |
| 1303 | } |
| 1304 | |
| 1305 | EGLBoolean eglBindAPI(EGLenum api) |
| 1306 | { |
| 1307 | clearError(); |
| 1308 | |
| 1309 | if (egl_init_drivers() == EGL_FALSE) { |
| 1310 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1311 | } |
| 1312 | |
| 1313 | // bind this API on all EGLs |
| 1314 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1315 | egl_connection_t* const cnx = &gEGLImpl; |
| 1316 | if (cnx->dso && cnx->egl.eglBindAPI) { |
| 1317 | res = cnx->egl.eglBindAPI(api); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1318 | } |
| 1319 | return res; |
| 1320 | } |
| 1321 | |
| 1322 | EGLenum eglQueryAPI(void) |
| 1323 | { |
| 1324 | clearError(); |
| 1325 | |
| 1326 | if (egl_init_drivers() == EGL_FALSE) { |
| 1327 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1328 | } |
| 1329 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1330 | egl_connection_t* const cnx = &gEGLImpl; |
| 1331 | if (cnx->dso && cnx->egl.eglQueryAPI) { |
| 1332 | return cnx->egl.eglQueryAPI(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1333 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1334 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1335 | // or, it can only be OpenGL ES |
| 1336 | return EGL_OPENGL_ES_API; |
| 1337 | } |
| 1338 | |
| 1339 | EGLBoolean eglReleaseThread(void) |
| 1340 | { |
| 1341 | clearError(); |
| 1342 | |
| 1343 | // If there is context bound to the thread, release it |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 1344 | egl_display_t::loseCurrent(get_context(getContext())); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1345 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1346 | egl_connection_t* const cnx = &gEGLImpl; |
| 1347 | if (cnx->dso && cnx->egl.eglReleaseThread) { |
| 1348 | cnx->egl.eglReleaseThread(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1349 | } |
| 1350 | egl_tls_t::clearTLS(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1351 | return EGL_TRUE; |
| 1352 | } |
| 1353 | |
| 1354 | EGLSurface eglCreatePbufferFromClientBuffer( |
| 1355 | EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, |
| 1356 | EGLConfig config, const EGLint *attrib_list) |
| 1357 | { |
| 1358 | clearError(); |
| 1359 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1360 | egl_connection_t* cnx = NULL; |
| 1361 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 1362 | if (!dp) return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1363 | if (cnx->egl.eglCreatePbufferFromClientBuffer) { |
| 1364 | return cnx->egl.eglCreatePbufferFromClientBuffer( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1365 | dp->disp.dpy, buftype, buffer, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1366 | } |
| 1367 | return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); |
| 1368 | } |
| 1369 | |
| 1370 | // ---------------------------------------------------------------------------- |
| 1371 | // EGL_EGLEXT_VERSION 3 |
| 1372 | // ---------------------------------------------------------------------------- |
| 1373 | |
| 1374 | EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, |
| 1375 | const EGLint *attrib_list) |
| 1376 | { |
| 1377 | clearError(); |
| 1378 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1379 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1380 | if (!dp) return EGL_FALSE; |
| 1381 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1382 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1383 | if (!_s.get()) |
| 1384 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1385 | |
| 1386 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1387 | if (s->cnx->egl.eglLockSurfaceKHR) { |
| 1388 | return s->cnx->egl.eglLockSurfaceKHR( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1389 | dp->disp.dpy, s->surface, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1390 | } |
| 1391 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1392 | } |
| 1393 | |
| 1394 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) |
| 1395 | { |
| 1396 | clearError(); |
| 1397 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1398 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1399 | if (!dp) return EGL_FALSE; |
| 1400 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1401 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1402 | if (!_s.get()) |
| 1403 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1404 | |
| 1405 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1406 | if (s->cnx->egl.eglUnlockSurfaceKHR) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1407 | return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1408 | } |
| 1409 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1410 | } |
| 1411 | |
| 1412 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1413 | EGLClientBuffer buffer, const EGLint *attrib_list) |
| 1414 | { |
| 1415 | clearError(); |
| 1416 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1417 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1418 | if (!dp) return EGL_NO_IMAGE_KHR; |
| 1419 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1420 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1421 | egl_context_t * const c = _c.get(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1422 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1423 | EGLImageKHR result = EGL_NO_IMAGE_KHR; |
| 1424 | egl_connection_t* const cnx = &gEGLImpl; |
| 1425 | if (cnx->dso && cnx->egl.eglCreateImageKHR) { |
| 1426 | result = cnx->egl.eglCreateImageKHR( |
| 1427 | dp->disp.dpy, |
| 1428 | c ? c->context : EGL_NO_CONTEXT, |
| 1429 | target, buffer, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1430 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1431 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) |
| 1435 | { |
| 1436 | clearError(); |
| 1437 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1438 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1439 | if (!dp) return EGL_FALSE; |
| 1440 | |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1441 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1442 | egl_connection_t* const cnx = &gEGLImpl; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1443 | if (cnx->dso && cnx->egl.eglDestroyImageKHR) { |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1444 | result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1445 | } |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1446 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | // ---------------------------------------------------------------------------- |
| 1450 | // EGL_EGLEXT_VERSION 5 |
| 1451 | // ---------------------------------------------------------------------------- |
| 1452 | |
| 1453 | |
| 1454 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) |
| 1455 | { |
| 1456 | clearError(); |
| 1457 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1458 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1459 | if (!dp) return EGL_NO_SYNC_KHR; |
| 1460 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1461 | EGLSyncKHR result = EGL_NO_SYNC_KHR; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1462 | egl_connection_t* const cnx = &gEGLImpl; |
| 1463 | if (cnx->dso && cnx->egl.eglCreateSyncKHR) { |
| 1464 | result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1465 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1466 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) |
| 1470 | { |
| 1471 | clearError(); |
| 1472 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1473 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1474 | if (!dp) return EGL_FALSE; |
| 1475 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1476 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1477 | egl_connection_t* const cnx = &gEGLImpl; |
| 1478 | if (cnx->dso && cnx->egl.eglDestroySyncKHR) { |
| 1479 | result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1480 | } |
| 1481 | return result; |
| 1482 | } |
| 1483 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 1484 | EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { |
| 1485 | clearError(); |
| 1486 | |
| 1487 | const egl_display_ptr dp = validate_display(dpy); |
| 1488 | if (!dp) return EGL_FALSE; |
| 1489 | |
| 1490 | EGLBoolean result = EGL_FALSE; |
| 1491 | egl_connection_t* const cnx = &gEGLImpl; |
| 1492 | if (cnx->dso && cnx->egl.eglSignalSyncKHR) { |
| 1493 | result = cnx->egl.eglSignalSyncKHR( |
| 1494 | dp->disp.dpy, sync, mode); |
| 1495 | } |
| 1496 | return result; |
| 1497 | } |
| 1498 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1499 | EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1500 | EGLint flags, EGLTimeKHR timeout) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1501 | { |
| 1502 | clearError(); |
| 1503 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1504 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1505 | if (!dp) return EGL_FALSE; |
| 1506 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1507 | EGLBoolean result = EGL_FALSE; |
| 1508 | egl_connection_t* const cnx = &gEGLImpl; |
| 1509 | if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { |
| 1510 | result = cnx->egl.eglClientWaitSyncKHR( |
| 1511 | dp->disp.dpy, sync, flags, timeout); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1512 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1513 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1516 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1517 | EGLint attribute, EGLint *value) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1518 | { |
| 1519 | clearError(); |
| 1520 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1521 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1522 | if (!dp) return EGL_FALSE; |
| 1523 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1524 | EGLBoolean result = EGL_FALSE; |
| 1525 | egl_connection_t* const cnx = &gEGLImpl; |
| 1526 | if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { |
| 1527 | result = cnx->egl.eglGetSyncAttribKHR( |
| 1528 | dp->disp.dpy, sync, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1529 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1530 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 1533 | EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list) |
| 1534 | { |
| 1535 | clearError(); |
| 1536 | |
| 1537 | const egl_display_ptr dp = validate_display(dpy); |
| 1538 | if (!dp) return EGL_NO_STREAM_KHR; |
| 1539 | |
| 1540 | EGLStreamKHR result = EGL_NO_STREAM_KHR; |
| 1541 | egl_connection_t* const cnx = &gEGLImpl; |
| 1542 | if (cnx->dso && cnx->egl.eglCreateStreamKHR) { |
| 1543 | result = cnx->egl.eglCreateStreamKHR( |
| 1544 | dp->disp.dpy, attrib_list); |
| 1545 | } |
| 1546 | return result; |
| 1547 | } |
| 1548 | |
| 1549 | EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream) |
| 1550 | { |
| 1551 | clearError(); |
| 1552 | |
| 1553 | const egl_display_ptr dp = validate_display(dpy); |
| 1554 | if (!dp) return EGL_FALSE; |
| 1555 | |
| 1556 | EGLBoolean result = EGL_FALSE; |
| 1557 | egl_connection_t* const cnx = &gEGLImpl; |
| 1558 | if (cnx->dso && cnx->egl.eglDestroyStreamKHR) { |
| 1559 | result = cnx->egl.eglDestroyStreamKHR( |
| 1560 | dp->disp.dpy, stream); |
| 1561 | } |
| 1562 | return result; |
| 1563 | } |
| 1564 | |
| 1565 | EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1566 | EGLenum attribute, EGLint value) |
| 1567 | { |
| 1568 | clearError(); |
| 1569 | |
| 1570 | const egl_display_ptr dp = validate_display(dpy); |
| 1571 | if (!dp) return EGL_FALSE; |
| 1572 | |
| 1573 | EGLBoolean result = EGL_FALSE; |
| 1574 | egl_connection_t* const cnx = &gEGLImpl; |
| 1575 | if (cnx->dso && cnx->egl.eglStreamAttribKHR) { |
| 1576 | result = cnx->egl.eglStreamAttribKHR( |
| 1577 | dp->disp.dpy, stream, attribute, value); |
| 1578 | } |
| 1579 | return result; |
| 1580 | } |
| 1581 | |
| 1582 | EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1583 | EGLenum attribute, EGLint *value) |
| 1584 | { |
| 1585 | clearError(); |
| 1586 | |
| 1587 | const egl_display_ptr dp = validate_display(dpy); |
| 1588 | if (!dp) return EGL_FALSE; |
| 1589 | |
| 1590 | EGLBoolean result = EGL_FALSE; |
| 1591 | egl_connection_t* const cnx = &gEGLImpl; |
| 1592 | if (cnx->dso && cnx->egl.eglQueryStreamKHR) { |
| 1593 | result = cnx->egl.eglQueryStreamKHR( |
| 1594 | dp->disp.dpy, stream, attribute, value); |
| 1595 | } |
| 1596 | return result; |
| 1597 | } |
| 1598 | |
| 1599 | EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1600 | EGLenum attribute, EGLuint64KHR *value) |
| 1601 | { |
| 1602 | clearError(); |
| 1603 | |
| 1604 | const egl_display_ptr dp = validate_display(dpy); |
| 1605 | if (!dp) return EGL_FALSE; |
| 1606 | |
| 1607 | EGLBoolean result = EGL_FALSE; |
| 1608 | egl_connection_t* const cnx = &gEGLImpl; |
| 1609 | if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) { |
| 1610 | result = cnx->egl.eglQueryStreamu64KHR( |
| 1611 | dp->disp.dpy, stream, attribute, value); |
| 1612 | } |
| 1613 | return result; |
| 1614 | } |
| 1615 | |
| 1616 | EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1617 | EGLenum attribute, EGLTimeKHR *value) |
| 1618 | { |
| 1619 | clearError(); |
| 1620 | |
| 1621 | const egl_display_ptr dp = validate_display(dpy); |
| 1622 | if (!dp) return EGL_FALSE; |
| 1623 | |
| 1624 | EGLBoolean result = EGL_FALSE; |
| 1625 | egl_connection_t* const cnx = &gEGLImpl; |
| 1626 | if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) { |
| 1627 | result = cnx->egl.eglQueryStreamTimeKHR( |
| 1628 | dp->disp.dpy, stream, attribute, value); |
| 1629 | } |
| 1630 | return result; |
| 1631 | } |
| 1632 | |
| 1633 | EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, |
| 1634 | EGLStreamKHR stream, const EGLint *attrib_list) |
| 1635 | { |
| 1636 | clearError(); |
| 1637 | |
| 1638 | egl_display_ptr dp = validate_display(dpy); |
| 1639 | if (!dp) return EGL_NO_SURFACE; |
| 1640 | |
| 1641 | egl_connection_t* const cnx = &gEGLImpl; |
| 1642 | if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) { |
| 1643 | EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR( |
| 1644 | dp->disp.dpy, config, stream, attrib_list); |
| 1645 | if (surface != EGL_NO_SURFACE) { |
| 1646 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 1647 | surface, cnx); |
| 1648 | return s; |
| 1649 | } |
| 1650 | } |
| 1651 | return EGL_NO_SURFACE; |
| 1652 | } |
| 1653 | |
| 1654 | EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, |
| 1655 | EGLStreamKHR stream) |
| 1656 | { |
| 1657 | clearError(); |
| 1658 | |
| 1659 | const egl_display_ptr dp = validate_display(dpy); |
| 1660 | if (!dp) return EGL_FALSE; |
| 1661 | |
| 1662 | EGLBoolean result = EGL_FALSE; |
| 1663 | egl_connection_t* const cnx = &gEGLImpl; |
| 1664 | if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) { |
| 1665 | result = cnx->egl.eglStreamConsumerGLTextureExternalKHR( |
| 1666 | dp->disp.dpy, stream); |
| 1667 | } |
| 1668 | return result; |
| 1669 | } |
| 1670 | |
| 1671 | EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy, |
| 1672 | EGLStreamKHR stream) |
| 1673 | { |
| 1674 | clearError(); |
| 1675 | |
| 1676 | const egl_display_ptr dp = validate_display(dpy); |
| 1677 | if (!dp) return EGL_FALSE; |
| 1678 | |
| 1679 | EGLBoolean result = EGL_FALSE; |
| 1680 | egl_connection_t* const cnx = &gEGLImpl; |
| 1681 | if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) { |
| 1682 | result = cnx->egl.eglStreamConsumerAcquireKHR( |
| 1683 | dp->disp.dpy, stream); |
| 1684 | } |
| 1685 | return result; |
| 1686 | } |
| 1687 | |
| 1688 | EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy, |
| 1689 | EGLStreamKHR stream) |
| 1690 | { |
| 1691 | clearError(); |
| 1692 | |
| 1693 | const egl_display_ptr dp = validate_display(dpy); |
| 1694 | if (!dp) return EGL_FALSE; |
| 1695 | |
| 1696 | EGLBoolean result = EGL_FALSE; |
| 1697 | egl_connection_t* const cnx = &gEGLImpl; |
| 1698 | if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) { |
| 1699 | result = cnx->egl.eglStreamConsumerReleaseKHR( |
| 1700 | dp->disp.dpy, stream); |
| 1701 | } |
| 1702 | return result; |
| 1703 | } |
| 1704 | |
| 1705 | EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR( |
| 1706 | EGLDisplay dpy, EGLStreamKHR stream) |
| 1707 | { |
| 1708 | clearError(); |
| 1709 | |
| 1710 | const egl_display_ptr dp = validate_display(dpy); |
| 1711 | if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR; |
| 1712 | |
| 1713 | EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR; |
| 1714 | egl_connection_t* const cnx = &gEGLImpl; |
| 1715 | if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) { |
| 1716 | result = cnx->egl.eglGetStreamFileDescriptorKHR( |
| 1717 | dp->disp.dpy, stream); |
| 1718 | } |
| 1719 | return result; |
| 1720 | } |
| 1721 | |
| 1722 | EGLStreamKHR eglCreateStreamFromFileDescriptorKHR( |
| 1723 | EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor) |
| 1724 | { |
| 1725 | clearError(); |
| 1726 | |
| 1727 | const egl_display_ptr dp = validate_display(dpy); |
| 1728 | if (!dp) return EGL_NO_STREAM_KHR; |
| 1729 | |
| 1730 | EGLStreamKHR result = EGL_NO_STREAM_KHR; |
| 1731 | egl_connection_t* const cnx = &gEGLImpl; |
| 1732 | if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) { |
| 1733 | result = cnx->egl.eglCreateStreamFromFileDescriptorKHR( |
| 1734 | dp->disp.dpy, file_descriptor); |
| 1735 | } |
| 1736 | return result; |
| 1737 | } |
| 1738 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1739 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 1740 | // EGL_EGLEXT_VERSION 15 |
| 1741 | // ---------------------------------------------------------------------------- |
| 1742 | |
| 1743 | EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { |
| 1744 | clearError(); |
| 1745 | const egl_display_ptr dp = validate_display(dpy); |
| 1746 | if (!dp) return EGL_FALSE; |
| 1747 | EGLint result = EGL_FALSE; |
| 1748 | egl_connection_t* const cnx = &gEGLImpl; |
| 1749 | if (cnx->dso && cnx->egl.eglWaitSyncKHR) { |
| 1750 | result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); |
| 1751 | } |
| 1752 | return result; |
| 1753 | } |
| 1754 | |
| 1755 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1756 | // ANDROID extensions |
| 1757 | // ---------------------------------------------------------------------------- |
| 1758 | |
Jamie Gennis | 331841b | 2012-09-06 14:52:00 -0700 | [diff] [blame] | 1759 | EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) |
| 1760 | { |
| 1761 | clearError(); |
| 1762 | |
| 1763 | const egl_display_ptr dp = validate_display(dpy); |
| 1764 | if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1765 | |
| 1766 | EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1767 | egl_connection_t* const cnx = &gEGLImpl; |
| 1768 | if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { |
| 1769 | result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); |
| 1770 | } |
| 1771 | return result; |
| 1772 | } |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1773 | |
Andy McFadden | 7284145 | 2013-03-01 16:25:32 -0800 | [diff] [blame] | 1774 | EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, |
| 1775 | EGLnsecsANDROID time) |
| 1776 | { |
| 1777 | clearError(); |
| 1778 | |
| 1779 | const egl_display_ptr dp = validate_display(dpy); |
| 1780 | if (!dp) { |
| 1781 | return EGL_FALSE; |
| 1782 | } |
| 1783 | |
| 1784 | SurfaceRef _s(dp.get(), surface); |
| 1785 | if (!_s.get()) { |
| 1786 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1787 | return EGL_FALSE; |
| 1788 | } |
| 1789 | |
| 1790 | egl_surface_t const * const s = get_surface(surface); |
| 1791 | native_window_set_buffers_timestamp(s->win.get(), time); |
| 1792 | |
| 1793 | return EGL_TRUE; |
| 1794 | } |
| 1795 | |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1796 | EGLClientBuffer eglCreateNativeClientBufferANDROID(const EGLint *attrib_list) |
| 1797 | { |
| 1798 | clearError(); |
| 1799 | |
| 1800 | int usage = 0; |
| 1801 | uint32_t width = 0; |
| 1802 | uint32_t height = 0; |
| 1803 | uint32_t format = 0; |
| 1804 | uint32_t red_size = 0; |
| 1805 | uint32_t green_size = 0; |
| 1806 | uint32_t blue_size = 0; |
| 1807 | uint32_t alpha_size = 0; |
| 1808 | |
Craig Donner | b40504a | 2016-06-03 17:54:25 -0700 | [diff] [blame] | 1809 | #define GET_NONNEGATIVE_VALUE(case_name, target) \ |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1810 | case case_name: \ |
Craig Donner | b40504a | 2016-06-03 17:54:25 -0700 | [diff] [blame] | 1811 | if (value >= 0) { \ |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1812 | target = value; \ |
| 1813 | } else { \ |
| 1814 | return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); \ |
| 1815 | } \ |
| 1816 | break |
| 1817 | |
| 1818 | if (attrib_list) { |
| 1819 | while (*attrib_list != EGL_NONE) { |
| 1820 | GLint attr = *attrib_list++; |
| 1821 | GLint value = *attrib_list++; |
| 1822 | switch (attr) { |
Craig Donner | b40504a | 2016-06-03 17:54:25 -0700 | [diff] [blame] | 1823 | GET_NONNEGATIVE_VALUE(EGL_WIDTH, width); |
| 1824 | GET_NONNEGATIVE_VALUE(EGL_HEIGHT, height); |
| 1825 | GET_NONNEGATIVE_VALUE(EGL_RED_SIZE, red_size); |
| 1826 | GET_NONNEGATIVE_VALUE(EGL_GREEN_SIZE, green_size); |
| 1827 | GET_NONNEGATIVE_VALUE(EGL_BLUE_SIZE, blue_size); |
| 1828 | GET_NONNEGATIVE_VALUE(EGL_ALPHA_SIZE, alpha_size); |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1829 | case EGL_NATIVE_BUFFER_USAGE_ANDROID: |
| 1830 | if (value & EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID) { |
| 1831 | usage |= GRALLOC_USAGE_PROTECTED; |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1832 | } |
Craig Donner | 8cfae6d | 2016-04-12 16:54:03 -0700 | [diff] [blame] | 1833 | if (value & EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID) { |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1834 | usage |= GRALLOC_USAGE_HW_RENDER; |
| 1835 | } |
Craig Donner | 8cfae6d | 2016-04-12 16:54:03 -0700 | [diff] [blame] | 1836 | if (value & EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID) { |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1837 | usage |= GRALLOC_USAGE_HW_TEXTURE; |
| 1838 | } |
| 1839 | // The buffer must be used for either a texture or a |
| 1840 | // renderbuffer. |
Craig Donner | 8cfae6d | 2016-04-12 16:54:03 -0700 | [diff] [blame] | 1841 | if ((value & EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID) && |
| 1842 | (value & EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID)) { |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1843 | return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); |
| 1844 | } |
| 1845 | break; |
| 1846 | default: |
| 1847 | return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); |
| 1848 | } |
| 1849 | } |
| 1850 | } |
Craig Donner | b40504a | 2016-06-03 17:54:25 -0700 | [diff] [blame] | 1851 | #undef GET_NONNEGATIVE_VALUE |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1852 | |
| 1853 | // Validate format. |
| 1854 | if (red_size == 8 && green_size == 8 && blue_size == 8) { |
| 1855 | if (alpha_size == 8) { |
| 1856 | format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 1857 | } else { |
| 1858 | format = HAL_PIXEL_FORMAT_RGB_888; |
| 1859 | } |
| 1860 | } else if (red_size == 5 && green_size == 6 && blue_size == 5 && |
| 1861 | alpha_size == 0) { |
Craig Donner | 478f7db | 2016-06-10 17:20:15 -0700 | [diff] [blame] | 1862 | format = HAL_PIXEL_FORMAT_RGB_565; |
Craig Donner | 05249fc | 2016-01-15 19:33:55 -0800 | [diff] [blame] | 1863 | } else { |
| 1864 | ALOGE("Invalid native pixel format { r=%d, g=%d, b=%d, a=%d }", |
| 1865 | red_size, green_size, blue_size, alpha_size); |
| 1866 | return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); |
| 1867 | } |
| 1868 | |
| 1869 | GraphicBuffer* gBuffer = new GraphicBuffer(width, height, format, usage); |
| 1870 | const status_t err = gBuffer->initCheck(); |
| 1871 | if (err != NO_ERROR) { |
| 1872 | ALOGE("Unable to create native buffer { w=%d, h=%d, f=%d, u=%#x }: %#x", |
| 1873 | width, height, format, usage, err); |
| 1874 | // Destroy the buffer. |
| 1875 | sp<GraphicBuffer> holder(gBuffer); |
| 1876 | return setError(EGL_BAD_ALLOC, (EGLClientBuffer)0); |
| 1877 | } |
| 1878 | ALOGD("Created new native buffer %p { w=%d, h=%d, f=%d, u=%#x }", |
| 1879 | gBuffer, width, height, format, usage); |
| 1880 | return static_cast<EGLClientBuffer>(gBuffer->getNativeBuffer()); |
| 1881 | } |
| 1882 | |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1883 | // ---------------------------------------------------------------------------- |
| 1884 | // NVIDIA extensions |
| 1885 | // ---------------------------------------------------------------------------- |
| 1886 | EGLuint64NV eglGetSystemTimeFrequencyNV() |
| 1887 | { |
| 1888 | clearError(); |
| 1889 | |
| 1890 | if (egl_init_drivers() == EGL_FALSE) { |
| 1891 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1892 | } |
| 1893 | |
| 1894 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1895 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1896 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1897 | if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { |
| 1898 | return cnx->egl.eglGetSystemTimeFrequencyNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1899 | } |
| 1900 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1901 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | EGLuint64NV eglGetSystemTimeNV() |
| 1905 | { |
| 1906 | clearError(); |
| 1907 | |
| 1908 | if (egl_init_drivers() == EGL_FALSE) { |
| 1909 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1910 | } |
| 1911 | |
| 1912 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1913 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1914 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1915 | if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { |
| 1916 | return cnx->egl.eglGetSystemTimeNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1917 | } |
| 1918 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1919 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1920 | } |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1921 | |
| 1922 | // ---------------------------------------------------------------------------- |
| 1923 | // Partial update extension |
| 1924 | // ---------------------------------------------------------------------------- |
| 1925 | EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, |
| 1926 | EGLint *rects, EGLint n_rects) |
| 1927 | { |
| 1928 | clearError(); |
| 1929 | |
| 1930 | const egl_display_ptr dp = validate_display(dpy); |
| 1931 | if (!dp) { |
| 1932 | setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1933 | return EGL_FALSE; |
| 1934 | } |
| 1935 | |
| 1936 | SurfaceRef _s(dp.get(), surface); |
| 1937 | if (!_s.get()) { |
| 1938 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1939 | return EGL_FALSE; |
| 1940 | } |
| 1941 | |
| 1942 | egl_surface_t const * const s = get_surface(surface); |
| 1943 | if (s->cnx->egl.eglSetDamageRegionKHR) { |
| 1944 | return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, |
| 1945 | rects, n_rects); |
| 1946 | } |
| 1947 | |
| 1948 | return EGL_FALSE; |
| 1949 | } |
Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1950 | |
| 1951 | EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface, |
| 1952 | EGLint framesAgo, EGLint numTimestamps, const EGLint *timestamps, |
| 1953 | EGLnsecsANDROID *values) |
| 1954 | { |
| 1955 | clearError(); |
| 1956 | |
| 1957 | const egl_display_ptr dp = validate_display(dpy); |
| 1958 | if (!dp) { |
| 1959 | setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1960 | return EGL_FALSE; |
| 1961 | } |
| 1962 | |
| 1963 | SurfaceRef _s(dp.get(), surface); |
| 1964 | if (!_s.get()) { |
| 1965 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1966 | return EGL_FALSE; |
| 1967 | } |
| 1968 | |
| 1969 | egl_surface_t const * const s = get_surface(surface); |
| 1970 | |
| 1971 | if (!s->enableTimestamps) { |
| 1972 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1973 | return EGL_FALSE; |
| 1974 | } |
| 1975 | |
| 1976 | nsecs_t* postedTime = nullptr; |
| 1977 | nsecs_t* acquireTime = nullptr; |
| 1978 | nsecs_t* refreshStartTime = nullptr; |
| 1979 | nsecs_t* GLCompositionDoneTime = nullptr; |
| 1980 | nsecs_t* displayRetireTime = nullptr; |
| 1981 | nsecs_t* releaseTime = nullptr; |
| 1982 | |
| 1983 | for (int i = 0; i < numTimestamps; i++) { |
| 1984 | switch (timestamps[i]) { |
| 1985 | case EGL_QUEUE_TIME_ANDROID: |
| 1986 | postedTime = &values[i]; |
| 1987 | break; |
| 1988 | case EGL_RENDERING_COMPLETE_TIME_ANDROID: |
| 1989 | acquireTime = &values[i]; |
| 1990 | break; |
| 1991 | case EGL_COMPOSITION_START_TIME_ANDROID: |
| 1992 | refreshStartTime = &values[i]; |
| 1993 | break; |
| 1994 | case EGL_COMPOSITION_FINISHED_TIME_ANDROID: |
| 1995 | GLCompositionDoneTime = &values[i]; |
| 1996 | break; |
| 1997 | case EGL_DISPLAY_RETIRE_TIME_ANDROID: |
| 1998 | displayRetireTime = &values[i]; |
| 1999 | break; |
| 2000 | case EGL_READS_DONE_TIME_ANDROID: |
| 2001 | releaseTime = &values[i]; |
| 2002 | break; |
| 2003 | default: |
| 2004 | setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 2005 | return EGL_FALSE; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | status_t ret = native_window_get_frame_timestamps(s->win.get(), framesAgo, |
| 2010 | postedTime, acquireTime, refreshStartTime, GLCompositionDoneTime, |
| 2011 | displayRetireTime, releaseTime); |
| 2012 | |
| 2013 | if (ret != NO_ERROR) { |
| 2014 | setError(EGL_BAD_ACCESS, EGL_FALSE); |
| 2015 | return EGL_FALSE; |
| 2016 | } |
| 2017 | |
| 2018 | return EGL_TRUE; |
| 2019 | } |
| 2020 | |
| 2021 | EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface surface, |
| 2022 | EGLint timestamp) |
| 2023 | { |
| 2024 | clearError(); |
| 2025 | |
| 2026 | const egl_display_ptr dp = validate_display(dpy); |
| 2027 | if (!dp) { |
| 2028 | setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 2029 | return EGL_FALSE; |
| 2030 | } |
| 2031 | |
| 2032 | SurfaceRef _s(dp.get(), surface); |
| 2033 | if (!_s.get()) { |
| 2034 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 2035 | return EGL_FALSE; |
| 2036 | } |
| 2037 | |
| 2038 | switch (timestamp) { |
| 2039 | case EGL_QUEUE_TIME_ANDROID: |
| 2040 | case EGL_RENDERING_COMPLETE_TIME_ANDROID: |
| 2041 | case EGL_COMPOSITION_START_TIME_ANDROID: |
| 2042 | case EGL_COMPOSITION_FINISHED_TIME_ANDROID: |
| 2043 | case EGL_DISPLAY_RETIRE_TIME_ANDROID: |
| 2044 | case EGL_READS_DONE_TIME_ANDROID: |
| 2045 | return EGL_TRUE; |
| 2046 | default: |
| 2047 | return EGL_FALSE; |
| 2048 | } |
| 2049 | } |