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