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