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