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