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