blob: cfae0951a68cfcc5405dc09b9ce5eb6143ffe7c3 [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
Jesse Hallc07b5202013-07-04 12:08:16 -070019#include <dlfcn.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070020#include <ctype.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include <hardware/gralloc.h>
25#include <system/window.h>
26
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070029
30#include <cutils/log.h>
31#include <cutils/atomic.h>
Mathias Agopian7db993a2012-03-25 00:49:46 -070032#include <cutils/compiler.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070033#include <cutils/properties.h>
34#include <cutils/memory.h>
35
36#include <utils/KeyedVector.h>
37#include <utils/SortedVector.h>
38#include <utils/String8.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080039#include <utils/Trace.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070040
Mathias Agopian39c24a22013-04-04 23:17:56 -070041#include "../egl_impl.h"
42#include "../glestrace.h"
43#include "../hooks.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070044
45#include "egl_display.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070046#include "egl_object.h"
47#include "egl_tls.h"
Mathias Agopianada798b2012-02-13 17:09:30 -080048#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070049
50using namespace android;
51
52// ----------------------------------------------------------------------------
53
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070054namespace android {
55
Mathias Agopian518ec112011-05-13 16:21:08 -070056struct extention_map_t {
57 const char* name;
58 __eglMustCastToProperFunctionPointerType address;
59};
60
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070061/*
Jesse Hall21558da2013-08-06 15:31:22 -070062 * This is the list of EGL extensions exposed to applications.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070063 *
Jesse Hall21558da2013-08-06 15:31:22 -070064 * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
65 * wrapper and are always available.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070066 *
Jesse Hall21558da2013-08-06 15:31:22 -070067 * The rest (gExtensionString) depend on support in the EGL driver, and are
68 * only available if the driver supports them. However, some of these must be
69 * supported because they are used by the Android system itself; these are
70 * listd as mandatory below and are required by the CDD. The system *assumes*
71 * the mandatory extensions are present and may not function properly if some
72 * are missing.
73 *
74 * NOTE: Both strings MUST have a single space as the last character.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070075 */
Jesse Hall21558da2013-08-06 15:31:22 -070076extern char const * const gBuiltinExtensionString =
77 "EGL_KHR_get_all_proc_addresses "
78 "EGL_ANDROID_presentation_time "
Dan Stozaa894d082015-02-19 15:27:36 -080079 "EGL_KHR_swap_buffers_with_damage "
Jesse Hall21558da2013-08-06 15:31:22 -070080 ;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070081extern char const * const gExtensionString =
82 "EGL_KHR_image " // mandatory
83 "EGL_KHR_image_base " // mandatory
84 "EGL_KHR_image_pixmap "
85 "EGL_KHR_lock_surface "
Jesse Hallc2e41222013-08-08 13:40:22 -070086 "EGL_KHR_gl_colorspace "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070087 "EGL_KHR_gl_texture_2D_image "
Season Li000d88f2015-07-01 11:39:40 -070088 "EGL_KHR_gl_texture_3D_image "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070089 "EGL_KHR_gl_texture_cubemap_image "
90 "EGL_KHR_gl_renderbuffer_image "
91 "EGL_KHR_reusable_sync "
92 "EGL_KHR_fence_sync "
Jamie Gennisf6d1c392013-04-25 18:48:41 -070093 "EGL_KHR_create_context "
Season Li000d88f2015-07-01 11:39:40 -070094 "EGL_KHR_config_attribs "
95 "EGL_KHR_surfaceless_context "
96 "EGL_KHR_stream "
97 "EGL_KHR_stream_fifo "
98 "EGL_KHR_stream_producer_eglsurface "
99 "EGL_KHR_stream_consumer_gltexture "
100 "EGL_KHR_stream_cross_process_fd "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700101 "EGL_EXT_create_context_robustness "
102 "EGL_NV_system_time "
103 "EGL_ANDROID_image_native_buffer " // mandatory
Mathias Agopian2bb71682013-03-27 17:32:41 -0700104 "EGL_KHR_wait_sync " // strongly recommended
Jamie Gennisdbe92452013-09-23 17:22:10 -0700105 "EGL_ANDROID_recordable " // mandatory
Dan Stozaa894d082015-02-19 15:27:36 -0800106 "EGL_KHR_partial_update " // strongly recommended
107 "EGL_EXT_buffer_age " // strongly recommended with partial_update
Jesse Hall408e59f2015-04-24 01:40:42 -0700108 "EGL_KHR_create_context_no_error "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700109 ;
110
111// extensions not exposed to applications but used by the ANDROID system
112// "EGL_ANDROID_blob_cache " // strongly recommended
113// "EGL_IMG_hibernate_process " // optional
114// "EGL_ANDROID_native_fence_sync " // strongly recommended
115// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1
Jamie Gennisdbe92452013-09-23 17:22:10 -0700116// "EGL_ANDROID_image_crop " // optional
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700117
118/*
119 * EGL Extensions entry-points exposed to 3rd party applications
120 * (keep in sync with gExtensionString above)
121 *
122 */
123static const extention_map_t sExtensionMap[] = {
124 // EGL_KHR_lock_surface
Mathias Agopian518ec112011-05-13 16:21:08 -0700125 { "eglLockSurfaceKHR",
126 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
127 { "eglUnlockSurfaceKHR",
128 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700129
130 // EGL_KHR_image, EGL_KHR_image_base
Mathias Agopian518ec112011-05-13 16:21:08 -0700131 { "eglCreateImageKHR",
132 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
133 { "eglDestroyImageKHR",
134 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700135
136 // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
137 { "eglCreateSyncKHR",
138 (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
139 { "eglDestroySyncKHR",
140 (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
141 { "eglClientWaitSyncKHR",
142 (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
143 { "eglSignalSyncKHR",
144 (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
145 { "eglGetSyncAttribKHR",
146 (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
147
148 // EGL_NV_system_time
Jonas Yang1c3d72a2011-08-26 20:04:39 +0800149 { "eglGetSystemTimeFrequencyNV",
150 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
151 { "eglGetSystemTimeNV",
152 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700153
Mathias Agopian2bb71682013-03-27 17:32:41 -0700154 // EGL_KHR_wait_sync
155 { "eglWaitSyncKHR",
156 (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700157
158 // EGL_ANDROID_presentation_time
159 { "eglPresentationTimeANDROID",
160 (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
Dan Stozaa894d082015-02-19 15:27:36 -0800161
162 // EGL_KHR_swap_buffers_with_damage
163 { "eglSwapBuffersWithDamageKHR",
164 (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
165
166 // EGL_KHR_partial_update
167 { "eglSetDamageRegionKHR",
168 (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
Season Li000d88f2015-07-01 11:39:40 -0700169
170 { "eglCreateStreamKHR",
171 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR },
172 { "eglDestroyStreamKHR",
173 (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR },
174 { "eglStreamAttribKHR",
175 (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR },
176 { "eglQueryStreamKHR",
177 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR },
178 { "eglQueryStreamu64KHR",
179 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR },
180 { "eglQueryStreamTimeKHR",
181 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR },
182 { "eglCreateStreamProducerSurfaceKHR",
183 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR },
184 { "eglStreamConsumerGLTextureExternalKHR",
185 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR },
186 { "eglStreamConsumerAcquireKHR",
187 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR },
188 { "eglStreamConsumerReleaseKHR",
189 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR },
190 { "eglGetStreamFileDescriptorKHR",
191 (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR },
192 { "eglCreateStreamFromFileDescriptorKHR",
193 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },
Mathias Agopian518ec112011-05-13 16:21:08 -0700194};
195
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700196/*
197 * These extensions entry-points should not be exposed to applications.
198 * They're used internally by the Android EGL layer.
199 */
200#define FILTER_EXTENSIONS(procname) \
201 (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \
202 !strcmp((procname), "eglHibernateProcessIMG") || \
203 !strcmp((procname), "eglAwakenProcessIMG") || \
204 !strcmp((procname), "eglDupNativeFenceFDANDROID"))
205
206
207
Mathias Agopian518ec112011-05-13 16:21:08 -0700208// accesses protected by sExtensionMapMutex
209static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
210static int sGLExtentionSlot = 0;
211static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
212
213static void(*findProcAddress(const char* name,
214 const extention_map_t* map, size_t n))() {
215 for (uint32_t i=0 ; i<n ; i++) {
216 if (!strcmp(name, map[i].name)) {
217 return map[i].address;
218 }
219 }
220 return NULL;
221}
222
223// ----------------------------------------------------------------------------
224
Mathias Agopian518ec112011-05-13 16:21:08 -0700225extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
226extern EGLBoolean egl_init_drivers();
227extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
Siva Velusamya73a9772012-12-18 14:56:55 -0800228extern int getEGLDebugLevel();
229extern void setEGLDebugLevel(int level);
Mathias Agopian518ec112011-05-13 16:21:08 -0700230extern gl_hooks_t gHooksTrace;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700231
Mathias Agopian518ec112011-05-13 16:21:08 -0700232} // namespace android;
233
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700234
Mathias Agopian518ec112011-05-13 16:21:08 -0700235// ----------------------------------------------------------------------------
236
237static inline void clearError() { egl_tls_t::clearError(); }
238static inline EGLContext getContext() { return egl_tls_t::getContext(); }
239
240// ----------------------------------------------------------------------------
241
242EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
243{
244 clearError();
245
Dan Stozac3289c42014-01-17 11:38:34 -0800246 uintptr_t index = reinterpret_cast<uintptr_t>(display);
Mathias Agopian518ec112011-05-13 16:21:08 -0700247 if (index >= NUM_DISPLAYS) {
248 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
249 }
250
251 if (egl_init_drivers() == EGL_FALSE) {
252 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
253 }
254
255 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
256 return dpy;
257}
258
259// ----------------------------------------------------------------------------
260// Initialization
261// ----------------------------------------------------------------------------
262
263EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
264{
265 clearError();
266
Jesse Hallb29e5e82012-04-04 16:53:42 -0700267 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700268 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
269
270 EGLBoolean res = dp->initialize(major, minor);
271
272 return res;
273}
274
275EGLBoolean eglTerminate(EGLDisplay dpy)
276{
277 // NOTE: don't unload the drivers b/c some APIs can be called
278 // after eglTerminate() has been called. eglTerminate() only
279 // terminates an EGLDisplay, not a EGL itself.
280
281 clearError();
282
Jesse Hallb29e5e82012-04-04 16:53:42 -0700283 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700284 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
285
286 EGLBoolean res = dp->terminate();
Jesse Hall47743382013-02-08 11:13:46 -0800287
Mathias Agopian518ec112011-05-13 16:21:08 -0700288 return res;
289}
290
291// ----------------------------------------------------------------------------
292// configuration
293// ----------------------------------------------------------------------------
294
295EGLBoolean eglGetConfigs( EGLDisplay dpy,
296 EGLConfig *configs,
297 EGLint config_size, EGLint *num_config)
298{
299 clearError();
300
Jesse Hallb29e5e82012-04-04 16:53:42 -0700301 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700302 if (!dp) return EGL_FALSE;
303
Mathias Agopian7773c432012-02-13 20:06:08 -0800304 if (num_config==0) {
305 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700306 }
307
Mathias Agopian7773c432012-02-13 20:06:08 -0800308 EGLBoolean res = EGL_FALSE;
309 *num_config = 0;
310
311 egl_connection_t* const cnx = &gEGLImpl;
312 if (cnx->dso) {
313 res = cnx->egl.eglGetConfigs(
314 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700315 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800316
317 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700318}
319
320EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
321 EGLConfig *configs, EGLint config_size,
322 EGLint *num_config)
323{
324 clearError();
325
Jesse Hallb29e5e82012-04-04 16:53:42 -0700326 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700327 if (!dp) return EGL_FALSE;
328
329 if (num_config==0) {
330 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
331 }
332
Mathias Agopian518ec112011-05-13 16:21:08 -0700333 EGLBoolean res = EGL_FALSE;
334 *num_config = 0;
335
Mathias Agopianada798b2012-02-13 17:09:30 -0800336 egl_connection_t* const cnx = &gEGLImpl;
337 if (cnx->dso) {
Romain Guy1cffc802012-10-15 18:13:05 -0700338 if (attrib_list) {
339 char value[PROPERTY_VALUE_MAX];
340 property_get("debug.egl.force_msaa", value, "false");
341
342 if (!strcmp(value, "true")) {
343 size_t attribCount = 0;
344 EGLint attrib = attrib_list[0];
345
346 // Only enable MSAA if the context is OpenGL ES 2.0 and
Romain Guybe3c3e42012-10-15 19:25:18 -0700347 // if no caveat is requested
Romain Guy1cffc802012-10-15 18:13:05 -0700348 const EGLint *attribRendererable = NULL;
349 const EGLint *attribCaveat = NULL;
350
351 // Count the number of attributes and look for
Romain Guybe3c3e42012-10-15 19:25:18 -0700352 // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
Romain Guy1cffc802012-10-15 18:13:05 -0700353 while (attrib != EGL_NONE) {
354 attrib = attrib_list[attribCount];
355 switch (attrib) {
356 case EGL_RENDERABLE_TYPE:
357 attribRendererable = &attrib_list[attribCount];
358 break;
359 case EGL_CONFIG_CAVEAT:
360 attribCaveat = &attrib_list[attribCount];
361 break;
362 }
363 attribCount++;
364 }
365
366 if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
367 (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
Jesse Hall47743382013-02-08 11:13:46 -0800368
Romain Guy1cffc802012-10-15 18:13:05 -0700369 // Insert 2 extra attributes to force-enable MSAA 4x
370 EGLint aaAttribs[attribCount + 4];
371 aaAttribs[0] = EGL_SAMPLE_BUFFERS;
372 aaAttribs[1] = 1;
373 aaAttribs[2] = EGL_SAMPLES;
374 aaAttribs[3] = 4;
375
376 memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
377
378 EGLint numConfigAA;
379 EGLBoolean resAA = cnx->egl.eglChooseConfig(
380 dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
381
382 if (resAA == EGL_TRUE && numConfigAA > 0) {
383 ALOGD("Enabling MSAA 4x");
384 *num_config = numConfigAA;
385 return resAA;
386 }
387 }
388 }
389 }
390
Mathias Agopian7773c432012-02-13 20:06:08 -0800391 res = cnx->egl.eglChooseConfig(
392 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700393 }
394 return res;
395}
396
397EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
398 EGLint attribute, EGLint *value)
399{
400 clearError();
401
Jesse Hallb29e5e82012-04-04 16:53:42 -0700402 egl_connection_t* cnx = NULL;
403 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
404 if (!dp) return EGL_FALSE;
Jesse Hall47743382013-02-08 11:13:46 -0800405
Mathias Agopian518ec112011-05-13 16:21:08 -0700406 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800407 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700408}
409
410// ----------------------------------------------------------------------------
411// surfaces
412// ----------------------------------------------------------------------------
413
Jesse Hallc2e41222013-08-08 13:40:22 -0700414// Turn linear formats into corresponding sRGB formats when colorspace is
415// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear
416// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800417// the modification isn't possible, the original dataSpace is returned.
418static android_dataspace modifyBufferDataspace( android_dataspace dataSpace,
419 EGLint colorspace) {
Jesse Hallc2e41222013-08-08 13:40:22 -0700420 if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800421 return HAL_DATASPACE_SRGB_LINEAR;
Jesse Hallc2e41222013-08-08 13:40:22 -0700422 } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800423 return HAL_DATASPACE_SRGB;
Jesse Hallc2e41222013-08-08 13:40:22 -0700424 }
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800425 return dataSpace;
Jesse Hallc2e41222013-08-08 13:40:22 -0700426}
427
Mathias Agopian518ec112011-05-13 16:21:08 -0700428EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
429 NativeWindowType window,
430 const EGLint *attrib_list)
431{
432 clearError();
433
Jesse Hallb29e5e82012-04-04 16:53:42 -0700434 egl_connection_t* cnx = NULL;
435 egl_display_ptr dp = validate_display_connection(dpy, cnx);
436 if (dp) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800437 EGLDisplay iDpy = dp->disp.dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700438
Andy McFaddend566ce32014-01-07 15:54:17 -0800439 int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
440 if (result != OK) {
441 ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
442 "failed (%#x) (already connected to another API?)",
443 window, result);
Jonathan Hamilton77a9b4a2013-07-17 09:41:42 -0700444 return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
Mathias Agopian81a63352011-07-29 17:55:48 -0700445 }
446
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700447 // Set the native window's buffers format to match what this config requests.
Jesse Hallc2e41222013-08-08 13:40:22 -0700448 // Whether to use sRGB gamma is not part of the EGLconfig, but is part
449 // of our native format. So if sRGB gamma is requested, we have to
450 // modify the EGLconfig's format before setting the native window's
451 // format.
Alistair Strachan733a8072015-02-12 12:33:25 -0800452
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700453 // by default, just pick RGBA_8888
454 EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800455 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700456
457 EGLint a = 0;
458 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
459 if (a > 0) {
460 // alpha-channel requested, there's really only one suitable format
461 format = HAL_PIXEL_FORMAT_RGBA_8888;
462 } else {
463 EGLint r, g, b;
464 r = g = b = 0;
465 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r);
466 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
467 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b);
468 EGLint colorDepth = r + g + b;
469 if (colorDepth <= 16) {
470 format = HAL_PIXEL_FORMAT_RGB_565;
471 } else {
472 format = HAL_PIXEL_FORMAT_RGBX_8888;
473 }
Jesse Hallc2e41222013-08-08 13:40:22 -0700474 }
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700475
476 // now select a corresponding sRGB format if needed
477 if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
478 for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
479 if (*attr == EGL_GL_COLORSPACE_KHR) {
Sandeep Shinde9c67bfd2015-02-10 16:04:15 +0530480 dataSpace = modifyBufferDataspace(dataSpace, *(attr+1));
Jamie Gennisbee205f2011-07-01 13:12:07 -0700481 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700482 }
483 }
Alistair Strachan733a8072015-02-12 12:33:25 -0800484
Jesse Hallc2e41222013-08-08 13:40:22 -0700485 if (format != 0) {
486 int err = native_window_set_buffers_format(window, format);
487 if (err != 0) {
488 ALOGE("error setting native window pixel format: %s (%d)",
489 strerror(-err), err);
490 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
491 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
492 }
493 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700494
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800495 if (dataSpace != 0) {
496 int err = native_window_set_buffers_data_space(window, dataSpace);
497 if (err != 0) {
498 ALOGE("error setting native window pixel dataSpace: %s (%d)",
499 strerror(-err), err);
500 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
501 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
502 }
503 }
504
Jamie Gennis59769462011-11-19 18:04:43 -0800505 // the EGL spec requires that a new EGLSurface default to swap interval
506 // 1, so explicitly set that on the window here.
507 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
508 anw->setSwapInterval(anw, 1);
509
Mathias Agopian518ec112011-05-13 16:21:08 -0700510 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800511 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700512 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700513 egl_surface_t* s = new egl_surface_t(dp.get(), config, window,
514 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700515 return s;
516 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700517
518 // EGLSurface creation failed
519 native_window_set_buffers_format(window, 0);
520 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Mathias Agopian518ec112011-05-13 16:21:08 -0700521 }
522 return EGL_NO_SURFACE;
523}
524
525EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
526 NativePixmapType pixmap,
527 const EGLint *attrib_list)
528{
529 clearError();
530
Jesse Hallb29e5e82012-04-04 16:53:42 -0700531 egl_connection_t* cnx = NULL;
532 egl_display_ptr dp = validate_display_connection(dpy, cnx);
533 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700534 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800535 dp->disp.dpy, config, pixmap, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700536 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700537 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
538 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700539 return s;
540 }
541 }
542 return EGL_NO_SURFACE;
543}
544
545EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
546 const EGLint *attrib_list)
547{
548 clearError();
549
Jesse Hallb29e5e82012-04-04 16:53:42 -0700550 egl_connection_t* cnx = NULL;
551 egl_display_ptr dp = validate_display_connection(dpy, cnx);
552 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700553 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800554 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700555 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700556 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
557 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700558 return s;
559 }
560 }
561 return EGL_NO_SURFACE;
562}
Jesse Hall47743382013-02-08 11:13:46 -0800563
Mathias Agopian518ec112011-05-13 16:21:08 -0700564EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
565{
566 clearError();
567
Jesse Hallb29e5e82012-04-04 16:53:42 -0700568 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700569 if (!dp) return EGL_FALSE;
570
Jesse Hallb29e5e82012-04-04 16:53:42 -0700571 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700572 if (!_s.get())
573 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700574
575 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800576 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700577 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700578 _s.terminate();
579 }
580 return result;
581}
582
583EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
584 EGLint attribute, EGLint *value)
585{
586 clearError();
587
Jesse Hallb29e5e82012-04-04 16:53:42 -0700588 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700589 if (!dp) return EGL_FALSE;
590
Jesse Hallb29e5e82012-04-04 16:53:42 -0700591 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700592 if (!_s.get())
593 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700594
Mathias Agopian518ec112011-05-13 16:21:08 -0700595 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian7773c432012-02-13 20:06:08 -0800596 return s->cnx->egl.eglQuerySurface(
597 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700598}
599
Jamie Gennise8696a42012-01-15 18:54:57 -0800600void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800601 ATRACE_CALL();
Jamie Gennise8696a42012-01-15 18:54:57 -0800602 clearError();
603
Jesse Hallb29e5e82012-04-04 16:53:42 -0700604 const egl_display_ptr dp = validate_display(dpy);
Jamie Gennise8696a42012-01-15 18:54:57 -0800605 if (!dp) {
606 return;
607 }
608
Jesse Hallb29e5e82012-04-04 16:53:42 -0700609 SurfaceRef _s(dp.get(), surface);
Jamie Gennise8696a42012-01-15 18:54:57 -0800610 if (!_s.get()) {
611 setError(EGL_BAD_SURFACE, EGL_FALSE);
612 return;
613 }
Jamie Gennise8696a42012-01-15 18:54:57 -0800614}
615
Mathias Agopian518ec112011-05-13 16:21:08 -0700616// ----------------------------------------------------------------------------
617// Contexts
618// ----------------------------------------------------------------------------
619
620EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
621 EGLContext share_list, const EGLint *attrib_list)
622{
623 clearError();
624
Jesse Hallb29e5e82012-04-04 16:53:42 -0700625 egl_connection_t* cnx = NULL;
626 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
Michael Chock0673e1e2012-06-21 12:53:17 -0700627 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700628 if (share_list != EGL_NO_CONTEXT) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700629 if (!ContextRef(dp.get(), share_list).get()) {
630 return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
631 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700632 egl_context_t* const c = get_context(share_list);
633 share_list = c->context;
634 }
635 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800636 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700637 if (context != EGL_NO_CONTEXT) {
638 // figure out if it's a GLESv1 or GLESv2
639 int version = 0;
640 if (attrib_list) {
641 while (*attrib_list != EGL_NONE) {
642 GLint attr = *attrib_list++;
643 GLint value = *attrib_list++;
644 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
645 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800646 version = egl_connection_t::GLESv1_INDEX;
Jesse Hall47743382013-02-08 11:13:46 -0800647 } else if (value == 2 || value == 3) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800648 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700649 }
650 }
651 };
652 }
Jesse Hallb29e5e82012-04-04 16:53:42 -0700653 egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
654 version);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800655#if EGL_TRACE
Siva Velusamya73a9772012-12-18 14:56:55 -0800656 if (getEGLDebugLevel() > 0)
Siva Velusamy0469dd62011-11-30 15:05:37 -0800657 GLTrace_eglCreateContext(version, c);
658#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700659 return c;
660 }
661 }
662 return EGL_NO_CONTEXT;
663}
664
665EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
666{
667 clearError();
668
Jesse Hallb29e5e82012-04-04 16:53:42 -0700669 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700670 if (!dp)
671 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700672
Jesse Hallb29e5e82012-04-04 16:53:42 -0700673 ContextRef _c(dp.get(), ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700674 if (!_c.get())
675 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Jesse Hall47743382013-02-08 11:13:46 -0800676
Mathias Agopian518ec112011-05-13 16:21:08 -0700677 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800678 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700679 if (result == EGL_TRUE) {
680 _c.terminate();
681 }
682 return result;
683}
684
Mathias Agopian518ec112011-05-13 16:21:08 -0700685EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
686 EGLSurface read, EGLContext ctx)
687{
688 clearError();
689
Jesse Hallb29e5e82012-04-04 16:53:42 -0700690 egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700691 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
692
Mathias Agopian5b287a62011-05-16 18:58:55 -0700693 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
694 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
695 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700696 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
697 (draw != EGL_NO_SURFACE) ) {
698 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
699 }
700
701 // get a reference to the object passed in
Jesse Hallb29e5e82012-04-04 16:53:42 -0700702 ContextRef _c(dp.get(), ctx);
703 SurfaceRef _d(dp.get(), draw);
704 SurfaceRef _r(dp.get(), read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700705
706 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700707 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700708 // EGL_NO_CONTEXT is valid
Michael Chock0673e1e2012-06-21 12:53:17 -0700709 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700710 }
711
712 // these are the underlying implementation's object
713 EGLContext impl_ctx = EGL_NO_CONTEXT;
714 EGLSurface impl_draw = EGL_NO_SURFACE;
715 EGLSurface impl_read = EGL_NO_SURFACE;
716
717 // these are our objects structs passed in
718 egl_context_t * c = NULL;
719 egl_surface_t const * d = NULL;
720 egl_surface_t const * r = NULL;
721
722 // these are the current objects structs
723 egl_context_t * cur_c = get_context(getContext());
Jesse Hall47743382013-02-08 11:13:46 -0800724
Mathias Agopian518ec112011-05-13 16:21:08 -0700725 if (ctx != EGL_NO_CONTEXT) {
726 c = get_context(ctx);
727 impl_ctx = c->context;
728 } else {
729 // no context given, use the implementation of the current context
Michael Chock0673e1e2012-06-21 12:53:17 -0700730 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
731 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
732 return setError(EGL_BAD_MATCH, EGL_FALSE);
733 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700734 if (cur_c == NULL) {
735 // no current context
Mathias Agopian518ec112011-05-13 16:21:08 -0700736 // not an error, there is just no current context.
737 return EGL_TRUE;
738 }
739 }
740
741 // retrieve the underlying implementation's draw EGLSurface
742 if (draw != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700743 if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700744 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -0700745 impl_draw = d->surface;
746 }
747
748 // retrieve the underlying implementation's read EGLSurface
749 if (read != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700750 if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700751 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700752 impl_read = r->surface;
753 }
754
Mathias Agopian518ec112011-05-13 16:21:08 -0700755
Jesse Hallb29e5e82012-04-04 16:53:42 -0700756 EGLBoolean result = dp->makeCurrent(c, cur_c,
Mathias Agopianfb87e542012-01-30 18:20:52 -0800757 draw, read, ctx,
758 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700759
760 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -0800761 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700762 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
763 egl_tls_t::setContext(ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800764#if EGL_TRACE
Siva Velusamya73a9772012-12-18 14:56:55 -0800765 if (getEGLDebugLevel() > 0)
Siva Velusamy93a826f2011-12-14 12:19:56 -0800766 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800767#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700768 _c.acquire();
769 _r.acquire();
770 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -0700771 } else {
772 setGLHooksThreadSpecific(&gHooksNoContext);
773 egl_tls_t::setContext(EGL_NO_CONTEXT);
774 }
Mathias Agopian5fecea72011-08-25 18:38:24 -0700775 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000776 // this will ALOGE the error
Mathias Agopian63108c32013-09-06 13:36:49 -0700777 egl_connection_t* const cnx = &gEGLImpl;
778 result = setError(cnx->egl.eglGetError(), EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700779 }
780 return result;
781}
782
783
784EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
785 EGLint attribute, EGLint *value)
786{
787 clearError();
788
Jesse Hallb29e5e82012-04-04 16:53:42 -0700789 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700790 if (!dp) return EGL_FALSE;
791
Jesse Hallb29e5e82012-04-04 16:53:42 -0700792 ContextRef _c(dp.get(), ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700793 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
794
Mathias Agopian518ec112011-05-13 16:21:08 -0700795 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -0800796 return c->cnx->egl.eglQueryContext(
797 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700798
Mathias Agopian518ec112011-05-13 16:21:08 -0700799}
800
801EGLContext eglGetCurrentContext(void)
802{
803 // could be called before eglInitialize(), but we wouldn't have a context
804 // then, and this function would correctly return EGL_NO_CONTEXT.
805
806 clearError();
807
808 EGLContext ctx = getContext();
809 return ctx;
810}
811
812EGLSurface eglGetCurrentSurface(EGLint readdraw)
813{
814 // could be called before eglInitialize(), but we wouldn't have a context
815 // then, and this function would correctly return EGL_NO_SURFACE.
816
817 clearError();
818
819 EGLContext ctx = getContext();
820 if (ctx) {
821 egl_context_t const * const c = get_context(ctx);
822 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
823 switch (readdraw) {
824 case EGL_READ: return c->read;
Jesse Hall47743382013-02-08 11:13:46 -0800825 case EGL_DRAW: return c->draw;
Mathias Agopian518ec112011-05-13 16:21:08 -0700826 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
827 }
828 }
829 return EGL_NO_SURFACE;
830}
831
832EGLDisplay eglGetCurrentDisplay(void)
833{
834 // could be called before eglInitialize(), but we wouldn't have a context
835 // then, and this function would correctly return EGL_NO_DISPLAY.
836
837 clearError();
838
839 EGLContext ctx = getContext();
840 if (ctx) {
841 egl_context_t const * const c = get_context(ctx);
842 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
843 return c->dpy;
844 }
845 return EGL_NO_DISPLAY;
846}
847
848EGLBoolean eglWaitGL(void)
849{
Mathias Agopian518ec112011-05-13 16:21:08 -0700850 clearError();
851
Mathias Agopianada798b2012-02-13 17:09:30 -0800852 egl_connection_t* const cnx = &gEGLImpl;
853 if (!cnx->dso)
854 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
855
856 return cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700857}
858
859EGLBoolean eglWaitNative(EGLint engine)
860{
Mathias Agopian518ec112011-05-13 16:21:08 -0700861 clearError();
862
Mathias Agopianada798b2012-02-13 17:09:30 -0800863 egl_connection_t* const cnx = &gEGLImpl;
864 if (!cnx->dso)
865 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
866
867 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -0700868}
869
870EGLint eglGetError(void)
871{
Mathias Agopianada798b2012-02-13 17:09:30 -0800872 EGLint err = EGL_SUCCESS;
873 egl_connection_t* const cnx = &gEGLImpl;
874 if (cnx->dso) {
875 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -0700876 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800877 if (err == EGL_SUCCESS) {
878 err = egl_tls_t::getError();
879 }
880 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -0700881}
882
Michael Chockc0ec5e22014-01-27 08:14:33 -0800883static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
Jesse Hallc07b5202013-07-04 12:08:16 -0700884 const char* procname) {
885 const egl_connection_t* cnx = &gEGLImpl;
886 void* proc = NULL;
887
Michael Chockc0ec5e22014-01-27 08:14:33 -0800888 proc = dlsym(cnx->libEgl, procname);
889 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
890
Jesse Hallc07b5202013-07-04 12:08:16 -0700891 proc = dlsym(cnx->libGles2, procname);
892 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
893
894 proc = dlsym(cnx->libGles1, procname);
895 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
896
897 return NULL;
898}
899
Mathias Agopian518ec112011-05-13 16:21:08 -0700900__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
901{
902 // eglGetProcAddress() could be the very first function called
903 // in which case we must make sure we've initialized ourselves, this
904 // happens the first time egl_get_display() is called.
905
906 clearError();
907
908 if (egl_init_drivers() == EGL_FALSE) {
909 setError(EGL_BAD_PARAMETER, NULL);
910 return NULL;
911 }
912
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700913 if (FILTER_EXTENSIONS(procname)) {
Jamie Gennisaca51c02011-11-03 17:42:43 -0700914 return NULL;
915 }
916
Mathias Agopian518ec112011-05-13 16:21:08 -0700917 __eglMustCastToProperFunctionPointerType addr;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700918 addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
Mathias Agopian518ec112011-05-13 16:21:08 -0700919 if (addr) return addr;
920
Michael Chockc0ec5e22014-01-27 08:14:33 -0800921 addr = findBuiltinWrapper(procname);
Jesse Hallc07b5202013-07-04 12:08:16 -0700922 if (addr) return addr;
Jamie Gennisaca51c02011-11-03 17:42:43 -0700923
Mathias Agopian518ec112011-05-13 16:21:08 -0700924 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
925 pthread_mutex_lock(&sExtensionMapMutex);
926
927 /*
928 * Since eglGetProcAddress() is not associated to anything, it needs
929 * to return a function pointer that "works" regardless of what
930 * the current context is.
931 *
932 * For this reason, we return a "forwarder", a small stub that takes
933 * care of calling the function associated with the context
934 * currently bound.
935 *
936 * We first look for extensions we've already resolved, if we're seeing
937 * this extension for the first time, we go through all our
938 * implementations and call eglGetProcAddress() and record the
939 * result in the appropriate implementation hooks and return the
940 * address of the forwarder corresponding to that hook set.
941 *
942 */
943
944 const String8 name(procname);
945 addr = sGLExtentionMap.valueFor(name);
946 const int slot = sGLExtentionSlot;
947
Steve Blocke6f43dd2012-01-06 19:20:56 +0000948 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
Mathias Agopian518ec112011-05-13 16:21:08 -0700949 "no more slots for eglGetProcAddress(\"%s\")",
950 procname);
951
Siva Velusamy0469dd62011-11-30 15:05:37 -0800952#if EGL_TRACE
953 gl_hooks_t *debugHooks = GLTrace_getGLHooks();
954#endif
955
Mathias Agopian518ec112011-05-13 16:21:08 -0700956 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
957 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -0800958
959 egl_connection_t* const cnx = &gEGLImpl;
960 if (cnx->dso && cnx->egl.eglGetProcAddress) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800961 // Extensions are independent of the bound context
luliuhui69d10072012-08-30 11:15:36 +0800962 addr =
Mathias Agopian7773c432012-02-13 20:06:08 -0800963 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
964 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700965#if EGL_TRACE
Mathias Agopianada798b2012-02-13 17:09:30 -0800966 debugHooks->ext.extensions[slot] =
967 gHooksTrace.ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700968#endif
Mathias Agopianada798b2012-02-13 17:09:30 -0800969 cnx->egl.eglGetProcAddress(procname);
luliuhui69d10072012-08-30 11:15:36 +0800970 if (addr) found = true;
Mathias Agopian518ec112011-05-13 16:21:08 -0700971 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800972
Mathias Agopian518ec112011-05-13 16:21:08 -0700973 if (found) {
974 addr = gExtensionForwarders[slot];
Mathias Agopian518ec112011-05-13 16:21:08 -0700975 sGLExtentionMap.add(name, addr);
976 sGLExtentionSlot++;
977 }
978 }
979
980 pthread_mutex_unlock(&sExtensionMapMutex);
981 return addr;
982}
983
Jamie Gennis28ef8d72012-04-05 20:34:54 -0700984class FrameCompletionThread : public Thread {
985public:
986
987 static void queueSync(EGLSyncKHR sync) {
988 static sp<FrameCompletionThread> thread(new FrameCompletionThread);
989 static bool running = false;
990 if (!running) {
991 thread->run("GPUFrameCompletion");
992 running = true;
993 }
994 {
995 Mutex::Autolock lock(thread->mMutex);
996 ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d",
997 thread->mFramesQueued).string());
998 thread->mQueue.push_back(sync);
999 thread->mCondition.signal();
1000 thread->mFramesQueued++;
1001 ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size());
1002 }
1003 }
1004
1005private:
1006 FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {}
1007
1008 virtual bool threadLoop() {
1009 EGLSyncKHR sync;
1010 uint32_t frameNum;
1011 {
1012 Mutex::Autolock lock(mMutex);
1013 while (mQueue.isEmpty()) {
1014 mCondition.wait(mMutex);
1015 }
1016 sync = mQueue[0];
1017 frameNum = mFramesCompleted;
1018 }
1019 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1020 {
1021 ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d",
1022 frameNum).string());
1023 EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
1024 if (result == EGL_FALSE) {
1025 ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
1026 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
1027 ALOGE("FrameCompletion: timeout waiting for fence");
1028 }
1029 eglDestroySyncKHR(dpy, sync);
1030 }
1031 {
1032 Mutex::Autolock lock(mMutex);
1033 mQueue.removeAt(0);
1034 mFramesCompleted++;
1035 ATRACE_INT("GPU Frames Outstanding", mQueue.size());
1036 }
1037 return true;
1038 }
1039
1040 uint32_t mFramesQueued;
1041 uint32_t mFramesCompleted;
1042 Vector<EGLSyncKHR> mQueue;
1043 Condition mCondition;
1044 Mutex mMutex;
1045};
1046
Dan Stozaa894d082015-02-19 15:27:36 -08001047EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
1048 EGLint *rects, EGLint n_rects)
Mathias Agopian518ec112011-05-13 16:21:08 -07001049{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001050 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001051 clearError();
1052
Jesse Hallb29e5e82012-04-04 16:53:42 -07001053 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001054 if (!dp) return EGL_FALSE;
1055
Jesse Hallb29e5e82012-04-04 16:53:42 -07001056 SurfaceRef _s(dp.get(), draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001057 if (!_s.get())
1058 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001059
Siva Velusamy0469dd62011-11-30 15:05:37 -08001060#if EGL_TRACE
Siva Velusamya73a9772012-12-18 14:56:55 -08001061 gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific();
1062 if (getEGLDebugLevel() > 0) {
1063 if (trace_hooks == NULL) {
1064 if (GLTrace_start() < 0) {
1065 ALOGE("Disabling Tracer for OpenGL ES");
1066 setEGLDebugLevel(0);
1067 } else {
1068 // switch over to the trace version of hooks
1069 EGLContext ctx = egl_tls_t::getContext();
1070 egl_context_t * const c = get_context(ctx);
1071 if (c) {
1072 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
1073 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
1074 }
1075 }
1076 }
1077
Siva Velusamy0469dd62011-11-30 15:05:37 -08001078 GLTrace_eglSwapBuffers(dpy, draw);
Siva Velusamya73a9772012-12-18 14:56:55 -08001079 } else if (trace_hooks != NULL) {
1080 // tracing is now disabled, so switch back to the non trace version
1081 EGLContext ctx = egl_tls_t::getContext();
1082 egl_context_t * const c = get_context(ctx);
1083 if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
1084 GLTrace_stop();
1085 }
Siva Velusamy0469dd62011-11-30 15:05:37 -08001086#endif
1087
Mathias Agopian518ec112011-05-13 16:21:08 -07001088 egl_surface_t const * const s = get_surface(draw);
Mathias Agopian7db993a2012-03-25 00:49:46 -07001089
Mathias Agopianed6d08b2013-04-16 16:39:46 -07001090 if (CC_UNLIKELY(dp->traceGpuCompletion)) {
1091 EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
1092 if (sync != EGL_NO_SYNC_KHR) {
1093 FrameCompletionThread::queueSync(sync);
1094 }
1095 }
1096
Mathias Agopian7db993a2012-03-25 00:49:46 -07001097 if (CC_UNLIKELY(dp->finishOnSwap)) {
1098 uint32_t pixel;
1099 egl_context_t * const c = get_context( egl_tls_t::getContext() );
1100 if (c) {
1101 // glReadPixels() ensures that the frame is complete
1102 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
1103 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
1104 }
1105 }
1106
Dan Stozaa894d082015-02-19 15:27:36 -08001107 if (n_rects == 0) {
1108 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1109 }
1110
1111 Vector<android_native_rect_t> androidRects;
1112 for (int r = 0; r < n_rects; ++r) {
1113 int offset = r * 4;
1114 int x = rects[offset];
1115 int y = rects[offset + 1];
1116 int width = rects[offset + 2];
1117 int height = rects[offset + 3];
1118 android_native_rect_t androidRect;
1119 androidRect.left = x;
1120 androidRect.top = y + height;
1121 androidRect.right = x + width;
1122 androidRect.bottom = y;
1123 androidRects.push_back(androidRect);
1124 }
1125 native_window_set_surface_damage(s->win.get(), androidRects.array(),
1126 androidRects.size());
1127
1128 if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1129 return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1130 rects, n_rects);
1131 } else {
1132 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1133 }
1134}
1135
1136EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1137{
1138 return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
Mathias Agopian518ec112011-05-13 16:21:08 -07001139}
1140
1141EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
1142 NativePixmapType target)
1143{
1144 clearError();
1145
Jesse Hallb29e5e82012-04-04 16:53:42 -07001146 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001147 if (!dp) return EGL_FALSE;
1148
Jesse Hallb29e5e82012-04-04 16:53:42 -07001149 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001150 if (!_s.get())
1151 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001152
Mathias Agopian518ec112011-05-13 16:21:08 -07001153 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -08001154 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -07001155}
1156
1157const char* eglQueryString(EGLDisplay dpy, EGLint name)
1158{
1159 clearError();
1160
Jesse Hallb29e5e82012-04-04 16:53:42 -07001161 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001162 if (!dp) return (const char *) NULL;
1163
1164 switch (name) {
1165 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001166 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001167 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001168 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001169 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001170 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001171 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001172 return dp->getClientApiString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001173 }
1174 return setError(EGL_BAD_PARAMETER, (const char *)0);
1175}
1176
Mathias Agopianca088332013-03-28 17:44:13 -07001177EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name)
1178{
1179 clearError();
1180
1181 const egl_display_ptr dp = validate_display(dpy);
1182 if (!dp) return (const char *) NULL;
1183
1184 switch (name) {
1185 case EGL_VENDOR:
1186 return dp->disp.queryString.vendor;
1187 case EGL_VERSION:
1188 return dp->disp.queryString.version;
1189 case EGL_EXTENSIONS:
1190 return dp->disp.queryString.extensions;
1191 case EGL_CLIENT_APIS:
1192 return dp->disp.queryString.clientApi;
1193 }
1194 return setError(EGL_BAD_PARAMETER, (const char *)0);
1195}
Mathias Agopian518ec112011-05-13 16:21:08 -07001196
1197// ----------------------------------------------------------------------------
1198// EGL 1.1
1199// ----------------------------------------------------------------------------
1200
1201EGLBoolean eglSurfaceAttrib(
1202 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1203{
1204 clearError();
1205
Jesse Hallb29e5e82012-04-04 16:53:42 -07001206 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001207 if (!dp) return EGL_FALSE;
1208
Jesse Hallb29e5e82012-04-04 16:53:42 -07001209 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001210 if (!_s.get())
1211 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001212
Mathias Agopian518ec112011-05-13 16:21:08 -07001213 egl_surface_t const * const s = get_surface(surface);
1214 if (s->cnx->egl.eglSurfaceAttrib) {
1215 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -08001216 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001217 }
1218 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1219}
1220
1221EGLBoolean eglBindTexImage(
1222 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1223{
1224 clearError();
1225
Jesse Hallb29e5e82012-04-04 16:53:42 -07001226 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001227 if (!dp) return EGL_FALSE;
1228
Jesse Hallb29e5e82012-04-04 16:53:42 -07001229 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001230 if (!_s.get())
1231 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001232
Mathias Agopian518ec112011-05-13 16:21:08 -07001233 egl_surface_t const * const s = get_surface(surface);
1234 if (s->cnx->egl.eglBindTexImage) {
1235 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001236 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001237 }
1238 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1239}
1240
1241EGLBoolean eglReleaseTexImage(
1242 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1243{
1244 clearError();
1245
Jesse Hallb29e5e82012-04-04 16:53:42 -07001246 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001247 if (!dp) return EGL_FALSE;
1248
Jesse Hallb29e5e82012-04-04 16:53:42 -07001249 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001250 if (!_s.get())
1251 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001252
Mathias Agopian518ec112011-05-13 16:21:08 -07001253 egl_surface_t const * const s = get_surface(surface);
1254 if (s->cnx->egl.eglReleaseTexImage) {
1255 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001256 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001257 }
1258 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1259}
1260
1261EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1262{
1263 clearError();
1264
Jesse Hallb29e5e82012-04-04 16:53:42 -07001265 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001266 if (!dp) return EGL_FALSE;
1267
1268 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001269 egl_connection_t* const cnx = &gEGLImpl;
1270 if (cnx->dso && cnx->egl.eglSwapInterval) {
1271 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -07001272 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001273
Mathias Agopian518ec112011-05-13 16:21:08 -07001274 return res;
1275}
1276
1277
1278// ----------------------------------------------------------------------------
1279// EGL 1.2
1280// ----------------------------------------------------------------------------
1281
1282EGLBoolean eglWaitClient(void)
1283{
1284 clearError();
1285
Mathias Agopianada798b2012-02-13 17:09:30 -08001286 egl_connection_t* const cnx = &gEGLImpl;
1287 if (!cnx->dso)
1288 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
1289
1290 EGLBoolean res;
1291 if (cnx->egl.eglWaitClient) {
1292 res = cnx->egl.eglWaitClient();
1293 } else {
1294 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001295 }
1296 return res;
1297}
1298
1299EGLBoolean eglBindAPI(EGLenum api)
1300{
1301 clearError();
1302
1303 if (egl_init_drivers() == EGL_FALSE) {
1304 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1305 }
1306
1307 // bind this API on all EGLs
1308 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001309 egl_connection_t* const cnx = &gEGLImpl;
1310 if (cnx->dso && cnx->egl.eglBindAPI) {
1311 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -07001312 }
1313 return res;
1314}
1315
1316EGLenum eglQueryAPI(void)
1317{
1318 clearError();
1319
1320 if (egl_init_drivers() == EGL_FALSE) {
1321 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1322 }
1323
Mathias Agopianada798b2012-02-13 17:09:30 -08001324 egl_connection_t* const cnx = &gEGLImpl;
1325 if (cnx->dso && cnx->egl.eglQueryAPI) {
1326 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -07001327 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001328
Mathias Agopian518ec112011-05-13 16:21:08 -07001329 // or, it can only be OpenGL ES
1330 return EGL_OPENGL_ES_API;
1331}
1332
1333EGLBoolean eglReleaseThread(void)
1334{
1335 clearError();
1336
Mathias Agopian4e620dd2013-05-30 16:07:36 -07001337#if EGL_TRACE
1338 if (getEGLDebugLevel() > 0)
1339 GLTrace_eglReleaseThread();
1340#endif
1341
Mathias Agopian518ec112011-05-13 16:21:08 -07001342 // If there is context bound to the thread, release it
Mathias Agopianfb87e542012-01-30 18:20:52 -08001343 egl_display_t::loseCurrent(get_context(getContext()));
Mathias Agopian518ec112011-05-13 16:21:08 -07001344
Mathias Agopianada798b2012-02-13 17:09:30 -08001345 egl_connection_t* const cnx = &gEGLImpl;
1346 if (cnx->dso && cnx->egl.eglReleaseThread) {
1347 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -07001348 }
1349 egl_tls_t::clearTLS();
Mathias Agopian518ec112011-05-13 16:21:08 -07001350 return EGL_TRUE;
1351}
1352
1353EGLSurface eglCreatePbufferFromClientBuffer(
1354 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1355 EGLConfig config, const EGLint *attrib_list)
1356{
1357 clearError();
1358
Jesse Hallb29e5e82012-04-04 16:53:42 -07001359 egl_connection_t* cnx = NULL;
1360 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1361 if (!dp) return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -07001362 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1363 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -08001364 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001365 }
1366 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1367}
1368
1369// ----------------------------------------------------------------------------
1370// EGL_EGLEXT_VERSION 3
1371// ----------------------------------------------------------------------------
1372
1373EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
1374 const EGLint *attrib_list)
1375{
1376 clearError();
1377
Jesse Hallb29e5e82012-04-04 16:53:42 -07001378 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001379 if (!dp) return EGL_FALSE;
1380
Jesse Hallb29e5e82012-04-04 16:53:42 -07001381 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001382 if (!_s.get())
1383 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001384
1385 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001386 if (s->cnx->egl.eglLockSurfaceKHR) {
1387 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -08001388 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001389 }
1390 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1391}
1392
1393EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
1394{
1395 clearError();
1396
Jesse Hallb29e5e82012-04-04 16:53:42 -07001397 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001398 if (!dp) return EGL_FALSE;
1399
Jesse Hallb29e5e82012-04-04 16:53:42 -07001400 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001401 if (!_s.get())
1402 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001403
1404 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001405 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -08001406 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001407 }
1408 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1409}
1410
1411EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1412 EGLClientBuffer buffer, const EGLint *attrib_list)
1413{
1414 clearError();
1415
Jesse Hallb29e5e82012-04-04 16:53:42 -07001416 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001417 if (!dp) return EGL_NO_IMAGE_KHR;
1418
Jesse Hallb29e5e82012-04-04 16:53:42 -07001419 ContextRef _c(dp.get(), ctx);
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001420 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -07001421
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001422 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1423 egl_connection_t* const cnx = &gEGLImpl;
1424 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1425 result = cnx->egl.eglCreateImageKHR(
1426 dp->disp.dpy,
1427 c ? c->context : EGL_NO_CONTEXT,
1428 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001429 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001430 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001431}
1432
1433EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1434{
1435 clearError();
1436
Jesse Hallb29e5e82012-04-04 16:53:42 -07001437 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001438 if (!dp) return EGL_FALSE;
1439
Steven Holte646a5c52012-06-04 20:02:11 -07001440 EGLBoolean result = EGL_FALSE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001441 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001442 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
Steven Holte646a5c52012-06-04 20:02:11 -07001443 result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001444 }
Steven Holte646a5c52012-06-04 20:02:11 -07001445 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001446}
1447
1448// ----------------------------------------------------------------------------
1449// EGL_EGLEXT_VERSION 5
1450// ----------------------------------------------------------------------------
1451
1452
1453EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1454{
1455 clearError();
1456
Jesse Hallb29e5e82012-04-04 16:53:42 -07001457 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001458 if (!dp) return EGL_NO_SYNC_KHR;
1459
Mathias Agopian518ec112011-05-13 16:21:08 -07001460 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001461 egl_connection_t* const cnx = &gEGLImpl;
1462 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1463 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001464 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001465 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001466}
1467
1468EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1469{
1470 clearError();
1471
Jesse Hallb29e5e82012-04-04 16:53:42 -07001472 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001473 if (!dp) return EGL_FALSE;
1474
Mathias Agopian518ec112011-05-13 16:21:08 -07001475 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001476 egl_connection_t* const cnx = &gEGLImpl;
1477 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1478 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001479 }
1480 return result;
1481}
1482
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001483EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
1484 clearError();
1485
1486 const egl_display_ptr dp = validate_display(dpy);
1487 if (!dp) return EGL_FALSE;
1488
1489 EGLBoolean result = EGL_FALSE;
1490 egl_connection_t* const cnx = &gEGLImpl;
1491 if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1492 result = cnx->egl.eglSignalSyncKHR(
1493 dp->disp.dpy, sync, mode);
1494 }
1495 return result;
1496}
1497
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001498EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1499 EGLint flags, EGLTimeKHR timeout)
Mathias Agopian518ec112011-05-13 16:21:08 -07001500{
1501 clearError();
1502
Jesse Hallb29e5e82012-04-04 16:53:42 -07001503 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001504 if (!dp) return EGL_FALSE;
1505
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001506 EGLBoolean result = EGL_FALSE;
1507 egl_connection_t* const cnx = &gEGLImpl;
1508 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1509 result = cnx->egl.eglClientWaitSyncKHR(
1510 dp->disp.dpy, sync, flags, timeout);
Mathias Agopian518ec112011-05-13 16:21:08 -07001511 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001512 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001513}
1514
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001515EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1516 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001517{
1518 clearError();
1519
Jesse Hallb29e5e82012-04-04 16:53:42 -07001520 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001521 if (!dp) return EGL_FALSE;
1522
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001523 EGLBoolean result = EGL_FALSE;
1524 egl_connection_t* const cnx = &gEGLImpl;
1525 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1526 result = cnx->egl.eglGetSyncAttribKHR(
1527 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001528 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001529 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001530}
1531
Season Li000d88f2015-07-01 11:39:40 -07001532EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list)
1533{
1534 clearError();
1535
1536 const egl_display_ptr dp = validate_display(dpy);
1537 if (!dp) return EGL_NO_STREAM_KHR;
1538
1539 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1540 egl_connection_t* const cnx = &gEGLImpl;
1541 if (cnx->dso && cnx->egl.eglCreateStreamKHR) {
1542 result = cnx->egl.eglCreateStreamKHR(
1543 dp->disp.dpy, attrib_list);
1544 }
1545 return result;
1546}
1547
1548EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream)
1549{
1550 clearError();
1551
1552 const egl_display_ptr dp = validate_display(dpy);
1553 if (!dp) return EGL_FALSE;
1554
1555 EGLBoolean result = EGL_FALSE;
1556 egl_connection_t* const cnx = &gEGLImpl;
1557 if (cnx->dso && cnx->egl.eglDestroyStreamKHR) {
1558 result = cnx->egl.eglDestroyStreamKHR(
1559 dp->disp.dpy, stream);
1560 }
1561 return result;
1562}
1563
1564EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream,
1565 EGLenum attribute, EGLint value)
1566{
1567 clearError();
1568
1569 const egl_display_ptr dp = validate_display(dpy);
1570 if (!dp) return EGL_FALSE;
1571
1572 EGLBoolean result = EGL_FALSE;
1573 egl_connection_t* const cnx = &gEGLImpl;
1574 if (cnx->dso && cnx->egl.eglStreamAttribKHR) {
1575 result = cnx->egl.eglStreamAttribKHR(
1576 dp->disp.dpy, stream, attribute, value);
1577 }
1578 return result;
1579}
1580
1581EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream,
1582 EGLenum attribute, EGLint *value)
1583{
1584 clearError();
1585
1586 const egl_display_ptr dp = validate_display(dpy);
1587 if (!dp) return EGL_FALSE;
1588
1589 EGLBoolean result = EGL_FALSE;
1590 egl_connection_t* const cnx = &gEGLImpl;
1591 if (cnx->dso && cnx->egl.eglQueryStreamKHR) {
1592 result = cnx->egl.eglQueryStreamKHR(
1593 dp->disp.dpy, stream, attribute, value);
1594 }
1595 return result;
1596}
1597
1598EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream,
1599 EGLenum attribute, EGLuint64KHR *value)
1600{
1601 clearError();
1602
1603 const egl_display_ptr dp = validate_display(dpy);
1604 if (!dp) return EGL_FALSE;
1605
1606 EGLBoolean result = EGL_FALSE;
1607 egl_connection_t* const cnx = &gEGLImpl;
1608 if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) {
1609 result = cnx->egl.eglQueryStreamu64KHR(
1610 dp->disp.dpy, stream, attribute, value);
1611 }
1612 return result;
1613}
1614
1615EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream,
1616 EGLenum attribute, EGLTimeKHR *value)
1617{
1618 clearError();
1619
1620 const egl_display_ptr dp = validate_display(dpy);
1621 if (!dp) return EGL_FALSE;
1622
1623 EGLBoolean result = EGL_FALSE;
1624 egl_connection_t* const cnx = &gEGLImpl;
1625 if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) {
1626 result = cnx->egl.eglQueryStreamTimeKHR(
1627 dp->disp.dpy, stream, attribute, value);
1628 }
1629 return result;
1630}
1631
1632EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config,
1633 EGLStreamKHR stream, const EGLint *attrib_list)
1634{
1635 clearError();
1636
1637 egl_display_ptr dp = validate_display(dpy);
1638 if (!dp) return EGL_NO_SURFACE;
1639
1640 egl_connection_t* const cnx = &gEGLImpl;
1641 if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) {
1642 EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(
1643 dp->disp.dpy, config, stream, attrib_list);
1644 if (surface != EGL_NO_SURFACE) {
1645 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
1646 surface, cnx);
1647 return s;
1648 }
1649 }
1650 return EGL_NO_SURFACE;
1651}
1652
1653EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy,
1654 EGLStreamKHR stream)
1655{
1656 clearError();
1657
1658 const egl_display_ptr dp = validate_display(dpy);
1659 if (!dp) return EGL_FALSE;
1660
1661 EGLBoolean result = EGL_FALSE;
1662 egl_connection_t* const cnx = &gEGLImpl;
1663 if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) {
1664 result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(
1665 dp->disp.dpy, stream);
1666 }
1667 return result;
1668}
1669
1670EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy,
1671 EGLStreamKHR stream)
1672{
1673 clearError();
1674
1675 const egl_display_ptr dp = validate_display(dpy);
1676 if (!dp) return EGL_FALSE;
1677
1678 EGLBoolean result = EGL_FALSE;
1679 egl_connection_t* const cnx = &gEGLImpl;
1680 if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) {
1681 result = cnx->egl.eglStreamConsumerAcquireKHR(
1682 dp->disp.dpy, stream);
1683 }
1684 return result;
1685}
1686
1687EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy,
1688 EGLStreamKHR stream)
1689{
1690 clearError();
1691
1692 const egl_display_ptr dp = validate_display(dpy);
1693 if (!dp) return EGL_FALSE;
1694
1695 EGLBoolean result = EGL_FALSE;
1696 egl_connection_t* const cnx = &gEGLImpl;
1697 if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) {
1698 result = cnx->egl.eglStreamConsumerReleaseKHR(
1699 dp->disp.dpy, stream);
1700 }
1701 return result;
1702}
1703
1704EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR(
1705 EGLDisplay dpy, EGLStreamKHR stream)
1706{
1707 clearError();
1708
1709 const egl_display_ptr dp = validate_display(dpy);
1710 if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;
1711
1712 EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;
1713 egl_connection_t* const cnx = &gEGLImpl;
1714 if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) {
1715 result = cnx->egl.eglGetStreamFileDescriptorKHR(
1716 dp->disp.dpy, stream);
1717 }
1718 return result;
1719}
1720
1721EGLStreamKHR eglCreateStreamFromFileDescriptorKHR(
1722 EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor)
1723{
1724 clearError();
1725
1726 const egl_display_ptr dp = validate_display(dpy);
1727 if (!dp) return EGL_NO_STREAM_KHR;
1728
1729 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1730 egl_connection_t* const cnx = &gEGLImpl;
1731 if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) {
1732 result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(
1733 dp->disp.dpy, file_descriptor);
1734 }
1735 return result;
1736}
1737
Mathias Agopian518ec112011-05-13 16:21:08 -07001738// ----------------------------------------------------------------------------
Mathias Agopian2bb71682013-03-27 17:32:41 -07001739// EGL_EGLEXT_VERSION 15
1740// ----------------------------------------------------------------------------
1741
1742EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
1743 clearError();
1744 const egl_display_ptr dp = validate_display(dpy);
1745 if (!dp) return EGL_FALSE;
1746 EGLint result = EGL_FALSE;
1747 egl_connection_t* const cnx = &gEGLImpl;
1748 if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
1749 result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1750 }
1751 return result;
1752}
1753
1754// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -07001755// ANDROID extensions
1756// ----------------------------------------------------------------------------
1757
Jamie Gennis331841b2012-09-06 14:52:00 -07001758EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync)
1759{
1760 clearError();
1761
1762 const egl_display_ptr dp = validate_display(dpy);
1763 if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1764
1765 EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1766 egl_connection_t* const cnx = &gEGLImpl;
1767 if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
1768 result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1769 }
1770 return result;
1771}
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001772
Andy McFadden72841452013-03-01 16:25:32 -08001773EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface,
1774 EGLnsecsANDROID time)
1775{
1776 clearError();
1777
1778 const egl_display_ptr dp = validate_display(dpy);
1779 if (!dp) {
1780 return EGL_FALSE;
1781 }
1782
1783 SurfaceRef _s(dp.get(), surface);
1784 if (!_s.get()) {
1785 setError(EGL_BAD_SURFACE, EGL_FALSE);
1786 return EGL_FALSE;
1787 }
1788
1789 egl_surface_t const * const s = get_surface(surface);
1790 native_window_set_buffers_timestamp(s->win.get(), time);
1791
1792 return EGL_TRUE;
1793}
1794
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001795// ----------------------------------------------------------------------------
1796// NVIDIA extensions
1797// ----------------------------------------------------------------------------
1798EGLuint64NV eglGetSystemTimeFrequencyNV()
1799{
1800 clearError();
1801
1802 if (egl_init_drivers() == EGL_FALSE) {
1803 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1804 }
1805
1806 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001807 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001808
Mathias Agopianada798b2012-02-13 17:09:30 -08001809 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1810 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001811 }
1812
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001813 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001814}
1815
1816EGLuint64NV eglGetSystemTimeNV()
1817{
1818 clearError();
1819
1820 if (egl_init_drivers() == EGL_FALSE) {
1821 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1822 }
1823
1824 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001825 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001826
Mathias Agopianada798b2012-02-13 17:09:30 -08001827 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1828 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001829 }
1830
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001831 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001832}
Dan Stozaa894d082015-02-19 15:27:36 -08001833
1834// ----------------------------------------------------------------------------
1835// Partial update extension
1836// ----------------------------------------------------------------------------
1837EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1838 EGLint *rects, EGLint n_rects)
1839{
1840 clearError();
1841
1842 const egl_display_ptr dp = validate_display(dpy);
1843 if (!dp) {
1844 setError(EGL_BAD_DISPLAY, EGL_FALSE);
1845 return EGL_FALSE;
1846 }
1847
1848 SurfaceRef _s(dp.get(), surface);
1849 if (!_s.get()) {
1850 setError(EGL_BAD_SURFACE, EGL_FALSE);
1851 return EGL_FALSE;
1852 }
1853
1854 egl_surface_t const * const s = get_surface(surface);
1855 if (s->cnx->egl.eglSetDamageRegionKHR) {
1856 return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,
1857 rects, n_rects);
1858 }
1859
1860 return EGL_FALSE;
1861}