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