| 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 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 19 | #include <ctype.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 20 | #include <dlfcn.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 21 | #include <stdlib.h> | 
|  | 22 | #include <string.h> | 
|  | 23 |  | 
| Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 24 | #include <hardware/gralloc1.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 25 |  | 
|  | 26 | #include <EGL/egl.h> | 
|  | 27 | #include <EGL/eglext.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 28 |  | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 29 | #include <android/hardware_buffer.h> | 
| Mathias Agopian | 89ed4c8 | 2017-02-09 18:48:34 -0800 | [diff] [blame] | 30 | #include <private/android/AHardwareBufferHelpers.h> | 
|  | 31 |  | 
| Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 32 | #include <cutils/compiler.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 33 | #include <cutils/properties.h> | 
| Mark Salyzyn | 7823e12 | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 34 | #include <log/log.h> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 35 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 36 | #include <condition_variable> | 
|  | 37 | #include <deque> | 
|  | 38 | #include <mutex> | 
|  | 39 | #include <unordered_map> | 
|  | 40 | #include <string> | 
|  | 41 | #include <thread> | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 42 |  | 
| Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 43 | #include "../egl_impl.h" | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | #include "egl_display.h" | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 46 | #include "egl_object.h" | 
|  | 47 | #include "egl_tls.h" | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 48 | #include "egl_trace.h" | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | using namespace android; | 
|  | 51 |  | 
|  | 52 | // ---------------------------------------------------------------------------- | 
|  | 53 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 54 | namespace android { | 
|  | 55 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 56 | using nsecs_t = int64_t; | 
|  | 57 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 58 | struct extention_map_t { | 
|  | 59 | const char* name; | 
|  | 60 | __eglMustCastToProperFunctionPointerType address; | 
|  | 61 | }; | 
|  | 62 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 63 | /* | 
| Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 64 | * This is the list of EGL extensions exposed to applications. | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 65 | * | 
| Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 66 | * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL | 
|  | 67 | * wrapper and are always available. | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 68 | * | 
| Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 69 | * The rest (gExtensionString) depend on support in the EGL driver, and are | 
|  | 70 | * only available if the driver supports them. However, some of these must be | 
|  | 71 | * supported because they are used by the Android system itself; these are | 
| Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 72 | * 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] | 73 | * the mandatory extensions are present and may not function properly if some | 
|  | 74 | * are missing. | 
|  | 75 | * | 
|  | 76 | * NOTE: Both strings MUST have a single space as the last character. | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 77 | */ | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 78 |  | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 79 | extern char const * const gBuiltinExtensionString; | 
|  | 80 | extern char const * const gExtensionString; | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 81 |  | 
| Courtney Goeltzenleuchter | 21b33cb | 2017-04-17 17:31:29 -0600 | [diff] [blame] | 82 | // clang-format off | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 83 | char const * const gBuiltinExtensionString = | 
| Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 84 | "EGL_KHR_get_all_proc_addresses " | 
|  | 85 | "EGL_ANDROID_presentation_time " | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 86 | "EGL_KHR_swap_buffers_with_damage " | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 87 | "EGL_ANDROID_get_native_client_buffer " | 
| Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 88 | "EGL_ANDROID_front_buffer_auto_refresh " | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 89 | "EGL_ANDROID_get_frame_timestamps " | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 90 | "EGL_EXT_surface_SMPTE2086_metadata " | 
|  | 91 | "EGL_EXT_surface_CTA861_3_metadata " | 
| Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 92 | ; | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 93 |  | 
|  | 94 | char const * const gExtensionString  = | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 95 | "EGL_KHR_image "                        // mandatory | 
|  | 96 | "EGL_KHR_image_base "                   // mandatory | 
| Krzysztof KosiĆski | 4245cba | 2018-03-30 16:21:39 -0700 | [diff] [blame] | 97 | "EGL_KHR_image_gl_colorspace " | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 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 | 
| Courtney Goeltzenleuchter | 0e4e395 | 2016-11-16 13:53:40 -0700 | [diff] [blame] | 121 | "EGL_EXT_pixel_format_float " | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 122 | "EGL_EXT_buffer_age "                   // strongly recommended with partial_update | 
| Jesse Hall | 408e59f | 2015-04-24 01:40:42 -0700 | [diff] [blame] | 123 | "EGL_KHR_create_context_no_error " | 
| Pablo Ceballos | ceb9ee7 | 2016-04-13 11:17:32 -0700 | [diff] [blame] | 124 | "EGL_KHR_mutable_render_buffer " | 
| Mika IsojÀrvi | f37864b | 2016-04-15 11:58:56 -0700 | [diff] [blame] | 125 | "EGL_EXT_yuv_surface " | 
| Craig Donner | aec8697 | 2016-04-28 18:09:40 -0700 | [diff] [blame] | 126 | "EGL_EXT_protected_content " | 
| Christian Poetzsch | a7805f6 | 2016-12-01 16:34:39 +0000 | [diff] [blame] | 127 | "EGL_IMG_context_priority " | 
| Pyry Haulos | 51d53c4 | 2017-03-06 09:39:09 -0800 | [diff] [blame] | 128 | "EGL_KHR_no_config_context " | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 129 | ; | 
| Courtney Goeltzenleuchter | 21b33cb | 2017-04-17 17:31:29 -0600 | [diff] [blame] | 130 | // clang-format on | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 131 |  | 
|  | 132 | // extensions not exposed to applications but used by the ANDROID system | 
|  | 133 | //      "EGL_ANDROID_blob_cache "               // strongly recommended | 
|  | 134 | //      "EGL_IMG_hibernate_process "            // optional | 
|  | 135 | //      "EGL_ANDROID_native_fence_sync "        // strongly recommended | 
|  | 136 | //      "EGL_ANDROID_framebuffer_target "       // mandatory for HWC 1.1 | 
| Jamie Gennis | dbe9245 | 2013-09-23 17:22:10 -0700 | [diff] [blame] | 137 | //      "EGL_ANDROID_image_crop "               // optional | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 138 |  | 
|  | 139 | /* | 
|  | 140 | * EGL Extensions entry-points exposed to 3rd party applications | 
|  | 141 | * (keep in sync with gExtensionString above) | 
|  | 142 | * | 
|  | 143 | */ | 
|  | 144 | static const extention_map_t sExtensionMap[] = { | 
|  | 145 | // EGL_KHR_lock_surface | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 146 | { "eglLockSurfaceKHR", | 
|  | 147 | (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, | 
|  | 148 | { "eglUnlockSurfaceKHR", | 
|  | 149 | (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 150 |  | 
|  | 151 | // EGL_KHR_image, EGL_KHR_image_base | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 152 | { "eglCreateImageKHR", | 
|  | 153 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, | 
|  | 154 | { "eglDestroyImageKHR", | 
|  | 155 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 156 |  | 
|  | 157 | // EGL_KHR_reusable_sync, EGL_KHR_fence_sync | 
|  | 158 | { "eglCreateSyncKHR", | 
|  | 159 | (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, | 
|  | 160 | { "eglDestroySyncKHR", | 
|  | 161 | (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, | 
|  | 162 | { "eglClientWaitSyncKHR", | 
|  | 163 | (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, | 
|  | 164 | { "eglSignalSyncKHR", | 
|  | 165 | (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, | 
|  | 166 | { "eglGetSyncAttribKHR", | 
|  | 167 | (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, | 
|  | 168 |  | 
|  | 169 | // EGL_NV_system_time | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 170 | { "eglGetSystemTimeFrequencyNV", | 
|  | 171 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, | 
|  | 172 | { "eglGetSystemTimeNV", | 
|  | 173 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 174 |  | 
| Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 175 | // EGL_KHR_wait_sync | 
|  | 176 | { "eglWaitSyncKHR", | 
|  | 177 | (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 178 |  | 
|  | 179 | // EGL_ANDROID_presentation_time | 
|  | 180 | { "eglPresentationTimeANDROID", | 
|  | 181 | (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 182 |  | 
|  | 183 | // EGL_KHR_swap_buffers_with_damage | 
|  | 184 | { "eglSwapBuffersWithDamageKHR", | 
|  | 185 | (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR }, | 
|  | 186 |  | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 187 | // EGL_ANDROID_get_native_client_buffer | 
|  | 188 | { "eglGetNativeClientBufferANDROID", | 
|  | 189 | (__eglMustCastToProperFunctionPointerType)&eglGetNativeClientBufferANDROID }, | 
|  | 190 |  | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 191 | // EGL_KHR_partial_update | 
|  | 192 | { "eglSetDamageRegionKHR", | 
|  | 193 | (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, | 
| Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 194 |  | 
|  | 195 | { "eglCreateStreamKHR", | 
|  | 196 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR }, | 
|  | 197 | { "eglDestroyStreamKHR", | 
|  | 198 | (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR }, | 
|  | 199 | { "eglStreamAttribKHR", | 
|  | 200 | (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR }, | 
|  | 201 | { "eglQueryStreamKHR", | 
|  | 202 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR }, | 
|  | 203 | { "eglQueryStreamu64KHR", | 
|  | 204 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR }, | 
|  | 205 | { "eglQueryStreamTimeKHR", | 
|  | 206 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR }, | 
|  | 207 | { "eglCreateStreamProducerSurfaceKHR", | 
|  | 208 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR }, | 
|  | 209 | { "eglStreamConsumerGLTextureExternalKHR", | 
|  | 210 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR }, | 
|  | 211 | { "eglStreamConsumerAcquireKHR", | 
|  | 212 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR }, | 
|  | 213 | { "eglStreamConsumerReleaseKHR", | 
|  | 214 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR }, | 
|  | 215 | { "eglGetStreamFileDescriptorKHR", | 
|  | 216 | (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR }, | 
|  | 217 | { "eglCreateStreamFromFileDescriptorKHR", | 
|  | 218 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR }, | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 219 |  | 
|  | 220 | // EGL_ANDROID_get_frame_timestamps | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 221 | { "eglGetNextFrameIdANDROID", | 
|  | 222 | (__eglMustCastToProperFunctionPointerType)&eglGetNextFrameIdANDROID }, | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 223 | { "eglGetCompositorTimingANDROID", | 
|  | 224 | (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingANDROID }, | 
|  | 225 | { "eglGetCompositorTimingSupportedANDROID", | 
|  | 226 | (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingSupportedANDROID }, | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 227 | { "eglGetFrameTimestampsANDROID", | 
|  | 228 | (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID }, | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 229 | { "eglGetFrameTimestampSupportedANDROID", | 
|  | 230 | (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampSupportedANDROID }, | 
| Craig Donner | 55901a2 | 2017-04-17 15:31:06 -0700 | [diff] [blame] | 231 |  | 
|  | 232 | // EGL_ANDROID_native_fence_sync | 
|  | 233 | { "eglDupNativeFenceFDANDROID", | 
|  | 234 | (__eglMustCastToProperFunctionPointerType)&eglDupNativeFenceFDANDROID }, | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 235 | }; | 
|  | 236 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 237 | /* | 
|  | 238 | * These extensions entry-points should not be exposed to applications. | 
|  | 239 | * They're used internally by the Android EGL layer. | 
|  | 240 | */ | 
|  | 241 | #define FILTER_EXTENSIONS(procname) \ | 
|  | 242 | (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") ||    \ | 
|  | 243 | !strcmp((procname), "eglHibernateProcessIMG")      ||    \ | 
| Craig Donner | 55901a2 | 2017-04-17 15:31:06 -0700 | [diff] [blame] | 244 | !strcmp((procname), "eglAwakenProcessIMG")) | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 245 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 246 | // accesses protected by sExtensionMapMutex | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 247 | static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; | 
|  | 248 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 249 | static int sGLExtentionSlot = 0; | 
|  | 250 | static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; | 
|  | 251 |  | 
|  | 252 | static void(*findProcAddress(const char* name, | 
|  | 253 | const extention_map_t* map, size_t n))() { | 
|  | 254 | for (uint32_t i=0 ; i<n ; i++) { | 
|  | 255 | if (!strcmp(name, map[i].name)) { | 
|  | 256 | return map[i].address; | 
|  | 257 | } | 
|  | 258 | } | 
|  | 259 | return NULL; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | // ---------------------------------------------------------------------------- | 
|  | 263 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 264 | extern void setGLHooksThreadSpecific(gl_hooks_t const *value); | 
|  | 265 | extern EGLBoolean egl_init_drivers(); | 
|  | 266 | extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 267 | extern gl_hooks_t gHooksTrace; | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 268 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 269 | } // namespace android; | 
|  | 270 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 271 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 272 | // ---------------------------------------------------------------------------- | 
|  | 273 |  | 
|  | 274 | static inline void clearError() { egl_tls_t::clearError(); } | 
|  | 275 | static inline EGLContext getContext() { return egl_tls_t::getContext(); } | 
|  | 276 |  | 
|  | 277 | // ---------------------------------------------------------------------------- | 
|  | 278 |  | 
|  | 279 | EGLDisplay eglGetDisplay(EGLNativeDisplayType display) | 
|  | 280 | { | 
| Jesse Hall | 1508ae6 | 2017-01-19 17:43:26 -0800 | [diff] [blame] | 281 | ATRACE_CALL(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 282 | clearError(); | 
|  | 283 |  | 
| Dan Stoza | c3289c4 | 2014-01-17 11:38:34 -0800 | [diff] [blame] | 284 | uintptr_t index = reinterpret_cast<uintptr_t>(display); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 285 | if (index >= NUM_DISPLAYS) { | 
|  | 286 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | if (egl_init_drivers() == EGL_FALSE) { | 
|  | 290 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); | 
|  | 291 | } | 
|  | 292 |  | 
|  | 293 | EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); | 
|  | 294 | return dpy; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | // ---------------------------------------------------------------------------- | 
|  | 298 | // Initialization | 
|  | 299 | // ---------------------------------------------------------------------------- | 
|  | 300 |  | 
|  | 301 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) | 
|  | 302 | { | 
|  | 303 | clearError(); | 
|  | 304 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 305 | egl_display_ptr dp = get_display(dpy); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 306 | if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 307 |  | 
|  | 308 | EGLBoolean res = dp->initialize(major, minor); | 
|  | 309 |  | 
|  | 310 | return res; | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | EGLBoolean eglTerminate(EGLDisplay dpy) | 
|  | 314 | { | 
|  | 315 | // NOTE: don't unload the drivers b/c some APIs can be called | 
|  | 316 | // after eglTerminate() has been called. eglTerminate() only | 
|  | 317 | // terminates an EGLDisplay, not a EGL itself. | 
|  | 318 |  | 
|  | 319 | clearError(); | 
|  | 320 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 321 | egl_display_ptr dp = get_display(dpy); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 322 | if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | EGLBoolean res = dp->terminate(); | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 325 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 326 | return res; | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 | // ---------------------------------------------------------------------------- | 
|  | 330 | // configuration | 
|  | 331 | // ---------------------------------------------------------------------------- | 
|  | 332 |  | 
|  | 333 | EGLBoolean eglGetConfigs(   EGLDisplay dpy, | 
|  | 334 | EGLConfig *configs, | 
|  | 335 | EGLint config_size, EGLint *num_config) | 
|  | 336 | { | 
|  | 337 | clearError(); | 
|  | 338 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 339 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 340 | if (!dp) return EGL_FALSE; | 
|  | 341 |  | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 342 | if (num_config==0) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 343 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 344 | } | 
|  | 345 |  | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 346 | EGLBoolean res = EGL_FALSE; | 
|  | 347 | *num_config = 0; | 
|  | 348 |  | 
|  | 349 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 350 | if (cnx->dso) { | 
|  | 351 | res = cnx->egl.eglGetConfigs( | 
|  | 352 | dp->disp.dpy, configs, config_size, num_config); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 353 | } | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 354 |  | 
|  | 355 | return res; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 356 | } | 
|  | 357 |  | 
|  | 358 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, | 
|  | 359 | EGLConfig *configs, EGLint config_size, | 
|  | 360 | EGLint *num_config) | 
|  | 361 | { | 
|  | 362 | clearError(); | 
|  | 363 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 364 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 365 | if (!dp) return EGL_FALSE; | 
|  | 366 |  | 
|  | 367 | if (num_config==0) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 368 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 369 | } | 
|  | 370 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 371 | EGLBoolean res = EGL_FALSE; | 
|  | 372 | *num_config = 0; | 
|  | 373 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 374 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 375 | if (cnx->dso) { | 
| Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 376 | if (attrib_list) { | 
|  | 377 | char value[PROPERTY_VALUE_MAX]; | 
|  | 378 | property_get("debug.egl.force_msaa", value, "false"); | 
|  | 379 |  | 
|  | 380 | if (!strcmp(value, "true")) { | 
|  | 381 | size_t attribCount = 0; | 
|  | 382 | EGLint attrib = attrib_list[0]; | 
|  | 383 |  | 
|  | 384 | // Only enable MSAA if the context is OpenGL ES 2.0 and | 
| Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 385 | // if no caveat is requested | 
| Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 386 | const EGLint *attribRendererable = NULL; | 
|  | 387 | const EGLint *attribCaveat = NULL; | 
|  | 388 |  | 
|  | 389 | // Count the number of attributes and look for | 
| Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 390 | // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT | 
| Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 391 | while (attrib != EGL_NONE) { | 
|  | 392 | attrib = attrib_list[attribCount]; | 
|  | 393 | switch (attrib) { | 
|  | 394 | case EGL_RENDERABLE_TYPE: | 
|  | 395 | attribRendererable = &attrib_list[attribCount]; | 
|  | 396 | break; | 
|  | 397 | case EGL_CONFIG_CAVEAT: | 
|  | 398 | attribCaveat = &attrib_list[attribCount]; | 
|  | 399 | break; | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 400 | default: | 
|  | 401 | break; | 
| Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 402 | } | 
|  | 403 | attribCount++; | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && | 
|  | 407 | (!attribCaveat || attribCaveat[1] != EGL_NONE)) { | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 408 |  | 
| Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 409 | // Insert 2 extra attributes to force-enable MSAA 4x | 
|  | 410 | EGLint aaAttribs[attribCount + 4]; | 
|  | 411 | aaAttribs[0] = EGL_SAMPLE_BUFFERS; | 
|  | 412 | aaAttribs[1] = 1; | 
|  | 413 | aaAttribs[2] = EGL_SAMPLES; | 
|  | 414 | aaAttribs[3] = 4; | 
|  | 415 |  | 
|  | 416 | memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); | 
|  | 417 |  | 
|  | 418 | EGLint numConfigAA; | 
|  | 419 | EGLBoolean resAA = cnx->egl.eglChooseConfig( | 
|  | 420 | dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); | 
|  | 421 |  | 
|  | 422 | if (resAA == EGL_TRUE && numConfigAA > 0) { | 
|  | 423 | ALOGD("Enabling MSAA 4x"); | 
|  | 424 | *num_config = numConfigAA; | 
|  | 425 | return resAA; | 
|  | 426 | } | 
|  | 427 | } | 
|  | 428 | } | 
|  | 429 | } | 
|  | 430 |  | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 431 | res = cnx->egl.eglChooseConfig( | 
|  | 432 | dp->disp.dpy, attrib_list, configs, config_size, num_config); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 433 | } | 
|  | 434 | return res; | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, | 
|  | 438 | EGLint attribute, EGLint *value) | 
|  | 439 | { | 
|  | 440 | clearError(); | 
|  | 441 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 442 | egl_connection_t* cnx = NULL; | 
|  | 443 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
|  | 444 | if (!dp) return EGL_FALSE; | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 445 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 446 | return cnx->egl.eglGetConfigAttrib( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 447 | dp->disp.dpy, config, attribute, value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 448 | } | 
|  | 449 |  | 
|  | 450 | // ---------------------------------------------------------------------------- | 
|  | 451 | // surfaces | 
|  | 452 | // ---------------------------------------------------------------------------- | 
|  | 453 |  | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 454 | // Turn linear formats into corresponding sRGB formats when colorspace is | 
|  | 455 | // EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear | 
|  | 456 | // 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] | 457 | // the modification isn't possible, the original dataSpace is returned. | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 458 | static android_dataspace modifyBufferDataspace(android_dataspace dataSpace, | 
|  | 459 | EGLint colorspace) { | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 460 | if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 461 | return HAL_DATASPACE_SRGB_LINEAR; | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 462 | } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 463 | return HAL_DATASPACE_SRGB; | 
| Courtney Goeltzenleuchter | 21b33cb | 2017-04-17 17:31:29 -0600 | [diff] [blame] | 464 | } else if (colorspace == EGL_GL_COLORSPACE_DISPLAY_P3_EXT) { | 
|  | 465 | return HAL_DATASPACE_DISPLAY_P3; | 
|  | 466 | } else if (colorspace == EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT) { | 
|  | 467 | return HAL_DATASPACE_DISPLAY_P3_LINEAR; | 
| Courtney Goeltzenleuchter | 33e2b78 | 2017-06-23 09:06:52 -0600 | [diff] [blame] | 468 | } else if (colorspace == EGL_GL_COLORSPACE_SCRGB_EXT) { | 
|  | 469 | return HAL_DATASPACE_V0_SCRGB; | 
| Courtney Goeltzenleuchter | 21b33cb | 2017-04-17 17:31:29 -0600 | [diff] [blame] | 470 | } else if (colorspace == EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT) { | 
|  | 471 | return HAL_DATASPACE_V0_SCRGB_LINEAR; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 472 | } else if (colorspace == EGL_GL_COLORSPACE_BT2020_LINEAR_EXT) { | 
|  | 473 | return HAL_DATASPACE_BT2020_LINEAR; | 
|  | 474 | } else if (colorspace == EGL_GL_COLORSPACE_BT2020_PQ_EXT) { | 
|  | 475 | return HAL_DATASPACE_BT2020_PQ; | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 476 | } | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 477 | return dataSpace; | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 478 | } | 
|  | 479 |  | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 480 | // stripAttributes is used by eglCreateWindowSurface, eglCreatePbufferSurface | 
|  | 481 | // and eglCreatePixmapSurface to clean up color space related Window parameters | 
|  | 482 | // that a driver does not advertise support for. | 
|  | 483 | // Return true if stripped_attrib_list has stripped contents. | 
|  | 484 |  | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 485 | static EGLBoolean stripAttributes(egl_display_ptr dp, const EGLint* attrib_list, | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 486 | EGLint format, | 
|  | 487 | std::vector<EGLint>& stripped_attrib_list) { | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 488 | std::vector<EGLint> allowedColorSpaces; | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 489 | bool haveColorSpaceSupport = dp->haveExtension("EGL_KHR_gl_colorspace"); | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 490 | switch (format) { | 
|  | 491 | case HAL_PIXEL_FORMAT_RGBA_8888: | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 492 | if (haveColorSpaceSupport) { | 
|  | 493 | // Spec says: | 
|  | 494 | //     [fn1] Only OpenGL and OpenGL ES contexts which support sRGB | 
|  | 495 | //     rendering must respect requests for EGL_GL_COLORSPACE_SRGB_KHR, and | 
|  | 496 | //     only to sRGB formats supported by the context (normally just SRGB8) | 
|  | 497 | //     Older versions not supporting sRGB rendering will ignore this | 
|  | 498 | //     surface attribute. | 
|  | 499 | // | 
|  | 500 | // We support sRGB and pixel format is SRGB8, so allow | 
|  | 501 | // the EGL_GL_COLORSPACE_SRGB_KHR and | 
|  | 502 | // EGL_GL_COLORSPACE_LINEAR_KHR | 
|  | 503 | // colorspaces to be specified. | 
|  | 504 |  | 
|  | 505 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_SRGB_KHR); | 
|  | 506 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_LINEAR_KHR); | 
|  | 507 | } | 
|  | 508 | if (findExtension(dp->disp.queryString.extensions, | 
|  | 509 | "EGL_EXT_gl_colorspace_display_p3_linear")) { | 
|  | 510 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT); | 
|  | 511 | } | 
|  | 512 | if (findExtension(dp->disp.queryString.extensions, | 
|  | 513 | "EGL_EXT_gl_colorspace_display_p3")) { | 
|  | 514 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_EXT); | 
|  | 515 | } | 
|  | 516 | if (findExtension(dp->disp.queryString.extensions, | 
|  | 517 | "EGL_EXT_gl_colorspace_bt2020_linear")) { | 
|  | 518 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_BT2020_LINEAR_EXT); | 
|  | 519 | } | 
|  | 520 | if (findExtension(dp->disp.queryString.extensions, | 
|  | 521 | "EGL_EXT_gl_colorspace_bt2020_pq")) { | 
|  | 522 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_BT2020_PQ_EXT); | 
|  | 523 | } | 
|  | 524 | if (findExtension(dp->disp.queryString.extensions, | 
|  | 525 | "EGL_EXT_gl_colorspace_scrgb_linear")) { | 
|  | 526 | allowedColorSpaces.push_back(EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT); | 
|  | 527 | } | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 528 | break; | 
|  | 529 |  | 
|  | 530 | case HAL_PIXEL_FORMAT_RGBA_FP16: | 
|  | 531 | case HAL_PIXEL_FORMAT_RGBA_1010102: | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 532 | case HAL_PIXEL_FORMAT_RGB_565: | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 533 | // Future: if driver supports XXXX extension, we can pass down that colorspace | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 534 | default: | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 535 | break; | 
|  | 536 | } | 
|  | 537 |  | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 538 | if (!attrib_list) return false; | 
|  | 539 |  | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 540 | bool stripped = false; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 541 | for (const EGLint* attr = attrib_list; attr[0] != EGL_NONE; attr += 2) { | 
|  | 542 | switch (attr[0]) { | 
|  | 543 | case EGL_GL_COLORSPACE_KHR: { | 
|  | 544 | EGLint colorSpace = attr[1]; | 
|  | 545 | bool found = false; | 
|  | 546 | // Verify that color space is allowed | 
|  | 547 | for (auto it : allowedColorSpaces) { | 
|  | 548 | if (colorSpace == it) { | 
|  | 549 | found = true; | 
|  | 550 | } | 
|  | 551 | } | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 552 | if (found) { | 
|  | 553 | // Found supported attribute | 
|  | 554 | stripped_attrib_list.push_back(attr[0]); | 
|  | 555 | stripped_attrib_list.push_back(attr[1]); | 
|  | 556 | } else if (!haveColorSpaceSupport) { | 
|  | 557 | // Device does not support colorspace extension | 
|  | 558 | // pass on the attribute and let downstream | 
|  | 559 | // components validate like normal | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 560 | stripped_attrib_list.push_back(attr[0]); | 
|  | 561 | stripped_attrib_list.push_back(attr[1]); | 
| Courtney Goeltzenleuchter | 52de2fd | 2018-02-01 09:51:58 -0700 | [diff] [blame] | 562 | } else { | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 563 | // Found supported attribute that driver does not | 
|  | 564 | // support, strip it. | 
| Courtney Goeltzenleuchter | 52de2fd | 2018-02-01 09:51:58 -0700 | [diff] [blame] | 565 | stripped = true; | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 566 | } | 
|  | 567 | } | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 568 | break; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 569 | default: | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 570 | stripped_attrib_list.push_back(attr[0]); | 
|  | 571 | stripped_attrib_list.push_back(attr[1]); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 572 | break; | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 573 | } | 
|  | 574 | } | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 575 |  | 
|  | 576 | // Make sure there is at least one attribute | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 577 | if (stripped) { | 
|  | 578 | stripped_attrib_list.push_back(EGL_NONE); | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 579 | } | 
|  | 580 | return stripped; | 
|  | 581 | } | 
|  | 582 |  | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 583 | static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, NativeWindowType window, | 
|  | 584 | const EGLint* attrib_list, EGLint& colorSpace, | 
|  | 585 | android_dataspace& dataSpace) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 586 | colorSpace = EGL_GL_COLORSPACE_LINEAR_KHR; | 
|  | 587 | dataSpace = HAL_DATASPACE_UNKNOWN; | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 588 |  | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 589 | if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { | 
|  | 590 | for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { | 
|  | 591 | if (*attr == EGL_GL_COLORSPACE_KHR) { | 
|  | 592 | colorSpace = attr[1]; | 
|  | 593 | bool found = false; | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 594 | bool verify = true; | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 595 | // Verify that color space is allowed | 
|  | 596 | if (colorSpace == EGL_GL_COLORSPACE_SRGB_KHR || | 
|  | 597 | colorSpace == EGL_GL_COLORSPACE_LINEAR_KHR) { | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 598 | // SRGB and LINEAR are always supported when EGL_KHR_gl_colorspace | 
|  | 599 | // is available, so no need to verify. | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 600 | found = true; | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 601 | verify = false; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 602 | } else if (colorSpace == EGL_GL_COLORSPACE_BT2020_LINEAR_EXT && | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 603 | dp->haveExtension("EGL_EXT_gl_colorspace_bt2020_linear")) { | 
|  | 604 | found = true; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 605 | } else if (colorSpace == EGL_GL_COLORSPACE_BT2020_PQ_EXT && | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 606 | dp->haveExtension("EGL_EXT_gl_colorspace_bt2020_pq")) { | 
|  | 607 | found = true; | 
| Courtney Goeltzenleuchter | 33e2b78 | 2017-06-23 09:06:52 -0600 | [diff] [blame] | 608 | } else if (colorSpace == EGL_GL_COLORSPACE_SCRGB_EXT && | 
|  | 609 | dp->haveExtension("EGL_EXT_gl_colorspace_scrgb")) { | 
|  | 610 | found = true; | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 611 | } else if (colorSpace == EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT && | 
|  | 612 | dp->haveExtension("EGL_EXT_gl_colorspace_scrgb_linear")) { | 
|  | 613 | found = true; | 
|  | 614 | } else if (colorSpace == EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT && | 
|  | 615 | dp->haveExtension("EGL_EXT_gl_colorspace_display_p3_linear")) { | 
|  | 616 | found = true; | 
|  | 617 | } else if (colorSpace == EGL_GL_COLORSPACE_DISPLAY_P3_EXT && | 
|  | 618 | dp->haveExtension("EGL_EXT_gl_colorspace_display_p3")) { | 
|  | 619 | found = true; | 
|  | 620 | } | 
|  | 621 | if (!found) { | 
|  | 622 | return false; | 
|  | 623 | } | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 624 | if (verify && window) { | 
|  | 625 | bool wide_color_support = true; | 
|  | 626 | // Ordinarily we'd put a call to native_window_get_wide_color_support | 
|  | 627 | // at the beginning of the function so that we'll have the | 
|  | 628 | // result when needed elsewhere in the function. | 
|  | 629 | // However, because eglCreateWindowSurface is called by SurfaceFlinger and | 
|  | 630 | // SurfaceFlinger is required to answer the call below we would | 
|  | 631 | // end up in a deadlock situation. By moving the call to only happen | 
|  | 632 | // if the application has specifically asked for wide-color we avoid | 
|  | 633 | // the deadlock with SurfaceFlinger since it will not ask for a | 
|  | 634 | // wide-color surface. | 
|  | 635 | int err = native_window_get_wide_color_support(window, &wide_color_support); | 
|  | 636 |  | 
|  | 637 | if (err) { | 
|  | 638 | ALOGE("getColorSpaceAttribute: invalid window (win=%p) " | 
|  | 639 | "failed (%#x) (already connected to another API?)", | 
|  | 640 | window, err); | 
|  | 641 | return false; | 
|  | 642 | } | 
|  | 643 | if (!wide_color_support) { | 
|  | 644 | // Application has asked for a wide-color colorspace but | 
|  | 645 | // wide-color support isn't available on the display the window is on. | 
|  | 646 | return false; | 
|  | 647 | } | 
|  | 648 | } | 
| Courtney Goeltzenleuchter | 1d4f7a2 | 2017-05-05 13:30:25 -0600 | [diff] [blame] | 649 | // Only change the dataSpace from default if the application | 
|  | 650 | // has explicitly set the color space with a EGL_GL_COLORSPACE_KHR attribute. | 
|  | 651 | dataSpace = modifyBufferDataspace(dataSpace, colorSpace); | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 652 | } | 
|  | 653 | } | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 654 | } | 
|  | 655 | return true; | 
|  | 656 | } | 
|  | 657 |  | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 658 | static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, const EGLint* attrib_list, | 
|  | 659 | EGLint& colorSpace, android_dataspace& dataSpace) { | 
|  | 660 | return getColorSpaceAttribute(dp, NULL, attrib_list, colorSpace, dataSpace); | 
|  | 661 | } | 
|  | 662 |  | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 663 | void getNativePixelFormat(EGLDisplay dpy, egl_connection_t* cnx, EGLConfig config, EGLint& format) { | 
|  | 664 | // Set the native window's buffers format to match what this config requests. | 
|  | 665 | // Whether to use sRGB gamma is not part of the EGLconfig, but is part | 
|  | 666 | // of our native format. So if sRGB gamma is requested, we have to | 
|  | 667 | // modify the EGLconfig's format before setting the native window's | 
|  | 668 | // format. | 
|  | 669 |  | 
|  | 670 | EGLint componentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; | 
|  | 671 | cnx->egl.eglGetConfigAttrib(dpy, config, EGL_COLOR_COMPONENT_TYPE_EXT, &componentType); | 
|  | 672 |  | 
|  | 673 | EGLint a = 0; | 
|  | 674 | EGLint r, g, b; | 
|  | 675 | r = g = b = 0; | 
|  | 676 | cnx->egl.eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r); | 
|  | 677 | cnx->egl.eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g); | 
|  | 678 | cnx->egl.eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b); | 
|  | 679 | cnx->egl.eglGetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &a); | 
|  | 680 | EGLint colorDepth = r + g + b; | 
|  | 681 |  | 
|  | 682 | // Today, the driver only understands sRGB and linear on 888X | 
|  | 683 | // formats. Strip other colorspaces from the attribute list and | 
|  | 684 | // only use them to set the dataspace via | 
|  | 685 | // native_window_set_buffers_dataspace | 
|  | 686 | // if pixel format is RGBX 8888 | 
|  | 687 | //    TBD: Can test for future extensions that indicate that driver | 
|  | 688 | //    handles requested color space and we can let it through. | 
|  | 689 | //    allow SRGB and LINEAR. All others need to be stripped. | 
|  | 690 | // else if 565, 4444 | 
|  | 691 | //    TBD: Can we assume these are supported if 8888 is? | 
|  | 692 | // else if FP16 or 1010102 | 
|  | 693 | //    strip colorspace from attribs. | 
|  | 694 | // endif | 
|  | 695 | if (a == 0) { | 
|  | 696 | if (colorDepth <= 16) { | 
|  | 697 | format = HAL_PIXEL_FORMAT_RGB_565; | 
|  | 698 | } else { | 
|  | 699 | if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) { | 
|  | 700 | if (colorDepth > 24) { | 
|  | 701 | format = HAL_PIXEL_FORMAT_RGBA_1010102; | 
|  | 702 | } else { | 
|  | 703 | format = HAL_PIXEL_FORMAT_RGBX_8888; | 
|  | 704 | } | 
|  | 705 | } else { | 
|  | 706 | format = HAL_PIXEL_FORMAT_RGBA_FP16; | 
|  | 707 | } | 
|  | 708 | } | 
|  | 709 | } else { | 
|  | 710 | if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) { | 
|  | 711 | if (colorDepth > 24) { | 
|  | 712 | format = HAL_PIXEL_FORMAT_RGBA_1010102; | 
|  | 713 | } else { | 
|  | 714 | format = HAL_PIXEL_FORMAT_RGBA_8888; | 
|  | 715 | } | 
|  | 716 | } else { | 
|  | 717 | format = HAL_PIXEL_FORMAT_RGBA_FP16; | 
|  | 718 | } | 
|  | 719 | } | 
|  | 720 | } | 
|  | 721 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 722 | EGLBoolean sendSurfaceMetadata(egl_surface_t* s) { | 
|  | 723 | android_smpte2086_metadata smpteMetadata; | 
|  | 724 | if (s->getSmpte2086Metadata(smpteMetadata)) { | 
|  | 725 | int err = | 
|  | 726 | native_window_set_buffers_smpte2086_metadata(s->getNativeWindow(), &smpteMetadata); | 
|  | 727 | s->resetSmpte2086Metadata(); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 728 | if (err != 0) { | 
|  | 729 | ALOGE("error setting native window smpte2086 metadata: %s (%d)", | 
|  | 730 | strerror(-err), err); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 731 | return EGL_FALSE; | 
|  | 732 | } | 
|  | 733 | } | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 734 | android_cta861_3_metadata cta8613Metadata; | 
|  | 735 | if (s->getCta8613Metadata(cta8613Metadata)) { | 
|  | 736 | int err = | 
|  | 737 | native_window_set_buffers_cta861_3_metadata(s->getNativeWindow(), &cta8613Metadata); | 
|  | 738 | s->resetCta8613Metadata(); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 739 | if (err != 0) { | 
|  | 740 | ALOGE("error setting native window CTS 861.3 metadata: %s (%d)", | 
|  | 741 | strerror(-err), err); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 742 | return EGL_FALSE; | 
|  | 743 | } | 
|  | 744 | } | 
|  | 745 | return EGL_TRUE; | 
|  | 746 | } | 
|  | 747 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 748 | EGLSurface eglCreateWindowSurface(  EGLDisplay dpy, EGLConfig config, | 
|  | 749 | NativeWindowType window, | 
|  | 750 | const EGLint *attrib_list) | 
|  | 751 | { | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 752 | const EGLint *origAttribList = attrib_list; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 753 | clearError(); | 
|  | 754 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 755 | egl_connection_t* cnx = NULL; | 
|  | 756 | egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
|  | 757 | if (dp) { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 758 | EGLDisplay iDpy = dp->disp.dpy; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 759 |  | 
| Mathias Agopian | 10e9ab5 | 2017-03-08 15:02:55 -0800 | [diff] [blame] | 760 | if (!window) { | 
|  | 761 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | 
|  | 762 | } | 
|  | 763 |  | 
|  | 764 | int value = 0; | 
|  | 765 | window->query(window, NATIVE_WINDOW_IS_VALID, &value); | 
|  | 766 | if (!value) { | 
|  | 767 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | 
|  | 768 | } | 
|  | 769 |  | 
| Andy McFadden | d566ce3 | 2014-01-07 15:54:17 -0800 | [diff] [blame] | 770 | int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 771 | if (result < 0) { | 
| Andy McFadden | d566ce3 | 2014-01-07 15:54:17 -0800 | [diff] [blame] | 772 | ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) " | 
|  | 773 | "failed (%#x) (already connected to another API?)", | 
|  | 774 | window, result); | 
| Jonathan Hamilton | 77a9b4a | 2013-07-17 09:41:42 -0700 | [diff] [blame] | 775 | return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | 
| Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 776 | } | 
|  | 777 |  | 
| Mathias Agopian | 9592156 | 2017-02-24 14:31:31 -0800 | [diff] [blame] | 778 | EGLint format; | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 779 | getNativePixelFormat(iDpy, cnx, config, format); | 
|  | 780 |  | 
|  | 781 | // now select correct colorspace and dataspace based on user's attribute list | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 782 | EGLint colorSpace; | 
|  | 783 | android_dataspace dataSpace; | 
| Courtney Goeltzenleuchter | e5d6f99 | 2017-07-07 14:55:40 -0600 | [diff] [blame] | 784 | if (!getColorSpaceAttribute(dp, window, attrib_list, colorSpace, dataSpace)) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 785 | ALOGE("error invalid colorspace: %d", colorSpace); | 
|  | 786 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 787 | } | 
| Alistair Strachan | 733a807 | 2015-02-12 12:33:25 -0800 | [diff] [blame] | 788 |  | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 789 | std::vector<EGLint> strippedAttribList; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 790 | if (stripAttributes(dp, attrib_list, format, strippedAttribList)) { | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 791 | // Had to modify the attribute list due to use of color space. | 
|  | 792 | // Use modified list from here on. | 
|  | 793 | attrib_list = strippedAttribList.data(); | 
|  | 794 | } | 
|  | 795 |  | 
| Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 796 | if (format != 0) { | 
|  | 797 | int err = native_window_set_buffers_format(window, format); | 
|  | 798 | if (err != 0) { | 
|  | 799 | ALOGE("error setting native window pixel format: %s (%d)", | 
|  | 800 | strerror(-err), err); | 
|  | 801 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); | 
|  | 802 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | 
|  | 803 | } | 
|  | 804 | } | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 805 |  | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 806 | if (dataSpace != 0) { | 
|  | 807 | int err = native_window_set_buffers_data_space(window, dataSpace); | 
|  | 808 | if (err != 0) { | 
|  | 809 | ALOGE("error setting native window pixel dataSpace: %s (%d)", | 
|  | 810 | strerror(-err), err); | 
|  | 811 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); | 
|  | 812 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | 
|  | 813 | } | 
|  | 814 | } | 
|  | 815 |  | 
| Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 816 | // the EGL spec requires that a new EGLSurface default to swap interval | 
|  | 817 | // 1, so explicitly set that on the window here. | 
|  | 818 | ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); | 
|  | 819 | anw->setSwapInterval(anw, 1); | 
|  | 820 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 821 | EGLSurface surface = cnx->egl.eglCreateWindowSurface( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 822 | iDpy, config, window, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 823 | if (surface != EGL_NO_SURFACE) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 824 | egl_surface_t* s = | 
|  | 825 | new egl_surface_t(dp.get(), config, window, surface, colorSpace, cnx); | 
| Courtney Goeltzenleuchter | a1e59f1 | 2018-03-05 08:19:25 -0700 | [diff] [blame] | 826 | return s; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 827 | } | 
| Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 828 |  | 
|  | 829 | // EGLSurface creation failed | 
|  | 830 | native_window_set_buffers_format(window, 0); | 
|  | 831 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 832 | } | 
|  | 833 | return EGL_NO_SURFACE; | 
|  | 834 | } | 
|  | 835 |  | 
|  | 836 | EGLSurface eglCreatePixmapSurface(  EGLDisplay dpy, EGLConfig config, | 
|  | 837 | NativePixmapType pixmap, | 
|  | 838 | const EGLint *attrib_list) | 
|  | 839 | { | 
|  | 840 | clearError(); | 
|  | 841 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 842 | egl_connection_t* cnx = NULL; | 
|  | 843 | egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 844 | EGLint colorSpace; | 
|  | 845 | android_dataspace dataSpace; | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 846 | if (dp) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 847 | // now select a corresponding sRGB format if needed | 
|  | 848 | if (!getColorSpaceAttribute(dp, attrib_list, colorSpace, dataSpace)) { | 
|  | 849 | ALOGE("error invalid colorspace: %d", colorSpace); | 
|  | 850 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); | 
|  | 851 | } | 
|  | 852 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 853 | EGLSurface surface = cnx->egl.eglCreatePixmapSurface( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 854 | dp->disp.dpy, config, pixmap, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 855 | if (surface != EGL_NO_SURFACE) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 856 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, surface, colorSpace, cnx); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 857 | return s; | 
|  | 858 | } | 
|  | 859 | } | 
|  | 860 | return EGL_NO_SURFACE; | 
|  | 861 | } | 
|  | 862 |  | 
|  | 863 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, | 
|  | 864 | const EGLint *attrib_list) | 
|  | 865 | { | 
|  | 866 | clearError(); | 
|  | 867 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 868 | egl_connection_t* cnx = NULL; | 
|  | 869 | egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
|  | 870 | if (dp) { | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 871 | EGLDisplay iDpy = dp->disp.dpy; | 
|  | 872 | EGLint format; | 
|  | 873 | getNativePixelFormat(iDpy, cnx, config, format); | 
|  | 874 |  | 
|  | 875 | // now select correct colorspace and dataspace based on user's attribute list | 
|  | 876 | EGLint colorSpace; | 
|  | 877 | android_dataspace dataSpace; | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 878 | if (!getColorSpaceAttribute(dp, attrib_list, colorSpace, dataSpace)) { | 
|  | 879 | ALOGE("error invalid colorspace: %d", colorSpace); | 
|  | 880 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); | 
|  | 881 | } | 
|  | 882 |  | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 883 | // Pbuffers are not displayed so we don't need to store the | 
|  | 884 | // colorspace. We do need to filter out color spaces the | 
|  | 885 | // driver doesn't know how to process. | 
|  | 886 | std::vector<EGLint> strippedAttribList; | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 887 | if (stripAttributes(dp, attrib_list, format, strippedAttribList)) { | 
| Courtney Goeltzenleuchter | eeaa52b | 2017-06-20 08:12:54 -0600 | [diff] [blame] | 888 | // Had to modify the attribute list due to use of color space. | 
|  | 889 | // Use modified list from here on. | 
|  | 890 | attrib_list = strippedAttribList.data(); | 
|  | 891 | } | 
|  | 892 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 893 | EGLSurface surface = cnx->egl.eglCreatePbufferSurface( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 894 | dp->disp.dpy, config, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 895 | if (surface != EGL_NO_SURFACE) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 896 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, surface, colorSpace, cnx); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 897 | return s; | 
|  | 898 | } | 
|  | 899 | } | 
|  | 900 | return EGL_NO_SURFACE; | 
|  | 901 | } | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 902 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 903 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) | 
|  | 904 | { | 
|  | 905 | clearError(); | 
|  | 906 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 907 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 908 | if (!dp) return EGL_FALSE; | 
|  | 909 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 910 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 911 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 912 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 913 |  | 
|  | 914 | egl_surface_t * const s = get_surface(surface); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 915 | EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 916 | if (result == EGL_TRUE) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 917 | _s.terminate(); | 
|  | 918 | } | 
|  | 919 | return result; | 
|  | 920 | } | 
|  | 921 |  | 
|  | 922 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, | 
|  | 923 | EGLint attribute, EGLint *value) | 
|  | 924 | { | 
|  | 925 | clearError(); | 
|  | 926 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 927 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 928 | if (!dp) return EGL_FALSE; | 
|  | 929 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 930 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 931 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 932 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 933 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 934 | egl_surface_t const * const s = get_surface(surface); | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 935 | if (s->getColorSpaceAttribute(attribute, value)) { | 
|  | 936 | return EGL_TRUE; | 
|  | 937 | } else if (s->getSmpte2086Attribute(attribute, value)) { | 
|  | 938 | return EGL_TRUE; | 
|  | 939 | } else if (s->getCta8613Attribute(attribute, value)) { | 
| Courtney Goeltzenleuchter | 3783657 | 2017-04-26 15:07:51 -0600 | [diff] [blame] | 940 | return EGL_TRUE; | 
|  | 941 | } | 
| Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 942 | return s->cnx->egl.eglQuerySurface(dp->disp.dpy, s->surface, attribute, value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 943 | } | 
|  | 944 |  | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 945 | void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { | 
| Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 946 | ATRACE_CALL(); | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 947 | clearError(); | 
|  | 948 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 949 | const egl_display_ptr dp = validate_display(dpy); | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 950 | if (!dp) { | 
|  | 951 | return; | 
|  | 952 | } | 
|  | 953 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 954 | SurfaceRef _s(dp.get(), surface); | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 955 | if (!_s.get()) { | 
|  | 956 | setError(EGL_BAD_SURFACE, EGL_FALSE); | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 957 | } | 
| Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 958 | } | 
|  | 959 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 960 | // ---------------------------------------------------------------------------- | 
|  | 961 | // Contexts | 
|  | 962 | // ---------------------------------------------------------------------------- | 
|  | 963 |  | 
|  | 964 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, | 
|  | 965 | EGLContext share_list, const EGLint *attrib_list) | 
|  | 966 | { | 
|  | 967 | clearError(); | 
|  | 968 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 969 | egl_connection_t* cnx = NULL; | 
|  | 970 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
| Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 971 | if (dp) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 972 | if (share_list != EGL_NO_CONTEXT) { | 
| Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 973 | if (!ContextRef(dp.get(), share_list).get()) { | 
|  | 974 | return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); | 
|  | 975 | } | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 976 | egl_context_t* const c = get_context(share_list); | 
|  | 977 | share_list = c->context; | 
|  | 978 | } | 
|  | 979 | EGLContext context = cnx->egl.eglCreateContext( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 980 | dp->disp.dpy, config, share_list, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 981 | if (context != EGL_NO_CONTEXT) { | 
|  | 982 | // figure out if it's a GLESv1 or GLESv2 | 
|  | 983 | int version = 0; | 
|  | 984 | if (attrib_list) { | 
|  | 985 | while (*attrib_list != EGL_NONE) { | 
|  | 986 | GLint attr = *attrib_list++; | 
|  | 987 | GLint value = *attrib_list++; | 
|  | 988 | if (attr == EGL_CONTEXT_CLIENT_VERSION) { | 
|  | 989 | if (value == 1) { | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 990 | version = egl_connection_t::GLESv1_INDEX; | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 991 | } else if (value == 2 || value == 3) { | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 992 | version = egl_connection_t::GLESv2_INDEX; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 993 | } | 
|  | 994 | } | 
|  | 995 | }; | 
|  | 996 | } | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 997 | egl_context_t* c = new egl_context_t(dpy, context, config, cnx, | 
|  | 998 | version); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 999 | return c; | 
|  | 1000 | } | 
|  | 1001 | } | 
|  | 1002 | return EGL_NO_CONTEXT; | 
|  | 1003 | } | 
|  | 1004 |  | 
|  | 1005 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) | 
|  | 1006 | { | 
|  | 1007 | clearError(); | 
|  | 1008 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1009 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1010 | if (!dp) | 
|  | 1011 | return EGL_FALSE; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1012 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1013 | ContextRef _c(dp.get(), ctx); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1014 | if (!_c.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1015 | return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1016 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1017 | egl_context_t * const c = get_context(ctx); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1018 | EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1019 | if (result == EGL_TRUE) { | 
|  | 1020 | _c.terminate(); | 
|  | 1021 | } | 
|  | 1022 | return result; | 
|  | 1023 | } | 
|  | 1024 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1025 | EGLBoolean eglMakeCurrent(  EGLDisplay dpy, EGLSurface draw, | 
|  | 1026 | EGLSurface read, EGLContext ctx) | 
|  | 1027 | { | 
|  | 1028 | clearError(); | 
|  | 1029 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1030 | egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1031 | if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1032 |  | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1033 | // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not | 
|  | 1034 | // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is | 
|  | 1035 | // a valid but uninitialized display. | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1036 | if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || | 
|  | 1037 | (draw != EGL_NO_SURFACE) ) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1038 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1039 | } | 
|  | 1040 |  | 
|  | 1041 | // get a reference to the object passed in | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1042 | ContextRef _c(dp.get(), ctx); | 
|  | 1043 | SurfaceRef _d(dp.get(), draw); | 
|  | 1044 | SurfaceRef _r(dp.get(), read); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1045 |  | 
|  | 1046 | // validate the context (if not EGL_NO_CONTEXT) | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1047 | if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1048 | // EGL_NO_CONTEXT is valid | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1049 | return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1050 | } | 
|  | 1051 |  | 
|  | 1052 | // these are the underlying implementation's object | 
|  | 1053 | EGLContext impl_ctx  = EGL_NO_CONTEXT; | 
|  | 1054 | EGLSurface impl_draw = EGL_NO_SURFACE; | 
|  | 1055 | EGLSurface impl_read = EGL_NO_SURFACE; | 
|  | 1056 |  | 
|  | 1057 | // these are our objects structs passed in | 
|  | 1058 | egl_context_t       * c = NULL; | 
|  | 1059 | egl_surface_t const * d = NULL; | 
|  | 1060 | egl_surface_t const * r = NULL; | 
|  | 1061 |  | 
|  | 1062 | // these are the current objects structs | 
|  | 1063 | egl_context_t * cur_c = get_context(getContext()); | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1064 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1065 | if (ctx != EGL_NO_CONTEXT) { | 
|  | 1066 | c = get_context(ctx); | 
|  | 1067 | impl_ctx = c->context; | 
|  | 1068 | } else { | 
|  | 1069 | // no context given, use the implementation of the current context | 
| Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 1070 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { | 
|  | 1071 | // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1072 | return setError(EGL_BAD_MATCH, (EGLBoolean)EGL_FALSE); | 
| Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 1073 | } | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1074 | if (cur_c == NULL) { | 
|  | 1075 | // no current context | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1076 | // not an error, there is just no current context. | 
|  | 1077 | return EGL_TRUE; | 
|  | 1078 | } | 
|  | 1079 | } | 
|  | 1080 |  | 
|  | 1081 | // retrieve the underlying implementation's draw EGLSurface | 
|  | 1082 | if (draw != EGL_NO_SURFACE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1083 | if (!_d.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1084 | d = get_surface(draw); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1085 | impl_draw = d->surface; | 
|  | 1086 | } | 
|  | 1087 |  | 
|  | 1088 | // retrieve the underlying implementation's read EGLSurface | 
|  | 1089 | if (read != EGL_NO_SURFACE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1090 | if (!_r.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1091 | r = get_surface(read); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1092 | impl_read = r->surface; | 
|  | 1093 | } | 
|  | 1094 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1095 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1096 | EGLBoolean result = dp->makeCurrent(c, cur_c, | 
| Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 1097 | draw, read, ctx, | 
|  | 1098 | impl_draw, impl_read, impl_ctx); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1099 |  | 
|  | 1100 | if (result == EGL_TRUE) { | 
| Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 1101 | if (c) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1102 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); | 
|  | 1103 | egl_tls_t::setContext(ctx); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1104 | _c.acquire(); | 
|  | 1105 | _r.acquire(); | 
|  | 1106 | _d.acquire(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1107 | } else { | 
|  | 1108 | setGLHooksThreadSpecific(&gHooksNoContext); | 
|  | 1109 | egl_tls_t::setContext(EGL_NO_CONTEXT); | 
|  | 1110 | } | 
| Mathias Agopian | 5fecea7 | 2011-08-25 18:38:24 -0700 | [diff] [blame] | 1111 | } else { | 
| Mike Stroyan | 02ba5c7 | 2017-05-08 10:47:24 -0600 | [diff] [blame] | 1112 |  | 
| Mike Stroyan | 47e741b | 2017-06-01 13:56:18 -0600 | [diff] [blame] | 1113 | if (cur_c != NULL) { | 
|  | 1114 | // Force return to current context for drivers that cannot handle errors | 
|  | 1115 | EGLBoolean restore_result = EGL_FALSE; | 
|  | 1116 | // get a reference to the old current objects | 
|  | 1117 | ContextRef _c2(dp.get(), cur_c); | 
|  | 1118 | SurfaceRef _d2(dp.get(), cur_c->draw); | 
|  | 1119 | SurfaceRef _r2(dp.get(), cur_c->read); | 
| Mike Stroyan | 02ba5c7 | 2017-05-08 10:47:24 -0600 | [diff] [blame] | 1120 |  | 
| Mike Stroyan | 02ba5c7 | 2017-05-08 10:47:24 -0600 | [diff] [blame] | 1121 | c = cur_c; | 
|  | 1122 | impl_ctx = c->context; | 
|  | 1123 | impl_draw = EGL_NO_SURFACE; | 
|  | 1124 | if (cur_c->draw != EGL_NO_SURFACE) { | 
|  | 1125 | d = get_surface(cur_c->draw); | 
|  | 1126 | impl_draw = d->surface; | 
|  | 1127 | } | 
|  | 1128 | impl_read = EGL_NO_SURFACE; | 
|  | 1129 | if (cur_c->read != EGL_NO_SURFACE) { | 
|  | 1130 | r = get_surface(cur_c->read); | 
|  | 1131 | impl_read = r->surface; | 
|  | 1132 | } | 
|  | 1133 | restore_result = dp->makeCurrent(c, cur_c, | 
|  | 1134 | cur_c->draw, cur_c->read, cur_c->context, | 
|  | 1135 | impl_draw, impl_read, impl_ctx); | 
| Mike Stroyan | 47e741b | 2017-06-01 13:56:18 -0600 | [diff] [blame] | 1136 | if (restore_result == EGL_TRUE) { | 
|  | 1137 | _c2.acquire(); | 
|  | 1138 | _r2.acquire(); | 
|  | 1139 | _d2.acquire(); | 
|  | 1140 | } else { | 
|  | 1141 | ALOGE("Could not restore original EGL context"); | 
|  | 1142 | } | 
| Mike Stroyan | 02ba5c7 | 2017-05-08 10:47:24 -0600 | [diff] [blame] | 1143 | } | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1144 | // this will ALOGE the error | 
| Mathias Agopian | 63108c3 | 2013-09-06 13:36:49 -0700 | [diff] [blame] | 1145 | egl_connection_t* const cnx = &gEGLImpl; | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1146 | result = setError(cnx->egl.eglGetError(), (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1147 | } | 
|  | 1148 | return result; | 
|  | 1149 | } | 
|  | 1150 |  | 
|  | 1151 |  | 
|  | 1152 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, | 
|  | 1153 | EGLint attribute, EGLint *value) | 
|  | 1154 | { | 
|  | 1155 | clearError(); | 
|  | 1156 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1157 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1158 | if (!dp) return EGL_FALSE; | 
|  | 1159 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1160 | ContextRef _c(dp.get(), ctx); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1161 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1162 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1163 | egl_context_t * const c = get_context(ctx); | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1164 | return c->cnx->egl.eglQueryContext( | 
|  | 1165 | dp->disp.dpy, c->context, attribute, value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1166 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1167 | } | 
|  | 1168 |  | 
|  | 1169 | EGLContext eglGetCurrentContext(void) | 
|  | 1170 | { | 
|  | 1171 | // could be called before eglInitialize(), but we wouldn't have a context | 
|  | 1172 | // then, and this function would correctly return EGL_NO_CONTEXT. | 
|  | 1173 |  | 
|  | 1174 | clearError(); | 
|  | 1175 |  | 
|  | 1176 | EGLContext ctx = getContext(); | 
|  | 1177 | return ctx; | 
|  | 1178 | } | 
|  | 1179 |  | 
|  | 1180 | EGLSurface eglGetCurrentSurface(EGLint readdraw) | 
|  | 1181 | { | 
|  | 1182 | // could be called before eglInitialize(), but we wouldn't have a context | 
|  | 1183 | // then, and this function would correctly return EGL_NO_SURFACE. | 
|  | 1184 |  | 
|  | 1185 | clearError(); | 
|  | 1186 |  | 
|  | 1187 | EGLContext ctx = getContext(); | 
|  | 1188 | if (ctx) { | 
|  | 1189 | egl_context_t const * const c = get_context(ctx); | 
|  | 1190 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); | 
|  | 1191 | switch (readdraw) { | 
|  | 1192 | case EGL_READ: return c->read; | 
| Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1193 | case EGL_DRAW: return c->draw; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1194 | default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); | 
|  | 1195 | } | 
|  | 1196 | } | 
|  | 1197 | return EGL_NO_SURFACE; | 
|  | 1198 | } | 
|  | 1199 |  | 
|  | 1200 | EGLDisplay eglGetCurrentDisplay(void) | 
|  | 1201 | { | 
|  | 1202 | // could be called before eglInitialize(), but we wouldn't have a context | 
|  | 1203 | // then, and this function would correctly return EGL_NO_DISPLAY. | 
|  | 1204 |  | 
|  | 1205 | clearError(); | 
|  | 1206 |  | 
|  | 1207 | EGLContext ctx = getContext(); | 
|  | 1208 | if (ctx) { | 
|  | 1209 | egl_context_t const * const c = get_context(ctx); | 
|  | 1210 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); | 
|  | 1211 | return c->dpy; | 
|  | 1212 | } | 
|  | 1213 | return EGL_NO_DISPLAY; | 
|  | 1214 | } | 
|  | 1215 |  | 
|  | 1216 | EGLBoolean eglWaitGL(void) | 
|  | 1217 | { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1218 | clearError(); | 
|  | 1219 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1220 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1221 | if (!cnx->dso) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1222 | return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1223 |  | 
|  | 1224 | return cnx->egl.eglWaitGL(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1225 | } | 
|  | 1226 |  | 
|  | 1227 | EGLBoolean eglWaitNative(EGLint engine) | 
|  | 1228 | { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1229 | clearError(); | 
|  | 1230 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1231 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1232 | if (!cnx->dso) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1233 | return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1234 |  | 
|  | 1235 | return cnx->egl.eglWaitNative(engine); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1236 | } | 
|  | 1237 |  | 
|  | 1238 | EGLint eglGetError(void) | 
|  | 1239 | { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1240 | EGLint err = EGL_SUCCESS; | 
|  | 1241 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1242 | if (cnx->dso) { | 
|  | 1243 | err = cnx->egl.eglGetError(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1244 | } | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1245 | if (err == EGL_SUCCESS) { | 
|  | 1246 | err = egl_tls_t::getError(); | 
|  | 1247 | } | 
|  | 1248 | return err; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1249 | } | 
|  | 1250 |  | 
| Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 1251 | static __eglMustCastToProperFunctionPointerType findBuiltinWrapper( | 
| Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 1252 | const char* procname) { | 
|  | 1253 | const egl_connection_t* cnx = &gEGLImpl; | 
|  | 1254 | void* proc = NULL; | 
|  | 1255 |  | 
| Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 1256 | proc = dlsym(cnx->libEgl, procname); | 
|  | 1257 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; | 
|  | 1258 |  | 
| Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 1259 | proc = dlsym(cnx->libGles2, procname); | 
|  | 1260 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; | 
|  | 1261 |  | 
|  | 1262 | proc = dlsym(cnx->libGles1, procname); | 
|  | 1263 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; | 
|  | 1264 |  | 
|  | 1265 | return NULL; | 
|  | 1266 | } | 
|  | 1267 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1268 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) | 
|  | 1269 | { | 
|  | 1270 | // eglGetProcAddress() could be the very first function called | 
|  | 1271 | // in which case we must make sure we've initialized ourselves, this | 
|  | 1272 | // happens the first time egl_get_display() is called. | 
|  | 1273 |  | 
|  | 1274 | clearError(); | 
|  | 1275 |  | 
|  | 1276 | if (egl_init_drivers() == EGL_FALSE) { | 
|  | 1277 | setError(EGL_BAD_PARAMETER, NULL); | 
|  | 1278 | return  NULL; | 
|  | 1279 | } | 
|  | 1280 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 1281 | if (FILTER_EXTENSIONS(procname)) { | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 1282 | return NULL; | 
|  | 1283 | } | 
|  | 1284 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1285 | __eglMustCastToProperFunctionPointerType addr; | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 1286 | addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1287 | if (addr) return addr; | 
|  | 1288 |  | 
| Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 1289 | addr = findBuiltinWrapper(procname); | 
| Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 1290 | if (addr) return addr; | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 1291 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1292 | // this protects accesses to sGLExtentionMap and sGLExtentionSlot | 
|  | 1293 | pthread_mutex_lock(&sExtensionMapMutex); | 
|  | 1294 |  | 
|  | 1295 | /* | 
|  | 1296 | * Since eglGetProcAddress() is not associated to anything, it needs | 
|  | 1297 | * to return a function pointer that "works" regardless of what | 
|  | 1298 | * the current context is. | 
|  | 1299 | * | 
|  | 1300 | * For this reason, we return a "forwarder", a small stub that takes | 
|  | 1301 | * care of calling the function associated with the context | 
|  | 1302 | * currently bound. | 
|  | 1303 | * | 
|  | 1304 | * We first look for extensions we've already resolved, if we're seeing | 
|  | 1305 | * this extension for the first time, we go through all our | 
|  | 1306 | * implementations and call eglGetProcAddress() and record the | 
|  | 1307 | * result in the appropriate implementation hooks and return the | 
|  | 1308 | * address of the forwarder corresponding to that hook set. | 
|  | 1309 | * | 
|  | 1310 | */ | 
|  | 1311 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1312 | const std::string name(procname); | 
|  | 1313 |  | 
|  | 1314 | auto& extentionMap = sGLExtentionMap; | 
|  | 1315 | auto pos = extentionMap.find(name); | 
|  | 1316 | addr = (pos != extentionMap.end()) ? pos->second : nullptr; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1317 | const int slot = sGLExtentionSlot; | 
|  | 1318 |  | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1319 | ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1320 | "no more slots for eglGetProcAddress(\"%s\")", | 
|  | 1321 | procname); | 
|  | 1322 |  | 
|  | 1323 | if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { | 
|  | 1324 | bool found = false; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1325 |  | 
|  | 1326 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1327 | if (cnx->dso && cnx->egl.eglGetProcAddress) { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1328 | // Extensions are independent of the bound context | 
| luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 1329 | addr = | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1330 | cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = | 
|  | 1331 | cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1332 | cnx->egl.eglGetProcAddress(procname); | 
| luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 1333 | if (addr) found = true; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1334 | } | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1335 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1336 | if (found) { | 
|  | 1337 | addr = gExtensionForwarders[slot]; | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1338 | extentionMap[name] = addr; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1339 | sGLExtentionSlot++; | 
|  | 1340 | } | 
|  | 1341 | } | 
|  | 1342 |  | 
|  | 1343 | pthread_mutex_unlock(&sExtensionMapMutex); | 
|  | 1344 | return addr; | 
|  | 1345 | } | 
|  | 1346 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1347 | class FrameCompletionThread { | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1348 | public: | 
|  | 1349 |  | 
|  | 1350 | static void queueSync(EGLSyncKHR sync) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1351 | static FrameCompletionThread thread; | 
|  | 1352 |  | 
|  | 1353 | char name[64]; | 
|  | 1354 |  | 
|  | 1355 | std::lock_guard<std::mutex> lock(thread.mMutex); | 
|  | 1356 | snprintf(name, sizeof(name), "kicked off frame %u", (unsigned int)thread.mFramesQueued); | 
|  | 1357 | ATRACE_NAME(name); | 
|  | 1358 |  | 
|  | 1359 | thread.mQueue.push_back(sync); | 
|  | 1360 | thread.mCondition.notify_one(); | 
|  | 1361 | thread.mFramesQueued++; | 
|  | 1362 | ATRACE_INT("GPU Frames Outstanding", int32_t(thread.mQueue.size())); | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1363 | } | 
|  | 1364 |  | 
|  | 1365 | private: | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1366 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1367 | FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) { | 
|  | 1368 | std::thread thread(&FrameCompletionThread::loop, this); | 
|  | 1369 | thread.detach(); | 
|  | 1370 | } | 
|  | 1371 |  | 
|  | 1372 | #pragma clang diagnostic push | 
|  | 1373 | #pragma clang diagnostic ignored "-Wmissing-noreturn" | 
|  | 1374 | void loop() { | 
|  | 1375 | while (true) { | 
|  | 1376 | threadLoop(); | 
|  | 1377 | } | 
|  | 1378 | } | 
|  | 1379 | #pragma clang diagnostic pop | 
|  | 1380 |  | 
|  | 1381 | void threadLoop() { | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1382 | EGLSyncKHR sync; | 
|  | 1383 | uint32_t frameNum; | 
|  | 1384 | { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1385 | std::unique_lock<std::mutex> lock(mMutex); | 
|  | 1386 | while (mQueue.empty()) { | 
|  | 1387 | mCondition.wait(lock); | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1388 | } | 
|  | 1389 | sync = mQueue[0]; | 
|  | 1390 | frameNum = mFramesCompleted; | 
|  | 1391 | } | 
|  | 1392 | EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 
|  | 1393 | { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1394 | char name[64]; | 
|  | 1395 | snprintf(name, sizeof(name), "waiting for frame %u", (unsigned int)frameNum); | 
|  | 1396 | ATRACE_NAME(name); | 
|  | 1397 |  | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1398 | EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); | 
|  | 1399 | if (result == EGL_FALSE) { | 
|  | 1400 | ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); | 
|  | 1401 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { | 
|  | 1402 | ALOGE("FrameCompletion: timeout waiting for fence"); | 
|  | 1403 | } | 
|  | 1404 | eglDestroySyncKHR(dpy, sync); | 
|  | 1405 | } | 
|  | 1406 | { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1407 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 1408 | mQueue.pop_front(); | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1409 | mFramesCompleted++; | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1410 | ATRACE_INT("GPU Frames Outstanding", int32_t(mQueue.size())); | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1411 | } | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1412 | } | 
|  | 1413 |  | 
|  | 1414 | uint32_t mFramesQueued; | 
|  | 1415 | uint32_t mFramesCompleted; | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1416 | std::deque<EGLSyncKHR> mQueue; | 
|  | 1417 | std::condition_variable mCondition; | 
|  | 1418 | std::mutex mMutex; | 
| Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 1419 | }; | 
|  | 1420 |  | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1421 | EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, | 
|  | 1422 | EGLint *rects, EGLint n_rects) | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1423 | { | 
| Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1424 | ATRACE_CALL(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1425 | clearError(); | 
|  | 1426 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1427 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1428 | if (!dp) return EGL_FALSE; | 
|  | 1429 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1430 | SurfaceRef _s(dp.get(), draw); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1431 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1432 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1433 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 1434 | egl_surface_t* const s = get_surface(draw); | 
| Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1435 |  | 
| Mathias Agopian | ed6d08b | 2013-04-16 16:39:46 -0700 | [diff] [blame] | 1436 | if (CC_UNLIKELY(dp->traceGpuCompletion)) { | 
|  | 1437 | EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); | 
|  | 1438 | if (sync != EGL_NO_SYNC_KHR) { | 
|  | 1439 | FrameCompletionThread::queueSync(sync); | 
|  | 1440 | } | 
|  | 1441 | } | 
|  | 1442 |  | 
| Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1443 | if (CC_UNLIKELY(dp->finishOnSwap)) { | 
|  | 1444 | uint32_t pixel; | 
|  | 1445 | egl_context_t * const c = get_context( egl_tls_t::getContext() ); | 
|  | 1446 | if (c) { | 
|  | 1447 | // glReadPixels() ensures that the frame is complete | 
|  | 1448 | s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, | 
|  | 1449 | GL_RGBA,GL_UNSIGNED_BYTE,&pixel); | 
|  | 1450 | } | 
|  | 1451 | } | 
|  | 1452 |  | 
| Courtney Goeltzenleuchter | 936799c | 2018-03-02 16:47:08 -0700 | [diff] [blame] | 1453 | if (!sendSurfaceMetadata(s)) { | 
|  | 1454 | native_window_api_disconnect(s->getNativeWindow(), NATIVE_WINDOW_API_EGL); | 
|  | 1455 | return setError(EGL_BAD_NATIVE_WINDOW, (EGLBoolean)EGL_FALSE); | 
|  | 1456 | } | 
|  | 1457 |  | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1458 | if (n_rects == 0) { | 
|  | 1459 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); | 
|  | 1460 | } | 
|  | 1461 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1462 | std::vector<android_native_rect_t> androidRects((size_t)n_rects); | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1463 | for (int r = 0; r < n_rects; ++r) { | 
|  | 1464 | int offset = r * 4; | 
|  | 1465 | int x = rects[offset]; | 
|  | 1466 | int y = rects[offset + 1]; | 
|  | 1467 | int width = rects[offset + 2]; | 
|  | 1468 | int height = rects[offset + 3]; | 
|  | 1469 | android_native_rect_t androidRect; | 
|  | 1470 | androidRect.left = x; | 
|  | 1471 | androidRect.top = y + height; | 
|  | 1472 | androidRect.right = x + width; | 
|  | 1473 | androidRect.bottom = y; | 
|  | 1474 | androidRects.push_back(androidRect); | 
|  | 1475 | } | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1476 | native_window_set_surface_damage(s->getNativeWindow(), androidRects.data(), androidRects.size()); | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1477 |  | 
|  | 1478 | if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { | 
|  | 1479 | return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, | 
|  | 1480 | rects, n_rects); | 
|  | 1481 | } else { | 
|  | 1482 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); | 
|  | 1483 | } | 
|  | 1484 | } | 
|  | 1485 |  | 
|  | 1486 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) | 
|  | 1487 | { | 
|  | 1488 | return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1489 | } | 
|  | 1490 |  | 
|  | 1491 | EGLBoolean eglCopyBuffers(  EGLDisplay dpy, EGLSurface surface, | 
|  | 1492 | NativePixmapType target) | 
|  | 1493 | { | 
|  | 1494 | clearError(); | 
|  | 1495 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1496 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1497 | if (!dp) return EGL_FALSE; | 
|  | 1498 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1499 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1500 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1501 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1502 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1503 | egl_surface_t const * const s = get_surface(surface); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1504 | return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | const char* eglQueryString(EGLDisplay dpy, EGLint name) | 
|  | 1508 | { | 
|  | 1509 | clearError(); | 
|  | 1510 |  | 
| Chia-I Wu | e57d135 | 2016-08-15 16:10:02 +0800 | [diff] [blame] | 1511 | // Generate an error quietly when client extensions (as defined by | 
|  | 1512 | // EGL_EXT_client_extensions) are queried.  We do not want to rely on | 
|  | 1513 | // validate_display to generate the error as validate_display would log | 
|  | 1514 | // the error, which can be misleading. | 
|  | 1515 | // | 
|  | 1516 | // If we want to support EGL_EXT_client_extensions later, we can return | 
|  | 1517 | // the client extension string here instead. | 
|  | 1518 | if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1519 | return setErrorQuiet(EGL_BAD_DISPLAY, (const char*)0); | 
| Chia-I Wu | e57d135 | 2016-08-15 16:10:02 +0800 | [diff] [blame] | 1520 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1521 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1522 | if (!dp) return (const char *) NULL; | 
|  | 1523 |  | 
|  | 1524 | switch (name) { | 
|  | 1525 | case EGL_VENDOR: | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1526 | return dp->getVendorString(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1527 | case EGL_VERSION: | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1528 | return dp->getVersionString(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1529 | case EGL_EXTENSIONS: | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1530 | return dp->getExtensionString(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1531 | case EGL_CLIENT_APIS: | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1532 | return dp->getClientApiString(); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1533 | default: | 
|  | 1534 | break; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1535 | } | 
|  | 1536 | return setError(EGL_BAD_PARAMETER, (const char *)0); | 
|  | 1537 | } | 
|  | 1538 |  | 
| Jiyong Park | 00b15b8 | 2017-08-10 20:30:56 +0900 | [diff] [blame] | 1539 | extern "C" EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) | 
| Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 1540 | { | 
|  | 1541 | clearError(); | 
|  | 1542 |  | 
|  | 1543 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1544 | if (!dp) return (const char *) NULL; | 
|  | 1545 |  | 
|  | 1546 | switch (name) { | 
|  | 1547 | case EGL_VENDOR: | 
|  | 1548 | return dp->disp.queryString.vendor; | 
|  | 1549 | case EGL_VERSION: | 
|  | 1550 | return dp->disp.queryString.version; | 
|  | 1551 | case EGL_EXTENSIONS: | 
|  | 1552 | return dp->disp.queryString.extensions; | 
|  | 1553 | case EGL_CLIENT_APIS: | 
|  | 1554 | return dp->disp.queryString.clientApi; | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1555 | default: | 
|  | 1556 | break; | 
| Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 1557 | } | 
|  | 1558 | return setError(EGL_BAD_PARAMETER, (const char *)0); | 
|  | 1559 | } | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1560 |  | 
|  | 1561 | // ---------------------------------------------------------------------------- | 
|  | 1562 | // EGL 1.1 | 
|  | 1563 | // ---------------------------------------------------------------------------- | 
|  | 1564 |  | 
|  | 1565 | EGLBoolean eglSurfaceAttrib( | 
|  | 1566 | EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) | 
|  | 1567 | { | 
|  | 1568 | clearError(); | 
|  | 1569 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1570 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1571 | if (!dp) return EGL_FALSE; | 
|  | 1572 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1573 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1574 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1575 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1576 |  | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1577 | egl_surface_t * const s = get_surface(surface); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1578 |  | 
| Pablo Ceballos | 02b05da | 2016-02-02 17:53:18 -0800 | [diff] [blame] | 1579 | if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1580 | if (!s->getNativeWindow()) { | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 1581 | setError(EGL_BAD_SURFACE, EGL_FALSE); | 
|  | 1582 | } | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1583 | int err = native_window_set_auto_refresh(s->getNativeWindow(), value != 0); | 
|  | 1584 | return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 1585 | } | 
|  | 1586 |  | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1587 | if (attribute == EGL_TIMESTAMPS_ANDROID) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1588 | if (!s->getNativeWindow()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1589 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 1590 | } | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 1591 | int err = native_window_enable_frame_timestamps(s->getNativeWindow(), value != 0); | 
|  | 1592 | return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 1593 | } | 
|  | 1594 |  | 
| Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame] | 1595 | if (s->setSmpte2086Attribute(attribute, value)) { | 
|  | 1596 | return EGL_TRUE; | 
|  | 1597 | } else if (s->setCta8613Attribute(attribute, value)) { | 
|  | 1598 | return EGL_TRUE; | 
|  | 1599 | } else if (s->cnx->egl.eglSurfaceAttrib) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1600 | return s->cnx->egl.eglSurfaceAttrib( | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1601 | dp->disp.dpy, s->surface, attribute, value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1602 | } | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1603 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1604 | } | 
|  | 1605 |  | 
|  | 1606 | EGLBoolean eglBindTexImage( | 
|  | 1607 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) | 
|  | 1608 | { | 
|  | 1609 | clearError(); | 
|  | 1610 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1611 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1612 | if (!dp) return EGL_FALSE; | 
|  | 1613 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1614 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1615 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1616 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1617 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1618 | egl_surface_t const * const s = get_surface(surface); | 
|  | 1619 | if (s->cnx->egl.eglBindTexImage) { | 
|  | 1620 | return s->cnx->egl.eglBindTexImage( | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1621 | dp->disp.dpy, s->surface, buffer); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1622 | } | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1623 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1624 | } | 
|  | 1625 |  | 
|  | 1626 | EGLBoolean eglReleaseTexImage( | 
|  | 1627 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) | 
|  | 1628 | { | 
|  | 1629 | clearError(); | 
|  | 1630 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1631 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1632 | if (!dp) return EGL_FALSE; | 
|  | 1633 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1634 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1635 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1636 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1637 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1638 | egl_surface_t const * const s = get_surface(surface); | 
|  | 1639 | if (s->cnx->egl.eglReleaseTexImage) { | 
|  | 1640 | return s->cnx->egl.eglReleaseTexImage( | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1641 | dp->disp.dpy, s->surface, buffer); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1642 | } | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1643 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1644 | } | 
|  | 1645 |  | 
|  | 1646 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) | 
|  | 1647 | { | 
|  | 1648 | clearError(); | 
|  | 1649 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1650 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1651 | if (!dp) return EGL_FALSE; | 
|  | 1652 |  | 
|  | 1653 | EGLBoolean res = EGL_TRUE; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1654 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1655 | if (cnx->dso && cnx->egl.eglSwapInterval) { | 
|  | 1656 | res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1657 | } | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1658 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1659 | return res; | 
|  | 1660 | } | 
|  | 1661 |  | 
|  | 1662 |  | 
|  | 1663 | // ---------------------------------------------------------------------------- | 
|  | 1664 | // EGL 1.2 | 
|  | 1665 | // ---------------------------------------------------------------------------- | 
|  | 1666 |  | 
|  | 1667 | EGLBoolean eglWaitClient(void) | 
|  | 1668 | { | 
|  | 1669 | clearError(); | 
|  | 1670 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1671 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1672 | if (!cnx->dso) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1673 | return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1674 |  | 
|  | 1675 | EGLBoolean res; | 
|  | 1676 | if (cnx->egl.eglWaitClient) { | 
|  | 1677 | res = cnx->egl.eglWaitClient(); | 
|  | 1678 | } else { | 
|  | 1679 | res = cnx->egl.eglWaitGL(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1680 | } | 
|  | 1681 | return res; | 
|  | 1682 | } | 
|  | 1683 |  | 
|  | 1684 | EGLBoolean eglBindAPI(EGLenum api) | 
|  | 1685 | { | 
|  | 1686 | clearError(); | 
|  | 1687 |  | 
|  | 1688 | if (egl_init_drivers() == EGL_FALSE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1689 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1690 | } | 
|  | 1691 |  | 
|  | 1692 | // bind this API on all EGLs | 
|  | 1693 | EGLBoolean res = EGL_TRUE; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1694 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1695 | if (cnx->dso && cnx->egl.eglBindAPI) { | 
|  | 1696 | res = cnx->egl.eglBindAPI(api); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1697 | } | 
|  | 1698 | return res; | 
|  | 1699 | } | 
|  | 1700 |  | 
|  | 1701 | EGLenum eglQueryAPI(void) | 
|  | 1702 | { | 
|  | 1703 | clearError(); | 
|  | 1704 |  | 
|  | 1705 | if (egl_init_drivers() == EGL_FALSE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1706 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1707 | } | 
|  | 1708 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1709 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1710 | if (cnx->dso && cnx->egl.eglQueryAPI) { | 
|  | 1711 | return cnx->egl.eglQueryAPI(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1712 | } | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1713 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1714 | // or, it can only be OpenGL ES | 
|  | 1715 | return EGL_OPENGL_ES_API; | 
|  | 1716 | } | 
|  | 1717 |  | 
|  | 1718 | EGLBoolean eglReleaseThread(void) | 
|  | 1719 | { | 
|  | 1720 | clearError(); | 
|  | 1721 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1722 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1723 | if (cnx->dso && cnx->egl.eglReleaseThread) { | 
|  | 1724 | cnx->egl.eglReleaseThread(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1725 | } | 
| Sai Kiran Korwar | 3ac517a | 2014-01-31 21:15:07 +0530 | [diff] [blame] | 1726 |  | 
|  | 1727 | // If there is context bound to the thread, release it | 
|  | 1728 | egl_display_t::loseCurrent(get_context(getContext())); | 
|  | 1729 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1730 | egl_tls_t::clearTLS(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1731 | return EGL_TRUE; | 
|  | 1732 | } | 
|  | 1733 |  | 
|  | 1734 | EGLSurface eglCreatePbufferFromClientBuffer( | 
|  | 1735 | EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, | 
|  | 1736 | EGLConfig config, const EGLint *attrib_list) | 
|  | 1737 | { | 
|  | 1738 | clearError(); | 
|  | 1739 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1740 | egl_connection_t* cnx = NULL; | 
|  | 1741 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); | 
|  | 1742 | if (!dp) return EGL_FALSE; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1743 | if (cnx->egl.eglCreatePbufferFromClientBuffer) { | 
|  | 1744 | return cnx->egl.eglCreatePbufferFromClientBuffer( | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1745 | dp->disp.dpy, buftype, buffer, config, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1746 | } | 
|  | 1747 | return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); | 
|  | 1748 | } | 
|  | 1749 |  | 
|  | 1750 | // ---------------------------------------------------------------------------- | 
|  | 1751 | // EGL_EGLEXT_VERSION 3 | 
|  | 1752 | // ---------------------------------------------------------------------------- | 
|  | 1753 |  | 
|  | 1754 | EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, | 
|  | 1755 | const EGLint *attrib_list) | 
|  | 1756 | { | 
|  | 1757 | clearError(); | 
|  | 1758 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1759 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1760 | if (!dp) return EGL_FALSE; | 
|  | 1761 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1762 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1763 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1764 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1765 |  | 
|  | 1766 | egl_surface_t const * const s = get_surface(surface); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1767 | if (s->cnx->egl.eglLockSurfaceKHR) { | 
|  | 1768 | return s->cnx->egl.eglLockSurfaceKHR( | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1769 | dp->disp.dpy, s->surface, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1770 | } | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1771 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1772 | } | 
|  | 1773 |  | 
|  | 1774 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) | 
|  | 1775 | { | 
|  | 1776 | clearError(); | 
|  | 1777 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1778 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1779 | if (!dp) return EGL_FALSE; | 
|  | 1780 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1781 | SurfaceRef _s(dp.get(), surface); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1782 | if (!_s.get()) | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1783 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1784 |  | 
|  | 1785 | egl_surface_t const * const s = get_surface(surface); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1786 | if (s->cnx->egl.eglUnlockSurfaceKHR) { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1787 | return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1788 | } | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1789 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1790 | } | 
|  | 1791 |  | 
|  | 1792 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, | 
|  | 1793 | EGLClientBuffer buffer, const EGLint *attrib_list) | 
|  | 1794 | { | 
|  | 1795 | clearError(); | 
|  | 1796 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1797 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1798 | if (!dp) return EGL_NO_IMAGE_KHR; | 
|  | 1799 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1800 | ContextRef _c(dp.get(), ctx); | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1801 | egl_context_t * const c = _c.get(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1802 |  | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1803 | EGLImageKHR result = EGL_NO_IMAGE_KHR; | 
|  | 1804 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1805 | if (cnx->dso && cnx->egl.eglCreateImageKHR) { | 
|  | 1806 | result = cnx->egl.eglCreateImageKHR( | 
|  | 1807 | dp->disp.dpy, | 
|  | 1808 | c ? c->context : EGL_NO_CONTEXT, | 
|  | 1809 | target, buffer, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1810 | } | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1811 | return result; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1812 | } | 
|  | 1813 |  | 
|  | 1814 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) | 
|  | 1815 | { | 
|  | 1816 | clearError(); | 
|  | 1817 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1818 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1819 | if (!dp) return EGL_FALSE; | 
|  | 1820 |  | 
| Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1821 | EGLBoolean result = EGL_FALSE; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1822 | egl_connection_t* const cnx = &gEGLImpl; | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1823 | if (cnx->dso && cnx->egl.eglDestroyImageKHR) { | 
| Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1824 | result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1825 | } | 
| Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1826 | return result; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1827 | } | 
|  | 1828 |  | 
|  | 1829 | // ---------------------------------------------------------------------------- | 
|  | 1830 | // EGL_EGLEXT_VERSION 5 | 
|  | 1831 | // ---------------------------------------------------------------------------- | 
|  | 1832 |  | 
|  | 1833 |  | 
|  | 1834 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) | 
|  | 1835 | { | 
|  | 1836 | clearError(); | 
|  | 1837 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1838 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1839 | if (!dp) return EGL_NO_SYNC_KHR; | 
|  | 1840 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1841 | EGLSyncKHR result = EGL_NO_SYNC_KHR; | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1842 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1843 | if (cnx->dso && cnx->egl.eglCreateSyncKHR) { | 
|  | 1844 | result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1845 | } | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1846 | return result; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1847 | } | 
|  | 1848 |  | 
|  | 1849 | EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) | 
|  | 1850 | { | 
|  | 1851 | clearError(); | 
|  | 1852 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1853 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1854 | if (!dp) return EGL_FALSE; | 
|  | 1855 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1856 | EGLBoolean result = EGL_FALSE; | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1857 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1858 | if (cnx->dso && cnx->egl.eglDestroySyncKHR) { | 
|  | 1859 | result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1860 | } | 
|  | 1861 | return result; | 
|  | 1862 | } | 
|  | 1863 |  | 
| Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 1864 | EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { | 
|  | 1865 | clearError(); | 
|  | 1866 |  | 
|  | 1867 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1868 | if (!dp) return EGL_FALSE; | 
|  | 1869 |  | 
|  | 1870 | EGLBoolean result = EGL_FALSE; | 
|  | 1871 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1872 | if (cnx->dso && cnx->egl.eglSignalSyncKHR) { | 
|  | 1873 | result = cnx->egl.eglSignalSyncKHR( | 
|  | 1874 | dp->disp.dpy, sync, mode); | 
|  | 1875 | } | 
|  | 1876 | return result; | 
|  | 1877 | } | 
|  | 1878 |  | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1879 | EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, | 
|  | 1880 | EGLint flags, EGLTimeKHR timeout) | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1881 | { | 
|  | 1882 | clearError(); | 
|  | 1883 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1884 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1885 | if (!dp) return EGL_FALSE; | 
|  | 1886 |  | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 1887 | EGLint result = EGL_FALSE; | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1888 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1889 | if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { | 
|  | 1890 | result = cnx->egl.eglClientWaitSyncKHR( | 
|  | 1891 | dp->disp.dpy, sync, flags, timeout); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1892 | } | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1893 | return result; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1894 | } | 
|  | 1895 |  | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1896 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, | 
|  | 1897 | EGLint attribute, EGLint *value) | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1898 | { | 
|  | 1899 | clearError(); | 
|  | 1900 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1901 | const egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1902 | if (!dp) return EGL_FALSE; | 
|  | 1903 |  | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1904 | EGLBoolean result = EGL_FALSE; | 
|  | 1905 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1906 | if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { | 
|  | 1907 | result = cnx->egl.eglGetSyncAttribKHR( | 
|  | 1908 | dp->disp.dpy, sync, attribute, value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1909 | } | 
| Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1910 | return result; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1911 | } | 
|  | 1912 |  | 
| Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 1913 | EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list) | 
|  | 1914 | { | 
|  | 1915 | clearError(); | 
|  | 1916 |  | 
|  | 1917 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1918 | if (!dp) return EGL_NO_STREAM_KHR; | 
|  | 1919 |  | 
|  | 1920 | EGLStreamKHR result = EGL_NO_STREAM_KHR; | 
|  | 1921 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1922 | if (cnx->dso && cnx->egl.eglCreateStreamKHR) { | 
|  | 1923 | result = cnx->egl.eglCreateStreamKHR( | 
|  | 1924 | dp->disp.dpy, attrib_list); | 
|  | 1925 | } | 
|  | 1926 | return result; | 
|  | 1927 | } | 
|  | 1928 |  | 
|  | 1929 | EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream) | 
|  | 1930 | { | 
|  | 1931 | clearError(); | 
|  | 1932 |  | 
|  | 1933 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1934 | if (!dp) return EGL_FALSE; | 
|  | 1935 |  | 
|  | 1936 | EGLBoolean result = EGL_FALSE; | 
|  | 1937 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1938 | if (cnx->dso && cnx->egl.eglDestroyStreamKHR) { | 
|  | 1939 | result = cnx->egl.eglDestroyStreamKHR( | 
|  | 1940 | dp->disp.dpy, stream); | 
|  | 1941 | } | 
|  | 1942 | return result; | 
|  | 1943 | } | 
|  | 1944 |  | 
|  | 1945 | EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, | 
|  | 1946 | EGLenum attribute, EGLint value) | 
|  | 1947 | { | 
|  | 1948 | clearError(); | 
|  | 1949 |  | 
|  | 1950 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1951 | if (!dp) return EGL_FALSE; | 
|  | 1952 |  | 
|  | 1953 | EGLBoolean result = EGL_FALSE; | 
|  | 1954 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1955 | if (cnx->dso && cnx->egl.eglStreamAttribKHR) { | 
|  | 1956 | result = cnx->egl.eglStreamAttribKHR( | 
|  | 1957 | dp->disp.dpy, stream, attribute, value); | 
|  | 1958 | } | 
|  | 1959 | return result; | 
|  | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, | 
|  | 1963 | EGLenum attribute, EGLint *value) | 
|  | 1964 | { | 
|  | 1965 | clearError(); | 
|  | 1966 |  | 
|  | 1967 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1968 | if (!dp) return EGL_FALSE; | 
|  | 1969 |  | 
|  | 1970 | EGLBoolean result = EGL_FALSE; | 
|  | 1971 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1972 | if (cnx->dso && cnx->egl.eglQueryStreamKHR) { | 
|  | 1973 | result = cnx->egl.eglQueryStreamKHR( | 
|  | 1974 | dp->disp.dpy, stream, attribute, value); | 
|  | 1975 | } | 
|  | 1976 | return result; | 
|  | 1977 | } | 
|  | 1978 |  | 
|  | 1979 | EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, | 
|  | 1980 | EGLenum attribute, EGLuint64KHR *value) | 
|  | 1981 | { | 
|  | 1982 | clearError(); | 
|  | 1983 |  | 
|  | 1984 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 1985 | if (!dp) return EGL_FALSE; | 
|  | 1986 |  | 
|  | 1987 | EGLBoolean result = EGL_FALSE; | 
|  | 1988 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 1989 | if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) { | 
|  | 1990 | result = cnx->egl.eglQueryStreamu64KHR( | 
|  | 1991 | dp->disp.dpy, stream, attribute, value); | 
|  | 1992 | } | 
|  | 1993 | return result; | 
|  | 1994 | } | 
|  | 1995 |  | 
|  | 1996 | EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, | 
|  | 1997 | EGLenum attribute, EGLTimeKHR *value) | 
|  | 1998 | { | 
|  | 1999 | clearError(); | 
|  | 2000 |  | 
|  | 2001 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2002 | if (!dp) return EGL_FALSE; | 
|  | 2003 |  | 
|  | 2004 | EGLBoolean result = EGL_FALSE; | 
|  | 2005 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2006 | if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) { | 
|  | 2007 | result = cnx->egl.eglQueryStreamTimeKHR( | 
|  | 2008 | dp->disp.dpy, stream, attribute, value); | 
|  | 2009 | } | 
|  | 2010 | return result; | 
|  | 2011 | } | 
|  | 2012 |  | 
|  | 2013 | EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, | 
|  | 2014 | EGLStreamKHR stream, const EGLint *attrib_list) | 
|  | 2015 | { | 
|  | 2016 | clearError(); | 
|  | 2017 |  | 
|  | 2018 | egl_display_ptr dp = validate_display(dpy); | 
|  | 2019 | if (!dp) return EGL_NO_SURFACE; | 
|  | 2020 |  | 
|  | 2021 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2022 | if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) { | 
|  | 2023 | EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR( | 
|  | 2024 | dp->disp.dpy, config, stream, attrib_list); | 
|  | 2025 | if (surface != EGL_NO_SURFACE) { | 
| Courtney Goeltzenleuchter | b1d70ec | 2018-02-08 18:09:33 -0700 | [diff] [blame] | 2026 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, surface, | 
|  | 2027 | EGL_GL_COLORSPACE_LINEAR_KHR, cnx); | 
| Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 2028 | return s; | 
|  | 2029 | } | 
|  | 2030 | } | 
|  | 2031 | return EGL_NO_SURFACE; | 
|  | 2032 | } | 
|  | 2033 |  | 
|  | 2034 | EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, | 
|  | 2035 | EGLStreamKHR stream) | 
|  | 2036 | { | 
|  | 2037 | clearError(); | 
|  | 2038 |  | 
|  | 2039 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2040 | if (!dp) return EGL_FALSE; | 
|  | 2041 |  | 
|  | 2042 | EGLBoolean result = EGL_FALSE; | 
|  | 2043 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2044 | if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) { | 
|  | 2045 | result = cnx->egl.eglStreamConsumerGLTextureExternalKHR( | 
|  | 2046 | dp->disp.dpy, stream); | 
|  | 2047 | } | 
|  | 2048 | return result; | 
|  | 2049 | } | 
|  | 2050 |  | 
|  | 2051 | EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy, | 
|  | 2052 | EGLStreamKHR stream) | 
|  | 2053 | { | 
|  | 2054 | clearError(); | 
|  | 2055 |  | 
|  | 2056 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2057 | if (!dp) return EGL_FALSE; | 
|  | 2058 |  | 
|  | 2059 | EGLBoolean result = EGL_FALSE; | 
|  | 2060 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2061 | if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) { | 
|  | 2062 | result = cnx->egl.eglStreamConsumerAcquireKHR( | 
|  | 2063 | dp->disp.dpy, stream); | 
|  | 2064 | } | 
|  | 2065 | return result; | 
|  | 2066 | } | 
|  | 2067 |  | 
|  | 2068 | EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy, | 
|  | 2069 | EGLStreamKHR stream) | 
|  | 2070 | { | 
|  | 2071 | clearError(); | 
|  | 2072 |  | 
|  | 2073 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2074 | if (!dp) return EGL_FALSE; | 
|  | 2075 |  | 
|  | 2076 | EGLBoolean result = EGL_FALSE; | 
|  | 2077 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2078 | if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) { | 
|  | 2079 | result = cnx->egl.eglStreamConsumerReleaseKHR( | 
|  | 2080 | dp->disp.dpy, stream); | 
|  | 2081 | } | 
|  | 2082 | return result; | 
|  | 2083 | } | 
|  | 2084 |  | 
|  | 2085 | EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR( | 
|  | 2086 | EGLDisplay dpy, EGLStreamKHR stream) | 
|  | 2087 | { | 
|  | 2088 | clearError(); | 
|  | 2089 |  | 
|  | 2090 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2091 | if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR; | 
|  | 2092 |  | 
|  | 2093 | EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR; | 
|  | 2094 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2095 | if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) { | 
|  | 2096 | result = cnx->egl.eglGetStreamFileDescriptorKHR( | 
|  | 2097 | dp->disp.dpy, stream); | 
|  | 2098 | } | 
|  | 2099 | return result; | 
|  | 2100 | } | 
|  | 2101 |  | 
|  | 2102 | EGLStreamKHR eglCreateStreamFromFileDescriptorKHR( | 
|  | 2103 | EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor) | 
|  | 2104 | { | 
|  | 2105 | clearError(); | 
|  | 2106 |  | 
|  | 2107 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2108 | if (!dp) return EGL_NO_STREAM_KHR; | 
|  | 2109 |  | 
|  | 2110 | EGLStreamKHR result = EGL_NO_STREAM_KHR; | 
|  | 2111 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2112 | if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) { | 
|  | 2113 | result = cnx->egl.eglCreateStreamFromFileDescriptorKHR( | 
|  | 2114 | dp->disp.dpy, file_descriptor); | 
|  | 2115 | } | 
|  | 2116 | return result; | 
|  | 2117 | } | 
|  | 2118 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2119 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 2120 | // EGL_EGLEXT_VERSION 15 | 
|  | 2121 | // ---------------------------------------------------------------------------- | 
|  | 2122 |  | 
|  | 2123 | EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { | 
|  | 2124 | clearError(); | 
|  | 2125 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2126 | if (!dp) return EGL_FALSE; | 
|  | 2127 | EGLint result = EGL_FALSE; | 
|  | 2128 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2129 | if (cnx->dso && cnx->egl.eglWaitSyncKHR) { | 
|  | 2130 | result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); | 
|  | 2131 | } | 
|  | 2132 | return result; | 
|  | 2133 | } | 
|  | 2134 |  | 
|  | 2135 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2136 | // ANDROID extensions | 
|  | 2137 | // ---------------------------------------------------------------------------- | 
|  | 2138 |  | 
| Jamie Gennis | 331841b | 2012-09-06 14:52:00 -0700 | [diff] [blame] | 2139 | EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) | 
|  | 2140 | { | 
|  | 2141 | clearError(); | 
|  | 2142 |  | 
|  | 2143 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2144 | if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; | 
|  | 2145 |  | 
|  | 2146 | EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; | 
|  | 2147 | egl_connection_t* const cnx = &gEGLImpl; | 
|  | 2148 | if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { | 
|  | 2149 | result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); | 
|  | 2150 | } | 
|  | 2151 | return result; | 
|  | 2152 | } | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2153 |  | 
| Andy McFadden | 7284145 | 2013-03-01 16:25:32 -0800 | [diff] [blame] | 2154 | EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, | 
|  | 2155 | EGLnsecsANDROID time) | 
|  | 2156 | { | 
|  | 2157 | clearError(); | 
|  | 2158 |  | 
|  | 2159 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2160 | if (!dp) { | 
|  | 2161 | return EGL_FALSE; | 
|  | 2162 | } | 
|  | 2163 |  | 
|  | 2164 | SurfaceRef _s(dp.get(), surface); | 
|  | 2165 | if (!_s.get()) { | 
|  | 2166 | setError(EGL_BAD_SURFACE, EGL_FALSE); | 
|  | 2167 | return EGL_FALSE; | 
|  | 2168 | } | 
|  | 2169 |  | 
|  | 2170 | egl_surface_t const * const s = get_surface(surface); | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2171 | native_window_set_buffers_timestamp(s->getNativeWindow(), time); | 
| Andy McFadden | 7284145 | 2013-03-01 16:25:32 -0800 | [diff] [blame] | 2172 |  | 
|  | 2173 | return EGL_TRUE; | 
|  | 2174 | } | 
|  | 2175 |  | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 2176 | EGLClientBuffer eglGetNativeClientBufferANDROID(const AHardwareBuffer *buffer) { | 
|  | 2177 | clearError(); | 
| Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 2178 | // AHardwareBuffer_to_ANativeWindowBuffer is a platform-only symbol and thus | 
|  | 2179 | // this function cannot be implemented when this libEGL is built for | 
|  | 2180 | // vendors. | 
|  | 2181 | #ifndef __ANDROID_VNDK__ | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 2182 | if (!buffer) return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); | 
| Mathias Agopian | 6196340 | 2017-02-24 16:38:15 -0800 | [diff] [blame] | 2183 | return const_cast<ANativeWindowBuffer *>(AHardwareBuffer_to_ANativeWindowBuffer(buffer)); | 
| Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 2184 | #else | 
|  | 2185 | return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); | 
|  | 2186 | #endif | 
| Craig Donner | 6076107 | 2017-01-27 12:30:44 -0800 | [diff] [blame] | 2187 | } | 
|  | 2188 |  | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2189 | // ---------------------------------------------------------------------------- | 
|  | 2190 | // NVIDIA extensions | 
|  | 2191 | // ---------------------------------------------------------------------------- | 
|  | 2192 | EGLuint64NV eglGetSystemTimeFrequencyNV() | 
|  | 2193 | { | 
|  | 2194 | clearError(); | 
|  | 2195 |  | 
|  | 2196 | if (egl_init_drivers() == EGL_FALSE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2197 | return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2198 | } | 
|  | 2199 |  | 
|  | 2200 | EGLuint64NV ret = 0; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 2201 | egl_connection_t* const cnx = &gEGLImpl; | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2202 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 2203 | if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { | 
|  | 2204 | return cnx->egl.eglGetSystemTimeFrequencyNV(); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2205 | } | 
|  | 2206 |  | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2207 | return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2208 | } | 
|  | 2209 |  | 
|  | 2210 | EGLuint64NV eglGetSystemTimeNV() | 
|  | 2211 | { | 
|  | 2212 | clearError(); | 
|  | 2213 |  | 
|  | 2214 | if (egl_init_drivers() == EGL_FALSE) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2215 | return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2216 | } | 
|  | 2217 |  | 
|  | 2218 | EGLuint64NV ret = 0; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 2219 | egl_connection_t* const cnx = &gEGLImpl; | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2220 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 2221 | if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { | 
|  | 2222 | return cnx->egl.eglGetSystemTimeNV(); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2223 | } | 
|  | 2224 |  | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2225 | return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0); | 
| Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 2226 | } | 
| Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 2227 |  | 
|  | 2228 | // ---------------------------------------------------------------------------- | 
|  | 2229 | // Partial update extension | 
|  | 2230 | // ---------------------------------------------------------------------------- | 
|  | 2231 | EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, | 
|  | 2232 | EGLint *rects, EGLint n_rects) | 
|  | 2233 | { | 
|  | 2234 | clearError(); | 
|  | 2235 |  | 
|  | 2236 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2237 | if (!dp) { | 
|  | 2238 | setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 2239 | return EGL_FALSE; | 
|  | 2240 | } | 
|  | 2241 |  | 
|  | 2242 | SurfaceRef _s(dp.get(), surface); | 
|  | 2243 | if (!_s.get()) { | 
|  | 2244 | setError(EGL_BAD_SURFACE, EGL_FALSE); | 
|  | 2245 | return EGL_FALSE; | 
|  | 2246 | } | 
|  | 2247 |  | 
|  | 2248 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2249 | if (s->cnx->egl.eglSetDamageRegionKHR) { | 
|  | 2250 | return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, | 
|  | 2251 | rects, n_rects); | 
|  | 2252 | } | 
|  | 2253 |  | 
|  | 2254 | return EGL_FALSE; | 
|  | 2255 | } | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2256 |  | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2257 | EGLBoolean eglGetNextFrameIdANDROID(EGLDisplay dpy, EGLSurface surface, | 
|  | 2258 | EGLuint64KHR *frameId) { | 
|  | 2259 | clearError(); | 
|  | 2260 |  | 
|  | 2261 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2262 | if (!dp) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2263 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2264 | } | 
|  | 2265 |  | 
|  | 2266 | SurfaceRef _s(dp.get(), surface); | 
|  | 2267 | if (!_s.get()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2268 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2269 | } | 
|  | 2270 |  | 
|  | 2271 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2272 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2273 | if (!s->getNativeWindow()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2274 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2275 | } | 
|  | 2276 |  | 
|  | 2277 | uint64_t nextFrameId = 0; | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2278 | int ret = native_window_get_next_frame_id(s->getNativeWindow(), &nextFrameId); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2279 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2280 | if (ret != 0) { | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2281 | // This should not happen. Return an error that is not in the spec | 
|  | 2282 | // so it's obvious something is very wrong. | 
|  | 2283 | ALOGE("eglGetNextFrameId: Unexpected error."); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2284 | return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2285 | } | 
|  | 2286 |  | 
|  | 2287 | *frameId = nextFrameId; | 
|  | 2288 | return EGL_TRUE; | 
|  | 2289 | } | 
|  | 2290 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2291 | EGLBoolean eglGetCompositorTimingANDROID(EGLDisplay dpy, EGLSurface surface, | 
|  | 2292 | EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values) | 
|  | 2293 | { | 
|  | 2294 | clearError(); | 
|  | 2295 |  | 
|  | 2296 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2297 | if (!dp) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2298 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2299 | } | 
|  | 2300 |  | 
|  | 2301 | SurfaceRef _s(dp.get(), surface); | 
|  | 2302 | if (!_s.get()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2303 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2304 | } | 
|  | 2305 |  | 
|  | 2306 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2307 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2308 | if (!s->getNativeWindow()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2309 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2310 | } | 
|  | 2311 |  | 
|  | 2312 | nsecs_t* compositeDeadline = nullptr; | 
|  | 2313 | nsecs_t* compositeInterval = nullptr; | 
|  | 2314 | nsecs_t* compositeToPresentLatency = nullptr; | 
|  | 2315 |  | 
|  | 2316 | for (int i = 0; i < numTimestamps; i++) { | 
|  | 2317 | switch (names[i]) { | 
|  | 2318 | case EGL_COMPOSITE_DEADLINE_ANDROID: | 
|  | 2319 | compositeDeadline = &values[i]; | 
|  | 2320 | break; | 
|  | 2321 | case EGL_COMPOSITE_INTERVAL_ANDROID: | 
|  | 2322 | compositeInterval = &values[i]; | 
|  | 2323 | break; | 
|  | 2324 | case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID: | 
|  | 2325 | compositeToPresentLatency = &values[i]; | 
|  | 2326 | break; | 
|  | 2327 | default: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2328 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2329 | } | 
|  | 2330 | } | 
|  | 2331 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2332 | int ret = native_window_get_compositor_timing(s->getNativeWindow(), | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2333 | compositeDeadline, compositeInterval, compositeToPresentLatency); | 
|  | 2334 |  | 
|  | 2335 | switch (ret) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2336 | case 0: | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2337 | return EGL_TRUE; | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2338 | case -ENOSYS: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2339 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2340 | default: | 
|  | 2341 | // This should not happen. Return an error that is not in the spec | 
|  | 2342 | // so it's obvious something is very wrong. | 
|  | 2343 | ALOGE("eglGetCompositorTiming: Unexpected error."); | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2344 | return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2345 | } | 
|  | 2346 | } | 
|  | 2347 |  | 
|  | 2348 | EGLBoolean eglGetCompositorTimingSupportedANDROID( | 
|  | 2349 | EGLDisplay dpy, EGLSurface surface, EGLint name) | 
|  | 2350 | { | 
|  | 2351 | clearError(); | 
|  | 2352 |  | 
|  | 2353 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2354 | if (!dp) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2355 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2356 | } | 
|  | 2357 |  | 
|  | 2358 | SurfaceRef _s(dp.get(), surface); | 
|  | 2359 | if (!_s.get()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2360 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2361 | } | 
|  | 2362 |  | 
|  | 2363 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2364 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2365 | ANativeWindow* window = s->getNativeWindow(); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2366 | if (!window) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2367 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2368 | } | 
|  | 2369 |  | 
|  | 2370 | switch (name) { | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2371 | case EGL_COMPOSITE_DEADLINE_ANDROID: | 
|  | 2372 | case EGL_COMPOSITE_INTERVAL_ANDROID: | 
|  | 2373 | case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID: | 
|  | 2374 | return EGL_TRUE; | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2375 | default: | 
|  | 2376 | return EGL_FALSE; | 
|  | 2377 | } | 
|  | 2378 | } | 
|  | 2379 |  | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2380 | EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface, | 
| Brian Anderson | 1049d1d | 2016-12-16 17:25:57 -0800 | [diff] [blame] | 2381 | EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps, | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2382 | EGLnsecsANDROID *values) | 
|  | 2383 | { | 
|  | 2384 | clearError(); | 
|  | 2385 |  | 
|  | 2386 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2387 | if (!dp) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2388 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2389 | } | 
|  | 2390 |  | 
|  | 2391 | SurfaceRef _s(dp.get(), surface); | 
|  | 2392 | if (!_s.get()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2393 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2394 | } | 
|  | 2395 |  | 
|  | 2396 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2397 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2398 | if (!s->getNativeWindow()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2399 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2400 | } | 
|  | 2401 |  | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 2402 | nsecs_t* requestedPresentTime = nullptr; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2403 | nsecs_t* acquireTime = nullptr; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2404 | nsecs_t* latchTime = nullptr; | 
|  | 2405 | nsecs_t* firstRefreshStartTime = nullptr; | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 2406 | nsecs_t* gpuCompositionDoneTime = nullptr; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2407 | nsecs_t* lastRefreshStartTime = nullptr; | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 2408 | nsecs_t* displayPresentTime = nullptr; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2409 | nsecs_t* dequeueReadyTime = nullptr; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2410 | nsecs_t* releaseTime = nullptr; | 
|  | 2411 |  | 
|  | 2412 | for (int i = 0; i < numTimestamps; i++) { | 
|  | 2413 | switch (timestamps[i]) { | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 2414 | case EGL_REQUESTED_PRESENT_TIME_ANDROID: | 
|  | 2415 | requestedPresentTime = &values[i]; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2416 | break; | 
|  | 2417 | case EGL_RENDERING_COMPLETE_TIME_ANDROID: | 
|  | 2418 | acquireTime = &values[i]; | 
|  | 2419 | break; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2420 | case EGL_COMPOSITION_LATCH_TIME_ANDROID: | 
|  | 2421 | latchTime = &values[i]; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2422 | break; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2423 | case EGL_FIRST_COMPOSITION_START_TIME_ANDROID: | 
|  | 2424 | firstRefreshStartTime = &values[i]; | 
|  | 2425 | break; | 
|  | 2426 | case EGL_LAST_COMPOSITION_START_TIME_ANDROID: | 
|  | 2427 | lastRefreshStartTime = &values[i]; | 
|  | 2428 | break; | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 2429 | case EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID: | 
|  | 2430 | gpuCompositionDoneTime = &values[i]; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2431 | break; | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 2432 | case EGL_DISPLAY_PRESENT_TIME_ANDROID: | 
|  | 2433 | displayPresentTime = &values[i]; | 
|  | 2434 | break; | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2435 | case EGL_DEQUEUE_READY_TIME_ANDROID: | 
|  | 2436 | dequeueReadyTime = &values[i]; | 
|  | 2437 | break; | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2438 | case EGL_READS_DONE_TIME_ANDROID: | 
|  | 2439 | releaseTime = &values[i]; | 
|  | 2440 | break; | 
|  | 2441 | default: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2442 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2443 | } | 
|  | 2444 | } | 
|  | 2445 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2446 | int ret = native_window_get_frame_timestamps(s->getNativeWindow(), frameId, | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2447 | requestedPresentTime, acquireTime, latchTime, firstRefreshStartTime, | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 2448 | lastRefreshStartTime, gpuCompositionDoneTime, displayPresentTime, | 
| Brian Anderson | 4e606e3 | 2017-03-16 15:34:57 -0700 | [diff] [blame] | 2449 | dequeueReadyTime, releaseTime); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2450 |  | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 2451 | switch (ret) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2452 | case 0: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2453 | return EGL_TRUE; | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2454 | case -ENOENT: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2455 | return setError(EGL_BAD_ACCESS, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2456 | case -ENOSYS: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2457 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2458 | case -EINVAL: | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2459 | return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); | 
|  | 2460 | default: | 
|  | 2461 | // This should not happen. Return an error that is not in the spec | 
|  | 2462 | // so it's obvious something is very wrong. | 
|  | 2463 | ALOGE("eglGetFrameTimestamps: Unexpected error."); | 
|  | 2464 | return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2465 | } | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2466 | } | 
|  | 2467 |  | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2468 | EGLBoolean eglGetFrameTimestampSupportedANDROID( | 
|  | 2469 | EGLDisplay dpy, EGLSurface surface, EGLint timestamp) | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2470 | { | 
|  | 2471 | clearError(); | 
|  | 2472 |  | 
|  | 2473 | const egl_display_ptr dp = validate_display(dpy); | 
|  | 2474 | if (!dp) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2475 | return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2476 | } | 
|  | 2477 |  | 
|  | 2478 | SurfaceRef _s(dp.get(), surface); | 
|  | 2479 | if (!_s.get()) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2480 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 2481 | } | 
|  | 2482 |  | 
|  | 2483 | egl_surface_t const * const s = get_surface(surface); | 
|  | 2484 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 2485 | ANativeWindow* window = s->getNativeWindow(); | 
| Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 2486 | if (!window) { | 
| Mathias Agopian | 737b896 | 2017-02-24 14:32:05 -0800 | [diff] [blame] | 2487 | return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2488 | } | 
|  | 2489 |  | 
|  | 2490 | switch (timestamp) { | 
| Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 2491 | case EGL_COMPOSITE_DEADLINE_ANDROID: | 
|  | 2492 | case EGL_COMPOSITE_INTERVAL_ANDROID: | 
|  | 2493 | case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID: | 
| Brian Anderson | dbd0ea8 | 2016-07-22 09:38:59 -0700 | [diff] [blame] | 2494 | case EGL_REQUESTED_PRESENT_TIME_ANDROID: | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2495 | case EGL_RENDERING_COMPLETE_TIME_ANDROID: | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2496 | case EGL_COMPOSITION_LATCH_TIME_ANDROID: | 
|  | 2497 | case EGL_FIRST_COMPOSITION_START_TIME_ANDROID: | 
|  | 2498 | case EGL_LAST_COMPOSITION_START_TIME_ANDROID: | 
| Brian Anderson | b04c6f0 | 2016-10-21 12:57:46 -0700 | [diff] [blame] | 2499 | case EGL_FIRST_COMPOSITION_GPU_FINISHED_TIME_ANDROID: | 
| Brian Anderson | f7fd56a | 2016-09-02 10:10:04 -0700 | [diff] [blame] | 2500 | case EGL_DEQUEUE_READY_TIME_ANDROID: | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2501 | case EGL_READS_DONE_TIME_ANDROID: | 
|  | 2502 | return EGL_TRUE; | 
| Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 2503 | case EGL_DISPLAY_PRESENT_TIME_ANDROID: { | 
|  | 2504 | int value = 0; | 
|  | 2505 | window->query(window, | 
|  | 2506 | NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &value); | 
|  | 2507 | return value == 0 ? EGL_FALSE : EGL_TRUE; | 
|  | 2508 | } | 
| Pablo Ceballos | c18be29 | 2016-05-31 14:55:42 -0700 | [diff] [blame] | 2509 | default: | 
|  | 2510 | return EGL_FALSE; | 
|  | 2511 | } | 
|  | 2512 | } |