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