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