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