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