blob: a5dc832bf6dead1b63b77a620d44278b86c2f006 [file] [log] [blame]
Mathias Agopian518ec112011-05-13 16:21:08 -07001/*
2 ** Copyright 2007, The Android Open Source Project
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17#include <ctype.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include <hardware/gralloc.h>
22#include <system/window.h>
23
24#include <EGL/egl.h>
25#include <EGL/eglext.h>
26#include <GLES/gl.h>
27#include <GLES/glext.h>
28
29#include <cutils/log.h>
30#include <cutils/atomic.h>
31#include <cutils/properties.h>
32#include <cutils/memory.h>
33
34#include <utils/KeyedVector.h>
35#include <utils/SortedVector.h>
36#include <utils/String8.h>
37
38#include "egl_impl.h"
39#include "egl_tls.h"
Siva Velusamy0469dd62011-11-30 15:05:37 -080040#include "glestrace.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070041#include "hooks.h"
42
43#include "egl_display.h"
44#include "egl_impl.h"
45#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
51// ----------------------------------------------------------------------------
52
Mathias Agopianbc2d79e2011-11-29 17:55:46 -080053#define EGL_VERSION_HW_ANDROID 0x3143
54
Mathias Agopian518ec112011-05-13 16:21:08 -070055struct extention_map_t {
56 const char* name;
57 __eglMustCastToProperFunctionPointerType address;
58};
59
60static const extention_map_t sExtentionMap[] = {
61 { "eglLockSurfaceKHR",
62 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
63 { "eglUnlockSurfaceKHR",
64 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
65 { "eglCreateImageKHR",
66 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
67 { "eglDestroyImageKHR",
68 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Jonas Yang1c3d72a2011-08-26 20:04:39 +080069 { "eglGetSystemTimeFrequencyNV",
70 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
71 { "eglGetSystemTimeNV",
72 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopian518ec112011-05-13 16:21:08 -070073};
74
75// accesses protected by sExtensionMapMutex
76static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
77static int sGLExtentionSlot = 0;
78static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
79
80static void(*findProcAddress(const char* name,
81 const extention_map_t* map, size_t n))() {
82 for (uint32_t i=0 ; i<n ; i++) {
83 if (!strcmp(name, map[i].name)) {
84 return map[i].address;
85 }
86 }
87 return NULL;
88}
89
90// ----------------------------------------------------------------------------
91
Mathias Agopian518ec112011-05-13 16:21:08 -070092namespace android {
93extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
94extern EGLBoolean egl_init_drivers();
95extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
96extern int gEGLDebugLevel;
97extern gl_hooks_t gHooksTrace;
Mathias Agopian518ec112011-05-13 16:21:08 -070098} // namespace android;
99
100// ----------------------------------------------------------------------------
101
102static inline void clearError() { egl_tls_t::clearError(); }
103static inline EGLContext getContext() { return egl_tls_t::getContext(); }
104
105// ----------------------------------------------------------------------------
106
107EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
108{
109 clearError();
110
111 uint32_t index = uint32_t(display);
112 if (index >= NUM_DISPLAYS) {
113 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
114 }
115
116 if (egl_init_drivers() == EGL_FALSE) {
117 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
118 }
119
120 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
121 return dpy;
122}
123
124// ----------------------------------------------------------------------------
125// Initialization
126// ----------------------------------------------------------------------------
127
128EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
129{
130 clearError();
131
132 egl_display_t * const dp = get_display(dpy);
133 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
134
135 EGLBoolean res = dp->initialize(major, minor);
136
137 return res;
138}
139
140EGLBoolean eglTerminate(EGLDisplay dpy)
141{
142 // NOTE: don't unload the drivers b/c some APIs can be called
143 // after eglTerminate() has been called. eglTerminate() only
144 // terminates an EGLDisplay, not a EGL itself.
145
146 clearError();
147
148 egl_display_t* const dp = get_display(dpy);
149 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
150
151 EGLBoolean res = dp->terminate();
152
153 return res;
154}
155
156// ----------------------------------------------------------------------------
157// configuration
158// ----------------------------------------------------------------------------
159
160EGLBoolean eglGetConfigs( EGLDisplay dpy,
161 EGLConfig *configs,
162 EGLint config_size, EGLint *num_config)
163{
164 clearError();
165
166 egl_display_t const * const dp = validate_display(dpy);
167 if (!dp) return EGL_FALSE;
168
Mathias Agopian7773c432012-02-13 20:06:08 -0800169 if (num_config==0) {
170 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700171 }
172
Mathias Agopian7773c432012-02-13 20:06:08 -0800173 EGLBoolean res = EGL_FALSE;
174 *num_config = 0;
175
176 egl_connection_t* const cnx = &gEGLImpl;
177 if (cnx->dso) {
178 res = cnx->egl.eglGetConfigs(
179 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700180 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800181
182 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700183}
184
185EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
186 EGLConfig *configs, EGLint config_size,
187 EGLint *num_config)
188{
189 clearError();
190
191 egl_display_t const * const dp = validate_display(dpy);
192 if (!dp) return EGL_FALSE;
193
194 if (num_config==0) {
195 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
196 }
197
Mathias Agopian518ec112011-05-13 16:21:08 -0700198 EGLBoolean res = EGL_FALSE;
199 *num_config = 0;
200
Mathias Agopianada798b2012-02-13 17:09:30 -0800201 egl_connection_t* const cnx = &gEGLImpl;
202 if (cnx->dso) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800203 res = cnx->egl.eglChooseConfig(
204 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700205 }
206 return res;
207}
208
209EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
210 EGLint attribute, EGLint *value)
211{
212 clearError();
213
214 egl_display_t const* dp = 0;
215 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
216 if (!cnx) return EGL_FALSE;
217
Mathias Agopian518ec112011-05-13 16:21:08 -0700218 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800219 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700220}
221
222// ----------------------------------------------------------------------------
223// surfaces
224// ----------------------------------------------------------------------------
225
226EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
227 NativeWindowType window,
228 const EGLint *attrib_list)
229{
230 clearError();
231
232 egl_display_t const* dp = 0;
233 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
234 if (cnx) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800235 EGLDisplay iDpy = dp->disp.dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700236 EGLint format;
237
Mathias Agopian81a63352011-07-29 17:55:48 -0700238 if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000239 ALOGE("EGLNativeWindowType %p already connected to another API",
Mathias Agopian81a63352011-07-29 17:55:48 -0700240 window);
241 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
242 }
243
Mathias Agopian518ec112011-05-13 16:21:08 -0700244 // set the native window's buffers format to match this config
245 if (cnx->egl.eglGetConfigAttrib(iDpy,
Mathias Agopian7773c432012-02-13 20:06:08 -0800246 config, EGL_NATIVE_VISUAL_ID, &format)) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700247 if (format != 0) {
Jamie Gennisbee205f2011-07-01 13:12:07 -0700248 int err = native_window_set_buffers_format(window, format);
249 if (err != 0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000250 ALOGE("error setting native window pixel format: %s (%d)",
Jamie Gennisbee205f2011-07-01 13:12:07 -0700251 strerror(-err), err);
Mathias Agopian81a63352011-07-29 17:55:48 -0700252 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Jamie Gennisbee205f2011-07-01 13:12:07 -0700253 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
254 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700255 }
256 }
257
Jamie Gennis59769462011-11-19 18:04:43 -0800258 // the EGL spec requires that a new EGLSurface default to swap interval
259 // 1, so explicitly set that on the window here.
260 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
261 anw->setSwapInterval(anw, 1);
262
Mathias Agopian518ec112011-05-13 16:21:08 -0700263 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800264 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700265 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800266 egl_surface_t* s = new egl_surface_t(dpy, config, window, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700267 return s;
268 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700269
270 // EGLSurface creation failed
271 native_window_set_buffers_format(window, 0);
272 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Mathias Agopian518ec112011-05-13 16:21:08 -0700273 }
274 return EGL_NO_SURFACE;
275}
276
277EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
278 NativePixmapType pixmap,
279 const EGLint *attrib_list)
280{
281 clearError();
282
283 egl_display_t const* dp = 0;
284 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
285 if (cnx) {
286 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800287 dp->disp.dpy, config, pixmap, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700288 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800289 egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700290 return s;
291 }
292 }
293 return EGL_NO_SURFACE;
294}
295
296EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
297 const EGLint *attrib_list)
298{
299 clearError();
300
301 egl_display_t const* dp = 0;
302 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
303 if (cnx) {
304 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800305 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700306 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800307 egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700308 return s;
309 }
310 }
311 return EGL_NO_SURFACE;
312}
313
314EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
315{
316 clearError();
317
318 egl_display_t const * const dp = validate_display(dpy);
319 if (!dp) return EGL_FALSE;
320
Mathias Agopianf0480de2011-11-13 20:50:07 -0800321 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700322 if (!_s.get())
323 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700324
325 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800326 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700327 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700328 _s.terminate();
329 }
330 return result;
331}
332
333EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
334 EGLint attribute, EGLint *value)
335{
336 clearError();
337
338 egl_display_t const * const dp = validate_display(dpy);
339 if (!dp) return EGL_FALSE;
340
Mathias Agopianf0480de2011-11-13 20:50:07 -0800341 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700342 if (!_s.get())
343 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700344
Mathias Agopian518ec112011-05-13 16:21:08 -0700345 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian7773c432012-02-13 20:06:08 -0800346 return s->cnx->egl.eglQuerySurface(
347 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700348}
349
Jamie Gennise8696a42012-01-15 18:54:57 -0800350void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
351 clearError();
352
353 egl_display_t const * const dp = validate_display(dpy);
354 if (!dp) {
355 return;
356 }
357
358 SurfaceRef _s(dp, surface);
359 if (!_s.get()) {
360 setError(EGL_BAD_SURFACE, EGL_FALSE);
361 return;
362 }
363
364 int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
365
366 egl_surface_t const * const s = get_surface(surface);
367 native_window_set_buffers_timestamp(s->win.get(), timestamp);
368}
369
Mathias Agopian518ec112011-05-13 16:21:08 -0700370// ----------------------------------------------------------------------------
371// Contexts
372// ----------------------------------------------------------------------------
373
374EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
375 EGLContext share_list, const EGLint *attrib_list)
376{
377 clearError();
378
379 egl_display_t const* dp = 0;
380 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
381 if (cnx) {
382 if (share_list != EGL_NO_CONTEXT) {
383 egl_context_t* const c = get_context(share_list);
384 share_list = c->context;
385 }
386 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800387 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700388 if (context != EGL_NO_CONTEXT) {
389 // figure out if it's a GLESv1 or GLESv2
390 int version = 0;
391 if (attrib_list) {
392 while (*attrib_list != EGL_NONE) {
393 GLint attr = *attrib_list++;
394 GLint value = *attrib_list++;
395 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
396 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800397 version = egl_connection_t::GLESv1_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700398 } else if (value == 2) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800399 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700400 }
401 }
402 };
403 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800404 egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800405#if EGL_TRACE
406 if (gEGLDebugLevel > 0)
407 GLTrace_eglCreateContext(version, c);
408#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700409 return c;
410 }
411 }
412 return EGL_NO_CONTEXT;
413}
414
415EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
416{
417 clearError();
418
419 egl_display_t const * const dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700420 if (!dp)
421 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700422
Mathias Agopianf0480de2011-11-13 20:50:07 -0800423 ContextRef _c(dp, ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700424 if (!_c.get())
425 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700426
Mathias Agopian518ec112011-05-13 16:21:08 -0700427 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800428 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700429 if (result == EGL_TRUE) {
430 _c.terminate();
431 }
432 return result;
433}
434
Mathias Agopian518ec112011-05-13 16:21:08 -0700435EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
436 EGLSurface read, EGLContext ctx)
437{
438 clearError();
439
440 egl_display_t const * const dp = get_display(dpy);
441 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
442
Mathias Agopian5b287a62011-05-16 18:58:55 -0700443 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
444 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
445 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700446 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
447 (draw != EGL_NO_SURFACE) ) {
448 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
449 }
450
451 // get a reference to the object passed in
Mathias Agopianf0480de2011-11-13 20:50:07 -0800452 ContextRef _c(dp, ctx);
453 SurfaceRef _d(dp, draw);
454 SurfaceRef _r(dp, read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700455
456 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700457 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700458 // EGL_NO_CONTEXT is valid
459 return EGL_FALSE;
460 }
461
462 // these are the underlying implementation's object
463 EGLContext impl_ctx = EGL_NO_CONTEXT;
464 EGLSurface impl_draw = EGL_NO_SURFACE;
465 EGLSurface impl_read = EGL_NO_SURFACE;
466
467 // these are our objects structs passed in
468 egl_context_t * c = NULL;
469 egl_surface_t const * d = NULL;
470 egl_surface_t const * r = NULL;
471
472 // these are the current objects structs
473 egl_context_t * cur_c = get_context(getContext());
474
475 if (ctx != EGL_NO_CONTEXT) {
476 c = get_context(ctx);
477 impl_ctx = c->context;
478 } else {
479 // no context given, use the implementation of the current context
480 if (cur_c == NULL) {
481 // no current context
482 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
483 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
484 return setError(EGL_BAD_MATCH, EGL_FALSE);
485 }
486 // not an error, there is just no current context.
487 return EGL_TRUE;
488 }
489 }
490
491 // retrieve the underlying implementation's draw EGLSurface
492 if (draw != EGL_NO_SURFACE) {
493 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -0700494 impl_draw = d->surface;
495 }
496
497 // retrieve the underlying implementation's read EGLSurface
498 if (read != EGL_NO_SURFACE) {
499 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700500 impl_read = r->surface;
501 }
502
Mathias Agopian518ec112011-05-13 16:21:08 -0700503
Mathias Agopianfb87e542012-01-30 18:20:52 -0800504 EGLBoolean result = const_cast<egl_display_t*>(dp)->makeCurrent(c, cur_c,
505 draw, read, ctx,
506 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700507
508 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -0800509 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700510 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
511 egl_tls_t::setContext(ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800512#if EGL_TRACE
513 if (gEGLDebugLevel > 0)
Siva Velusamy93a826f2011-12-14 12:19:56 -0800514 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800515#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700516 _c.acquire();
517 _r.acquire();
518 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -0700519 } else {
520 setGLHooksThreadSpecific(&gHooksNoContext);
521 egl_tls_t::setContext(EGL_NO_CONTEXT);
522 }
Mathias Agopian5fecea72011-08-25 18:38:24 -0700523 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000524 // this will ALOGE the error
Mathias Agopian5fecea72011-08-25 18:38:24 -0700525 result = setError(c->cnx->egl.eglGetError(), EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700526 }
527 return result;
528}
529
530
531EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
532 EGLint attribute, EGLint *value)
533{
534 clearError();
535
536 egl_display_t const * const dp = validate_display(dpy);
537 if (!dp) return EGL_FALSE;
538
Mathias Agopianf0480de2011-11-13 20:50:07 -0800539 ContextRef _c(dp, ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700540 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
541
Mathias Agopian518ec112011-05-13 16:21:08 -0700542 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -0800543 return c->cnx->egl.eglQueryContext(
544 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700545
Mathias Agopian518ec112011-05-13 16:21:08 -0700546}
547
548EGLContext eglGetCurrentContext(void)
549{
550 // could be called before eglInitialize(), but we wouldn't have a context
551 // then, and this function would correctly return EGL_NO_CONTEXT.
552
553 clearError();
554
555 EGLContext ctx = getContext();
556 return ctx;
557}
558
559EGLSurface eglGetCurrentSurface(EGLint readdraw)
560{
561 // could be called before eglInitialize(), but we wouldn't have a context
562 // then, and this function would correctly return EGL_NO_SURFACE.
563
564 clearError();
565
566 EGLContext ctx = getContext();
567 if (ctx) {
568 egl_context_t const * const c = get_context(ctx);
569 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
570 switch (readdraw) {
571 case EGL_READ: return c->read;
572 case EGL_DRAW: return c->draw;
573 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
574 }
575 }
576 return EGL_NO_SURFACE;
577}
578
579EGLDisplay eglGetCurrentDisplay(void)
580{
581 // could be called before eglInitialize(), but we wouldn't have a context
582 // then, and this function would correctly return EGL_NO_DISPLAY.
583
584 clearError();
585
586 EGLContext ctx = getContext();
587 if (ctx) {
588 egl_context_t const * const c = get_context(ctx);
589 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
590 return c->dpy;
591 }
592 return EGL_NO_DISPLAY;
593}
594
595EGLBoolean eglWaitGL(void)
596{
Mathias Agopian518ec112011-05-13 16:21:08 -0700597 clearError();
598
Mathias Agopianada798b2012-02-13 17:09:30 -0800599 egl_connection_t* const cnx = &gEGLImpl;
600 if (!cnx->dso)
601 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
602
603 return cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700604}
605
606EGLBoolean eglWaitNative(EGLint engine)
607{
Mathias Agopian518ec112011-05-13 16:21:08 -0700608 clearError();
609
Mathias Agopianada798b2012-02-13 17:09:30 -0800610 egl_connection_t* const cnx = &gEGLImpl;
611 if (!cnx->dso)
612 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
613
614 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -0700615}
616
617EGLint eglGetError(void)
618{
Mathias Agopianada798b2012-02-13 17:09:30 -0800619 EGLint err = EGL_SUCCESS;
620 egl_connection_t* const cnx = &gEGLImpl;
621 if (cnx->dso) {
622 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -0700623 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800624 if (err == EGL_SUCCESS) {
625 err = egl_tls_t::getError();
626 }
627 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -0700628}
629
Mathias Agopian518ec112011-05-13 16:21:08 -0700630__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
631{
632 // eglGetProcAddress() could be the very first function called
633 // in which case we must make sure we've initialized ourselves, this
634 // happens the first time egl_get_display() is called.
635
636 clearError();
637
638 if (egl_init_drivers() == EGL_FALSE) {
639 setError(EGL_BAD_PARAMETER, NULL);
640 return NULL;
641 }
642
Jamie Gennisaca51c02011-11-03 17:42:43 -0700643 // The EGL_ANDROID_blob_cache extension should not be exposed to
644 // applications. It is used internally by the Android EGL layer.
Jamie Gennisc42fcf02011-11-09 15:35:34 -0800645 if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID")) {
Jamie Gennisaca51c02011-11-03 17:42:43 -0700646 return NULL;
647 }
648
Mathias Agopian518ec112011-05-13 16:21:08 -0700649 __eglMustCastToProperFunctionPointerType addr;
650 addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap));
651 if (addr) return addr;
652
Jamie Gennisaca51c02011-11-03 17:42:43 -0700653
Mathias Agopian518ec112011-05-13 16:21:08 -0700654 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
655 pthread_mutex_lock(&sExtensionMapMutex);
656
657 /*
658 * Since eglGetProcAddress() is not associated to anything, it needs
659 * to return a function pointer that "works" regardless of what
660 * the current context is.
661 *
662 * For this reason, we return a "forwarder", a small stub that takes
663 * care of calling the function associated with the context
664 * currently bound.
665 *
666 * We first look for extensions we've already resolved, if we're seeing
667 * this extension for the first time, we go through all our
668 * implementations and call eglGetProcAddress() and record the
669 * result in the appropriate implementation hooks and return the
670 * address of the forwarder corresponding to that hook set.
671 *
672 */
673
674 const String8 name(procname);
675 addr = sGLExtentionMap.valueFor(name);
676 const int slot = sGLExtentionSlot;
677
Steve Blocke6f43dd2012-01-06 19:20:56 +0000678 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
Mathias Agopian518ec112011-05-13 16:21:08 -0700679 "no more slots for eglGetProcAddress(\"%s\")",
680 procname);
681
Siva Velusamy0469dd62011-11-30 15:05:37 -0800682#if EGL_TRACE
683 gl_hooks_t *debugHooks = GLTrace_getGLHooks();
684#endif
685
Mathias Agopian518ec112011-05-13 16:21:08 -0700686 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
687 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -0800688
689 egl_connection_t* const cnx = &gEGLImpl;
690 if (cnx->dso && cnx->egl.eglGetProcAddress) {
691 found = true;
692 // Extensions are independent of the bound context
Mathias Agopian7773c432012-02-13 20:06:08 -0800693 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
694 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700695#if EGL_TRACE
Mathias Agopianada798b2012-02-13 17:09:30 -0800696 debugHooks->ext.extensions[slot] =
697 gHooksTrace.ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700698#endif
Mathias Agopianada798b2012-02-13 17:09:30 -0800699 cnx->egl.eglGetProcAddress(procname);
Mathias Agopian518ec112011-05-13 16:21:08 -0700700 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800701
Mathias Agopian518ec112011-05-13 16:21:08 -0700702 if (found) {
703 addr = gExtensionForwarders[slot];
Mathias Agopian518ec112011-05-13 16:21:08 -0700704 sGLExtentionMap.add(name, addr);
705 sGLExtentionSlot++;
706 }
707 }
708
709 pthread_mutex_unlock(&sExtensionMapMutex);
710 return addr;
711}
712
713EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
714{
Mathias Agopian518ec112011-05-13 16:21:08 -0700715 clearError();
716
717 egl_display_t const * const dp = validate_display(dpy);
718 if (!dp) return EGL_FALSE;
719
Mathias Agopianf0480de2011-11-13 20:50:07 -0800720 SurfaceRef _s(dp, draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700721 if (!_s.get())
722 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700723
Siva Velusamy0469dd62011-11-30 15:05:37 -0800724#if EGL_TRACE
725 if (gEGLDebugLevel > 0)
726 GLTrace_eglSwapBuffers(dpy, draw);
727#endif
728
Mathias Agopian518ec112011-05-13 16:21:08 -0700729 egl_surface_t const * const s = get_surface(draw);
Mathias Agopianada798b2012-02-13 17:09:30 -0800730 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700731}
732
733EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
734 NativePixmapType target)
735{
736 clearError();
737
738 egl_display_t const * const dp = validate_display(dpy);
739 if (!dp) return EGL_FALSE;
740
Mathias Agopianf0480de2011-11-13 20:50:07 -0800741 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700742 if (!_s.get())
743 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700744
Mathias Agopian518ec112011-05-13 16:21:08 -0700745 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800746 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -0700747}
748
749const char* eglQueryString(EGLDisplay dpy, EGLint name)
750{
751 clearError();
752
753 egl_display_t const * const dp = validate_display(dpy);
754 if (!dp) return (const char *) NULL;
755
756 switch (name) {
757 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800758 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700759 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800760 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700761 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800762 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700763 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800764 return dp->getClientApiString();
Mathias Agopianada798b2012-02-13 17:09:30 -0800765 case EGL_VERSION_HW_ANDROID:
766 return dp->disp.queryString.version;
Mathias Agopian518ec112011-05-13 16:21:08 -0700767 }
768 return setError(EGL_BAD_PARAMETER, (const char *)0);
769}
770
771
772// ----------------------------------------------------------------------------
773// EGL 1.1
774// ----------------------------------------------------------------------------
775
776EGLBoolean eglSurfaceAttrib(
777 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
778{
779 clearError();
780
781 egl_display_t const * const dp = validate_display(dpy);
782 if (!dp) return EGL_FALSE;
783
Mathias Agopianf0480de2011-11-13 20:50:07 -0800784 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700785 if (!_s.get())
786 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700787
Mathias Agopian518ec112011-05-13 16:21:08 -0700788 egl_surface_t const * const s = get_surface(surface);
789 if (s->cnx->egl.eglSurfaceAttrib) {
790 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -0800791 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700792 }
793 return setError(EGL_BAD_SURFACE, EGL_FALSE);
794}
795
796EGLBoolean eglBindTexImage(
797 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
798{
799 clearError();
800
801 egl_display_t const * const dp = validate_display(dpy);
802 if (!dp) return EGL_FALSE;
803
Mathias Agopianf0480de2011-11-13 20:50:07 -0800804 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700805 if (!_s.get())
806 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700807
Mathias Agopian518ec112011-05-13 16:21:08 -0700808 egl_surface_t const * const s = get_surface(surface);
809 if (s->cnx->egl.eglBindTexImage) {
810 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -0800811 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -0700812 }
813 return setError(EGL_BAD_SURFACE, EGL_FALSE);
814}
815
816EGLBoolean eglReleaseTexImage(
817 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
818{
819 clearError();
820
821 egl_display_t const * const dp = validate_display(dpy);
822 if (!dp) return EGL_FALSE;
823
Mathias Agopianf0480de2011-11-13 20:50:07 -0800824 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700825 if (!_s.get())
826 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700827
Mathias Agopian518ec112011-05-13 16:21:08 -0700828 egl_surface_t const * const s = get_surface(surface);
829 if (s->cnx->egl.eglReleaseTexImage) {
830 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -0800831 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -0700832 }
833 return setError(EGL_BAD_SURFACE, EGL_FALSE);
834}
835
836EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
837{
838 clearError();
839
840 egl_display_t const * const dp = validate_display(dpy);
841 if (!dp) return EGL_FALSE;
842
843 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -0800844 egl_connection_t* const cnx = &gEGLImpl;
845 if (cnx->dso && cnx->egl.eglSwapInterval) {
846 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -0700847 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800848
Mathias Agopian518ec112011-05-13 16:21:08 -0700849 return res;
850}
851
852
853// ----------------------------------------------------------------------------
854// EGL 1.2
855// ----------------------------------------------------------------------------
856
857EGLBoolean eglWaitClient(void)
858{
859 clearError();
860
Mathias Agopianada798b2012-02-13 17:09:30 -0800861 egl_connection_t* const cnx = &gEGLImpl;
862 if (!cnx->dso)
863 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
864
865 EGLBoolean res;
866 if (cnx->egl.eglWaitClient) {
867 res = cnx->egl.eglWaitClient();
868 } else {
869 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700870 }
871 return res;
872}
873
874EGLBoolean eglBindAPI(EGLenum api)
875{
876 clearError();
877
878 if (egl_init_drivers() == EGL_FALSE) {
879 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
880 }
881
882 // bind this API on all EGLs
883 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -0800884 egl_connection_t* const cnx = &gEGLImpl;
885 if (cnx->dso && cnx->egl.eglBindAPI) {
886 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -0700887 }
888 return res;
889}
890
891EGLenum eglQueryAPI(void)
892{
893 clearError();
894
895 if (egl_init_drivers() == EGL_FALSE) {
896 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
897 }
898
Mathias Agopianada798b2012-02-13 17:09:30 -0800899 egl_connection_t* const cnx = &gEGLImpl;
900 if (cnx->dso && cnx->egl.eglQueryAPI) {
901 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -0700902 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800903
Mathias Agopian518ec112011-05-13 16:21:08 -0700904 // or, it can only be OpenGL ES
905 return EGL_OPENGL_ES_API;
906}
907
908EGLBoolean eglReleaseThread(void)
909{
910 clearError();
911
912 // If there is context bound to the thread, release it
Mathias Agopianfb87e542012-01-30 18:20:52 -0800913 egl_display_t::loseCurrent(get_context(getContext()));
Mathias Agopian518ec112011-05-13 16:21:08 -0700914
Mathias Agopianada798b2012-02-13 17:09:30 -0800915 egl_connection_t* const cnx = &gEGLImpl;
916 if (cnx->dso && cnx->egl.eglReleaseThread) {
917 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -0700918 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800919
Mathias Agopian518ec112011-05-13 16:21:08 -0700920 egl_tls_t::clearTLS();
Siva Velusamy0469dd62011-11-30 15:05:37 -0800921#if EGL_TRACE
922 if (gEGLDebugLevel > 0)
923 GLTrace_eglReleaseThread();
924#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700925 return EGL_TRUE;
926}
927
928EGLSurface eglCreatePbufferFromClientBuffer(
929 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
930 EGLConfig config, const EGLint *attrib_list)
931{
932 clearError();
933
934 egl_display_t const* dp = 0;
935 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
936 if (!cnx) return EGL_FALSE;
937 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
938 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -0800939 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700940 }
941 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
942}
943
944// ----------------------------------------------------------------------------
945// EGL_EGLEXT_VERSION 3
946// ----------------------------------------------------------------------------
947
948EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
949 const EGLint *attrib_list)
950{
951 clearError();
952
953 egl_display_t const * const dp = validate_display(dpy);
954 if (!dp) return EGL_FALSE;
955
Mathias Agopianf0480de2011-11-13 20:50:07 -0800956 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700957 if (!_s.get())
958 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700959
960 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700961 if (s->cnx->egl.eglLockSurfaceKHR) {
962 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -0800963 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700964 }
965 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
966}
967
968EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
969{
970 clearError();
971
972 egl_display_t const * const dp = validate_display(dpy);
973 if (!dp) return EGL_FALSE;
974
Mathias Agopianf0480de2011-11-13 20:50:07 -0800975 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700976 if (!_s.get())
977 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700978
979 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700980 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800981 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700982 }
983 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
984}
985
986EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
987 EGLClientBuffer buffer, const EGLint *attrib_list)
988{
989 clearError();
990
991 egl_display_t const * const dp = validate_display(dpy);
992 if (!dp) return EGL_NO_IMAGE_KHR;
993
Mathias Agopian7c0441a2012-02-14 17:14:36 -0800994 ContextRef _c(dp, ctx);
995 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -0700996
Mathias Agopian7c0441a2012-02-14 17:14:36 -0800997 EGLImageKHR result = EGL_NO_IMAGE_KHR;
998 egl_connection_t* const cnx = &gEGLImpl;
999 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1000 result = cnx->egl.eglCreateImageKHR(
1001 dp->disp.dpy,
1002 c ? c->context : EGL_NO_CONTEXT,
1003 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001004 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001005 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001006}
1007
1008EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1009{
1010 clearError();
1011
1012 egl_display_t const * const dp = validate_display(dpy);
1013 if (!dp) return EGL_FALSE;
1014
Mathias Agopianada798b2012-02-13 17:09:30 -08001015 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001016 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
1017 cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001018 }
Mathias Agopian518ec112011-05-13 16:21:08 -07001019 return EGL_TRUE;
1020}
1021
1022// ----------------------------------------------------------------------------
1023// EGL_EGLEXT_VERSION 5
1024// ----------------------------------------------------------------------------
1025
1026
1027EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1028{
1029 clearError();
1030
1031 egl_display_t const * const dp = validate_display(dpy);
1032 if (!dp) return EGL_NO_SYNC_KHR;
1033
Mathias Agopian518ec112011-05-13 16:21:08 -07001034 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001035 egl_connection_t* const cnx = &gEGLImpl;
1036 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1037 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001038 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001039 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001040}
1041
1042EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1043{
1044 clearError();
1045
1046 egl_display_t const * const dp = validate_display(dpy);
1047 if (!dp) return EGL_FALSE;
1048
Mathias Agopian518ec112011-05-13 16:21:08 -07001049 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001050 egl_connection_t* const cnx = &gEGLImpl;
1051 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1052 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001053 }
1054 return result;
1055}
1056
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001057EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1058 EGLint flags, EGLTimeKHR timeout)
Mathias Agopian518ec112011-05-13 16:21:08 -07001059{
1060 clearError();
1061
1062 egl_display_t const * const dp = validate_display(dpy);
1063 if (!dp) return EGL_FALSE;
1064
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001065 EGLBoolean result = EGL_FALSE;
1066 egl_connection_t* const cnx = &gEGLImpl;
1067 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1068 result = cnx->egl.eglClientWaitSyncKHR(
1069 dp->disp.dpy, sync, flags, timeout);
Mathias Agopian518ec112011-05-13 16:21:08 -07001070 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001071 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001072}
1073
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001074EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1075 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001076{
1077 clearError();
1078
1079 egl_display_t const * const dp = validate_display(dpy);
1080 if (!dp) return EGL_FALSE;
1081
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001082 EGLBoolean result = EGL_FALSE;
1083 egl_connection_t* const cnx = &gEGLImpl;
1084 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1085 result = cnx->egl.eglGetSyncAttribKHR(
1086 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001087 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001088 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001089}
1090
1091// ----------------------------------------------------------------------------
1092// ANDROID extensions
1093// ----------------------------------------------------------------------------
1094
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001095/* ANDROID extensions entry-point go here */
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001096
1097// ----------------------------------------------------------------------------
1098// NVIDIA extensions
1099// ----------------------------------------------------------------------------
1100EGLuint64NV eglGetSystemTimeFrequencyNV()
1101{
1102 clearError();
1103
1104 if (egl_init_drivers() == EGL_FALSE) {
1105 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1106 }
1107
1108 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001109 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001110
Mathias Agopianada798b2012-02-13 17:09:30 -08001111 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1112 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001113 }
1114
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001115 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001116}
1117
1118EGLuint64NV eglGetSystemTimeNV()
1119{
1120 clearError();
1121
1122 if (egl_init_drivers() == EGL_FALSE) {
1123 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1124 }
1125
1126 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001127 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001128
Mathias Agopianada798b2012-02-13 17:09:30 -08001129 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1130 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001131 }
1132
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001133 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001134}