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