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