blob: 1672397a975661cab3f0f1f2b3a78f795308c88a [file] [log] [blame]
Jesse Hall47743382013-02-08 11:13:46 -08001/*
Mathias Agopian518ec112011-05-13 16:21:08 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall47743382013-02-08 11:13:46 -08004 ** 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 Agopian518ec112011-05-13 16:21:08 -07007 **
Jesse Hall47743382013-02-08 11:13:46 -08008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopian518ec112011-05-13 16:21:08 -07009 **
Jesse Hall47743382013-02-08 11:13:46 -080010 ** 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 Agopian518ec112011-05-13 16:21:08 -070014 ** limitations under the License.
15 */
16
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Mathias Agopian518ec112011-05-13 16:21:08 -070019#include <ctype.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070020#include <dlfcn.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070021#include <stdlib.h>
22#include <string.h>
23
24#include <hardware/gralloc.h>
25#include <system/window.h>
26
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070029
Mathias Agopian518ec112011-05-13 16:21:08 -070030#include <cutils/atomic.h>
Mathias Agopian7db993a2012-03-25 00:49:46 -070031#include <cutils/compiler.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070032#include <cutils/memory.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070033#include <cutils/properties.h>
Mark Salyzyn7823e122016-09-29 08:08:05 -070034#include <log/log.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070035
Craig Donner68671532016-07-18 10:19:54 -070036#include <gui/ISurfaceComposer.h>
37
Craig Donner05249fc2016-01-15 19:33:55 -080038#include <ui/GraphicBuffer.h>
39
Mathias Agopian518ec112011-05-13 16:21:08 -070040#include <utils/KeyedVector.h>
41#include <utils/SortedVector.h>
42#include <utils/String8.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080043#include <utils/Trace.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070044
Craig Donner68671532016-07-18 10:19:54 -070045#include "binder/Binder.h"
46#include "binder/Parcel.h"
47#include "binder/IServiceManager.h"
48
Mathias Agopian39c24a22013-04-04 23:17:56 -070049#include "../egl_impl.h"
Mathias Agopian39c24a22013-04-04 23:17:56 -070050#include "../hooks.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070051
52#include "egl_display.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070053#include "egl_object.h"
54#include "egl_tls.h"
Mathias Agopianada798b2012-02-13 17:09:30 -080055#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070056
57using namespace android;
58
Pablo Ceballosb1e2c722016-07-14 08:02:14 -070059#define ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS 0
60
Mathias Agopian518ec112011-05-13 16:21:08 -070061// ----------------------------------------------------------------------------
62
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070063namespace android {
64
Mathias Agopian518ec112011-05-13 16:21:08 -070065struct extention_map_t {
66 const char* name;
67 __eglMustCastToProperFunctionPointerType address;
68};
69
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070070/*
Jesse Hall21558da2013-08-06 15:31:22 -070071 * This is the list of EGL extensions exposed to applications.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070072 *
Jesse Hall21558da2013-08-06 15:31:22 -070073 * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
74 * wrapper and are always available.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070075 *
Jesse Hall21558da2013-08-06 15:31:22 -070076 * The rest (gExtensionString) depend on support in the EGL driver, and are
77 * only available if the driver supports them. However, some of these must be
78 * supported because they are used by the Android system itself; these are
Pablo Ceballos02b05da2016-02-02 17:53:18 -080079 * listed as mandatory below and are required by the CDD. The system *assumes*
Jesse Hall21558da2013-08-06 15:31:22 -070080 * the mandatory extensions are present and may not function properly if some
81 * are missing.
82 *
83 * NOTE: Both strings MUST have a single space as the last character.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070084 */
Jesse Hall21558da2013-08-06 15:31:22 -070085extern char const * const gBuiltinExtensionString =
86 "EGL_KHR_get_all_proc_addresses "
87 "EGL_ANDROID_presentation_time "
Dan Stozaa894d082015-02-19 15:27:36 -080088 "EGL_KHR_swap_buffers_with_damage "
Craig Donner05249fc2016-01-15 19:33:55 -080089 "EGL_ANDROID_create_native_client_buffer "
Pablo Ceballos02b05da2016-02-02 17:53:18 -080090 "EGL_ANDROID_front_buffer_auto_refresh "
Pablo Ceballosb1e2c722016-07-14 08:02:14 -070091#if ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS
Pablo Ceballosc18be292016-05-31 14:55:42 -070092 "EGL_ANDROID_get_frame_timestamps "
Pablo Ceballosb1e2c722016-07-14 08:02:14 -070093#endif
Jesse Hall21558da2013-08-06 15:31:22 -070094 ;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070095extern char const * const gExtensionString =
96 "EGL_KHR_image " // mandatory
97 "EGL_KHR_image_base " // mandatory
98 "EGL_KHR_image_pixmap "
99 "EGL_KHR_lock_surface "
Jesse Hallc2e41222013-08-08 13:40:22 -0700100 "EGL_KHR_gl_colorspace "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700101 "EGL_KHR_gl_texture_2D_image "
Season Li000d88f2015-07-01 11:39:40 -0700102 "EGL_KHR_gl_texture_3D_image "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700103 "EGL_KHR_gl_texture_cubemap_image "
104 "EGL_KHR_gl_renderbuffer_image "
105 "EGL_KHR_reusable_sync "
106 "EGL_KHR_fence_sync "
Jamie Gennisf6d1c392013-04-25 18:48:41 -0700107 "EGL_KHR_create_context "
Season Li000d88f2015-07-01 11:39:40 -0700108 "EGL_KHR_config_attribs "
109 "EGL_KHR_surfaceless_context "
110 "EGL_KHR_stream "
111 "EGL_KHR_stream_fifo "
112 "EGL_KHR_stream_producer_eglsurface "
113 "EGL_KHR_stream_consumer_gltexture "
114 "EGL_KHR_stream_cross_process_fd "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700115 "EGL_EXT_create_context_robustness "
116 "EGL_NV_system_time "
117 "EGL_ANDROID_image_native_buffer " // mandatory
Mathias Agopian2bb71682013-03-27 17:32:41 -0700118 "EGL_KHR_wait_sync " // strongly recommended
Jamie Gennisdbe92452013-09-23 17:22:10 -0700119 "EGL_ANDROID_recordable " // mandatory
Dan Stozaa894d082015-02-19 15:27:36 -0800120 "EGL_KHR_partial_update " // strongly recommended
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700121 "EGL_EXT_pixel_format_float "
Dan Stozaa894d082015-02-19 15:27:36 -0800122 "EGL_EXT_buffer_age " // strongly recommended with partial_update
Jesse Hall408e59f2015-04-24 01:40:42 -0700123 "EGL_KHR_create_context_no_error "
Pablo Ceballosceb9ee72016-04-13 11:17:32 -0700124 "EGL_KHR_mutable_render_buffer "
Mika Isojärvif37864b2016-04-15 11:58:56 -0700125 "EGL_EXT_yuv_surface "
Craig Donneraec86972016-04-28 18:09:40 -0700126 "EGL_EXT_protected_content "
Christian Poetzscha7805f62016-12-01 16:34:39 +0000127 "EGL_IMG_context_priority "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700128 ;
129
130// extensions not exposed to applications but used by the ANDROID system
131// "EGL_ANDROID_blob_cache " // strongly recommended
132// "EGL_IMG_hibernate_process " // optional
133// "EGL_ANDROID_native_fence_sync " // strongly recommended
134// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1
Jamie Gennisdbe92452013-09-23 17:22:10 -0700135// "EGL_ANDROID_image_crop " // optional
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700136
137/*
138 * EGL Extensions entry-points exposed to 3rd party applications
139 * (keep in sync with gExtensionString above)
140 *
141 */
142static const extention_map_t sExtensionMap[] = {
143 // EGL_KHR_lock_surface
Mathias Agopian518ec112011-05-13 16:21:08 -0700144 { "eglLockSurfaceKHR",
145 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
146 { "eglUnlockSurfaceKHR",
147 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700148
149 // EGL_KHR_image, EGL_KHR_image_base
Mathias Agopian518ec112011-05-13 16:21:08 -0700150 { "eglCreateImageKHR",
151 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
152 { "eglDestroyImageKHR",
153 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700154
155 // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
156 { "eglCreateSyncKHR",
157 (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
158 { "eglDestroySyncKHR",
159 (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
160 { "eglClientWaitSyncKHR",
161 (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
162 { "eglSignalSyncKHR",
163 (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
164 { "eglGetSyncAttribKHR",
165 (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
166
167 // EGL_NV_system_time
Jonas Yang1c3d72a2011-08-26 20:04:39 +0800168 { "eglGetSystemTimeFrequencyNV",
169 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
170 { "eglGetSystemTimeNV",
171 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700172
Mathias Agopian2bb71682013-03-27 17:32:41 -0700173 // EGL_KHR_wait_sync
174 { "eglWaitSyncKHR",
175 (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700176
177 // EGL_ANDROID_presentation_time
178 { "eglPresentationTimeANDROID",
179 (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
Dan Stozaa894d082015-02-19 15:27:36 -0800180
181 // EGL_KHR_swap_buffers_with_damage
182 { "eglSwapBuffersWithDamageKHR",
183 (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
184
Craig Donner05249fc2016-01-15 19:33:55 -0800185 // EGL_ANDROID_native_client_buffer
186 { "eglCreateNativeClientBufferANDROID",
187 (__eglMustCastToProperFunctionPointerType)&eglCreateNativeClientBufferANDROID },
188
Dan Stozaa894d082015-02-19 15:27:36 -0800189 // EGL_KHR_partial_update
190 { "eglSetDamageRegionKHR",
191 (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
Season Li000d88f2015-07-01 11:39:40 -0700192
193 { "eglCreateStreamKHR",
194 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR },
195 { "eglDestroyStreamKHR",
196 (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR },
197 { "eglStreamAttribKHR",
198 (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR },
199 { "eglQueryStreamKHR",
200 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR },
201 { "eglQueryStreamu64KHR",
202 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR },
203 { "eglQueryStreamTimeKHR",
204 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR },
205 { "eglCreateStreamProducerSurfaceKHR",
206 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR },
207 { "eglStreamConsumerGLTextureExternalKHR",
208 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR },
209 { "eglStreamConsumerAcquireKHR",
210 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR },
211 { "eglStreamConsumerReleaseKHR",
212 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR },
213 { "eglGetStreamFileDescriptorKHR",
214 (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR },
215 { "eglCreateStreamFromFileDescriptorKHR",
216 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },
Pablo Ceballosc18be292016-05-31 14:55:42 -0700217
218 // EGL_ANDROID_get_frame_timestamps
219 { "eglGetFrameTimestampsANDROID",
220 (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID },
221 { "eglQueryTimestampSupportedANDROID",
222 (__eglMustCastToProperFunctionPointerType)&eglQueryTimestampSupportedANDROID },
Mathias Agopian518ec112011-05-13 16:21:08 -0700223};
224
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700225/*
226 * These extensions entry-points should not be exposed to applications.
227 * They're used internally by the Android EGL layer.
228 */
229#define FILTER_EXTENSIONS(procname) \
230 (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \
231 !strcmp((procname), "eglHibernateProcessIMG") || \
232 !strcmp((procname), "eglAwakenProcessIMG") || \
233 !strcmp((procname), "eglDupNativeFenceFDANDROID"))
234
235
236
Mathias Agopian518ec112011-05-13 16:21:08 -0700237// accesses protected by sExtensionMapMutex
238static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
239static int sGLExtentionSlot = 0;
240static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
241
242static void(*findProcAddress(const char* name,
243 const extention_map_t* map, size_t n))() {
244 for (uint32_t i=0 ; i<n ; i++) {
245 if (!strcmp(name, map[i].name)) {
246 return map[i].address;
247 }
248 }
249 return NULL;
250}
251
252// ----------------------------------------------------------------------------
253
Mathias Agopian518ec112011-05-13 16:21:08 -0700254extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
255extern EGLBoolean egl_init_drivers();
256extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
Mathias Agopian518ec112011-05-13 16:21:08 -0700257extern gl_hooks_t gHooksTrace;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700258
Mathias Agopian518ec112011-05-13 16:21:08 -0700259} // namespace android;
260
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700261
Mathias Agopian518ec112011-05-13 16:21:08 -0700262// ----------------------------------------------------------------------------
263
264static inline void clearError() { egl_tls_t::clearError(); }
265static inline EGLContext getContext() { return egl_tls_t::getContext(); }
266
267// ----------------------------------------------------------------------------
268
269EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
270{
Jesse Hall1508ae62017-01-19 17:43:26 -0800271 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700272 clearError();
273
Dan Stozac3289c42014-01-17 11:38:34 -0800274 uintptr_t index = reinterpret_cast<uintptr_t>(display);
Mathias Agopian518ec112011-05-13 16:21:08 -0700275 if (index >= NUM_DISPLAYS) {
276 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
277 }
278
279 if (egl_init_drivers() == EGL_FALSE) {
280 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
281 }
282
283 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
284 return dpy;
285}
286
287// ----------------------------------------------------------------------------
288// Initialization
289// ----------------------------------------------------------------------------
290
291EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
292{
293 clearError();
294
Jesse Hallb29e5e82012-04-04 16:53:42 -0700295 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700296 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
297
298 EGLBoolean res = dp->initialize(major, minor);
299
300 return res;
301}
302
303EGLBoolean eglTerminate(EGLDisplay dpy)
304{
305 // NOTE: don't unload the drivers b/c some APIs can be called
306 // after eglTerminate() has been called. eglTerminate() only
307 // terminates an EGLDisplay, not a EGL itself.
308
309 clearError();
310
Jesse Hallb29e5e82012-04-04 16:53:42 -0700311 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700312 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
313
314 EGLBoolean res = dp->terminate();
Jesse Hall47743382013-02-08 11:13:46 -0800315
Mathias Agopian518ec112011-05-13 16:21:08 -0700316 return res;
317}
318
319// ----------------------------------------------------------------------------
320// configuration
321// ----------------------------------------------------------------------------
322
323EGLBoolean eglGetConfigs( EGLDisplay dpy,
324 EGLConfig *configs,
325 EGLint config_size, EGLint *num_config)
326{
327 clearError();
328
Jesse Hallb29e5e82012-04-04 16:53:42 -0700329 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700330 if (!dp) return EGL_FALSE;
331
Mathias Agopian7773c432012-02-13 20:06:08 -0800332 if (num_config==0) {
333 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700334 }
335
Mathias Agopian7773c432012-02-13 20:06:08 -0800336 EGLBoolean res = EGL_FALSE;
337 *num_config = 0;
338
339 egl_connection_t* const cnx = &gEGLImpl;
340 if (cnx->dso) {
341 res = cnx->egl.eglGetConfigs(
342 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700343 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800344
345 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700346}
347
348EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
349 EGLConfig *configs, EGLint config_size,
350 EGLint *num_config)
351{
352 clearError();
353
Jesse Hallb29e5e82012-04-04 16:53:42 -0700354 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700355 if (!dp) return EGL_FALSE;
356
357 if (num_config==0) {
358 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
359 }
360
Mathias Agopian518ec112011-05-13 16:21:08 -0700361 EGLBoolean res = EGL_FALSE;
362 *num_config = 0;
363
Mathias Agopianada798b2012-02-13 17:09:30 -0800364 egl_connection_t* const cnx = &gEGLImpl;
365 if (cnx->dso) {
Romain Guy1cffc802012-10-15 18:13:05 -0700366 if (attrib_list) {
367 char value[PROPERTY_VALUE_MAX];
368 property_get("debug.egl.force_msaa", value, "false");
369
370 if (!strcmp(value, "true")) {
371 size_t attribCount = 0;
372 EGLint attrib = attrib_list[0];
373
374 // Only enable MSAA if the context is OpenGL ES 2.0 and
Romain Guybe3c3e42012-10-15 19:25:18 -0700375 // if no caveat is requested
Romain Guy1cffc802012-10-15 18:13:05 -0700376 const EGLint *attribRendererable = NULL;
377 const EGLint *attribCaveat = NULL;
378
379 // Count the number of attributes and look for
Romain Guybe3c3e42012-10-15 19:25:18 -0700380 // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
Romain Guy1cffc802012-10-15 18:13:05 -0700381 while (attrib != EGL_NONE) {
382 attrib = attrib_list[attribCount];
383 switch (attrib) {
384 case EGL_RENDERABLE_TYPE:
385 attribRendererable = &attrib_list[attribCount];
386 break;
387 case EGL_CONFIG_CAVEAT:
388 attribCaveat = &attrib_list[attribCount];
389 break;
390 }
391 attribCount++;
392 }
393
394 if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
395 (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
Jesse Hall47743382013-02-08 11:13:46 -0800396
Romain Guy1cffc802012-10-15 18:13:05 -0700397 // Insert 2 extra attributes to force-enable MSAA 4x
398 EGLint aaAttribs[attribCount + 4];
399 aaAttribs[0] = EGL_SAMPLE_BUFFERS;
400 aaAttribs[1] = 1;
401 aaAttribs[2] = EGL_SAMPLES;
402 aaAttribs[3] = 4;
403
404 memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
405
406 EGLint numConfigAA;
407 EGLBoolean resAA = cnx->egl.eglChooseConfig(
408 dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
409
410 if (resAA == EGL_TRUE && numConfigAA > 0) {
411 ALOGD("Enabling MSAA 4x");
412 *num_config = numConfigAA;
413 return resAA;
414 }
415 }
416 }
417 }
418
Mathias Agopian7773c432012-02-13 20:06:08 -0800419 res = cnx->egl.eglChooseConfig(
420 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700421 }
422 return res;
423}
424
425EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
426 EGLint attribute, EGLint *value)
427{
428 clearError();
429
Jesse Hallb29e5e82012-04-04 16:53:42 -0700430 egl_connection_t* cnx = NULL;
431 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
432 if (!dp) return EGL_FALSE;
Jesse Hall47743382013-02-08 11:13:46 -0800433
Mathias Agopian518ec112011-05-13 16:21:08 -0700434 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800435 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700436}
437
438// ----------------------------------------------------------------------------
439// surfaces
440// ----------------------------------------------------------------------------
441
Jesse Hallc2e41222013-08-08 13:40:22 -0700442// Turn linear formats into corresponding sRGB formats when colorspace is
443// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear
444// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800445// the modification isn't possible, the original dataSpace is returned.
446static android_dataspace modifyBufferDataspace( android_dataspace dataSpace,
447 EGLint colorspace) {
Jesse Hallc2e41222013-08-08 13:40:22 -0700448 if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800449 return HAL_DATASPACE_SRGB_LINEAR;
Jesse Hallc2e41222013-08-08 13:40:22 -0700450 } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800451 return HAL_DATASPACE_SRGB;
Jesse Hallc2e41222013-08-08 13:40:22 -0700452 }
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800453 return dataSpace;
Jesse Hallc2e41222013-08-08 13:40:22 -0700454}
455
Mathias Agopian518ec112011-05-13 16:21:08 -0700456EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
457 NativeWindowType window,
458 const EGLint *attrib_list)
459{
460 clearError();
461
Jesse Hallb29e5e82012-04-04 16:53:42 -0700462 egl_connection_t* cnx = NULL;
463 egl_display_ptr dp = validate_display_connection(dpy, cnx);
464 if (dp) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800465 EGLDisplay iDpy = dp->disp.dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700466
Andy McFaddend566ce32014-01-07 15:54:17 -0800467 int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
468 if (result != OK) {
469 ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
470 "failed (%#x) (already connected to another API?)",
471 window, result);
Jonathan Hamilton77a9b4a2013-07-17 09:41:42 -0700472 return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
Mathias Agopian81a63352011-07-29 17:55:48 -0700473 }
474
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700475 // Set the native window's buffers format to match what this config requests.
Jesse Hallc2e41222013-08-08 13:40:22 -0700476 // Whether to use sRGB gamma is not part of the EGLconfig, but is part
477 // of our native format. So if sRGB gamma is requested, we have to
478 // modify the EGLconfig's format before setting the native window's
479 // format.
Alistair Strachan733a8072015-02-12 12:33:25 -0800480
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700481 EGLint componentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
482 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_COLOR_COMPONENT_TYPE_EXT,
483 &componentType);
484
485 // by default, just pick appropriate RGBA
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700486 EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700487 if (dp->haveExtension("EGL_EXT_pixel_format_float") &&
488 (componentType == EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)) {
489 format = HAL_PIXEL_FORMAT_RGBA_FP16;
490 }
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800491 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700492
493 EGLint a = 0;
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700494 EGLint r, g, b;
495 r = g = b = 0;
496 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r);
497 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
498 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b);
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700499 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700500 EGLint colorDepth = r + g + b;
501
502 if (a == 0) {
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700503 if (colorDepth <= 16) {
504 format = HAL_PIXEL_FORMAT_RGB_565;
505 } else {
Courtney Goeltzenleuchter0e4e3952016-11-16 13:53:40 -0700506 if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
507 if (colorDepth > 24) {
508 format = HAL_PIXEL_FORMAT_RGBA_1010102;
509 } else {
510 format = HAL_PIXEL_FORMAT_RGBX_8888;
511 }
512 } else {
513 format = HAL_PIXEL_FORMAT_RGBA_FP16;
514 }
515 }
516 } else {
517 if (componentType == EGL_COLOR_COMPONENT_TYPE_FIXED_EXT) {
518 if (colorDepth > 24) {
519 format = HAL_PIXEL_FORMAT_RGBA_1010102;
520 } else {
521 format = HAL_PIXEL_FORMAT_RGBA_8888;
522 }
523 } else {
524 format = HAL_PIXEL_FORMAT_RGBA_FP16;
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700525 }
Jesse Hallc2e41222013-08-08 13:40:22 -0700526 }
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700527
528 // now select a corresponding sRGB format if needed
529 if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
530 for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
531 if (*attr == EGL_GL_COLORSPACE_KHR) {
Sandeep Shinde9c67bfd2015-02-10 16:04:15 +0530532 dataSpace = modifyBufferDataspace(dataSpace, *(attr+1));
Jamie Gennisbee205f2011-07-01 13:12:07 -0700533 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700534 }
535 }
Alistair Strachan733a8072015-02-12 12:33:25 -0800536
Jesse Hallc2e41222013-08-08 13:40:22 -0700537 if (format != 0) {
538 int err = native_window_set_buffers_format(window, format);
539 if (err != 0) {
540 ALOGE("error setting native window pixel format: %s (%d)",
541 strerror(-err), err);
542 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
543 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
544 }
545 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700546
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800547 if (dataSpace != 0) {
548 int err = native_window_set_buffers_data_space(window, dataSpace);
549 if (err != 0) {
550 ALOGE("error setting native window pixel dataSpace: %s (%d)",
551 strerror(-err), err);
552 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
553 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
554 }
555 }
556
Jamie Gennis59769462011-11-19 18:04:43 -0800557 // the EGL spec requires that a new EGLSurface default to swap interval
558 // 1, so explicitly set that on the window here.
559 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
560 anw->setSwapInterval(anw, 1);
561
Mathias Agopian518ec112011-05-13 16:21:08 -0700562 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800563 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700564 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700565 egl_surface_t* s = new egl_surface_t(dp.get(), config, window,
566 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700567 return s;
568 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700569
570 // EGLSurface creation failed
571 native_window_set_buffers_format(window, 0);
572 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Mathias Agopian518ec112011-05-13 16:21:08 -0700573 }
574 return EGL_NO_SURFACE;
575}
576
577EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
578 NativePixmapType pixmap,
579 const EGLint *attrib_list)
580{
581 clearError();
582
Jesse Hallb29e5e82012-04-04 16:53:42 -0700583 egl_connection_t* cnx = NULL;
584 egl_display_ptr dp = validate_display_connection(dpy, cnx);
585 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700586 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800587 dp->disp.dpy, config, pixmap, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700588 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700589 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
590 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700591 return s;
592 }
593 }
594 return EGL_NO_SURFACE;
595}
596
597EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
598 const EGLint *attrib_list)
599{
600 clearError();
601
Jesse Hallb29e5e82012-04-04 16:53:42 -0700602 egl_connection_t* cnx = NULL;
603 egl_display_ptr dp = validate_display_connection(dpy, cnx);
604 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700605 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800606 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700607 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700608 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
609 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700610 return s;
611 }
612 }
613 return EGL_NO_SURFACE;
614}
Jesse Hall47743382013-02-08 11:13:46 -0800615
Mathias Agopian518ec112011-05-13 16:21:08 -0700616EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
617{
618 clearError();
619
Jesse Hallb29e5e82012-04-04 16:53:42 -0700620 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700621 if (!dp) return EGL_FALSE;
622
Jesse Hallb29e5e82012-04-04 16:53:42 -0700623 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700624 if (!_s.get())
625 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700626
627 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800628 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700629 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700630 _s.terminate();
631 }
632 return result;
633}
634
635EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
636 EGLint attribute, EGLint *value)
637{
638 clearError();
639
Jesse Hallb29e5e82012-04-04 16:53:42 -0700640 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700641 if (!dp) return EGL_FALSE;
642
Jesse Hallb29e5e82012-04-04 16:53:42 -0700643 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700644 if (!_s.get())
645 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700646
Mathias Agopian518ec112011-05-13 16:21:08 -0700647 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian7773c432012-02-13 20:06:08 -0800648 return s->cnx->egl.eglQuerySurface(
649 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700650}
651
Jamie Gennise8696a42012-01-15 18:54:57 -0800652void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800653 ATRACE_CALL();
Jamie Gennise8696a42012-01-15 18:54:57 -0800654 clearError();
655
Jesse Hallb29e5e82012-04-04 16:53:42 -0700656 const egl_display_ptr dp = validate_display(dpy);
Jamie Gennise8696a42012-01-15 18:54:57 -0800657 if (!dp) {
658 return;
659 }
660
Jesse Hallb29e5e82012-04-04 16:53:42 -0700661 SurfaceRef _s(dp.get(), surface);
Jamie Gennise8696a42012-01-15 18:54:57 -0800662 if (!_s.get()) {
663 setError(EGL_BAD_SURFACE, EGL_FALSE);
664 return;
665 }
Jamie Gennise8696a42012-01-15 18:54:57 -0800666}
667
Mathias Agopian518ec112011-05-13 16:21:08 -0700668// ----------------------------------------------------------------------------
669// Contexts
670// ----------------------------------------------------------------------------
671
672EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
673 EGLContext share_list, const EGLint *attrib_list)
674{
675 clearError();
676
Jesse Hallb29e5e82012-04-04 16:53:42 -0700677 egl_connection_t* cnx = NULL;
678 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
Michael Chock0673e1e2012-06-21 12:53:17 -0700679 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700680 if (share_list != EGL_NO_CONTEXT) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700681 if (!ContextRef(dp.get(), share_list).get()) {
682 return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
683 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700684 egl_context_t* const c = get_context(share_list);
685 share_list = c->context;
686 }
687 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800688 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700689 if (context != EGL_NO_CONTEXT) {
690 // figure out if it's a GLESv1 or GLESv2
691 int version = 0;
692 if (attrib_list) {
693 while (*attrib_list != EGL_NONE) {
694 GLint attr = *attrib_list++;
695 GLint value = *attrib_list++;
696 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
697 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800698 version = egl_connection_t::GLESv1_INDEX;
Jesse Hall47743382013-02-08 11:13:46 -0800699 } else if (value == 2 || value == 3) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800700 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700701 }
702 }
703 };
704 }
Jesse Hallb29e5e82012-04-04 16:53:42 -0700705 egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
706 version);
Mathias Agopian518ec112011-05-13 16:21:08 -0700707 return c;
708 }
709 }
710 return EGL_NO_CONTEXT;
711}
712
713EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
714{
715 clearError();
716
Jesse Hallb29e5e82012-04-04 16:53:42 -0700717 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700718 if (!dp)
719 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700720
Jesse Hallb29e5e82012-04-04 16:53:42 -0700721 ContextRef _c(dp.get(), ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700722 if (!_c.get())
723 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Jesse Hall47743382013-02-08 11:13:46 -0800724
Mathias Agopian518ec112011-05-13 16:21:08 -0700725 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800726 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700727 if (result == EGL_TRUE) {
728 _c.terminate();
729 }
730 return result;
731}
732
Mathias Agopian518ec112011-05-13 16:21:08 -0700733EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
734 EGLSurface read, EGLContext ctx)
735{
736 clearError();
737
Jesse Hallb29e5e82012-04-04 16:53:42 -0700738 egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700739 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
740
Mathias Agopian5b287a62011-05-16 18:58:55 -0700741 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
742 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
743 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700744 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
745 (draw != EGL_NO_SURFACE) ) {
746 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
747 }
748
749 // get a reference to the object passed in
Jesse Hallb29e5e82012-04-04 16:53:42 -0700750 ContextRef _c(dp.get(), ctx);
751 SurfaceRef _d(dp.get(), draw);
752 SurfaceRef _r(dp.get(), read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700753
754 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700755 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700756 // EGL_NO_CONTEXT is valid
Michael Chock0673e1e2012-06-21 12:53:17 -0700757 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700758 }
759
760 // these are the underlying implementation's object
761 EGLContext impl_ctx = EGL_NO_CONTEXT;
762 EGLSurface impl_draw = EGL_NO_SURFACE;
763 EGLSurface impl_read = EGL_NO_SURFACE;
764
765 // these are our objects structs passed in
766 egl_context_t * c = NULL;
767 egl_surface_t const * d = NULL;
768 egl_surface_t const * r = NULL;
769
770 // these are the current objects structs
771 egl_context_t * cur_c = get_context(getContext());
Jesse Hall47743382013-02-08 11:13:46 -0800772
Mathias Agopian518ec112011-05-13 16:21:08 -0700773 if (ctx != EGL_NO_CONTEXT) {
774 c = get_context(ctx);
775 impl_ctx = c->context;
776 } else {
777 // no context given, use the implementation of the current context
Michael Chock0673e1e2012-06-21 12:53:17 -0700778 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
779 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
780 return setError(EGL_BAD_MATCH, EGL_FALSE);
781 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700782 if (cur_c == NULL) {
783 // no current context
Mathias Agopian518ec112011-05-13 16:21:08 -0700784 // not an error, there is just no current context.
785 return EGL_TRUE;
786 }
787 }
788
789 // retrieve the underlying implementation's draw EGLSurface
790 if (draw != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700791 if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700792 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -0700793 impl_draw = d->surface;
794 }
795
796 // retrieve the underlying implementation's read EGLSurface
797 if (read != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700798 if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700799 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700800 impl_read = r->surface;
801 }
802
Mathias Agopian518ec112011-05-13 16:21:08 -0700803
Jesse Hallb29e5e82012-04-04 16:53:42 -0700804 EGLBoolean result = dp->makeCurrent(c, cur_c,
Mathias Agopianfb87e542012-01-30 18:20:52 -0800805 draw, read, ctx,
806 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700807
808 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -0800809 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700810 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
811 egl_tls_t::setContext(ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700812 _c.acquire();
813 _r.acquire();
814 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -0700815 } else {
816 setGLHooksThreadSpecific(&gHooksNoContext);
817 egl_tls_t::setContext(EGL_NO_CONTEXT);
818 }
Mathias Agopian5fecea72011-08-25 18:38:24 -0700819 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000820 // this will ALOGE the error
Mathias Agopian63108c32013-09-06 13:36:49 -0700821 egl_connection_t* const cnx = &gEGLImpl;
822 result = setError(cnx->egl.eglGetError(), EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700823 }
824 return result;
825}
826
827
828EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
829 EGLint attribute, EGLint *value)
830{
831 clearError();
832
Jesse Hallb29e5e82012-04-04 16:53:42 -0700833 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700834 if (!dp) return EGL_FALSE;
835
Jesse Hallb29e5e82012-04-04 16:53:42 -0700836 ContextRef _c(dp.get(), ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700837 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
838
Mathias Agopian518ec112011-05-13 16:21:08 -0700839 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -0800840 return c->cnx->egl.eglQueryContext(
841 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700842
Mathias Agopian518ec112011-05-13 16:21:08 -0700843}
844
845EGLContext eglGetCurrentContext(void)
846{
847 // could be called before eglInitialize(), but we wouldn't have a context
848 // then, and this function would correctly return EGL_NO_CONTEXT.
849
850 clearError();
851
852 EGLContext ctx = getContext();
853 return ctx;
854}
855
856EGLSurface eglGetCurrentSurface(EGLint readdraw)
857{
858 // could be called before eglInitialize(), but we wouldn't have a context
859 // then, and this function would correctly return EGL_NO_SURFACE.
860
861 clearError();
862
863 EGLContext ctx = getContext();
864 if (ctx) {
865 egl_context_t const * const c = get_context(ctx);
866 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
867 switch (readdraw) {
868 case EGL_READ: return c->read;
Jesse Hall47743382013-02-08 11:13:46 -0800869 case EGL_DRAW: return c->draw;
Mathias Agopian518ec112011-05-13 16:21:08 -0700870 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
871 }
872 }
873 return EGL_NO_SURFACE;
874}
875
876EGLDisplay eglGetCurrentDisplay(void)
877{
878 // could be called before eglInitialize(), but we wouldn't have a context
879 // then, and this function would correctly return EGL_NO_DISPLAY.
880
881 clearError();
882
883 EGLContext ctx = getContext();
884 if (ctx) {
885 egl_context_t const * const c = get_context(ctx);
886 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
887 return c->dpy;
888 }
889 return EGL_NO_DISPLAY;
890}
891
892EGLBoolean eglWaitGL(void)
893{
Mathias Agopian518ec112011-05-13 16:21:08 -0700894 clearError();
895
Mathias Agopianada798b2012-02-13 17:09:30 -0800896 egl_connection_t* const cnx = &gEGLImpl;
897 if (!cnx->dso)
898 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
899
900 return cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700901}
902
903EGLBoolean eglWaitNative(EGLint engine)
904{
Mathias Agopian518ec112011-05-13 16:21:08 -0700905 clearError();
906
Mathias Agopianada798b2012-02-13 17:09:30 -0800907 egl_connection_t* const cnx = &gEGLImpl;
908 if (!cnx->dso)
909 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
910
911 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -0700912}
913
914EGLint eglGetError(void)
915{
Mathias Agopianada798b2012-02-13 17:09:30 -0800916 EGLint err = EGL_SUCCESS;
917 egl_connection_t* const cnx = &gEGLImpl;
918 if (cnx->dso) {
919 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -0700920 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800921 if (err == EGL_SUCCESS) {
922 err = egl_tls_t::getError();
923 }
924 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -0700925}
926
Michael Chockc0ec5e22014-01-27 08:14:33 -0800927static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
Jesse Hallc07b5202013-07-04 12:08:16 -0700928 const char* procname) {
929 const egl_connection_t* cnx = &gEGLImpl;
930 void* proc = NULL;
931
Michael Chockc0ec5e22014-01-27 08:14:33 -0800932 proc = dlsym(cnx->libEgl, procname);
933 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
934
Jesse Hallc07b5202013-07-04 12:08:16 -0700935 proc = dlsym(cnx->libGles2, procname);
936 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
937
938 proc = dlsym(cnx->libGles1, procname);
939 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
940
941 return NULL;
942}
943
Mathias Agopian518ec112011-05-13 16:21:08 -0700944__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
945{
946 // eglGetProcAddress() could be the very first function called
947 // in which case we must make sure we've initialized ourselves, this
948 // happens the first time egl_get_display() is called.
949
950 clearError();
951
952 if (egl_init_drivers() == EGL_FALSE) {
953 setError(EGL_BAD_PARAMETER, NULL);
954 return NULL;
955 }
956
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700957 if (FILTER_EXTENSIONS(procname)) {
Jamie Gennisaca51c02011-11-03 17:42:43 -0700958 return NULL;
959 }
960
Mathias Agopian518ec112011-05-13 16:21:08 -0700961 __eglMustCastToProperFunctionPointerType addr;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700962 addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
Mathias Agopian518ec112011-05-13 16:21:08 -0700963 if (addr) return addr;
964
Michael Chockc0ec5e22014-01-27 08:14:33 -0800965 addr = findBuiltinWrapper(procname);
Jesse Hallc07b5202013-07-04 12:08:16 -0700966 if (addr) return addr;
Jamie Gennisaca51c02011-11-03 17:42:43 -0700967
Mathias Agopian518ec112011-05-13 16:21:08 -0700968 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
969 pthread_mutex_lock(&sExtensionMapMutex);
970
971 /*
972 * Since eglGetProcAddress() is not associated to anything, it needs
973 * to return a function pointer that "works" regardless of what
974 * the current context is.
975 *
976 * For this reason, we return a "forwarder", a small stub that takes
977 * care of calling the function associated with the context
978 * currently bound.
979 *
980 * We first look for extensions we've already resolved, if we're seeing
981 * this extension for the first time, we go through all our
982 * implementations and call eglGetProcAddress() and record the
983 * result in the appropriate implementation hooks and return the
984 * address of the forwarder corresponding to that hook set.
985 *
986 */
987
988 const String8 name(procname);
989 addr = sGLExtentionMap.valueFor(name);
990 const int slot = sGLExtentionSlot;
991
Steve Blocke6f43dd2012-01-06 19:20:56 +0000992 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
Mathias Agopian518ec112011-05-13 16:21:08 -0700993 "no more slots for eglGetProcAddress(\"%s\")",
994 procname);
995
996 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
997 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -0800998
999 egl_connection_t* const cnx = &gEGLImpl;
1000 if (cnx->dso && cnx->egl.eglGetProcAddress) {
Mathias Agopianada798b2012-02-13 17:09:30 -08001001 // Extensions are independent of the bound context
luliuhui69d10072012-08-30 11:15:36 +08001002 addr =
Mathias Agopian7773c432012-02-13 20:06:08 -08001003 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
1004 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
Mathias Agopianada798b2012-02-13 17:09:30 -08001005 cnx->egl.eglGetProcAddress(procname);
luliuhui69d10072012-08-30 11:15:36 +08001006 if (addr) found = true;
Mathias Agopian518ec112011-05-13 16:21:08 -07001007 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001008
Mathias Agopian518ec112011-05-13 16:21:08 -07001009 if (found) {
1010 addr = gExtensionForwarders[slot];
Mathias Agopian518ec112011-05-13 16:21:08 -07001011 sGLExtentionMap.add(name, addr);
1012 sGLExtentionSlot++;
1013 }
1014 }
1015
1016 pthread_mutex_unlock(&sExtensionMapMutex);
1017 return addr;
1018}
1019
Jamie Gennis28ef8d72012-04-05 20:34:54 -07001020class FrameCompletionThread : public Thread {
1021public:
1022
1023 static void queueSync(EGLSyncKHR sync) {
1024 static sp<FrameCompletionThread> thread(new FrameCompletionThread);
1025 static bool running = false;
1026 if (!running) {
1027 thread->run("GPUFrameCompletion");
1028 running = true;
1029 }
1030 {
1031 Mutex::Autolock lock(thread->mMutex);
1032 ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d",
1033 thread->mFramesQueued).string());
1034 thread->mQueue.push_back(sync);
1035 thread->mCondition.signal();
1036 thread->mFramesQueued++;
1037 ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size());
1038 }
1039 }
1040
1041private:
1042 FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {}
1043
1044 virtual bool threadLoop() {
1045 EGLSyncKHR sync;
1046 uint32_t frameNum;
1047 {
1048 Mutex::Autolock lock(mMutex);
1049 while (mQueue.isEmpty()) {
1050 mCondition.wait(mMutex);
1051 }
1052 sync = mQueue[0];
1053 frameNum = mFramesCompleted;
1054 }
1055 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1056 {
1057 ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d",
1058 frameNum).string());
1059 EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
1060 if (result == EGL_FALSE) {
1061 ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
1062 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
1063 ALOGE("FrameCompletion: timeout waiting for fence");
1064 }
1065 eglDestroySyncKHR(dpy, sync);
1066 }
1067 {
1068 Mutex::Autolock lock(mMutex);
1069 mQueue.removeAt(0);
1070 mFramesCompleted++;
1071 ATRACE_INT("GPU Frames Outstanding", mQueue.size());
1072 }
1073 return true;
1074 }
1075
1076 uint32_t mFramesQueued;
1077 uint32_t mFramesCompleted;
1078 Vector<EGLSyncKHR> mQueue;
1079 Condition mCondition;
1080 Mutex mMutex;
1081};
1082
Dan Stozaa894d082015-02-19 15:27:36 -08001083EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
1084 EGLint *rects, EGLint n_rects)
Mathias Agopian518ec112011-05-13 16:21:08 -07001085{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001086 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001087 clearError();
1088
Jesse Hallb29e5e82012-04-04 16:53:42 -07001089 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001090 if (!dp) return EGL_FALSE;
1091
Jesse Hallb29e5e82012-04-04 16:53:42 -07001092 SurfaceRef _s(dp.get(), draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001093 if (!_s.get())
1094 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001095
Mathias Agopian518ec112011-05-13 16:21:08 -07001096 egl_surface_t const * const s = get_surface(draw);
Mathias Agopian7db993a2012-03-25 00:49:46 -07001097
Mathias Agopianed6d08b2013-04-16 16:39:46 -07001098 if (CC_UNLIKELY(dp->traceGpuCompletion)) {
1099 EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
1100 if (sync != EGL_NO_SYNC_KHR) {
1101 FrameCompletionThread::queueSync(sync);
1102 }
1103 }
1104
Mathias Agopian7db993a2012-03-25 00:49:46 -07001105 if (CC_UNLIKELY(dp->finishOnSwap)) {
1106 uint32_t pixel;
1107 egl_context_t * const c = get_context( egl_tls_t::getContext() );
1108 if (c) {
1109 // glReadPixels() ensures that the frame is complete
1110 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
1111 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
1112 }
1113 }
1114
Dan Stozaa894d082015-02-19 15:27:36 -08001115 if (n_rects == 0) {
1116 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1117 }
1118
1119 Vector<android_native_rect_t> androidRects;
1120 for (int r = 0; r < n_rects; ++r) {
1121 int offset = r * 4;
1122 int x = rects[offset];
1123 int y = rects[offset + 1];
1124 int width = rects[offset + 2];
1125 int height = rects[offset + 3];
1126 android_native_rect_t androidRect;
1127 androidRect.left = x;
1128 androidRect.top = y + height;
1129 androidRect.right = x + width;
1130 androidRect.bottom = y;
1131 androidRects.push_back(androidRect);
1132 }
1133 native_window_set_surface_damage(s->win.get(), androidRects.array(),
1134 androidRects.size());
1135
1136 if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1137 return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1138 rects, n_rects);
1139 } else {
1140 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1141 }
1142}
1143
1144EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1145{
1146 return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
Mathias Agopian518ec112011-05-13 16:21:08 -07001147}
1148
1149EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
1150 NativePixmapType target)
1151{
1152 clearError();
1153
Jesse Hallb29e5e82012-04-04 16:53:42 -07001154 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001155 if (!dp) return EGL_FALSE;
1156
Jesse Hallb29e5e82012-04-04 16:53:42 -07001157 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001158 if (!_s.get())
1159 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001160
Mathias Agopian518ec112011-05-13 16:21:08 -07001161 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -08001162 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -07001163}
1164
1165const char* eglQueryString(EGLDisplay dpy, EGLint name)
1166{
1167 clearError();
1168
Chia-I Wue57d1352016-08-15 16:10:02 +08001169 // Generate an error quietly when client extensions (as defined by
1170 // EGL_EXT_client_extensions) are queried. We do not want to rely on
1171 // validate_display to generate the error as validate_display would log
1172 // the error, which can be misleading.
1173 //
1174 // If we want to support EGL_EXT_client_extensions later, we can return
1175 // the client extension string here instead.
1176 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
1177 return setErrorQuiet(EGL_BAD_DISPLAY, nullptr);
1178
Jesse Hallb29e5e82012-04-04 16:53:42 -07001179 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001180 if (!dp) return (const char *) NULL;
1181
1182 switch (name) {
1183 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001184 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001185 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001186 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001187 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001188 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001189 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001190 return dp->getClientApiString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001191 }
1192 return setError(EGL_BAD_PARAMETER, (const char *)0);
1193}
1194
Mathias Agopianca088332013-03-28 17:44:13 -07001195EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name)
1196{
1197 clearError();
1198
1199 const egl_display_ptr dp = validate_display(dpy);
1200 if (!dp) return (const char *) NULL;
1201
1202 switch (name) {
1203 case EGL_VENDOR:
1204 return dp->disp.queryString.vendor;
1205 case EGL_VERSION:
1206 return dp->disp.queryString.version;
1207 case EGL_EXTENSIONS:
1208 return dp->disp.queryString.extensions;
1209 case EGL_CLIENT_APIS:
1210 return dp->disp.queryString.clientApi;
1211 }
1212 return setError(EGL_BAD_PARAMETER, (const char *)0);
1213}
Mathias Agopian518ec112011-05-13 16:21:08 -07001214
1215// ----------------------------------------------------------------------------
1216// EGL 1.1
1217// ----------------------------------------------------------------------------
1218
1219EGLBoolean eglSurfaceAttrib(
1220 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1221{
1222 clearError();
1223
Jesse Hallb29e5e82012-04-04 16:53:42 -07001224 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001225 if (!dp) return EGL_FALSE;
1226
Jesse Hallb29e5e82012-04-04 16:53:42 -07001227 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001228 if (!_s.get())
1229 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001230
Pablo Ceballosc18be292016-05-31 14:55:42 -07001231 egl_surface_t * const s = get_surface(surface);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001232
Pablo Ceballos02b05da2016-02-02 17:53:18 -08001233 if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) {
Brian Anderson069b3652016-07-22 10:32:47 -07001234 if (!s->win.get()) {
1235 setError(EGL_BAD_SURFACE, EGL_FALSE);
1236 }
Pablo Ceballosf051ade2016-03-15 18:27:20 -07001237 int err = native_window_set_auto_refresh(s->win.get(),
1238 value ? true : false);
1239 return (err == NO_ERROR) ? EGL_TRUE :
1240 setError(EGL_BAD_SURFACE, EGL_FALSE);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001241 }
1242
Pablo Ceballosb1e2c722016-07-14 08:02:14 -07001243#if ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS
Pablo Ceballosc18be292016-05-31 14:55:42 -07001244 if (attribute == EGL_TIMESTAMPS_ANDROID) {
Brian Anderson069b3652016-07-22 10:32:47 -07001245 if (!s->win.get()) {
1246 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1247 }
Brian Anderson069b3652016-07-22 10:32:47 -07001248 int err = native_window_enable_frame_timestamps(
1249 s->win.get(), value ? true : false);
1250 return (err == NO_ERROR) ? EGL_TRUE :
1251 setError(EGL_BAD_SURFACE, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07001252 }
Pablo Ceballosb1e2c722016-07-14 08:02:14 -07001253#endif
Pablo Ceballosc18be292016-05-31 14:55:42 -07001254
Mathias Agopian518ec112011-05-13 16:21:08 -07001255 if (s->cnx->egl.eglSurfaceAttrib) {
1256 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -08001257 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001258 }
1259 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1260}
1261
1262EGLBoolean eglBindTexImage(
1263 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1264{
1265 clearError();
1266
Jesse Hallb29e5e82012-04-04 16:53:42 -07001267 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001268 if (!dp) return EGL_FALSE;
1269
Jesse Hallb29e5e82012-04-04 16:53:42 -07001270 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001271 if (!_s.get())
1272 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001273
Mathias Agopian518ec112011-05-13 16:21:08 -07001274 egl_surface_t const * const s = get_surface(surface);
1275 if (s->cnx->egl.eglBindTexImage) {
1276 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001277 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001278 }
1279 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1280}
1281
1282EGLBoolean eglReleaseTexImage(
1283 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1284{
1285 clearError();
1286
Jesse Hallb29e5e82012-04-04 16:53:42 -07001287 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001288 if (!dp) return EGL_FALSE;
1289
Jesse Hallb29e5e82012-04-04 16:53:42 -07001290 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001291 if (!_s.get())
1292 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001293
Mathias Agopian518ec112011-05-13 16:21:08 -07001294 egl_surface_t const * const s = get_surface(surface);
1295 if (s->cnx->egl.eglReleaseTexImage) {
1296 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001297 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001298 }
1299 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1300}
1301
1302EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1303{
1304 clearError();
1305
Jesse Hallb29e5e82012-04-04 16:53:42 -07001306 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001307 if (!dp) return EGL_FALSE;
1308
1309 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001310 egl_connection_t* const cnx = &gEGLImpl;
1311 if (cnx->dso && cnx->egl.eglSwapInterval) {
1312 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -07001313 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001314
Mathias Agopian518ec112011-05-13 16:21:08 -07001315 return res;
1316}
1317
1318
1319// ----------------------------------------------------------------------------
1320// EGL 1.2
1321// ----------------------------------------------------------------------------
1322
1323EGLBoolean eglWaitClient(void)
1324{
1325 clearError();
1326
Mathias Agopianada798b2012-02-13 17:09:30 -08001327 egl_connection_t* const cnx = &gEGLImpl;
1328 if (!cnx->dso)
1329 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
1330
1331 EGLBoolean res;
1332 if (cnx->egl.eglWaitClient) {
1333 res = cnx->egl.eglWaitClient();
1334 } else {
1335 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001336 }
1337 return res;
1338}
1339
1340EGLBoolean eglBindAPI(EGLenum api)
1341{
1342 clearError();
1343
1344 if (egl_init_drivers() == EGL_FALSE) {
1345 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1346 }
1347
1348 // bind this API on all EGLs
1349 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001350 egl_connection_t* const cnx = &gEGLImpl;
1351 if (cnx->dso && cnx->egl.eglBindAPI) {
1352 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -07001353 }
1354 return res;
1355}
1356
1357EGLenum eglQueryAPI(void)
1358{
1359 clearError();
1360
1361 if (egl_init_drivers() == EGL_FALSE) {
1362 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1363 }
1364
Mathias Agopianada798b2012-02-13 17:09:30 -08001365 egl_connection_t* const cnx = &gEGLImpl;
1366 if (cnx->dso && cnx->egl.eglQueryAPI) {
1367 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -07001368 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001369
Mathias Agopian518ec112011-05-13 16:21:08 -07001370 // or, it can only be OpenGL ES
1371 return EGL_OPENGL_ES_API;
1372}
1373
1374EGLBoolean eglReleaseThread(void)
1375{
1376 clearError();
1377
Mathias Agopianada798b2012-02-13 17:09:30 -08001378 egl_connection_t* const cnx = &gEGLImpl;
1379 if (cnx->dso && cnx->egl.eglReleaseThread) {
1380 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -07001381 }
Sai Kiran Korwar3ac517a2014-01-31 21:15:07 +05301382
1383 // If there is context bound to the thread, release it
1384 egl_display_t::loseCurrent(get_context(getContext()));
1385
Mathias Agopian518ec112011-05-13 16:21:08 -07001386 egl_tls_t::clearTLS();
Mathias Agopian518ec112011-05-13 16:21:08 -07001387 return EGL_TRUE;
1388}
1389
1390EGLSurface eglCreatePbufferFromClientBuffer(
1391 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1392 EGLConfig config, const EGLint *attrib_list)
1393{
1394 clearError();
1395
Jesse Hallb29e5e82012-04-04 16:53:42 -07001396 egl_connection_t* cnx = NULL;
1397 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1398 if (!dp) return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -07001399 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1400 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -08001401 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001402 }
1403 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1404}
1405
1406// ----------------------------------------------------------------------------
1407// EGL_EGLEXT_VERSION 3
1408// ----------------------------------------------------------------------------
1409
1410EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
1411 const EGLint *attrib_list)
1412{
1413 clearError();
1414
Jesse Hallb29e5e82012-04-04 16:53:42 -07001415 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001416 if (!dp) return EGL_FALSE;
1417
Jesse Hallb29e5e82012-04-04 16:53:42 -07001418 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001419 if (!_s.get())
1420 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001421
1422 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001423 if (s->cnx->egl.eglLockSurfaceKHR) {
1424 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -08001425 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001426 }
1427 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1428}
1429
1430EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
1431{
1432 clearError();
1433
Jesse Hallb29e5e82012-04-04 16:53:42 -07001434 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001435 if (!dp) return EGL_FALSE;
1436
Jesse Hallb29e5e82012-04-04 16:53:42 -07001437 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001438 if (!_s.get())
1439 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001440
1441 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001442 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -08001443 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001444 }
1445 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1446}
1447
1448EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1449 EGLClientBuffer buffer, const EGLint *attrib_list)
1450{
1451 clearError();
1452
Jesse Hallb29e5e82012-04-04 16:53:42 -07001453 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001454 if (!dp) return EGL_NO_IMAGE_KHR;
1455
Jesse Hallb29e5e82012-04-04 16:53:42 -07001456 ContextRef _c(dp.get(), ctx);
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001457 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -07001458
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001459 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1460 egl_connection_t* const cnx = &gEGLImpl;
1461 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1462 result = cnx->egl.eglCreateImageKHR(
1463 dp->disp.dpy,
1464 c ? c->context : EGL_NO_CONTEXT,
1465 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001466 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001467 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001468}
1469
1470EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1471{
1472 clearError();
1473
Jesse Hallb29e5e82012-04-04 16:53:42 -07001474 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001475 if (!dp) return EGL_FALSE;
1476
Steven Holte646a5c52012-06-04 20:02:11 -07001477 EGLBoolean result = EGL_FALSE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001478 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001479 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
Steven Holte646a5c52012-06-04 20:02:11 -07001480 result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001481 }
Steven Holte646a5c52012-06-04 20:02:11 -07001482 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001483}
1484
1485// ----------------------------------------------------------------------------
1486// EGL_EGLEXT_VERSION 5
1487// ----------------------------------------------------------------------------
1488
1489
1490EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1491{
1492 clearError();
1493
Jesse Hallb29e5e82012-04-04 16:53:42 -07001494 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001495 if (!dp) return EGL_NO_SYNC_KHR;
1496
Mathias Agopian518ec112011-05-13 16:21:08 -07001497 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001498 egl_connection_t* const cnx = &gEGLImpl;
1499 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1500 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001501 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001502 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001503}
1504
1505EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1506{
1507 clearError();
1508
Jesse Hallb29e5e82012-04-04 16:53:42 -07001509 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001510 if (!dp) return EGL_FALSE;
1511
Mathias Agopian518ec112011-05-13 16:21:08 -07001512 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001513 egl_connection_t* const cnx = &gEGLImpl;
1514 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1515 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001516 }
1517 return result;
1518}
1519
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001520EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
1521 clearError();
1522
1523 const egl_display_ptr dp = validate_display(dpy);
1524 if (!dp) return EGL_FALSE;
1525
1526 EGLBoolean result = EGL_FALSE;
1527 egl_connection_t* const cnx = &gEGLImpl;
1528 if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1529 result = cnx->egl.eglSignalSyncKHR(
1530 dp->disp.dpy, sync, mode);
1531 }
1532 return result;
1533}
1534
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001535EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1536 EGLint flags, EGLTimeKHR timeout)
Mathias Agopian518ec112011-05-13 16:21:08 -07001537{
1538 clearError();
1539
Jesse Hallb29e5e82012-04-04 16:53:42 -07001540 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001541 if (!dp) return EGL_FALSE;
1542
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001543 EGLBoolean result = EGL_FALSE;
1544 egl_connection_t* const cnx = &gEGLImpl;
1545 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1546 result = cnx->egl.eglClientWaitSyncKHR(
1547 dp->disp.dpy, sync, flags, timeout);
Mathias Agopian518ec112011-05-13 16:21:08 -07001548 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001549 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001550}
1551
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001552EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1553 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001554{
1555 clearError();
1556
Jesse Hallb29e5e82012-04-04 16:53:42 -07001557 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001558 if (!dp) return EGL_FALSE;
1559
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001560 EGLBoolean result = EGL_FALSE;
1561 egl_connection_t* const cnx = &gEGLImpl;
1562 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1563 result = cnx->egl.eglGetSyncAttribKHR(
1564 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001565 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001566 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001567}
1568
Season Li000d88f2015-07-01 11:39:40 -07001569EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list)
1570{
1571 clearError();
1572
1573 const egl_display_ptr dp = validate_display(dpy);
1574 if (!dp) return EGL_NO_STREAM_KHR;
1575
1576 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1577 egl_connection_t* const cnx = &gEGLImpl;
1578 if (cnx->dso && cnx->egl.eglCreateStreamKHR) {
1579 result = cnx->egl.eglCreateStreamKHR(
1580 dp->disp.dpy, attrib_list);
1581 }
1582 return result;
1583}
1584
1585EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream)
1586{
1587 clearError();
1588
1589 const egl_display_ptr dp = validate_display(dpy);
1590 if (!dp) return EGL_FALSE;
1591
1592 EGLBoolean result = EGL_FALSE;
1593 egl_connection_t* const cnx = &gEGLImpl;
1594 if (cnx->dso && cnx->egl.eglDestroyStreamKHR) {
1595 result = cnx->egl.eglDestroyStreamKHR(
1596 dp->disp.dpy, stream);
1597 }
1598 return result;
1599}
1600
1601EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream,
1602 EGLenum attribute, EGLint value)
1603{
1604 clearError();
1605
1606 const egl_display_ptr dp = validate_display(dpy);
1607 if (!dp) return EGL_FALSE;
1608
1609 EGLBoolean result = EGL_FALSE;
1610 egl_connection_t* const cnx = &gEGLImpl;
1611 if (cnx->dso && cnx->egl.eglStreamAttribKHR) {
1612 result = cnx->egl.eglStreamAttribKHR(
1613 dp->disp.dpy, stream, attribute, value);
1614 }
1615 return result;
1616}
1617
1618EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream,
1619 EGLenum attribute, EGLint *value)
1620{
1621 clearError();
1622
1623 const egl_display_ptr dp = validate_display(dpy);
1624 if (!dp) return EGL_FALSE;
1625
1626 EGLBoolean result = EGL_FALSE;
1627 egl_connection_t* const cnx = &gEGLImpl;
1628 if (cnx->dso && cnx->egl.eglQueryStreamKHR) {
1629 result = cnx->egl.eglQueryStreamKHR(
1630 dp->disp.dpy, stream, attribute, value);
1631 }
1632 return result;
1633}
1634
1635EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream,
1636 EGLenum attribute, EGLuint64KHR *value)
1637{
1638 clearError();
1639
1640 const egl_display_ptr dp = validate_display(dpy);
1641 if (!dp) return EGL_FALSE;
1642
1643 EGLBoolean result = EGL_FALSE;
1644 egl_connection_t* const cnx = &gEGLImpl;
1645 if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) {
1646 result = cnx->egl.eglQueryStreamu64KHR(
1647 dp->disp.dpy, stream, attribute, value);
1648 }
1649 return result;
1650}
1651
1652EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream,
1653 EGLenum attribute, EGLTimeKHR *value)
1654{
1655 clearError();
1656
1657 const egl_display_ptr dp = validate_display(dpy);
1658 if (!dp) return EGL_FALSE;
1659
1660 EGLBoolean result = EGL_FALSE;
1661 egl_connection_t* const cnx = &gEGLImpl;
1662 if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) {
1663 result = cnx->egl.eglQueryStreamTimeKHR(
1664 dp->disp.dpy, stream, attribute, value);
1665 }
1666 return result;
1667}
1668
1669EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config,
1670 EGLStreamKHR stream, const EGLint *attrib_list)
1671{
1672 clearError();
1673
1674 egl_display_ptr dp = validate_display(dpy);
1675 if (!dp) return EGL_NO_SURFACE;
1676
1677 egl_connection_t* const cnx = &gEGLImpl;
1678 if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) {
1679 EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(
1680 dp->disp.dpy, config, stream, attrib_list);
1681 if (surface != EGL_NO_SURFACE) {
1682 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
1683 surface, cnx);
1684 return s;
1685 }
1686 }
1687 return EGL_NO_SURFACE;
1688}
1689
1690EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy,
1691 EGLStreamKHR stream)
1692{
1693 clearError();
1694
1695 const egl_display_ptr dp = validate_display(dpy);
1696 if (!dp) return EGL_FALSE;
1697
1698 EGLBoolean result = EGL_FALSE;
1699 egl_connection_t* const cnx = &gEGLImpl;
1700 if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) {
1701 result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(
1702 dp->disp.dpy, stream);
1703 }
1704 return result;
1705}
1706
1707EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy,
1708 EGLStreamKHR stream)
1709{
1710 clearError();
1711
1712 const egl_display_ptr dp = validate_display(dpy);
1713 if (!dp) return EGL_FALSE;
1714
1715 EGLBoolean result = EGL_FALSE;
1716 egl_connection_t* const cnx = &gEGLImpl;
1717 if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) {
1718 result = cnx->egl.eglStreamConsumerAcquireKHR(
1719 dp->disp.dpy, stream);
1720 }
1721 return result;
1722}
1723
1724EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy,
1725 EGLStreamKHR stream)
1726{
1727 clearError();
1728
1729 const egl_display_ptr dp = validate_display(dpy);
1730 if (!dp) return EGL_FALSE;
1731
1732 EGLBoolean result = EGL_FALSE;
1733 egl_connection_t* const cnx = &gEGLImpl;
1734 if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) {
1735 result = cnx->egl.eglStreamConsumerReleaseKHR(
1736 dp->disp.dpy, stream);
1737 }
1738 return result;
1739}
1740
1741EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR(
1742 EGLDisplay dpy, EGLStreamKHR stream)
1743{
1744 clearError();
1745
1746 const egl_display_ptr dp = validate_display(dpy);
1747 if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;
1748
1749 EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;
1750 egl_connection_t* const cnx = &gEGLImpl;
1751 if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) {
1752 result = cnx->egl.eglGetStreamFileDescriptorKHR(
1753 dp->disp.dpy, stream);
1754 }
1755 return result;
1756}
1757
1758EGLStreamKHR eglCreateStreamFromFileDescriptorKHR(
1759 EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor)
1760{
1761 clearError();
1762
1763 const egl_display_ptr dp = validate_display(dpy);
1764 if (!dp) return EGL_NO_STREAM_KHR;
1765
1766 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1767 egl_connection_t* const cnx = &gEGLImpl;
1768 if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) {
1769 result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(
1770 dp->disp.dpy, file_descriptor);
1771 }
1772 return result;
1773}
1774
Mathias Agopian518ec112011-05-13 16:21:08 -07001775// ----------------------------------------------------------------------------
Mathias Agopian2bb71682013-03-27 17:32:41 -07001776// EGL_EGLEXT_VERSION 15
1777// ----------------------------------------------------------------------------
1778
1779EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
1780 clearError();
1781 const egl_display_ptr dp = validate_display(dpy);
1782 if (!dp) return EGL_FALSE;
1783 EGLint result = EGL_FALSE;
1784 egl_connection_t* const cnx = &gEGLImpl;
1785 if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
1786 result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1787 }
1788 return result;
1789}
1790
1791// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -07001792// ANDROID extensions
1793// ----------------------------------------------------------------------------
1794
Jamie Gennis331841b2012-09-06 14:52:00 -07001795EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync)
1796{
1797 clearError();
1798
1799 const egl_display_ptr dp = validate_display(dpy);
1800 if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1801
1802 EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1803 egl_connection_t* const cnx = &gEGLImpl;
1804 if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
1805 result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1806 }
1807 return result;
1808}
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001809
Andy McFadden72841452013-03-01 16:25:32 -08001810EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface,
1811 EGLnsecsANDROID time)
1812{
1813 clearError();
1814
1815 const egl_display_ptr dp = validate_display(dpy);
1816 if (!dp) {
1817 return EGL_FALSE;
1818 }
1819
1820 SurfaceRef _s(dp.get(), surface);
1821 if (!_s.get()) {
1822 setError(EGL_BAD_SURFACE, EGL_FALSE);
1823 return EGL_FALSE;
1824 }
1825
1826 egl_surface_t const * const s = get_surface(surface);
1827 native_window_set_buffers_timestamp(s->win.get(), time);
1828
1829 return EGL_TRUE;
1830}
1831
Craig Donner05249fc2016-01-15 19:33:55 -08001832EGLClientBuffer eglCreateNativeClientBufferANDROID(const EGLint *attrib_list)
1833{
1834 clearError();
1835
1836 int usage = 0;
1837 uint32_t width = 0;
1838 uint32_t height = 0;
1839 uint32_t format = 0;
Craig Donner6ebc46a2016-10-21 15:23:44 -07001840 uint32_t layer_count = 1;
Craig Donner05249fc2016-01-15 19:33:55 -08001841 uint32_t red_size = 0;
1842 uint32_t green_size = 0;
1843 uint32_t blue_size = 0;
1844 uint32_t alpha_size = 0;
1845
Craig Donnerb40504a2016-06-03 17:54:25 -07001846#define GET_NONNEGATIVE_VALUE(case_name, target) \
Craig Donner05249fc2016-01-15 19:33:55 -08001847 case case_name: \
Craig Donnerb40504a2016-06-03 17:54:25 -07001848 if (value >= 0) { \
Craig Donner05249fc2016-01-15 19:33:55 -08001849 target = value; \
1850 } else { \
1851 return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0); \
1852 } \
1853 break
1854
1855 if (attrib_list) {
1856 while (*attrib_list != EGL_NONE) {
1857 GLint attr = *attrib_list++;
1858 GLint value = *attrib_list++;
1859 switch (attr) {
Craig Donnerb40504a2016-06-03 17:54:25 -07001860 GET_NONNEGATIVE_VALUE(EGL_WIDTH, width);
1861 GET_NONNEGATIVE_VALUE(EGL_HEIGHT, height);
1862 GET_NONNEGATIVE_VALUE(EGL_RED_SIZE, red_size);
1863 GET_NONNEGATIVE_VALUE(EGL_GREEN_SIZE, green_size);
1864 GET_NONNEGATIVE_VALUE(EGL_BLUE_SIZE, blue_size);
1865 GET_NONNEGATIVE_VALUE(EGL_ALPHA_SIZE, alpha_size);
Craig Donner6ebc46a2016-10-21 15:23:44 -07001866 GET_NONNEGATIVE_VALUE(EGL_LAYER_COUNT_ANDROID, layer_count);
Craig Donner05249fc2016-01-15 19:33:55 -08001867 case EGL_NATIVE_BUFFER_USAGE_ANDROID:
1868 if (value & EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID) {
1869 usage |= GRALLOC_USAGE_PROTECTED;
Craig Donner05249fc2016-01-15 19:33:55 -08001870 }
Craig Donner8cfae6d2016-04-12 16:54:03 -07001871 if (value & EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID) {
Craig Donner05249fc2016-01-15 19:33:55 -08001872 usage |= GRALLOC_USAGE_HW_RENDER;
1873 }
Craig Donner8cfae6d2016-04-12 16:54:03 -07001874 if (value & EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID) {
Craig Donner05249fc2016-01-15 19:33:55 -08001875 usage |= GRALLOC_USAGE_HW_TEXTURE;
1876 }
Craig Donner05249fc2016-01-15 19:33:55 -08001877 break;
1878 default:
1879 return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0);
1880 }
1881 }
1882 }
Craig Donnerb40504a2016-06-03 17:54:25 -07001883#undef GET_NONNEGATIVE_VALUE
Craig Donner05249fc2016-01-15 19:33:55 -08001884
1885 // Validate format.
1886 if (red_size == 8 && green_size == 8 && blue_size == 8) {
1887 if (alpha_size == 8) {
1888 format = HAL_PIXEL_FORMAT_RGBA_8888;
1889 } else {
1890 format = HAL_PIXEL_FORMAT_RGB_888;
1891 }
1892 } else if (red_size == 5 && green_size == 6 && blue_size == 5 &&
1893 alpha_size == 0) {
Craig Donner478f7db2016-06-10 17:20:15 -07001894 format = HAL_PIXEL_FORMAT_RGB_565;
Craig Donner05249fc2016-01-15 19:33:55 -08001895 } else {
Craig Donner6ebc46a2016-10-21 15:23:44 -07001896 ALOGE("Invalid native pixel format { r=%u, g=%u, b=%u, a=%u }",
Craig Donner05249fc2016-01-15 19:33:55 -08001897 red_size, green_size, blue_size, alpha_size);
1898 return setError(EGL_BAD_PARAMETER, (EGLClientBuffer)0);
1899 }
1900
Craig Donner68671532016-07-18 10:19:54 -07001901#define CHECK_ERROR_CONDITION(message) \
1902 if (err != NO_ERROR) { \
1903 ALOGE(message); \
1904 goto error_condition; \
1905 }
1906
1907 // The holder is used to destroy the buffer if an error occurs.
1908 GraphicBuffer* gBuffer = new GraphicBuffer();
1909 sp<IServiceManager> sm = defaultServiceManager();
1910 sp<IBinder> surfaceFlinger = sm->getService(String16("SurfaceFlinger"));
1911 sp<IBinder> allocator;
1912 Parcel sc_data, sc_reply, data, reply;
1913 status_t err = NO_ERROR;
1914 if (sm == NULL) {
1915 ALOGE("Unable to connect to ServiceManager");
1916 goto error_condition;
1917 }
1918
1919 // Obtain an allocator.
1920 if (surfaceFlinger == NULL) {
1921 ALOGE("Unable to connect to SurfaceFlinger");
1922 goto error_condition;
1923 }
1924 sc_data.writeInterfaceToken(String16("android.ui.ISurfaceComposer"));
1925 err = surfaceFlinger->transact(
1926 BnSurfaceComposer::CREATE_GRAPHIC_BUFFER_ALLOC, sc_data, &sc_reply);
1927 CHECK_ERROR_CONDITION("Unable to obtain allocator from SurfaceFlinger");
1928 allocator = sc_reply.readStrongBinder();
1929
1930 if (allocator == NULL) {
1931 ALOGE("Unable to obtain an ISurfaceComposer");
1932 goto error_condition;
1933 }
1934 data.writeInterfaceToken(String16("android.ui.IGraphicBufferAlloc"));
1935 err = data.writeUint32(width);
1936 CHECK_ERROR_CONDITION("Unable to write width");
1937 err = data.writeUint32(height);
1938 CHECK_ERROR_CONDITION("Unable to write height");
1939 err = data.writeInt32(static_cast<int32_t>(format));
1940 CHECK_ERROR_CONDITION("Unable to write format");
Craig Donner6ebc46a2016-10-21 15:23:44 -07001941 err = data.writeUint32(layer_count);
1942 CHECK_ERROR_CONDITION("Unable to write layer count");
1943 err = data.writeUint32(usage);
Craig Donner68671532016-07-18 10:19:54 -07001944 CHECK_ERROR_CONDITION("Unable to write usage");
Dan Stoza024e9312016-08-24 12:17:29 -07001945 err = data.writeUtf8AsUtf16(
1946 std::string("[eglCreateNativeClientBufferANDROID pid ") +
1947 std::to_string(getpid()) + ']');
1948 CHECK_ERROR_CONDITION("Unable to write requestor name");
Craig Donner68671532016-07-18 10:19:54 -07001949 err = allocator->transact(IBinder::FIRST_CALL_TRANSACTION, data,
1950 &reply);
1951 CHECK_ERROR_CONDITION(
1952 "Unable to request buffer allocation from surface composer");
1953 err = reply.readInt32();
1954 CHECK_ERROR_CONDITION("Unable to obtain buffer from surface composer");
1955 err = reply.read(*gBuffer);
1956 CHECK_ERROR_CONDITION("Unable to read buffer from surface composer");
1957
1958 err = gBuffer->initCheck();
Craig Donner05249fc2016-01-15 19:33:55 -08001959 if (err != NO_ERROR) {
Craig Donner6ebc46a2016-10-21 15:23:44 -07001960 ALOGE("Unable to create native buffer "
1961 "{ w=%u, h=%u, f=%u, u=%#x, lc=%u}: %#x", width, height, format,
1962 usage, layer_count, err);
Craig Donner68671532016-07-18 10:19:54 -07001963 goto error_condition;
Craig Donner05249fc2016-01-15 19:33:55 -08001964 }
Craig Donner6ebc46a2016-10-21 15:23:44 -07001965 ALOGV("Created new native buffer %p { w=%u, h=%u, f=%u, u=%#x, lc=%u}",
1966 gBuffer, width, height, format, usage, layer_count);
Craig Donner05249fc2016-01-15 19:33:55 -08001967 return static_cast<EGLClientBuffer>(gBuffer->getNativeBuffer());
Craig Donner68671532016-07-18 10:19:54 -07001968
1969#undef CHECK_ERROR_CONDITION
1970
1971error_condition:
1972 // Delete the buffer.
1973 sp<GraphicBuffer> holder(gBuffer);
1974 return setError(EGL_BAD_ALLOC, (EGLClientBuffer)0);
Craig Donner05249fc2016-01-15 19:33:55 -08001975}
1976
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001977// ----------------------------------------------------------------------------
1978// NVIDIA extensions
1979// ----------------------------------------------------------------------------
1980EGLuint64NV eglGetSystemTimeFrequencyNV()
1981{
1982 clearError();
1983
1984 if (egl_init_drivers() == EGL_FALSE) {
1985 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1986 }
1987
1988 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001989 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001990
Mathias Agopianada798b2012-02-13 17:09:30 -08001991 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1992 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001993 }
1994
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001995 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001996}
1997
1998EGLuint64NV eglGetSystemTimeNV()
1999{
2000 clearError();
2001
2002 if (egl_init_drivers() == EGL_FALSE) {
2003 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
2004 }
2005
2006 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08002007 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08002008
Mathias Agopianada798b2012-02-13 17:09:30 -08002009 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
2010 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08002011 }
2012
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07002013 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08002014}
Dan Stozaa894d082015-02-19 15:27:36 -08002015
2016// ----------------------------------------------------------------------------
2017// Partial update extension
2018// ----------------------------------------------------------------------------
2019EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
2020 EGLint *rects, EGLint n_rects)
2021{
2022 clearError();
2023
2024 const egl_display_ptr dp = validate_display(dpy);
2025 if (!dp) {
2026 setError(EGL_BAD_DISPLAY, EGL_FALSE);
2027 return EGL_FALSE;
2028 }
2029
2030 SurfaceRef _s(dp.get(), surface);
2031 if (!_s.get()) {
2032 setError(EGL_BAD_SURFACE, EGL_FALSE);
2033 return EGL_FALSE;
2034 }
2035
2036 egl_surface_t const * const s = get_surface(surface);
2037 if (s->cnx->egl.eglSetDamageRegionKHR) {
2038 return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,
2039 rects, n_rects);
2040 }
2041
2042 return EGL_FALSE;
2043}
Pablo Ceballosc18be292016-05-31 14:55:42 -07002044
2045EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface,
2046 EGLint framesAgo, EGLint numTimestamps, const EGLint *timestamps,
2047 EGLnsecsANDROID *values)
2048{
2049 clearError();
2050
2051 const egl_display_ptr dp = validate_display(dpy);
2052 if (!dp) {
Brian Anderson069b3652016-07-22 10:32:47 -07002053 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002054 }
2055
2056 SurfaceRef _s(dp.get(), surface);
2057 if (!_s.get()) {
Brian Anderson069b3652016-07-22 10:32:47 -07002058 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002059 }
2060
2061 egl_surface_t const * const s = get_surface(surface);
2062
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07002063 if (!s->win.get()) {
Brian Anderson069b3652016-07-22 10:32:47 -07002064 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002065 }
2066
Brian Andersondbd0ea82016-07-22 09:38:59 -07002067 nsecs_t* requestedPresentTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002068 nsecs_t* acquireTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002069 nsecs_t* latchTime = nullptr;
2070 nsecs_t* firstRefreshStartTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002071 nsecs_t* GLCompositionDoneTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002072 nsecs_t* lastRefreshStartTime = nullptr;
Brian Anderson069b3652016-07-22 10:32:47 -07002073 nsecs_t* displayPresentTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002074 nsecs_t* displayRetireTime = nullptr;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002075 nsecs_t* dequeueReadyTime = nullptr;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002076 nsecs_t* releaseTime = nullptr;
2077
2078 for (int i = 0; i < numTimestamps; i++) {
2079 switch (timestamps[i]) {
Brian Andersondbd0ea82016-07-22 09:38:59 -07002080 case EGL_REQUESTED_PRESENT_TIME_ANDROID:
2081 requestedPresentTime = &values[i];
Pablo Ceballosc18be292016-05-31 14:55:42 -07002082 break;
2083 case EGL_RENDERING_COMPLETE_TIME_ANDROID:
2084 acquireTime = &values[i];
2085 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002086 case EGL_COMPOSITION_LATCH_TIME_ANDROID:
2087 latchTime = &values[i];
Pablo Ceballosc18be292016-05-31 14:55:42 -07002088 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002089 case EGL_FIRST_COMPOSITION_START_TIME_ANDROID:
2090 firstRefreshStartTime = &values[i];
2091 break;
2092 case EGL_LAST_COMPOSITION_START_TIME_ANDROID:
2093 lastRefreshStartTime = &values[i];
2094 break;
2095 case EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID:
Pablo Ceballosc18be292016-05-31 14:55:42 -07002096 GLCompositionDoneTime = &values[i];
2097 break;
Brian Anderson069b3652016-07-22 10:32:47 -07002098 case EGL_DISPLAY_PRESENT_TIME_ANDROID:
2099 displayPresentTime = &values[i];
2100 break;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002101 case EGL_DISPLAY_RETIRE_TIME_ANDROID:
2102 displayRetireTime = &values[i];
2103 break;
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002104 case EGL_DEQUEUE_READY_TIME_ANDROID:
2105 dequeueReadyTime = &values[i];
2106 break;
Pablo Ceballosc18be292016-05-31 14:55:42 -07002107 case EGL_READS_DONE_TIME_ANDROID:
2108 releaseTime = &values[i];
2109 break;
2110 default:
Brian Anderson069b3652016-07-22 10:32:47 -07002111 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002112 }
2113 }
2114
2115 status_t ret = native_window_get_frame_timestamps(s->win.get(), framesAgo,
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002116 requestedPresentTime, acquireTime, latchTime, firstRefreshStartTime,
2117 lastRefreshStartTime, GLCompositionDoneTime, displayPresentTime,
2118 displayRetireTime, dequeueReadyTime, releaseTime);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002119
Brian Anderson069b3652016-07-22 10:32:47 -07002120 switch (ret) {
2121 case NO_ERROR:
2122 return EGL_TRUE;
2123 case NAME_NOT_FOUND:
2124 return setError(EGL_BAD_ACCESS, EGL_FALSE);
Brian Anderson7c3ba8a2016-07-25 12:48:08 -07002125 case INVALID_OPERATION:
2126 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Brian Anderson069b3652016-07-22 10:32:47 -07002127 case BAD_VALUE:
2128 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
2129 default:
2130 // This should not happen. Return an error that is not in the spec
2131 // so it's obvious something is very wrong.
2132 return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002133 }
Pablo Ceballosc18be292016-05-31 14:55:42 -07002134}
2135
2136EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface surface,
2137 EGLint timestamp)
2138{
2139 clearError();
2140
2141 const egl_display_ptr dp = validate_display(dpy);
2142 if (!dp) {
Brian Anderson069b3652016-07-22 10:32:47 -07002143 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002144 }
2145
2146 SurfaceRef _s(dp.get(), surface);
2147 if (!_s.get()) {
Brian Anderson069b3652016-07-22 10:32:47 -07002148 return setError(EGL_BAD_SURFACE, EGL_FALSE);
2149 }
2150
2151 egl_surface_t const * const s = get_surface(surface);
2152
2153 ANativeWindow* window = s->win.get();
2154 if (!window) {
2155 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Pablo Ceballosc18be292016-05-31 14:55:42 -07002156 }
2157
2158 switch (timestamp) {
Pablo Ceballosb1e2c722016-07-14 08:02:14 -07002159#if ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS
Brian Andersondbd0ea82016-07-22 09:38:59 -07002160 case EGL_REQUESTED_PRESENT_TIME_ANDROID:
Pablo Ceballosc18be292016-05-31 14:55:42 -07002161 case EGL_RENDERING_COMPLETE_TIME_ANDROID:
Brian Andersonf7fd56a2016-09-02 10:10:04 -07002162 case EGL_COMPOSITION_LATCH_TIME_ANDROID:
2163 case EGL_FIRST_COMPOSITION_START_TIME_ANDROID:
2164 case EGL_LAST_COMPOSITION_START_TIME_ANDROID:
2165 case EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID:
2166 case EGL_DEQUEUE_READY_TIME_ANDROID:
Pablo Ceballosc18be292016-05-31 14:55:42 -07002167 case EGL_READS_DONE_TIME_ANDROID:
2168 return EGL_TRUE;
Brian Anderson069b3652016-07-22 10:32:47 -07002169 case EGL_DISPLAY_PRESENT_TIME_ANDROID: {
2170 int value = 0;
2171 window->query(window,
2172 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &value);
2173 return value == 0 ? EGL_FALSE : EGL_TRUE;
2174 }
2175 case EGL_DISPLAY_RETIRE_TIME_ANDROID: {
2176 int value = 0;
2177 window->query(window,
2178 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_RETIRE, &value);
2179 return value == 0 ? EGL_FALSE : EGL_TRUE;
2180 }
Pablo Ceballosb1e2c722016-07-14 08:02:14 -07002181#endif
Pablo Ceballosc18be292016-05-31 14:55:42 -07002182 default:
2183 return EGL_FALSE;
2184 }
2185}