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