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