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