blob: 5bd74649201b43a247e2686aa672712b9eef2880 [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"
Mathias Agopian39c24a22013-04-04 23:17:56 -070042#include "../hooks.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070043
44#include "egl_display.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070045#include "egl_object.h"
46#include "egl_tls.h"
Mathias Agopianada798b2012-02-13 17:09:30 -080047#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070048
49using namespace android;
50
Jesse Halla2ba4282013-09-14 21:00:14 -070051// This extension has not been ratified yet, so can't be shipped.
52// Implementation is incomplete and untested.
53#define ENABLE_EGL_KHR_GL_COLORSPACE 0
54
Mathias Agopian518ec112011-05-13 16:21:08 -070055// ----------------------------------------------------------------------------
56
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070057namespace android {
58
Mathias Agopian518ec112011-05-13 16:21:08 -070059struct extention_map_t {
60 const char* name;
61 __eglMustCastToProperFunctionPointerType address;
62};
63
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070064/*
Jesse Hall21558da2013-08-06 15:31:22 -070065 * This is the list of EGL extensions exposed to applications.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070066 *
Jesse Hall21558da2013-08-06 15:31:22 -070067 * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
68 * wrapper and are always available.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070069 *
Jesse Hall21558da2013-08-06 15:31:22 -070070 * The rest (gExtensionString) depend on support in the EGL driver, and are
71 * only available if the driver supports them. However, some of these must be
72 * supported because they are used by the Android system itself; these are
73 * listd as mandatory below and are required by the CDD. The system *assumes*
74 * the mandatory extensions are present and may not function properly if some
75 * are missing.
76 *
77 * NOTE: Both strings MUST have a single space as the last character.
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070078 */
Jesse Hall21558da2013-08-06 15:31:22 -070079extern char const * const gBuiltinExtensionString =
80 "EGL_KHR_get_all_proc_addresses "
81 "EGL_ANDROID_presentation_time "
Dan Stozaa894d082015-02-19 15:27:36 -080082 "EGL_KHR_swap_buffers_with_damage "
Jesse Hall21558da2013-08-06 15:31:22 -070083 ;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070084extern char const * const gExtensionString =
85 "EGL_KHR_image " // mandatory
86 "EGL_KHR_image_base " // mandatory
87 "EGL_KHR_image_pixmap "
88 "EGL_KHR_lock_surface "
Jesse Halla2ba4282013-09-14 21:00:14 -070089#if (ENABLE_EGL_KHR_GL_COLORSPACE != 0)
Jesse Hallc2e41222013-08-08 13:40:22 -070090 "EGL_KHR_gl_colorspace "
Jesse Halla2ba4282013-09-14 21:00:14 -070091#endif
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070092 "EGL_KHR_gl_texture_2D_image "
Season Li000d88f2015-07-01 11:39:40 -070093 "EGL_KHR_gl_texture_3D_image "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -070094 "EGL_KHR_gl_texture_cubemap_image "
95 "EGL_KHR_gl_renderbuffer_image "
96 "EGL_KHR_reusable_sync "
97 "EGL_KHR_fence_sync "
Jamie Gennisf6d1c392013-04-25 18:48:41 -070098 "EGL_KHR_create_context "
Season Li000d88f2015-07-01 11:39:40 -070099 "EGL_KHR_config_attribs "
100 "EGL_KHR_surfaceless_context "
101 "EGL_KHR_stream "
102 "EGL_KHR_stream_fifo "
103 "EGL_KHR_stream_producer_eglsurface "
104 "EGL_KHR_stream_consumer_gltexture "
105 "EGL_KHR_stream_cross_process_fd "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700106 "EGL_EXT_create_context_robustness "
107 "EGL_NV_system_time "
108 "EGL_ANDROID_image_native_buffer " // mandatory
Mathias Agopian2bb71682013-03-27 17:32:41 -0700109 "EGL_KHR_wait_sync " // strongly recommended
Jamie Gennisdbe92452013-09-23 17:22:10 -0700110 "EGL_ANDROID_recordable " // mandatory
Dan Stozaa894d082015-02-19 15:27:36 -0800111 "EGL_KHR_partial_update " // strongly recommended
112 "EGL_EXT_buffer_age " // strongly recommended with partial_update
Jesse Hall408e59f2015-04-24 01:40:42 -0700113 "EGL_KHR_create_context_no_error "
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700114 ;
115
116// extensions not exposed to applications but used by the ANDROID system
117// "EGL_ANDROID_blob_cache " // strongly recommended
118// "EGL_IMG_hibernate_process " // optional
119// "EGL_ANDROID_native_fence_sync " // strongly recommended
120// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1
Jamie Gennisdbe92452013-09-23 17:22:10 -0700121// "EGL_ANDROID_image_crop " // optional
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700122
123/*
124 * EGL Extensions entry-points exposed to 3rd party applications
125 * (keep in sync with gExtensionString above)
126 *
127 */
128static const extention_map_t sExtensionMap[] = {
129 // EGL_KHR_lock_surface
Mathias Agopian518ec112011-05-13 16:21:08 -0700130 { "eglLockSurfaceKHR",
131 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
132 { "eglUnlockSurfaceKHR",
133 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700134
135 // EGL_KHR_image, EGL_KHR_image_base
Mathias Agopian518ec112011-05-13 16:21:08 -0700136 { "eglCreateImageKHR",
137 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
138 { "eglDestroyImageKHR",
139 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700140
141 // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
142 { "eglCreateSyncKHR",
143 (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
144 { "eglDestroySyncKHR",
145 (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
146 { "eglClientWaitSyncKHR",
147 (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
148 { "eglSignalSyncKHR",
149 (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
150 { "eglGetSyncAttribKHR",
151 (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
152
153 // EGL_NV_system_time
Jonas Yang1c3d72a2011-08-26 20:04:39 +0800154 { "eglGetSystemTimeFrequencyNV",
155 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
156 { "eglGetSystemTimeNV",
157 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700158
Mathias Agopian2bb71682013-03-27 17:32:41 -0700159 // EGL_KHR_wait_sync
160 { "eglWaitSyncKHR",
161 (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700162
163 // EGL_ANDROID_presentation_time
164 { "eglPresentationTimeANDROID",
165 (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
Dan Stozaa894d082015-02-19 15:27:36 -0800166
167 // EGL_KHR_swap_buffers_with_damage
168 { "eglSwapBuffersWithDamageKHR",
169 (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
170
171 // EGL_KHR_partial_update
172 { "eglSetDamageRegionKHR",
173 (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
Season Li000d88f2015-07-01 11:39:40 -0700174
175 { "eglCreateStreamKHR",
176 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR },
177 { "eglDestroyStreamKHR",
178 (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR },
179 { "eglStreamAttribKHR",
180 (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR },
181 { "eglQueryStreamKHR",
182 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR },
183 { "eglQueryStreamu64KHR",
184 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR },
185 { "eglQueryStreamTimeKHR",
186 (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR },
187 { "eglCreateStreamProducerSurfaceKHR",
188 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR },
189 { "eglStreamConsumerGLTextureExternalKHR",
190 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR },
191 { "eglStreamConsumerAcquireKHR",
192 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR },
193 { "eglStreamConsumerReleaseKHR",
194 (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR },
195 { "eglGetStreamFileDescriptorKHR",
196 (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR },
197 { "eglCreateStreamFromFileDescriptorKHR",
198 (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },
Mathias Agopian518ec112011-05-13 16:21:08 -0700199};
200
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700201/*
202 * These extensions entry-points should not be exposed to applications.
203 * They're used internally by the Android EGL layer.
204 */
205#define FILTER_EXTENSIONS(procname) \
206 (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \
207 !strcmp((procname), "eglHibernateProcessIMG") || \
208 !strcmp((procname), "eglAwakenProcessIMG") || \
209 !strcmp((procname), "eglDupNativeFenceFDANDROID"))
210
211
212
Mathias Agopian518ec112011-05-13 16:21:08 -0700213// accesses protected by sExtensionMapMutex
214static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
215static int sGLExtentionSlot = 0;
216static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
217
218static void(*findProcAddress(const char* name,
219 const extention_map_t* map, size_t n))() {
220 for (uint32_t i=0 ; i<n ; i++) {
221 if (!strcmp(name, map[i].name)) {
222 return map[i].address;
223 }
224 }
225 return NULL;
226}
227
228// ----------------------------------------------------------------------------
229
Mathias Agopian518ec112011-05-13 16:21:08 -0700230extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
231extern EGLBoolean egl_init_drivers();
232extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
Mathias Agopian518ec112011-05-13 16:21:08 -0700233extern gl_hooks_t gHooksTrace;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700234
Mathias Agopian518ec112011-05-13 16:21:08 -0700235} // namespace android;
236
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700237
Mathias Agopian518ec112011-05-13 16:21:08 -0700238// ----------------------------------------------------------------------------
239
240static inline void clearError() { egl_tls_t::clearError(); }
241static inline EGLContext getContext() { return egl_tls_t::getContext(); }
242
243// ----------------------------------------------------------------------------
244
245EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
246{
247 clearError();
248
Dan Stozac3289c42014-01-17 11:38:34 -0800249 uintptr_t index = reinterpret_cast<uintptr_t>(display);
Mathias Agopian518ec112011-05-13 16:21:08 -0700250 if (index >= NUM_DISPLAYS) {
251 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
252 }
253
254 if (egl_init_drivers() == EGL_FALSE) {
255 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
256 }
257
258 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
259 return dpy;
260}
261
262// ----------------------------------------------------------------------------
263// Initialization
264// ----------------------------------------------------------------------------
265
266EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
267{
268 clearError();
269
Jesse Hallb29e5e82012-04-04 16:53:42 -0700270 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700271 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
272
273 EGLBoolean res = dp->initialize(major, minor);
274
275 return res;
276}
277
278EGLBoolean eglTerminate(EGLDisplay dpy)
279{
280 // NOTE: don't unload the drivers b/c some APIs can be called
281 // after eglTerminate() has been called. eglTerminate() only
282 // terminates an EGLDisplay, not a EGL itself.
283
284 clearError();
285
Jesse Hallb29e5e82012-04-04 16:53:42 -0700286 egl_display_ptr dp = get_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700287 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
288
289 EGLBoolean res = dp->terminate();
Jesse Hall47743382013-02-08 11:13:46 -0800290
Mathias Agopian518ec112011-05-13 16:21:08 -0700291 return res;
292}
293
294// ----------------------------------------------------------------------------
295// configuration
296// ----------------------------------------------------------------------------
297
298EGLBoolean eglGetConfigs( EGLDisplay dpy,
299 EGLConfig *configs,
300 EGLint config_size, EGLint *num_config)
301{
302 clearError();
303
Jesse Hallb29e5e82012-04-04 16:53:42 -0700304 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700305 if (!dp) return EGL_FALSE;
306
Mathias Agopian7773c432012-02-13 20:06:08 -0800307 if (num_config==0) {
308 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700309 }
310
Mathias Agopian7773c432012-02-13 20:06:08 -0800311 EGLBoolean res = EGL_FALSE;
312 *num_config = 0;
313
314 egl_connection_t* const cnx = &gEGLImpl;
315 if (cnx->dso) {
316 res = cnx->egl.eglGetConfigs(
317 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700318 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800319
320 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700321}
322
323EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
324 EGLConfig *configs, EGLint config_size,
325 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
332 if (num_config==0) {
333 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
334 }
335
Mathias Agopian518ec112011-05-13 16:21:08 -0700336 EGLBoolean res = EGL_FALSE;
337 *num_config = 0;
338
Mathias Agopianada798b2012-02-13 17:09:30 -0800339 egl_connection_t* const cnx = &gEGLImpl;
340 if (cnx->dso) {
Romain Guy1cffc802012-10-15 18:13:05 -0700341 if (attrib_list) {
342 char value[PROPERTY_VALUE_MAX];
343 property_get("debug.egl.force_msaa", value, "false");
344
345 if (!strcmp(value, "true")) {
346 size_t attribCount = 0;
347 EGLint attrib = attrib_list[0];
348
349 // Only enable MSAA if the context is OpenGL ES 2.0 and
Romain Guybe3c3e42012-10-15 19:25:18 -0700350 // if no caveat is requested
Romain Guy1cffc802012-10-15 18:13:05 -0700351 const EGLint *attribRendererable = NULL;
352 const EGLint *attribCaveat = NULL;
353
354 // Count the number of attributes and look for
Romain Guybe3c3e42012-10-15 19:25:18 -0700355 // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
Romain Guy1cffc802012-10-15 18:13:05 -0700356 while (attrib != EGL_NONE) {
357 attrib = attrib_list[attribCount];
358 switch (attrib) {
359 case EGL_RENDERABLE_TYPE:
360 attribRendererable = &attrib_list[attribCount];
361 break;
362 case EGL_CONFIG_CAVEAT:
363 attribCaveat = &attrib_list[attribCount];
364 break;
365 }
366 attribCount++;
367 }
368
369 if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
370 (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
Jesse Hall47743382013-02-08 11:13:46 -0800371
Romain Guy1cffc802012-10-15 18:13:05 -0700372 // Insert 2 extra attributes to force-enable MSAA 4x
373 EGLint aaAttribs[attribCount + 4];
374 aaAttribs[0] = EGL_SAMPLE_BUFFERS;
375 aaAttribs[1] = 1;
376 aaAttribs[2] = EGL_SAMPLES;
377 aaAttribs[3] = 4;
378
379 memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
380
381 EGLint numConfigAA;
382 EGLBoolean resAA = cnx->egl.eglChooseConfig(
383 dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
384
385 if (resAA == EGL_TRUE && numConfigAA > 0) {
386 ALOGD("Enabling MSAA 4x");
387 *num_config = numConfigAA;
388 return resAA;
389 }
390 }
391 }
392 }
393
Mathias Agopian7773c432012-02-13 20:06:08 -0800394 res = cnx->egl.eglChooseConfig(
395 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700396 }
397 return res;
398}
399
400EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
401 EGLint attribute, EGLint *value)
402{
403 clearError();
404
Jesse Hallb29e5e82012-04-04 16:53:42 -0700405 egl_connection_t* cnx = NULL;
406 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
407 if (!dp) return EGL_FALSE;
Jesse Hall47743382013-02-08 11:13:46 -0800408
Mathias Agopian518ec112011-05-13 16:21:08 -0700409 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800410 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700411}
412
413// ----------------------------------------------------------------------------
414// surfaces
415// ----------------------------------------------------------------------------
416
Jesse Halla2ba4282013-09-14 21:00:14 -0700417// The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't
Jesse Hallc2e41222013-08-08 13:40:22 -0700418// been added to the Khronos egl.h.
419#define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE
420#define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB
421#define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR
422
423// Turn linear formats into corresponding sRGB formats when colorspace is
424// EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear
425// formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800426// the modification isn't possible, the original dataSpace is returned.
427static android_dataspace modifyBufferDataspace( android_dataspace dataSpace,
428 EGLint colorspace) {
Jesse Hallc2e41222013-08-08 13:40:22 -0700429 if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800430 return HAL_DATASPACE_SRGB_LINEAR;
Jesse Hallc2e41222013-08-08 13:40:22 -0700431 } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800432 return HAL_DATASPACE_SRGB;
Jesse Hallc2e41222013-08-08 13:40:22 -0700433 }
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800434 return dataSpace;
Jesse Hallc2e41222013-08-08 13:40:22 -0700435}
436
Mathias Agopian518ec112011-05-13 16:21:08 -0700437EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
438 NativeWindowType window,
439 const EGLint *attrib_list)
440{
441 clearError();
442
Jesse Hallb29e5e82012-04-04 16:53:42 -0700443 egl_connection_t* cnx = NULL;
444 egl_display_ptr dp = validate_display_connection(dpy, cnx);
445 if (dp) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800446 EGLDisplay iDpy = dp->disp.dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700447
Andy McFaddend566ce32014-01-07 15:54:17 -0800448 int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
449 if (result != OK) {
450 ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
451 "failed (%#x) (already connected to another API?)",
452 window, result);
Jonathan Hamilton77a9b4a2013-07-17 09:41:42 -0700453 return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
Mathias Agopian81a63352011-07-29 17:55:48 -0700454 }
455
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700456 // Set the native window's buffers format to match what this config requests.
Jesse Hallc2e41222013-08-08 13:40:22 -0700457 // Whether to use sRGB gamma is not part of the EGLconfig, but is part
458 // of our native format. So if sRGB gamma is requested, we have to
459 // modify the EGLconfig's format before setting the native window's
460 // format.
Alistair Strachan733a8072015-02-12 12:33:25 -0800461
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700462 // by default, just pick RGBA_8888
463 EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800464 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700465
466 EGLint a = 0;
467 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
468 if (a > 0) {
469 // alpha-channel requested, there's really only one suitable format
470 format = HAL_PIXEL_FORMAT_RGBA_8888;
471 } else {
472 EGLint r, g, b;
473 r = g = b = 0;
474 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r);
475 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
476 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b);
477 EGLint colorDepth = r + g + b;
478 if (colorDepth <= 16) {
479 format = HAL_PIXEL_FORMAT_RGB_565;
480 } else {
481 format = HAL_PIXEL_FORMAT_RGBX_8888;
482 }
Jesse Hallc2e41222013-08-08 13:40:22 -0700483 }
Mathias Agopian0f288fc2013-08-21 16:36:34 -0700484
485 // now select a corresponding sRGB format if needed
486 if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
487 for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
488 if (*attr == EGL_GL_COLORSPACE_KHR) {
Jesse Halla2ba4282013-09-14 21:00:14 -0700489 if (ENABLE_EGL_KHR_GL_COLORSPACE) {
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800490 dataSpace = modifyBufferDataspace(dataSpace, *(attr+1));
Jesse Halla2ba4282013-09-14 21:00:14 -0700491 } else {
492 // Normally we'd pass through unhandled attributes to
493 // the driver. But in case the driver implements this
494 // extension but we're disabling it, we want to prevent
495 // it getting through -- support will be broken without
496 // our help.
497 ALOGE("sRGB window surfaces not supported");
498 return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
499 }
Jamie Gennisbee205f2011-07-01 13:12:07 -0700500 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700501 }
502 }
Alistair Strachan733a8072015-02-12 12:33:25 -0800503
Jesse Hallc2e41222013-08-08 13:40:22 -0700504 if (format != 0) {
505 int err = native_window_set_buffers_format(window, format);
506 if (err != 0) {
507 ALOGE("error setting native window pixel format: %s (%d)",
508 strerror(-err), err);
509 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
510 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
511 }
512 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700513
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800514 if (dataSpace != 0) {
515 int err = native_window_set_buffers_data_space(window, dataSpace);
516 if (err != 0) {
517 ALOGE("error setting native window pixel dataSpace: %s (%d)",
518 strerror(-err), err);
519 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
520 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
521 }
522 }
523
Jamie Gennis59769462011-11-19 18:04:43 -0800524 // the EGL spec requires that a new EGLSurface default to swap interval
525 // 1, so explicitly set that on the window here.
526 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
527 anw->setSwapInterval(anw, 1);
528
Mathias Agopian518ec112011-05-13 16:21:08 -0700529 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800530 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700531 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700532 egl_surface_t* s = new egl_surface_t(dp.get(), config, window,
533 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700534 return s;
535 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700536
537 // EGLSurface creation failed
538 native_window_set_buffers_format(window, 0);
539 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Mathias Agopian518ec112011-05-13 16:21:08 -0700540 }
541 return EGL_NO_SURFACE;
542}
543
544EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
545 NativePixmapType pixmap,
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.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800554 dp->disp.dpy, config, pixmap, 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}
563
564EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
565 const EGLint *attrib_list)
566{
567 clearError();
568
Jesse Hallb29e5e82012-04-04 16:53:42 -0700569 egl_connection_t* cnx = NULL;
570 egl_display_ptr dp = validate_display_connection(dpy, cnx);
571 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700572 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800573 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700574 if (surface != EGL_NO_SURFACE) {
Jesse Hallb29e5e82012-04-04 16:53:42 -0700575 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
576 surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700577 return s;
578 }
579 }
580 return EGL_NO_SURFACE;
581}
Jesse Hall47743382013-02-08 11:13:46 -0800582
Mathias Agopian518ec112011-05-13 16:21:08 -0700583EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
584{
585 clearError();
586
Jesse Hallb29e5e82012-04-04 16:53:42 -0700587 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700588 if (!dp) return EGL_FALSE;
589
Jesse Hallb29e5e82012-04-04 16:53:42 -0700590 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700591 if (!_s.get())
592 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700593
594 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800595 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700596 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700597 _s.terminate();
598 }
599 return result;
600}
601
602EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
603 EGLint attribute, EGLint *value)
604{
605 clearError();
606
Jesse Hallb29e5e82012-04-04 16:53:42 -0700607 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700608 if (!dp) return EGL_FALSE;
609
Jesse Hallb29e5e82012-04-04 16:53:42 -0700610 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700611 if (!_s.get())
612 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700613
Mathias Agopian518ec112011-05-13 16:21:08 -0700614 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian7773c432012-02-13 20:06:08 -0800615 return s->cnx->egl.eglQuerySurface(
616 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700617}
618
Jamie Gennise8696a42012-01-15 18:54:57 -0800619void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800620 ATRACE_CALL();
Jamie Gennise8696a42012-01-15 18:54:57 -0800621 clearError();
622
Jesse Hallb29e5e82012-04-04 16:53:42 -0700623 const egl_display_ptr dp = validate_display(dpy);
Jamie Gennise8696a42012-01-15 18:54:57 -0800624 if (!dp) {
625 return;
626 }
627
Jesse Hallb29e5e82012-04-04 16:53:42 -0700628 SurfaceRef _s(dp.get(), surface);
Jamie Gennise8696a42012-01-15 18:54:57 -0800629 if (!_s.get()) {
630 setError(EGL_BAD_SURFACE, EGL_FALSE);
631 return;
632 }
Jamie Gennise8696a42012-01-15 18:54:57 -0800633}
634
Mathias Agopian518ec112011-05-13 16:21:08 -0700635// ----------------------------------------------------------------------------
636// Contexts
637// ----------------------------------------------------------------------------
638
639EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
640 EGLContext share_list, const EGLint *attrib_list)
641{
642 clearError();
643
Jesse Hallb29e5e82012-04-04 16:53:42 -0700644 egl_connection_t* cnx = NULL;
645 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
Michael Chock0673e1e2012-06-21 12:53:17 -0700646 if (dp) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700647 if (share_list != EGL_NO_CONTEXT) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700648 if (!ContextRef(dp.get(), share_list).get()) {
649 return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
650 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700651 egl_context_t* const c = get_context(share_list);
652 share_list = c->context;
653 }
654 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800655 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700656 if (context != EGL_NO_CONTEXT) {
657 // figure out if it's a GLESv1 or GLESv2
658 int version = 0;
659 if (attrib_list) {
660 while (*attrib_list != EGL_NONE) {
661 GLint attr = *attrib_list++;
662 GLint value = *attrib_list++;
663 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
664 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800665 version = egl_connection_t::GLESv1_INDEX;
Jesse Hall47743382013-02-08 11:13:46 -0800666 } else if (value == 2 || value == 3) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800667 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700668 }
669 }
670 };
671 }
Jesse Hallb29e5e82012-04-04 16:53:42 -0700672 egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
673 version);
Mathias Agopian518ec112011-05-13 16:21:08 -0700674 return c;
675 }
676 }
677 return EGL_NO_CONTEXT;
678}
679
680EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
681{
682 clearError();
683
Jesse Hallb29e5e82012-04-04 16:53:42 -0700684 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700685 if (!dp)
686 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700687
Jesse Hallb29e5e82012-04-04 16:53:42 -0700688 ContextRef _c(dp.get(), ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700689 if (!_c.get())
690 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Jesse Hall47743382013-02-08 11:13:46 -0800691
Mathias Agopian518ec112011-05-13 16:21:08 -0700692 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800693 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700694 if (result == EGL_TRUE) {
695 _c.terminate();
696 }
697 return result;
698}
699
Mathias Agopian518ec112011-05-13 16:21:08 -0700700EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
701 EGLSurface read, EGLContext ctx)
702{
703 clearError();
704
Jesse Hallb29e5e82012-04-04 16:53:42 -0700705 egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700706 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
707
Mathias Agopian5b287a62011-05-16 18:58:55 -0700708 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
709 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
710 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700711 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
712 (draw != EGL_NO_SURFACE) ) {
713 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
714 }
715
716 // get a reference to the object passed in
Jesse Hallb29e5e82012-04-04 16:53:42 -0700717 ContextRef _c(dp.get(), ctx);
718 SurfaceRef _d(dp.get(), draw);
719 SurfaceRef _r(dp.get(), read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700720
721 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700722 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700723 // EGL_NO_CONTEXT is valid
Michael Chock0673e1e2012-06-21 12:53:17 -0700724 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700725 }
726
727 // these are the underlying implementation's object
728 EGLContext impl_ctx = EGL_NO_CONTEXT;
729 EGLSurface impl_draw = EGL_NO_SURFACE;
730 EGLSurface impl_read = EGL_NO_SURFACE;
731
732 // these are our objects structs passed in
733 egl_context_t * c = NULL;
734 egl_surface_t const * d = NULL;
735 egl_surface_t const * r = NULL;
736
737 // these are the current objects structs
738 egl_context_t * cur_c = get_context(getContext());
Jesse Hall47743382013-02-08 11:13:46 -0800739
Mathias Agopian518ec112011-05-13 16:21:08 -0700740 if (ctx != EGL_NO_CONTEXT) {
741 c = get_context(ctx);
742 impl_ctx = c->context;
743 } else {
744 // no context given, use the implementation of the current context
Michael Chock0673e1e2012-06-21 12:53:17 -0700745 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
746 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
747 return setError(EGL_BAD_MATCH, EGL_FALSE);
748 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700749 if (cur_c == NULL) {
750 // no current context
Mathias Agopian518ec112011-05-13 16:21:08 -0700751 // not an error, there is just no current context.
752 return EGL_TRUE;
753 }
754 }
755
756 // retrieve the underlying implementation's draw EGLSurface
757 if (draw != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700758 if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700759 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -0700760 impl_draw = d->surface;
761 }
762
763 // retrieve the underlying implementation's read EGLSurface
764 if (read != EGL_NO_SURFACE) {
Michael Chock0673e1e2012-06-21 12:53:17 -0700765 if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700766 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700767 impl_read = r->surface;
768 }
769
Mathias Agopian518ec112011-05-13 16:21:08 -0700770
Jesse Hallb29e5e82012-04-04 16:53:42 -0700771 EGLBoolean result = dp->makeCurrent(c, cur_c,
Mathias Agopianfb87e542012-01-30 18:20:52 -0800772 draw, read, ctx,
773 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700774
775 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -0800776 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700777 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
778 egl_tls_t::setContext(ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700779 _c.acquire();
780 _r.acquire();
781 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -0700782 } else {
783 setGLHooksThreadSpecific(&gHooksNoContext);
784 egl_tls_t::setContext(EGL_NO_CONTEXT);
785 }
Mathias Agopian5fecea72011-08-25 18:38:24 -0700786 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000787 // this will ALOGE the error
Mathias Agopian63108c32013-09-06 13:36:49 -0700788 egl_connection_t* const cnx = &gEGLImpl;
789 result = setError(cnx->egl.eglGetError(), EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700790 }
791 return result;
792}
793
794
795EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
796 EGLint attribute, EGLint *value)
797{
798 clearError();
799
Jesse Hallb29e5e82012-04-04 16:53:42 -0700800 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -0700801 if (!dp) return EGL_FALSE;
802
Jesse Hallb29e5e82012-04-04 16:53:42 -0700803 ContextRef _c(dp.get(), ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700804 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
805
Mathias Agopian518ec112011-05-13 16:21:08 -0700806 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -0800807 return c->cnx->egl.eglQueryContext(
808 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700809
Mathias Agopian518ec112011-05-13 16:21:08 -0700810}
811
812EGLContext eglGetCurrentContext(void)
813{
814 // could be called before eglInitialize(), but we wouldn't have a context
815 // then, and this function would correctly return EGL_NO_CONTEXT.
816
817 clearError();
818
819 EGLContext ctx = getContext();
820 return ctx;
821}
822
823EGLSurface eglGetCurrentSurface(EGLint readdraw)
824{
825 // could be called before eglInitialize(), but we wouldn't have a context
826 // then, and this function would correctly return EGL_NO_SURFACE.
827
828 clearError();
829
830 EGLContext ctx = getContext();
831 if (ctx) {
832 egl_context_t const * const c = get_context(ctx);
833 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
834 switch (readdraw) {
835 case EGL_READ: return c->read;
Jesse Hall47743382013-02-08 11:13:46 -0800836 case EGL_DRAW: return c->draw;
Mathias Agopian518ec112011-05-13 16:21:08 -0700837 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
838 }
839 }
840 return EGL_NO_SURFACE;
841}
842
843EGLDisplay eglGetCurrentDisplay(void)
844{
845 // could be called before eglInitialize(), but we wouldn't have a context
846 // then, and this function would correctly return EGL_NO_DISPLAY.
847
848 clearError();
849
850 EGLContext ctx = getContext();
851 if (ctx) {
852 egl_context_t const * const c = get_context(ctx);
853 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
854 return c->dpy;
855 }
856 return EGL_NO_DISPLAY;
857}
858
859EGLBoolean eglWaitGL(void)
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.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700868}
869
870EGLBoolean eglWaitNative(EGLint engine)
871{
Mathias Agopian518ec112011-05-13 16:21:08 -0700872 clearError();
873
Mathias Agopianada798b2012-02-13 17:09:30 -0800874 egl_connection_t* const cnx = &gEGLImpl;
875 if (!cnx->dso)
876 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
877
878 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -0700879}
880
881EGLint eglGetError(void)
882{
Mathias Agopianada798b2012-02-13 17:09:30 -0800883 EGLint err = EGL_SUCCESS;
884 egl_connection_t* const cnx = &gEGLImpl;
885 if (cnx->dso) {
886 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -0700887 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800888 if (err == EGL_SUCCESS) {
889 err = egl_tls_t::getError();
890 }
891 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -0700892}
893
Michael Chockc0ec5e22014-01-27 08:14:33 -0800894static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
Jesse Hallc07b5202013-07-04 12:08:16 -0700895 const char* procname) {
896 const egl_connection_t* cnx = &gEGLImpl;
897 void* proc = NULL;
898
Michael Chockc0ec5e22014-01-27 08:14:33 -0800899 proc = dlsym(cnx->libEgl, procname);
900 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
901
Jesse Hallc07b5202013-07-04 12:08:16 -0700902 proc = dlsym(cnx->libGles2, procname);
903 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
904
905 proc = dlsym(cnx->libGles1, procname);
906 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
907
908 return NULL;
909}
910
Mathias Agopian518ec112011-05-13 16:21:08 -0700911__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
912{
913 // eglGetProcAddress() could be the very first function called
914 // in which case we must make sure we've initialized ourselves, this
915 // happens the first time egl_get_display() is called.
916
917 clearError();
918
919 if (egl_init_drivers() == EGL_FALSE) {
920 setError(EGL_BAD_PARAMETER, NULL);
921 return NULL;
922 }
923
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700924 if (FILTER_EXTENSIONS(procname)) {
Jamie Gennisaca51c02011-11-03 17:42:43 -0700925 return NULL;
926 }
927
Mathias Agopian518ec112011-05-13 16:21:08 -0700928 __eglMustCastToProperFunctionPointerType addr;
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -0700929 addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
Mathias Agopian518ec112011-05-13 16:21:08 -0700930 if (addr) return addr;
931
Michael Chockc0ec5e22014-01-27 08:14:33 -0800932 addr = findBuiltinWrapper(procname);
Jesse Hallc07b5202013-07-04 12:08:16 -0700933 if (addr) return addr;
Jamie Gennisaca51c02011-11-03 17:42:43 -0700934
Mathias Agopian518ec112011-05-13 16:21:08 -0700935 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
936 pthread_mutex_lock(&sExtensionMapMutex);
937
938 /*
939 * Since eglGetProcAddress() is not associated to anything, it needs
940 * to return a function pointer that "works" regardless of what
941 * the current context is.
942 *
943 * For this reason, we return a "forwarder", a small stub that takes
944 * care of calling the function associated with the context
945 * currently bound.
946 *
947 * We first look for extensions we've already resolved, if we're seeing
948 * this extension for the first time, we go through all our
949 * implementations and call eglGetProcAddress() and record the
950 * result in the appropriate implementation hooks and return the
951 * address of the forwarder corresponding to that hook set.
952 *
953 */
954
955 const String8 name(procname);
956 addr = sGLExtentionMap.valueFor(name);
957 const int slot = sGLExtentionSlot;
958
Steve Blocke6f43dd2012-01-06 19:20:56 +0000959 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
Mathias Agopian518ec112011-05-13 16:21:08 -0700960 "no more slots for eglGetProcAddress(\"%s\")",
961 procname);
962
963 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
964 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -0800965
966 egl_connection_t* const cnx = &gEGLImpl;
967 if (cnx->dso && cnx->egl.eglGetProcAddress) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800968 // Extensions are independent of the bound context
luliuhui69d10072012-08-30 11:15:36 +0800969 addr =
Mathias Agopian7773c432012-02-13 20:06:08 -0800970 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
971 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
Mathias Agopianada798b2012-02-13 17:09:30 -0800972 cnx->egl.eglGetProcAddress(procname);
luliuhui69d10072012-08-30 11:15:36 +0800973 if (addr) found = true;
Mathias Agopian518ec112011-05-13 16:21:08 -0700974 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800975
Mathias Agopian518ec112011-05-13 16:21:08 -0700976 if (found) {
977 addr = gExtensionForwarders[slot];
Mathias Agopian518ec112011-05-13 16:21:08 -0700978 sGLExtentionMap.add(name, addr);
979 sGLExtentionSlot++;
980 }
981 }
982
983 pthread_mutex_unlock(&sExtensionMapMutex);
984 return addr;
985}
986
Jamie Gennis28ef8d72012-04-05 20:34:54 -0700987class FrameCompletionThread : public Thread {
988public:
989
990 static void queueSync(EGLSyncKHR sync) {
991 static sp<FrameCompletionThread> thread(new FrameCompletionThread);
992 static bool running = false;
993 if (!running) {
994 thread->run("GPUFrameCompletion");
995 running = true;
996 }
997 {
998 Mutex::Autolock lock(thread->mMutex);
999 ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d",
1000 thread->mFramesQueued).string());
1001 thread->mQueue.push_back(sync);
1002 thread->mCondition.signal();
1003 thread->mFramesQueued++;
1004 ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size());
1005 }
1006 }
1007
1008private:
1009 FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {}
1010
1011 virtual bool threadLoop() {
1012 EGLSyncKHR sync;
1013 uint32_t frameNum;
1014 {
1015 Mutex::Autolock lock(mMutex);
1016 while (mQueue.isEmpty()) {
1017 mCondition.wait(mMutex);
1018 }
1019 sync = mQueue[0];
1020 frameNum = mFramesCompleted;
1021 }
1022 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1023 {
1024 ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d",
1025 frameNum).string());
1026 EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
1027 if (result == EGL_FALSE) {
1028 ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
1029 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
1030 ALOGE("FrameCompletion: timeout waiting for fence");
1031 }
1032 eglDestroySyncKHR(dpy, sync);
1033 }
1034 {
1035 Mutex::Autolock lock(mMutex);
1036 mQueue.removeAt(0);
1037 mFramesCompleted++;
1038 ATRACE_INT("GPU Frames Outstanding", mQueue.size());
1039 }
1040 return true;
1041 }
1042
1043 uint32_t mFramesQueued;
1044 uint32_t mFramesCompleted;
1045 Vector<EGLSyncKHR> mQueue;
1046 Condition mCondition;
1047 Mutex mMutex;
1048};
1049
Dan Stozaa894d082015-02-19 15:27:36 -08001050EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
1051 EGLint *rects, EGLint n_rects)
Mathias Agopian518ec112011-05-13 16:21:08 -07001052{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001053 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001054 clearError();
1055
Jesse Hallb29e5e82012-04-04 16:53:42 -07001056 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001057 if (!dp) return EGL_FALSE;
1058
Jesse Hallb29e5e82012-04-04 16:53:42 -07001059 SurfaceRef _s(dp.get(), draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001060 if (!_s.get())
1061 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001062
Mathias Agopian518ec112011-05-13 16:21:08 -07001063 egl_surface_t const * const s = get_surface(draw);
Mathias Agopian7db993a2012-03-25 00:49:46 -07001064
Mathias Agopianed6d08b2013-04-16 16:39:46 -07001065 if (CC_UNLIKELY(dp->traceGpuCompletion)) {
1066 EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
1067 if (sync != EGL_NO_SYNC_KHR) {
1068 FrameCompletionThread::queueSync(sync);
1069 }
1070 }
1071
Mathias Agopian7db993a2012-03-25 00:49:46 -07001072 if (CC_UNLIKELY(dp->finishOnSwap)) {
1073 uint32_t pixel;
1074 egl_context_t * const c = get_context( egl_tls_t::getContext() );
1075 if (c) {
1076 // glReadPixels() ensures that the frame is complete
1077 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
1078 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
1079 }
1080 }
1081
Dan Stozaa894d082015-02-19 15:27:36 -08001082 if (n_rects == 0) {
1083 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1084 }
1085
1086 Vector<android_native_rect_t> androidRects;
1087 for (int r = 0; r < n_rects; ++r) {
1088 int offset = r * 4;
1089 int x = rects[offset];
1090 int y = rects[offset + 1];
1091 int width = rects[offset + 2];
1092 int height = rects[offset + 3];
1093 android_native_rect_t androidRect;
1094 androidRect.left = x;
1095 androidRect.top = y + height;
1096 androidRect.right = x + width;
1097 androidRect.bottom = y;
1098 androidRects.push_back(androidRect);
1099 }
1100 native_window_set_surface_damage(s->win.get(), androidRects.array(),
1101 androidRects.size());
1102
1103 if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1104 return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1105 rects, n_rects);
1106 } else {
1107 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1108 }
1109}
1110
1111EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1112{
1113 return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
Mathias Agopian518ec112011-05-13 16:21:08 -07001114}
1115
1116EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
1117 NativePixmapType target)
1118{
1119 clearError();
1120
Jesse Hallb29e5e82012-04-04 16:53:42 -07001121 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001122 if (!dp) return EGL_FALSE;
1123
Jesse Hallb29e5e82012-04-04 16:53:42 -07001124 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001125 if (!_s.get())
1126 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001127
Mathias Agopian518ec112011-05-13 16:21:08 -07001128 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -08001129 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -07001130}
1131
1132const char* eglQueryString(EGLDisplay dpy, EGLint name)
1133{
1134 clearError();
1135
Jesse Hallb29e5e82012-04-04 16:53:42 -07001136 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001137 if (!dp) return (const char *) NULL;
1138
1139 switch (name) {
1140 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001141 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001142 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001143 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001144 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001145 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001146 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001147 return dp->getClientApiString();
Mathias Agopian518ec112011-05-13 16:21:08 -07001148 }
1149 return setError(EGL_BAD_PARAMETER, (const char *)0);
1150}
1151
Mathias Agopianca088332013-03-28 17:44:13 -07001152EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name)
1153{
1154 clearError();
1155
1156 const egl_display_ptr dp = validate_display(dpy);
1157 if (!dp) return (const char *) NULL;
1158
1159 switch (name) {
1160 case EGL_VENDOR:
1161 return dp->disp.queryString.vendor;
1162 case EGL_VERSION:
1163 return dp->disp.queryString.version;
1164 case EGL_EXTENSIONS:
1165 return dp->disp.queryString.extensions;
1166 case EGL_CLIENT_APIS:
1167 return dp->disp.queryString.clientApi;
1168 }
1169 return setError(EGL_BAD_PARAMETER, (const char *)0);
1170}
Mathias Agopian518ec112011-05-13 16:21:08 -07001171
1172// ----------------------------------------------------------------------------
1173// EGL 1.1
1174// ----------------------------------------------------------------------------
1175
1176EGLBoolean eglSurfaceAttrib(
1177 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1178{
1179 clearError();
1180
Jesse Hallb29e5e82012-04-04 16:53:42 -07001181 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001182 if (!dp) return EGL_FALSE;
1183
Jesse Hallb29e5e82012-04-04 16:53:42 -07001184 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001185 if (!_s.get())
1186 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001187
Mathias Agopian518ec112011-05-13 16:21:08 -07001188 egl_surface_t const * const s = get_surface(surface);
Pablo Ceballosccdfd602015-10-07 15:05:45 -07001189
1190 //XXX: temporary hack for the EGL hook-up for single buffer mode
1191 if (attribute == EGL_RENDER_BUFFER && (value == EGL_BACK_BUFFER ||
1192 value == EGL_SINGLE_BUFFER)) {
1193 return (native_window_set_single_buffer_mode(s->win.get(),
1194 value == EGL_SINGLE_BUFFER)) ? EGL_TRUE : EGL_FALSE;
1195 }
1196
Mathias Agopian518ec112011-05-13 16:21:08 -07001197 if (s->cnx->egl.eglSurfaceAttrib) {
1198 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -08001199 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001200 }
1201 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1202}
1203
1204EGLBoolean eglBindTexImage(
1205 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1206{
1207 clearError();
1208
Jesse Hallb29e5e82012-04-04 16:53:42 -07001209 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001210 if (!dp) return EGL_FALSE;
1211
Jesse Hallb29e5e82012-04-04 16:53:42 -07001212 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001213 if (!_s.get())
1214 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001215
Mathias Agopian518ec112011-05-13 16:21:08 -07001216 egl_surface_t const * const s = get_surface(surface);
1217 if (s->cnx->egl.eglBindTexImage) {
1218 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001219 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001220 }
1221 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1222}
1223
1224EGLBoolean eglReleaseTexImage(
1225 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1226{
1227 clearError();
1228
Jesse Hallb29e5e82012-04-04 16:53:42 -07001229 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001230 if (!dp) return EGL_FALSE;
1231
Jesse Hallb29e5e82012-04-04 16:53:42 -07001232 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001233 if (!_s.get())
1234 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001235
Mathias Agopian518ec112011-05-13 16:21:08 -07001236 egl_surface_t const * const s = get_surface(surface);
1237 if (s->cnx->egl.eglReleaseTexImage) {
1238 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -08001239 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -07001240 }
1241 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1242}
1243
1244EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1245{
1246 clearError();
1247
Jesse Hallb29e5e82012-04-04 16:53:42 -07001248 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001249 if (!dp) return EGL_FALSE;
1250
1251 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001252 egl_connection_t* const cnx = &gEGLImpl;
1253 if (cnx->dso && cnx->egl.eglSwapInterval) {
1254 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -07001255 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001256
Mathias Agopian518ec112011-05-13 16:21:08 -07001257 return res;
1258}
1259
1260
1261// ----------------------------------------------------------------------------
1262// EGL 1.2
1263// ----------------------------------------------------------------------------
1264
1265EGLBoolean eglWaitClient(void)
1266{
1267 clearError();
1268
Mathias Agopianada798b2012-02-13 17:09:30 -08001269 egl_connection_t* const cnx = &gEGLImpl;
1270 if (!cnx->dso)
1271 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
1272
1273 EGLBoolean res;
1274 if (cnx->egl.eglWaitClient) {
1275 res = cnx->egl.eglWaitClient();
1276 } else {
1277 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -07001278 }
1279 return res;
1280}
1281
1282EGLBoolean eglBindAPI(EGLenum api)
1283{
1284 clearError();
1285
1286 if (egl_init_drivers() == EGL_FALSE) {
1287 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1288 }
1289
1290 // bind this API on all EGLs
1291 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001292 egl_connection_t* const cnx = &gEGLImpl;
1293 if (cnx->dso && cnx->egl.eglBindAPI) {
1294 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -07001295 }
1296 return res;
1297}
1298
1299EGLenum eglQueryAPI(void)
1300{
1301 clearError();
1302
1303 if (egl_init_drivers() == EGL_FALSE) {
1304 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1305 }
1306
Mathias Agopianada798b2012-02-13 17:09:30 -08001307 egl_connection_t* const cnx = &gEGLImpl;
1308 if (cnx->dso && cnx->egl.eglQueryAPI) {
1309 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -07001310 }
Mathias Agopianada798b2012-02-13 17:09:30 -08001311
Mathias Agopian518ec112011-05-13 16:21:08 -07001312 // or, it can only be OpenGL ES
1313 return EGL_OPENGL_ES_API;
1314}
1315
1316EGLBoolean eglReleaseThread(void)
1317{
1318 clearError();
1319
1320 // If there is context bound to the thread, release it
Mathias Agopianfb87e542012-01-30 18:20:52 -08001321 egl_display_t::loseCurrent(get_context(getContext()));
Mathias Agopian518ec112011-05-13 16:21:08 -07001322
Mathias Agopianada798b2012-02-13 17:09:30 -08001323 egl_connection_t* const cnx = &gEGLImpl;
1324 if (cnx->dso && cnx->egl.eglReleaseThread) {
1325 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -07001326 }
1327 egl_tls_t::clearTLS();
Mathias Agopian518ec112011-05-13 16:21:08 -07001328 return EGL_TRUE;
1329}
1330
1331EGLSurface eglCreatePbufferFromClientBuffer(
1332 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1333 EGLConfig config, const EGLint *attrib_list)
1334{
1335 clearError();
1336
Jesse Hallb29e5e82012-04-04 16:53:42 -07001337 egl_connection_t* cnx = NULL;
1338 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1339 if (!dp) return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -07001340 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1341 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -08001342 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001343 }
1344 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1345}
1346
1347// ----------------------------------------------------------------------------
1348// EGL_EGLEXT_VERSION 3
1349// ----------------------------------------------------------------------------
1350
1351EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
1352 const EGLint *attrib_list)
1353{
1354 clearError();
1355
Jesse Hallb29e5e82012-04-04 16:53:42 -07001356 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001357 if (!dp) return EGL_FALSE;
1358
Jesse Hallb29e5e82012-04-04 16:53:42 -07001359 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001360 if (!_s.get())
1361 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001362
1363 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001364 if (s->cnx->egl.eglLockSurfaceKHR) {
1365 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -08001366 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001367 }
1368 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1369}
1370
1371EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
1372{
1373 clearError();
1374
Jesse Hallb29e5e82012-04-04 16:53:42 -07001375 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001376 if (!dp) return EGL_FALSE;
1377
Jesse Hallb29e5e82012-04-04 16:53:42 -07001378 SurfaceRef _s(dp.get(), surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -07001379 if (!_s.get())
1380 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -07001381
1382 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001383 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -08001384 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -07001385 }
1386 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1387}
1388
1389EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1390 EGLClientBuffer buffer, const EGLint *attrib_list)
1391{
1392 clearError();
1393
Jesse Hallb29e5e82012-04-04 16:53:42 -07001394 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001395 if (!dp) return EGL_NO_IMAGE_KHR;
1396
Jesse Hallb29e5e82012-04-04 16:53:42 -07001397 ContextRef _c(dp.get(), ctx);
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001398 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -07001399
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001400 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1401 egl_connection_t* const cnx = &gEGLImpl;
1402 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1403 result = cnx->egl.eglCreateImageKHR(
1404 dp->disp.dpy,
1405 c ? c->context : EGL_NO_CONTEXT,
1406 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001407 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001408 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001409}
1410
1411EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
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
Steven Holte646a5c52012-06-04 20:02:11 -07001418 EGLBoolean result = EGL_FALSE;
Mathias Agopianada798b2012-02-13 17:09:30 -08001419 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001420 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
Steven Holte646a5c52012-06-04 20:02:11 -07001421 result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001422 }
Steven Holte646a5c52012-06-04 20:02:11 -07001423 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001424}
1425
1426// ----------------------------------------------------------------------------
1427// EGL_EGLEXT_VERSION 5
1428// ----------------------------------------------------------------------------
1429
1430
1431EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1432{
1433 clearError();
1434
Jesse Hallb29e5e82012-04-04 16:53:42 -07001435 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001436 if (!dp) return EGL_NO_SYNC_KHR;
1437
Mathias Agopian518ec112011-05-13 16:21:08 -07001438 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001439 egl_connection_t* const cnx = &gEGLImpl;
1440 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1441 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001442 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001443 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001444}
1445
1446EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1447{
1448 clearError();
1449
Jesse Hallb29e5e82012-04-04 16:53:42 -07001450 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001451 if (!dp) return EGL_FALSE;
1452
Mathias Agopian518ec112011-05-13 16:21:08 -07001453 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001454 egl_connection_t* const cnx = &gEGLImpl;
1455 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1456 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001457 }
1458 return result;
1459}
1460
Mathias Agopiane9b3dfb2013-03-27 14:30:19 -07001461EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
1462 clearError();
1463
1464 const egl_display_ptr dp = validate_display(dpy);
1465 if (!dp) return EGL_FALSE;
1466
1467 EGLBoolean result = EGL_FALSE;
1468 egl_connection_t* const cnx = &gEGLImpl;
1469 if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1470 result = cnx->egl.eglSignalSyncKHR(
1471 dp->disp.dpy, sync, mode);
1472 }
1473 return result;
1474}
1475
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001476EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1477 EGLint flags, EGLTimeKHR timeout)
Mathias Agopian518ec112011-05-13 16:21:08 -07001478{
1479 clearError();
1480
Jesse Hallb29e5e82012-04-04 16:53:42 -07001481 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001482 if (!dp) return EGL_FALSE;
1483
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001484 EGLBoolean result = EGL_FALSE;
1485 egl_connection_t* const cnx = &gEGLImpl;
1486 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1487 result = cnx->egl.eglClientWaitSyncKHR(
1488 dp->disp.dpy, sync, flags, timeout);
Mathias Agopian518ec112011-05-13 16:21:08 -07001489 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001490 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001491}
1492
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001493EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1494 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001495{
1496 clearError();
1497
Jesse Hallb29e5e82012-04-04 16:53:42 -07001498 const egl_display_ptr dp = validate_display(dpy);
Mathias Agopian518ec112011-05-13 16:21:08 -07001499 if (!dp) return EGL_FALSE;
1500
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001501 EGLBoolean result = EGL_FALSE;
1502 egl_connection_t* const cnx = &gEGLImpl;
1503 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1504 result = cnx->egl.eglGetSyncAttribKHR(
1505 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001506 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001507 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001508}
1509
Season Li000d88f2015-07-01 11:39:40 -07001510EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list)
1511{
1512 clearError();
1513
1514 const egl_display_ptr dp = validate_display(dpy);
1515 if (!dp) return EGL_NO_STREAM_KHR;
1516
1517 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1518 egl_connection_t* const cnx = &gEGLImpl;
1519 if (cnx->dso && cnx->egl.eglCreateStreamKHR) {
1520 result = cnx->egl.eglCreateStreamKHR(
1521 dp->disp.dpy, attrib_list);
1522 }
1523 return result;
1524}
1525
1526EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream)
1527{
1528 clearError();
1529
1530 const egl_display_ptr dp = validate_display(dpy);
1531 if (!dp) return EGL_FALSE;
1532
1533 EGLBoolean result = EGL_FALSE;
1534 egl_connection_t* const cnx = &gEGLImpl;
1535 if (cnx->dso && cnx->egl.eglDestroyStreamKHR) {
1536 result = cnx->egl.eglDestroyStreamKHR(
1537 dp->disp.dpy, stream);
1538 }
1539 return result;
1540}
1541
1542EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream,
1543 EGLenum attribute, EGLint value)
1544{
1545 clearError();
1546
1547 const egl_display_ptr dp = validate_display(dpy);
1548 if (!dp) return EGL_FALSE;
1549
1550 EGLBoolean result = EGL_FALSE;
1551 egl_connection_t* const cnx = &gEGLImpl;
1552 if (cnx->dso && cnx->egl.eglStreamAttribKHR) {
1553 result = cnx->egl.eglStreamAttribKHR(
1554 dp->disp.dpy, stream, attribute, value);
1555 }
1556 return result;
1557}
1558
1559EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream,
1560 EGLenum attribute, EGLint *value)
1561{
1562 clearError();
1563
1564 const egl_display_ptr dp = validate_display(dpy);
1565 if (!dp) return EGL_FALSE;
1566
1567 EGLBoolean result = EGL_FALSE;
1568 egl_connection_t* const cnx = &gEGLImpl;
1569 if (cnx->dso && cnx->egl.eglQueryStreamKHR) {
1570 result = cnx->egl.eglQueryStreamKHR(
1571 dp->disp.dpy, stream, attribute, value);
1572 }
1573 return result;
1574}
1575
1576EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream,
1577 EGLenum attribute, EGLuint64KHR *value)
1578{
1579 clearError();
1580
1581 const egl_display_ptr dp = validate_display(dpy);
1582 if (!dp) return EGL_FALSE;
1583
1584 EGLBoolean result = EGL_FALSE;
1585 egl_connection_t* const cnx = &gEGLImpl;
1586 if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) {
1587 result = cnx->egl.eglQueryStreamu64KHR(
1588 dp->disp.dpy, stream, attribute, value);
1589 }
1590 return result;
1591}
1592
1593EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream,
1594 EGLenum attribute, EGLTimeKHR *value)
1595{
1596 clearError();
1597
1598 const egl_display_ptr dp = validate_display(dpy);
1599 if (!dp) return EGL_FALSE;
1600
1601 EGLBoolean result = EGL_FALSE;
1602 egl_connection_t* const cnx = &gEGLImpl;
1603 if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) {
1604 result = cnx->egl.eglQueryStreamTimeKHR(
1605 dp->disp.dpy, stream, attribute, value);
1606 }
1607 return result;
1608}
1609
1610EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config,
1611 EGLStreamKHR stream, const EGLint *attrib_list)
1612{
1613 clearError();
1614
1615 egl_display_ptr dp = validate_display(dpy);
1616 if (!dp) return EGL_NO_SURFACE;
1617
1618 egl_connection_t* const cnx = &gEGLImpl;
1619 if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) {
1620 EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(
1621 dp->disp.dpy, config, stream, attrib_list);
1622 if (surface != EGL_NO_SURFACE) {
1623 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
1624 surface, cnx);
1625 return s;
1626 }
1627 }
1628 return EGL_NO_SURFACE;
1629}
1630
1631EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy,
1632 EGLStreamKHR stream)
1633{
1634 clearError();
1635
1636 const egl_display_ptr dp = validate_display(dpy);
1637 if (!dp) return EGL_FALSE;
1638
1639 EGLBoolean result = EGL_FALSE;
1640 egl_connection_t* const cnx = &gEGLImpl;
1641 if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) {
1642 result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(
1643 dp->disp.dpy, stream);
1644 }
1645 return result;
1646}
1647
1648EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy,
1649 EGLStreamKHR stream)
1650{
1651 clearError();
1652
1653 const egl_display_ptr dp = validate_display(dpy);
1654 if (!dp) return EGL_FALSE;
1655
1656 EGLBoolean result = EGL_FALSE;
1657 egl_connection_t* const cnx = &gEGLImpl;
1658 if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) {
1659 result = cnx->egl.eglStreamConsumerAcquireKHR(
1660 dp->disp.dpy, stream);
1661 }
1662 return result;
1663}
1664
1665EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy,
1666 EGLStreamKHR stream)
1667{
1668 clearError();
1669
1670 const egl_display_ptr dp = validate_display(dpy);
1671 if (!dp) return EGL_FALSE;
1672
1673 EGLBoolean result = EGL_FALSE;
1674 egl_connection_t* const cnx = &gEGLImpl;
1675 if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) {
1676 result = cnx->egl.eglStreamConsumerReleaseKHR(
1677 dp->disp.dpy, stream);
1678 }
1679 return result;
1680}
1681
1682EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR(
1683 EGLDisplay dpy, EGLStreamKHR stream)
1684{
1685 clearError();
1686
1687 const egl_display_ptr dp = validate_display(dpy);
1688 if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;
1689
1690 EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;
1691 egl_connection_t* const cnx = &gEGLImpl;
1692 if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) {
1693 result = cnx->egl.eglGetStreamFileDescriptorKHR(
1694 dp->disp.dpy, stream);
1695 }
1696 return result;
1697}
1698
1699EGLStreamKHR eglCreateStreamFromFileDescriptorKHR(
1700 EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor)
1701{
1702 clearError();
1703
1704 const egl_display_ptr dp = validate_display(dpy);
1705 if (!dp) return EGL_NO_STREAM_KHR;
1706
1707 EGLStreamKHR result = EGL_NO_STREAM_KHR;
1708 egl_connection_t* const cnx = &gEGLImpl;
1709 if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) {
1710 result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(
1711 dp->disp.dpy, file_descriptor);
1712 }
1713 return result;
1714}
1715
Mathias Agopian518ec112011-05-13 16:21:08 -07001716// ----------------------------------------------------------------------------
Mathias Agopian2bb71682013-03-27 17:32:41 -07001717// EGL_EGLEXT_VERSION 15
1718// ----------------------------------------------------------------------------
1719
1720EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
1721 clearError();
1722 const egl_display_ptr dp = validate_display(dpy);
1723 if (!dp) return EGL_FALSE;
1724 EGLint result = EGL_FALSE;
1725 egl_connection_t* const cnx = &gEGLImpl;
1726 if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
1727 result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1728 }
1729 return result;
1730}
1731
1732// ----------------------------------------------------------------------------
Mathias Agopian518ec112011-05-13 16:21:08 -07001733// ANDROID extensions
1734// ----------------------------------------------------------------------------
1735
Jamie Gennis331841b2012-09-06 14:52:00 -07001736EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync)
1737{
1738 clearError();
1739
1740 const egl_display_ptr dp = validate_display(dpy);
1741 if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1742
1743 EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1744 egl_connection_t* const cnx = &gEGLImpl;
1745 if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
1746 result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1747 }
1748 return result;
1749}
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001750
Andy McFadden72841452013-03-01 16:25:32 -08001751EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface,
1752 EGLnsecsANDROID time)
1753{
1754 clearError();
1755
1756 const egl_display_ptr dp = validate_display(dpy);
1757 if (!dp) {
1758 return EGL_FALSE;
1759 }
1760
1761 SurfaceRef _s(dp.get(), surface);
1762 if (!_s.get()) {
1763 setError(EGL_BAD_SURFACE, EGL_FALSE);
1764 return EGL_FALSE;
1765 }
1766
1767 egl_surface_t const * const s = get_surface(surface);
1768 native_window_set_buffers_timestamp(s->win.get(), time);
1769
1770 return EGL_TRUE;
1771}
1772
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001773// ----------------------------------------------------------------------------
1774// NVIDIA extensions
1775// ----------------------------------------------------------------------------
1776EGLuint64NV eglGetSystemTimeFrequencyNV()
1777{
1778 clearError();
1779
1780 if (egl_init_drivers() == EGL_FALSE) {
1781 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1782 }
1783
1784 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001785 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001786
Mathias Agopianada798b2012-02-13 17:09:30 -08001787 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1788 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001789 }
1790
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001791 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001792}
1793
1794EGLuint64NV eglGetSystemTimeNV()
1795{
1796 clearError();
1797
1798 if (egl_init_drivers() == EGL_FALSE) {
1799 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1800 }
1801
1802 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001803 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001804
Mathias Agopianada798b2012-02-13 17:09:30 -08001805 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1806 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001807 }
1808
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001809 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001810}
Dan Stozaa894d082015-02-19 15:27:36 -08001811
1812// ----------------------------------------------------------------------------
1813// Partial update extension
1814// ----------------------------------------------------------------------------
1815EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1816 EGLint *rects, EGLint n_rects)
1817{
1818 clearError();
1819
1820 const egl_display_ptr dp = validate_display(dpy);
1821 if (!dp) {
1822 setError(EGL_BAD_DISPLAY, EGL_FALSE);
1823 return EGL_FALSE;
1824 }
1825
1826 SurfaceRef _s(dp.get(), surface);
1827 if (!_s.get()) {
1828 setError(EGL_BAD_SURFACE, EGL_FALSE);
1829 return EGL_FALSE;
1830 }
1831
1832 egl_surface_t const * const s = get_surface(surface);
1833 if (s->cnx->egl.eglSetDamageRegionKHR) {
1834 return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,
1835 rects, n_rects);
1836 }
1837
1838 return EGL_FALSE;
1839}