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