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