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