blob: 8bfa16d06537012388ea18bd50bcb65dd54f3f66 [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
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Mathias Agopian518ec112011-05-13 16:21:08 -070019#include <ctype.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include <hardware/gralloc.h>
24#include <system/window.h>
25
26#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES/gl.h>
29#include <GLES/glext.h>
30
31#include <cutils/log.h>
32#include <cutils/atomic.h>
Mathias Agopian7db993a2012-03-25 00:49:46 -070033#include <cutils/compiler.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070034#include <cutils/properties.h>
35#include <cutils/memory.h>
36
37#include <utils/KeyedVector.h>
38#include <utils/SortedVector.h>
39#include <utils/String8.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080040#include <utils/Trace.h>
Mathias Agopian518ec112011-05-13 16:21:08 -070041
42#include "egl_impl.h"
43#include "egl_tls.h"
Siva Velusamy0469dd62011-11-30 15:05:37 -080044#include "glestrace.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070045#include "hooks.h"
46
47#include "egl_display.h"
48#include "egl_impl.h"
49#include "egl_object.h"
50#include "egl_tls.h"
Mathias Agopianada798b2012-02-13 17:09:30 -080051#include "egldefs.h"
Mathias Agopian518ec112011-05-13 16:21:08 -070052
53using namespace android;
54
55// ----------------------------------------------------------------------------
56
Mathias Agopianbc2d79e2011-11-29 17:55:46 -080057#define EGL_VERSION_HW_ANDROID 0x3143
58
Mathias Agopian518ec112011-05-13 16:21:08 -070059struct extention_map_t {
60 const char* name;
61 __eglMustCastToProperFunctionPointerType address;
62};
63
64static const extention_map_t sExtentionMap[] = {
65 { "eglLockSurfaceKHR",
66 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
67 { "eglUnlockSurfaceKHR",
68 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
69 { "eglCreateImageKHR",
70 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
71 { "eglDestroyImageKHR",
72 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
Jonas Yang1c3d72a2011-08-26 20:04:39 +080073 { "eglGetSystemTimeFrequencyNV",
74 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
75 { "eglGetSystemTimeNV",
76 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
Mathias Agopian518ec112011-05-13 16:21:08 -070077};
78
79// accesses protected by sExtensionMapMutex
80static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
81static int sGLExtentionSlot = 0;
82static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
83
84static void(*findProcAddress(const char* name,
85 const extention_map_t* map, size_t n))() {
86 for (uint32_t i=0 ; i<n ; i++) {
87 if (!strcmp(name, map[i].name)) {
88 return map[i].address;
89 }
90 }
91 return NULL;
92}
93
94// ----------------------------------------------------------------------------
95
Mathias Agopian518ec112011-05-13 16:21:08 -070096namespace android {
97extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
98extern EGLBoolean egl_init_drivers();
99extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
100extern int gEGLDebugLevel;
101extern gl_hooks_t gHooksTrace;
Mathias Agopian518ec112011-05-13 16:21:08 -0700102} // namespace android;
103
104// ----------------------------------------------------------------------------
105
106static inline void clearError() { egl_tls_t::clearError(); }
107static inline EGLContext getContext() { return egl_tls_t::getContext(); }
108
109// ----------------------------------------------------------------------------
110
111EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
112{
113 clearError();
114
115 uint32_t index = uint32_t(display);
116 if (index >= NUM_DISPLAYS) {
117 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
118 }
119
120 if (egl_init_drivers() == EGL_FALSE) {
121 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
122 }
123
124 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
125 return dpy;
126}
127
128// ----------------------------------------------------------------------------
129// Initialization
130// ----------------------------------------------------------------------------
131
132EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
133{
134 clearError();
135
136 egl_display_t * const dp = get_display(dpy);
137 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
138
139 EGLBoolean res = dp->initialize(major, minor);
140
141 return res;
142}
143
144EGLBoolean eglTerminate(EGLDisplay dpy)
145{
146 // NOTE: don't unload the drivers b/c some APIs can be called
147 // after eglTerminate() has been called. eglTerminate() only
148 // terminates an EGLDisplay, not a EGL itself.
149
150 clearError();
151
152 egl_display_t* const dp = get_display(dpy);
153 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
154
155 EGLBoolean res = dp->terminate();
156
157 return res;
158}
159
160// ----------------------------------------------------------------------------
161// configuration
162// ----------------------------------------------------------------------------
163
164EGLBoolean eglGetConfigs( EGLDisplay dpy,
165 EGLConfig *configs,
166 EGLint config_size, EGLint *num_config)
167{
168 clearError();
169
170 egl_display_t const * const dp = validate_display(dpy);
171 if (!dp) return EGL_FALSE;
172
Mathias Agopian7773c432012-02-13 20:06:08 -0800173 if (num_config==0) {
174 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700175 }
176
Mathias Agopian7773c432012-02-13 20:06:08 -0800177 EGLBoolean res = EGL_FALSE;
178 *num_config = 0;
179
180 egl_connection_t* const cnx = &gEGLImpl;
181 if (cnx->dso) {
182 res = cnx->egl.eglGetConfigs(
183 dp->disp.dpy, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700184 }
Mathias Agopian7773c432012-02-13 20:06:08 -0800185
186 return res;
Mathias Agopian518ec112011-05-13 16:21:08 -0700187}
188
189EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
190 EGLConfig *configs, EGLint config_size,
191 EGLint *num_config)
192{
193 clearError();
194
195 egl_display_t const * const dp = validate_display(dpy);
196 if (!dp) return EGL_FALSE;
197
198 if (num_config==0) {
199 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
200 }
201
Mathias Agopian518ec112011-05-13 16:21:08 -0700202 EGLBoolean res = EGL_FALSE;
203 *num_config = 0;
204
Mathias Agopianada798b2012-02-13 17:09:30 -0800205 egl_connection_t* const cnx = &gEGLImpl;
206 if (cnx->dso) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800207 res = cnx->egl.eglChooseConfig(
208 dp->disp.dpy, attrib_list, configs, config_size, num_config);
Mathias Agopian518ec112011-05-13 16:21:08 -0700209 }
210 return res;
211}
212
213EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
214 EGLint attribute, EGLint *value)
215{
216 clearError();
217
218 egl_display_t const* dp = 0;
219 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
220 if (!cnx) return EGL_FALSE;
221
Mathias Agopian518ec112011-05-13 16:21:08 -0700222 return cnx->egl.eglGetConfigAttrib(
Mathias Agopian7773c432012-02-13 20:06:08 -0800223 dp->disp.dpy, config, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700224}
225
226// ----------------------------------------------------------------------------
227// surfaces
228// ----------------------------------------------------------------------------
229
230EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
231 NativeWindowType window,
232 const EGLint *attrib_list)
233{
234 clearError();
235
236 egl_display_t const* dp = 0;
237 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
238 if (cnx) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800239 EGLDisplay iDpy = dp->disp.dpy;
Mathias Agopian518ec112011-05-13 16:21:08 -0700240 EGLint format;
241
Mathias Agopian81a63352011-07-29 17:55:48 -0700242 if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000243 ALOGE("EGLNativeWindowType %p already connected to another API",
Mathias Agopian81a63352011-07-29 17:55:48 -0700244 window);
245 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
246 }
247
Mathias Agopian518ec112011-05-13 16:21:08 -0700248 // set the native window's buffers format to match this config
249 if (cnx->egl.eglGetConfigAttrib(iDpy,
Mathias Agopian7773c432012-02-13 20:06:08 -0800250 config, EGL_NATIVE_VISUAL_ID, &format)) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700251 if (format != 0) {
Jamie Gennisbee205f2011-07-01 13:12:07 -0700252 int err = native_window_set_buffers_format(window, format);
253 if (err != 0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000254 ALOGE("error setting native window pixel format: %s (%d)",
Jamie Gennisbee205f2011-07-01 13:12:07 -0700255 strerror(-err), err);
Mathias Agopian81a63352011-07-29 17:55:48 -0700256 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Jamie Gennisbee205f2011-07-01 13:12:07 -0700257 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
258 }
Mathias Agopian518ec112011-05-13 16:21:08 -0700259 }
260 }
261
Jamie Gennis59769462011-11-19 18:04:43 -0800262 // the EGL spec requires that a new EGLSurface default to swap interval
263 // 1, so explicitly set that on the window here.
264 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
265 anw->setSwapInterval(anw, 1);
266
Mathias Agopian518ec112011-05-13 16:21:08 -0700267 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800268 iDpy, config, window, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700269 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800270 egl_surface_t* s = new egl_surface_t(dpy, config, window, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700271 return s;
272 }
Mathias Agopian81a63352011-07-29 17:55:48 -0700273
274 // EGLSurface creation failed
275 native_window_set_buffers_format(window, 0);
276 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
Mathias Agopian518ec112011-05-13 16:21:08 -0700277 }
278 return EGL_NO_SURFACE;
279}
280
281EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
282 NativePixmapType pixmap,
283 const EGLint *attrib_list)
284{
285 clearError();
286
287 egl_display_t const* dp = 0;
288 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
289 if (cnx) {
290 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800291 dp->disp.dpy, config, pixmap, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700292 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800293 egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700294 return s;
295 }
296 }
297 return EGL_NO_SURFACE;
298}
299
300EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
301 const EGLint *attrib_list)
302{
303 clearError();
304
305 egl_display_t const* dp = 0;
306 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
307 if (cnx) {
308 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
Mathias Agopian7773c432012-02-13 20:06:08 -0800309 dp->disp.dpy, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700310 if (surface != EGL_NO_SURFACE) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800311 egl_surface_t* s = new egl_surface_t(dpy, config, NULL, surface, cnx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700312 return s;
313 }
314 }
315 return EGL_NO_SURFACE;
316}
317
318EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
319{
320 clearError();
321
322 egl_display_t const * const dp = validate_display(dpy);
323 if (!dp) return EGL_FALSE;
324
Mathias Agopianf0480de2011-11-13 20:50:07 -0800325 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700326 if (!_s.get())
327 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700328
329 egl_surface_t * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800330 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700331 if (result == EGL_TRUE) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700332 _s.terminate();
333 }
334 return result;
335}
336
337EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
338 EGLint attribute, EGLint *value)
339{
340 clearError();
341
342 egl_display_t const * const dp = validate_display(dpy);
343 if (!dp) return EGL_FALSE;
344
Mathias Agopianf0480de2011-11-13 20:50:07 -0800345 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700346 if (!_s.get())
347 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700348
Mathias Agopian518ec112011-05-13 16:21:08 -0700349 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian7773c432012-02-13 20:06:08 -0800350 return s->cnx->egl.eglQuerySurface(
351 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700352}
353
Jamie Gennise8696a42012-01-15 18:54:57 -0800354void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800355 ATRACE_CALL();
Jamie Gennise8696a42012-01-15 18:54:57 -0800356 clearError();
357
358 egl_display_t const * const dp = validate_display(dpy);
359 if (!dp) {
360 return;
361 }
362
363 SurfaceRef _s(dp, surface);
364 if (!_s.get()) {
365 setError(EGL_BAD_SURFACE, EGL_FALSE);
366 return;
367 }
368
369 int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
370
371 egl_surface_t const * const s = get_surface(surface);
372 native_window_set_buffers_timestamp(s->win.get(), timestamp);
373}
374
Mathias Agopian518ec112011-05-13 16:21:08 -0700375// ----------------------------------------------------------------------------
376// Contexts
377// ----------------------------------------------------------------------------
378
379EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
380 EGLContext share_list, const EGLint *attrib_list)
381{
382 clearError();
383
384 egl_display_t const* dp = 0;
385 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
386 if (cnx) {
387 if (share_list != EGL_NO_CONTEXT) {
388 egl_context_t* const c = get_context(share_list);
389 share_list = c->context;
390 }
391 EGLContext context = cnx->egl.eglCreateContext(
Mathias Agopian7773c432012-02-13 20:06:08 -0800392 dp->disp.dpy, config, share_list, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700393 if (context != EGL_NO_CONTEXT) {
394 // figure out if it's a GLESv1 or GLESv2
395 int version = 0;
396 if (attrib_list) {
397 while (*attrib_list != EGL_NONE) {
398 GLint attr = *attrib_list++;
399 GLint value = *attrib_list++;
400 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
401 if (value == 1) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800402 version = egl_connection_t::GLESv1_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700403 } else if (value == 2) {
Mathias Agopian7773c432012-02-13 20:06:08 -0800404 version = egl_connection_t::GLESv2_INDEX;
Mathias Agopian518ec112011-05-13 16:21:08 -0700405 }
406 }
407 };
408 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800409 egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800410#if EGL_TRACE
411 if (gEGLDebugLevel > 0)
412 GLTrace_eglCreateContext(version, c);
413#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700414 return c;
415 }
416 }
417 return EGL_NO_CONTEXT;
418}
419
420EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
421{
422 clearError();
423
424 egl_display_t const * const dp = validate_display(dpy);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700425 if (!dp)
426 return EGL_FALSE;
Mathias Agopian518ec112011-05-13 16:21:08 -0700427
Mathias Agopianf0480de2011-11-13 20:50:07 -0800428 ContextRef _c(dp, ctx);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700429 if (!_c.get())
430 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700431
Mathias Agopian518ec112011-05-13 16:21:08 -0700432 egl_context_t * const c = get_context(ctx);
Mathias Agopianada798b2012-02-13 17:09:30 -0800433 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
Mathias Agopian518ec112011-05-13 16:21:08 -0700434 if (result == EGL_TRUE) {
435 _c.terminate();
436 }
437 return result;
438}
439
Mathias Agopian518ec112011-05-13 16:21:08 -0700440EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
441 EGLSurface read, EGLContext ctx)
442{
443 clearError();
444
445 egl_display_t const * const dp = get_display(dpy);
446 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
447
Mathias Agopian5b287a62011-05-16 18:58:55 -0700448 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
449 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
450 // a valid but uninitialized display.
Mathias Agopian518ec112011-05-13 16:21:08 -0700451 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
452 (draw != EGL_NO_SURFACE) ) {
453 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
454 }
455
456 // get a reference to the object passed in
Mathias Agopianf0480de2011-11-13 20:50:07 -0800457 ContextRef _c(dp, ctx);
458 SurfaceRef _d(dp, draw);
459 SurfaceRef _r(dp, read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700460
461 // validate the context (if not EGL_NO_CONTEXT)
Mathias Agopian5b287a62011-05-16 18:58:55 -0700462 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700463 // EGL_NO_CONTEXT is valid
464 return EGL_FALSE;
465 }
466
467 // these are the underlying implementation's object
468 EGLContext impl_ctx = EGL_NO_CONTEXT;
469 EGLSurface impl_draw = EGL_NO_SURFACE;
470 EGLSurface impl_read = EGL_NO_SURFACE;
471
472 // these are our objects structs passed in
473 egl_context_t * c = NULL;
474 egl_surface_t const * d = NULL;
475 egl_surface_t const * r = NULL;
476
477 // these are the current objects structs
478 egl_context_t * cur_c = get_context(getContext());
479
480 if (ctx != EGL_NO_CONTEXT) {
481 c = get_context(ctx);
482 impl_ctx = c->context;
483 } else {
484 // no context given, use the implementation of the current context
485 if (cur_c == NULL) {
486 // no current context
487 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
488 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
489 return setError(EGL_BAD_MATCH, EGL_FALSE);
490 }
491 // not an error, there is just no current context.
492 return EGL_TRUE;
493 }
494 }
495
496 // retrieve the underlying implementation's draw EGLSurface
497 if (draw != EGL_NO_SURFACE) {
498 d = get_surface(draw);
Mathias Agopian518ec112011-05-13 16:21:08 -0700499 impl_draw = d->surface;
500 }
501
502 // retrieve the underlying implementation's read EGLSurface
503 if (read != EGL_NO_SURFACE) {
504 r = get_surface(read);
Mathias Agopian518ec112011-05-13 16:21:08 -0700505 impl_read = r->surface;
506 }
507
Mathias Agopian518ec112011-05-13 16:21:08 -0700508
Mathias Agopianfb87e542012-01-30 18:20:52 -0800509 EGLBoolean result = const_cast<egl_display_t*>(dp)->makeCurrent(c, cur_c,
510 draw, read, ctx,
511 impl_draw, impl_read, impl_ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700512
513 if (result == EGL_TRUE) {
Mathias Agopianfb87e542012-01-30 18:20:52 -0800514 if (c) {
Mathias Agopian518ec112011-05-13 16:21:08 -0700515 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
516 egl_tls_t::setContext(ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800517#if EGL_TRACE
518 if (gEGLDebugLevel > 0)
Siva Velusamy93a826f2011-12-14 12:19:56 -0800519 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
Siva Velusamy0469dd62011-11-30 15:05:37 -0800520#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700521 _c.acquire();
522 _r.acquire();
523 _d.acquire();
Mathias Agopian518ec112011-05-13 16:21:08 -0700524 } else {
525 setGLHooksThreadSpecific(&gHooksNoContext);
526 egl_tls_t::setContext(EGL_NO_CONTEXT);
527 }
Mathias Agopian5fecea72011-08-25 18:38:24 -0700528 } else {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000529 // this will ALOGE the error
Mathias Agopian5fecea72011-08-25 18:38:24 -0700530 result = setError(c->cnx->egl.eglGetError(), EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700531 }
532 return result;
533}
534
535
536EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
537 EGLint attribute, EGLint *value)
538{
539 clearError();
540
541 egl_display_t const * const dp = validate_display(dpy);
542 if (!dp) return EGL_FALSE;
543
Mathias Agopianf0480de2011-11-13 20:50:07 -0800544 ContextRef _c(dp, ctx);
Mathias Agopian518ec112011-05-13 16:21:08 -0700545 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
546
Mathias Agopian518ec112011-05-13 16:21:08 -0700547 egl_context_t * const c = get_context(ctx);
Mathias Agopian7773c432012-02-13 20:06:08 -0800548 return c->cnx->egl.eglQueryContext(
549 dp->disp.dpy, c->context, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700550
Mathias Agopian518ec112011-05-13 16:21:08 -0700551}
552
553EGLContext eglGetCurrentContext(void)
554{
555 // could be called before eglInitialize(), but we wouldn't have a context
556 // then, and this function would correctly return EGL_NO_CONTEXT.
557
558 clearError();
559
560 EGLContext ctx = getContext();
561 return ctx;
562}
563
564EGLSurface eglGetCurrentSurface(EGLint readdraw)
565{
566 // could be called before eglInitialize(), but we wouldn't have a context
567 // then, and this function would correctly return EGL_NO_SURFACE.
568
569 clearError();
570
571 EGLContext ctx = getContext();
572 if (ctx) {
573 egl_context_t const * const c = get_context(ctx);
574 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
575 switch (readdraw) {
576 case EGL_READ: return c->read;
577 case EGL_DRAW: return c->draw;
578 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
579 }
580 }
581 return EGL_NO_SURFACE;
582}
583
584EGLDisplay eglGetCurrentDisplay(void)
585{
586 // could be called before eglInitialize(), but we wouldn't have a context
587 // then, and this function would correctly return EGL_NO_DISPLAY.
588
589 clearError();
590
591 EGLContext ctx = getContext();
592 if (ctx) {
593 egl_context_t const * const c = get_context(ctx);
594 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
595 return c->dpy;
596 }
597 return EGL_NO_DISPLAY;
598}
599
600EGLBoolean eglWaitGL(void)
601{
Mathias Agopian518ec112011-05-13 16:21:08 -0700602 clearError();
603
Mathias Agopianada798b2012-02-13 17:09:30 -0800604 egl_connection_t* const cnx = &gEGLImpl;
605 if (!cnx->dso)
606 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
607
608 return cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700609}
610
611EGLBoolean eglWaitNative(EGLint engine)
612{
Mathias Agopian518ec112011-05-13 16:21:08 -0700613 clearError();
614
Mathias Agopianada798b2012-02-13 17:09:30 -0800615 egl_connection_t* const cnx = &gEGLImpl;
616 if (!cnx->dso)
617 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
618
619 return cnx->egl.eglWaitNative(engine);
Mathias Agopian518ec112011-05-13 16:21:08 -0700620}
621
622EGLint eglGetError(void)
623{
Mathias Agopianada798b2012-02-13 17:09:30 -0800624 EGLint err = EGL_SUCCESS;
625 egl_connection_t* const cnx = &gEGLImpl;
626 if (cnx->dso) {
627 err = cnx->egl.eglGetError();
Mathias Agopian518ec112011-05-13 16:21:08 -0700628 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800629 if (err == EGL_SUCCESS) {
630 err = egl_tls_t::getError();
631 }
632 return err;
Mathias Agopian518ec112011-05-13 16:21:08 -0700633}
634
Mathias Agopian518ec112011-05-13 16:21:08 -0700635__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
636{
637 // eglGetProcAddress() could be the very first function called
638 // in which case we must make sure we've initialized ourselves, this
639 // happens the first time egl_get_display() is called.
640
641 clearError();
642
643 if (egl_init_drivers() == EGL_FALSE) {
644 setError(EGL_BAD_PARAMETER, NULL);
645 return NULL;
646 }
647
Jamie Gennisaca51c02011-11-03 17:42:43 -0700648 // The EGL_ANDROID_blob_cache extension should not be exposed to
649 // applications. It is used internally by the Android EGL layer.
Jamie Gennisc42fcf02011-11-09 15:35:34 -0800650 if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID")) {
Jamie Gennisaca51c02011-11-03 17:42:43 -0700651 return NULL;
652 }
653
Mathias Agopian518ec112011-05-13 16:21:08 -0700654 __eglMustCastToProperFunctionPointerType addr;
655 addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap));
656 if (addr) return addr;
657
Jamie Gennisaca51c02011-11-03 17:42:43 -0700658
Mathias Agopian518ec112011-05-13 16:21:08 -0700659 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
660 pthread_mutex_lock(&sExtensionMapMutex);
661
662 /*
663 * Since eglGetProcAddress() is not associated to anything, it needs
664 * to return a function pointer that "works" regardless of what
665 * the current context is.
666 *
667 * For this reason, we return a "forwarder", a small stub that takes
668 * care of calling the function associated with the context
669 * currently bound.
670 *
671 * We first look for extensions we've already resolved, if we're seeing
672 * this extension for the first time, we go through all our
673 * implementations and call eglGetProcAddress() and record the
674 * result in the appropriate implementation hooks and return the
675 * address of the forwarder corresponding to that hook set.
676 *
677 */
678
679 const String8 name(procname);
680 addr = sGLExtentionMap.valueFor(name);
681 const int slot = sGLExtentionSlot;
682
Steve Blocke6f43dd2012-01-06 19:20:56 +0000683 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
Mathias Agopian518ec112011-05-13 16:21:08 -0700684 "no more slots for eglGetProcAddress(\"%s\")",
685 procname);
686
Siva Velusamy0469dd62011-11-30 15:05:37 -0800687#if EGL_TRACE
688 gl_hooks_t *debugHooks = GLTrace_getGLHooks();
689#endif
690
Mathias Agopian518ec112011-05-13 16:21:08 -0700691 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
692 bool found = false;
Mathias Agopianada798b2012-02-13 17:09:30 -0800693
694 egl_connection_t* const cnx = &gEGLImpl;
695 if (cnx->dso && cnx->egl.eglGetProcAddress) {
696 found = true;
697 // Extensions are independent of the bound context
Mathias Agopian7773c432012-02-13 20:06:08 -0800698 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
699 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700700#if EGL_TRACE
Mathias Agopianada798b2012-02-13 17:09:30 -0800701 debugHooks->ext.extensions[slot] =
702 gHooksTrace.ext.extensions[slot] =
Mathias Agopian518ec112011-05-13 16:21:08 -0700703#endif
Mathias Agopianada798b2012-02-13 17:09:30 -0800704 cnx->egl.eglGetProcAddress(procname);
Mathias Agopian518ec112011-05-13 16:21:08 -0700705 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800706
Mathias Agopian518ec112011-05-13 16:21:08 -0700707 if (found) {
708 addr = gExtensionForwarders[slot];
Mathias Agopian518ec112011-05-13 16:21:08 -0700709 sGLExtentionMap.add(name, addr);
710 sGLExtentionSlot++;
711 }
712 }
713
714 pthread_mutex_unlock(&sExtensionMapMutex);
715 return addr;
716}
717
718EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw)
719{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800720 ATRACE_CALL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700721 clearError();
722
723 egl_display_t const * const dp = validate_display(dpy);
724 if (!dp) return EGL_FALSE;
725
Mathias Agopianf0480de2011-11-13 20:50:07 -0800726 SurfaceRef _s(dp, draw);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700727 if (!_s.get())
728 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700729
Siva Velusamy0469dd62011-11-30 15:05:37 -0800730#if EGL_TRACE
731 if (gEGLDebugLevel > 0)
732 GLTrace_eglSwapBuffers(dpy, draw);
733#endif
734
Mathias Agopian518ec112011-05-13 16:21:08 -0700735 egl_surface_t const * const s = get_surface(draw);
Mathias Agopian7db993a2012-03-25 00:49:46 -0700736
737 if (CC_UNLIKELY(dp->finishOnSwap)) {
738 uint32_t pixel;
739 egl_context_t * const c = get_context( egl_tls_t::getContext() );
740 if (c) {
741 // glReadPixels() ensures that the frame is complete
742 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
743 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
744 }
745 }
746
Mathias Agopianada798b2012-02-13 17:09:30 -0800747 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700748}
749
750EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
751 NativePixmapType target)
752{
753 clearError();
754
755 egl_display_t const * const dp = validate_display(dpy);
756 if (!dp) return EGL_FALSE;
757
Mathias Agopianf0480de2011-11-13 20:50:07 -0800758 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700759 if (!_s.get())
760 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700761
Mathias Agopian518ec112011-05-13 16:21:08 -0700762 egl_surface_t const * const s = get_surface(surface);
Mathias Agopianada798b2012-02-13 17:09:30 -0800763 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
Mathias Agopian518ec112011-05-13 16:21:08 -0700764}
765
766const char* eglQueryString(EGLDisplay dpy, EGLint name)
767{
768 clearError();
769
770 egl_display_t const * const dp = validate_display(dpy);
771 if (!dp) return (const char *) NULL;
772
773 switch (name) {
774 case EGL_VENDOR:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800775 return dp->getVendorString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700776 case EGL_VERSION:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800777 return dp->getVersionString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700778 case EGL_EXTENSIONS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800779 return dp->getExtensionString();
Mathias Agopian518ec112011-05-13 16:21:08 -0700780 case EGL_CLIENT_APIS:
Mathias Agopian4b9511c2011-11-13 23:52:47 -0800781 return dp->getClientApiString();
Mathias Agopianada798b2012-02-13 17:09:30 -0800782 case EGL_VERSION_HW_ANDROID:
783 return dp->disp.queryString.version;
Mathias Agopian518ec112011-05-13 16:21:08 -0700784 }
785 return setError(EGL_BAD_PARAMETER, (const char *)0);
786}
787
788
789// ----------------------------------------------------------------------------
790// EGL 1.1
791// ----------------------------------------------------------------------------
792
793EGLBoolean eglSurfaceAttrib(
794 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
795{
796 clearError();
797
798 egl_display_t const * const dp = validate_display(dpy);
799 if (!dp) return EGL_FALSE;
800
Mathias Agopianf0480de2011-11-13 20:50:07 -0800801 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700802 if (!_s.get())
803 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700804
Mathias Agopian518ec112011-05-13 16:21:08 -0700805 egl_surface_t const * const s = get_surface(surface);
806 if (s->cnx->egl.eglSurfaceAttrib) {
807 return s->cnx->egl.eglSurfaceAttrib(
Mathias Agopianada798b2012-02-13 17:09:30 -0800808 dp->disp.dpy, s->surface, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -0700809 }
810 return setError(EGL_BAD_SURFACE, EGL_FALSE);
811}
812
813EGLBoolean eglBindTexImage(
814 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
815{
816 clearError();
817
818 egl_display_t const * const dp = validate_display(dpy);
819 if (!dp) return EGL_FALSE;
820
Mathias Agopianf0480de2011-11-13 20:50:07 -0800821 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700822 if (!_s.get())
823 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700824
Mathias Agopian518ec112011-05-13 16:21:08 -0700825 egl_surface_t const * const s = get_surface(surface);
826 if (s->cnx->egl.eglBindTexImage) {
827 return s->cnx->egl.eglBindTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -0800828 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -0700829 }
830 return setError(EGL_BAD_SURFACE, EGL_FALSE);
831}
832
833EGLBoolean eglReleaseTexImage(
834 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
835{
836 clearError();
837
838 egl_display_t const * const dp = validate_display(dpy);
839 if (!dp) return EGL_FALSE;
840
Mathias Agopianf0480de2011-11-13 20:50:07 -0800841 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700842 if (!_s.get())
843 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700844
Mathias Agopian518ec112011-05-13 16:21:08 -0700845 egl_surface_t const * const s = get_surface(surface);
846 if (s->cnx->egl.eglReleaseTexImage) {
847 return s->cnx->egl.eglReleaseTexImage(
Mathias Agopianada798b2012-02-13 17:09:30 -0800848 dp->disp.dpy, s->surface, buffer);
Mathias Agopian518ec112011-05-13 16:21:08 -0700849 }
850 return setError(EGL_BAD_SURFACE, EGL_FALSE);
851}
852
853EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
854{
855 clearError();
856
857 egl_display_t const * const dp = validate_display(dpy);
858 if (!dp) return EGL_FALSE;
859
860 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -0800861 egl_connection_t* const cnx = &gEGLImpl;
862 if (cnx->dso && cnx->egl.eglSwapInterval) {
863 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
Mathias Agopian518ec112011-05-13 16:21:08 -0700864 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800865
Mathias Agopian518ec112011-05-13 16:21:08 -0700866 return res;
867}
868
869
870// ----------------------------------------------------------------------------
871// EGL 1.2
872// ----------------------------------------------------------------------------
873
874EGLBoolean eglWaitClient(void)
875{
876 clearError();
877
Mathias Agopianada798b2012-02-13 17:09:30 -0800878 egl_connection_t* const cnx = &gEGLImpl;
879 if (!cnx->dso)
880 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
881
882 EGLBoolean res;
883 if (cnx->egl.eglWaitClient) {
884 res = cnx->egl.eglWaitClient();
885 } else {
886 res = cnx->egl.eglWaitGL();
Mathias Agopian518ec112011-05-13 16:21:08 -0700887 }
888 return res;
889}
890
891EGLBoolean eglBindAPI(EGLenum api)
892{
893 clearError();
894
895 if (egl_init_drivers() == EGL_FALSE) {
896 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
897 }
898
899 // bind this API on all EGLs
900 EGLBoolean res = EGL_TRUE;
Mathias Agopianada798b2012-02-13 17:09:30 -0800901 egl_connection_t* const cnx = &gEGLImpl;
902 if (cnx->dso && cnx->egl.eglBindAPI) {
903 res = cnx->egl.eglBindAPI(api);
Mathias Agopian518ec112011-05-13 16:21:08 -0700904 }
905 return res;
906}
907
908EGLenum eglQueryAPI(void)
909{
910 clearError();
911
912 if (egl_init_drivers() == EGL_FALSE) {
913 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
914 }
915
Mathias Agopianada798b2012-02-13 17:09:30 -0800916 egl_connection_t* const cnx = &gEGLImpl;
917 if (cnx->dso && cnx->egl.eglQueryAPI) {
918 return cnx->egl.eglQueryAPI();
Mathias Agopian518ec112011-05-13 16:21:08 -0700919 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800920
Mathias Agopian518ec112011-05-13 16:21:08 -0700921 // or, it can only be OpenGL ES
922 return EGL_OPENGL_ES_API;
923}
924
925EGLBoolean eglReleaseThread(void)
926{
927 clearError();
928
929 // If there is context bound to the thread, release it
Mathias Agopianfb87e542012-01-30 18:20:52 -0800930 egl_display_t::loseCurrent(get_context(getContext()));
Mathias Agopian518ec112011-05-13 16:21:08 -0700931
Mathias Agopianada798b2012-02-13 17:09:30 -0800932 egl_connection_t* const cnx = &gEGLImpl;
933 if (cnx->dso && cnx->egl.eglReleaseThread) {
934 cnx->egl.eglReleaseThread();
Mathias Agopian518ec112011-05-13 16:21:08 -0700935 }
Mathias Agopianada798b2012-02-13 17:09:30 -0800936
Mathias Agopian518ec112011-05-13 16:21:08 -0700937 egl_tls_t::clearTLS();
Siva Velusamy0469dd62011-11-30 15:05:37 -0800938#if EGL_TRACE
939 if (gEGLDebugLevel > 0)
940 GLTrace_eglReleaseThread();
941#endif
Mathias Agopian518ec112011-05-13 16:21:08 -0700942 return EGL_TRUE;
943}
944
945EGLSurface eglCreatePbufferFromClientBuffer(
946 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
947 EGLConfig config, const EGLint *attrib_list)
948{
949 clearError();
950
951 egl_display_t const* dp = 0;
952 egl_connection_t* cnx = validate_display_config(dpy, config, dp);
953 if (!cnx) return EGL_FALSE;
954 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
955 return cnx->egl.eglCreatePbufferFromClientBuffer(
Mathias Agopian7773c432012-02-13 20:06:08 -0800956 dp->disp.dpy, buftype, buffer, config, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700957 }
958 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
959}
960
961// ----------------------------------------------------------------------------
962// EGL_EGLEXT_VERSION 3
963// ----------------------------------------------------------------------------
964
965EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
966 const EGLint *attrib_list)
967{
968 clearError();
969
970 egl_display_t const * const dp = validate_display(dpy);
971 if (!dp) return EGL_FALSE;
972
Mathias Agopianf0480de2011-11-13 20:50:07 -0800973 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700974 if (!_s.get())
975 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700976
977 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700978 if (s->cnx->egl.eglLockSurfaceKHR) {
979 return s->cnx->egl.eglLockSurfaceKHR(
Mathias Agopianada798b2012-02-13 17:09:30 -0800980 dp->disp.dpy, s->surface, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -0700981 }
982 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
983}
984
985EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
986{
987 clearError();
988
989 egl_display_t const * const dp = validate_display(dpy);
990 if (!dp) return EGL_FALSE;
991
Mathias Agopianf0480de2011-11-13 20:50:07 -0800992 SurfaceRef _s(dp, surface);
Mathias Agopian5b287a62011-05-16 18:58:55 -0700993 if (!_s.get())
994 return setError(EGL_BAD_SURFACE, EGL_FALSE);
Mathias Agopian518ec112011-05-13 16:21:08 -0700995
996 egl_surface_t const * const s = get_surface(surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700997 if (s->cnx->egl.eglUnlockSurfaceKHR) {
Mathias Agopianada798b2012-02-13 17:09:30 -0800998 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
Mathias Agopian518ec112011-05-13 16:21:08 -0700999 }
1000 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1001}
1002
1003EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1004 EGLClientBuffer buffer, const EGLint *attrib_list)
1005{
1006 clearError();
1007
1008 egl_display_t const * const dp = validate_display(dpy);
1009 if (!dp) return EGL_NO_IMAGE_KHR;
1010
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001011 ContextRef _c(dp, ctx);
1012 egl_context_t * const c = _c.get();
Mathias Agopian518ec112011-05-13 16:21:08 -07001013
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001014 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1015 egl_connection_t* const cnx = &gEGLImpl;
1016 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1017 result = cnx->egl.eglCreateImageKHR(
1018 dp->disp.dpy,
1019 c ? c->context : EGL_NO_CONTEXT,
1020 target, buffer, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001021 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001022 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001023}
1024
1025EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1026{
1027 clearError();
1028
1029 egl_display_t const * const dp = validate_display(dpy);
1030 if (!dp) return EGL_FALSE;
1031
Mathias Agopianada798b2012-02-13 17:09:30 -08001032 egl_connection_t* const cnx = &gEGLImpl;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001033 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
1034 cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
Mathias Agopian518ec112011-05-13 16:21:08 -07001035 }
Mathias Agopian518ec112011-05-13 16:21:08 -07001036 return EGL_TRUE;
1037}
1038
1039// ----------------------------------------------------------------------------
1040// EGL_EGLEXT_VERSION 5
1041// ----------------------------------------------------------------------------
1042
1043
1044EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1045{
1046 clearError();
1047
1048 egl_display_t const * const dp = validate_display(dpy);
1049 if (!dp) return EGL_NO_SYNC_KHR;
1050
Mathias Agopian518ec112011-05-13 16:21:08 -07001051 EGLSyncKHR result = EGL_NO_SYNC_KHR;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001052 egl_connection_t* const cnx = &gEGLImpl;
1053 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1054 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
Mathias Agopian518ec112011-05-13 16:21:08 -07001055 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001056 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001057}
1058
1059EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1060{
1061 clearError();
1062
1063 egl_display_t const * const dp = validate_display(dpy);
1064 if (!dp) return EGL_FALSE;
1065
Mathias Agopian518ec112011-05-13 16:21:08 -07001066 EGLBoolean result = EGL_FALSE;
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001067 egl_connection_t* const cnx = &gEGLImpl;
1068 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1069 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
Mathias Agopian518ec112011-05-13 16:21:08 -07001070 }
1071 return result;
1072}
1073
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001074EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1075 EGLint flags, EGLTimeKHR timeout)
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.eglClientWaitSyncKHR) {
1085 result = cnx->egl.eglClientWaitSyncKHR(
1086 dp->disp.dpy, sync, flags, timeout);
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
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001091EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1092 EGLint attribute, EGLint *value)
Mathias Agopian518ec112011-05-13 16:21:08 -07001093{
1094 clearError();
1095
1096 egl_display_t const * const dp = validate_display(dpy);
1097 if (!dp) return EGL_FALSE;
1098
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001099 EGLBoolean result = EGL_FALSE;
1100 egl_connection_t* const cnx = &gEGLImpl;
1101 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1102 result = cnx->egl.eglGetSyncAttribKHR(
1103 dp->disp.dpy, sync, attribute, value);
Mathias Agopian518ec112011-05-13 16:21:08 -07001104 }
Mathias Agopian7c0441a2012-02-14 17:14:36 -08001105 return result;
Mathias Agopian518ec112011-05-13 16:21:08 -07001106}
1107
1108// ----------------------------------------------------------------------------
1109// ANDROID extensions
1110// ----------------------------------------------------------------------------
1111
Mathias Agopian4b9511c2011-11-13 23:52:47 -08001112/* ANDROID extensions entry-point go here */
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001113
1114// ----------------------------------------------------------------------------
1115// NVIDIA extensions
1116// ----------------------------------------------------------------------------
1117EGLuint64NV eglGetSystemTimeFrequencyNV()
1118{
1119 clearError();
1120
1121 if (egl_init_drivers() == EGL_FALSE) {
1122 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1123 }
1124
1125 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001126 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001127
Mathias Agopianada798b2012-02-13 17:09:30 -08001128 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1129 return cnx->egl.eglGetSystemTimeFrequencyNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001130 }
1131
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001132 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001133}
1134
1135EGLuint64NV eglGetSystemTimeNV()
1136{
1137 clearError();
1138
1139 if (egl_init_drivers() == EGL_FALSE) {
1140 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1141 }
1142
1143 EGLuint64NV ret = 0;
Mathias Agopianada798b2012-02-13 17:09:30 -08001144 egl_connection_t* const cnx = &gEGLImpl;
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001145
Mathias Agopianada798b2012-02-13 17:09:30 -08001146 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1147 return cnx->egl.eglGetSystemTimeNV();
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001148 }
1149
Mathias Agopian0e8bbee2011-10-05 19:15:05 -07001150 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
Jonas Yang1c3d72a2011-08-26 20:04:39 +08001151}