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