2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // libEGL.cpp: Implements the exported EGL functions.
11 #include "common/debug.h"
12 #include "common/version.h"
13 #include "libGLESv2/Context.h"
14 #include "libGLESv2/Texture.h"
15 #include "libGLESv2/main.h"
16 #include "libGLESv2/renderer/SwapChain.h"
18 #include "libEGL/main.h"
19 #include "libEGL/Display.h"
20 #include "libEGL/Surface.h"
22 bool validateDisplay(egl::Display *display)
24 if (display == EGL_NO_DISPLAY)
26 return egl::error(EGL_BAD_DISPLAY, false);
29 if (!display->isInitialized())
31 return egl::error(EGL_NOT_INITIALIZED, false);
37 bool validateConfig(egl::Display *display, EGLConfig config)
39 if (!validateDisplay(display))
44 if (!display->isValidConfig(config))
46 return egl::error(EGL_BAD_CONFIG, false);
52 bool validateContext(egl::Display *display, gl::Context *context)
54 if (!validateDisplay(display))
59 if (!display->isValidContext(context))
61 return egl::error(EGL_BAD_CONTEXT, false);
67 bool validateSurface(egl::Display *display, egl::Surface *surface)
69 if (!validateDisplay(display))
74 if (!display->isValidSurface(surface))
76 return egl::error(EGL_BAD_SURFACE, false);
84 EGLint __stdcall eglGetError(void)
88 EGLint error = egl::getCurrentError();
90 if (error != EGL_SUCCESS)
92 egl::setCurrentError(EGL_SUCCESS);
98 EGLDisplay __stdcall eglGetDisplay(EGLNativeDisplayType display_id)
100 EVENT("(EGLNativeDisplayType display_id = 0x%0.8p)", display_id);
104 return egl::Display::getDisplay(display_id);
106 catch(std::bad_alloc&)
108 return egl::error(EGL_BAD_ALLOC, EGL_NO_DISPLAY);
112 EGLBoolean __stdcall eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
114 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint *major = 0x%0.8p, EGLint *minor = 0x%0.8p)",
119 if (dpy == EGL_NO_DISPLAY)
121 return egl::error(EGL_BAD_DISPLAY, EGL_FALSE);
124 egl::Display *display = static_cast<egl::Display*>(dpy);
126 if (!display->initialize())
128 return egl::error(EGL_NOT_INITIALIZED, EGL_FALSE);
131 if (major) *major = 1;
132 if (minor) *minor = 4;
134 return egl::success(EGL_TRUE);
136 catch(std::bad_alloc&)
138 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
142 EGLBoolean __stdcall eglTerminate(EGLDisplay dpy)
144 EVENT("(EGLDisplay dpy = 0x%0.8p)", dpy);
148 if (dpy == EGL_NO_DISPLAY)
150 return egl::error(EGL_BAD_DISPLAY, EGL_FALSE);
153 egl::Display *display = static_cast<egl::Display*>(dpy);
155 display->terminate();
157 return egl::success(EGL_TRUE);
159 catch(std::bad_alloc&)
161 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
165 const char *__stdcall eglQueryString(EGLDisplay dpy, EGLint name)
167 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint name = %d)", dpy, name);
171 egl::Display *display = static_cast<egl::Display*>(dpy);
173 if (!validateDisplay(display))
180 case EGL_CLIENT_APIS:
181 return egl::success("OpenGL_ES");
183 return egl::success(display->getExtensionString());
185 return egl::success(display->getVendorString());
187 return egl::success("1.4 (ANGLE " ANGLE_VERSION_STRING ")");
190 return egl::error(EGL_BAD_PARAMETER, (const char*)NULL);
192 catch(std::bad_alloc&)
194 return egl::error(EGL_BAD_ALLOC, (const char*)NULL);
198 EGLBoolean __stdcall eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
200 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig *configs = 0x%0.8p, "
201 "EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
202 dpy, configs, config_size, num_config);
206 egl::Display *display = static_cast<egl::Display*>(dpy);
208 if (!validateDisplay(display))
215 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
218 const EGLint attribList[] = {EGL_NONE};
220 if (!display->getConfigs(configs, attribList, config_size, num_config))
222 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
225 return egl::success(EGL_TRUE);
227 catch(std::bad_alloc&)
229 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
233 EGLBoolean __stdcall eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
235 EVENT("(EGLDisplay dpy = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p, "
236 "EGLConfig *configs = 0x%0.8p, EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
237 dpy, attrib_list, configs, config_size, num_config);
241 egl::Display *display = static_cast<egl::Display*>(dpy);
243 if (!validateDisplay(display))
250 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
253 const EGLint attribList[] = {EGL_NONE};
257 attrib_list = attribList;
260 display->getConfigs(configs, attrib_list, config_size, num_config);
262 return egl::success(EGL_TRUE);
264 catch(std::bad_alloc&)
266 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
270 EGLBoolean __stdcall eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
272 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
273 dpy, config, attribute, value);
277 egl::Display *display = static_cast<egl::Display*>(dpy);
279 if (!validateConfig(display, config))
284 if (!display->getConfigAttrib(config, attribute, value))
286 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
289 return egl::success(EGL_TRUE);
291 catch(std::bad_alloc&)
293 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
297 EGLSurface __stdcall eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
299 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativeWindowType win = 0x%0.8p, "
300 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, win, attrib_list);
304 egl::Display *display = static_cast<egl::Display*>(dpy);
306 if (!validateConfig(display, config))
308 return EGL_NO_SURFACE;
311 HWND window = (HWND)win;
313 if (!IsWindow(window))
315 return egl::error(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
318 return display->createWindowSurface(window, config, attrib_list);
320 catch(std::bad_alloc&)
322 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
326 EGLSurface __stdcall eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
328 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
329 dpy, config, attrib_list);
333 egl::Display *display = static_cast<egl::Display*>(dpy);
335 if (!validateConfig(display, config))
337 return EGL_NO_SURFACE;
340 return display->createOffscreenSurface(config, NULL, attrib_list);
342 catch(std::bad_alloc&)
344 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
348 EGLSurface __stdcall eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
350 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativePixmapType pixmap = 0x%0.8p, "
351 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, pixmap, attrib_list);
355 egl::Display *display = static_cast<egl::Display*>(dpy);
357 if (!validateConfig(display, config))
359 return EGL_NO_SURFACE;
362 UNIMPLEMENTED(); // FIXME
364 return egl::success(EGL_NO_SURFACE);
366 catch(std::bad_alloc&)
368 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
372 EGLBoolean __stdcall eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
374 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
378 egl::Display *display = static_cast<egl::Display*>(dpy);
379 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
381 if (!validateSurface(display, eglSurface))
386 if (surface == EGL_NO_SURFACE)
388 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
391 display->destroySurface((egl::Surface*)surface);
393 return egl::success(EGL_TRUE);
395 catch(std::bad_alloc&)
397 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
401 EGLBoolean __stdcall eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
403 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
404 dpy, surface, attribute, value);
408 egl::Display *display = static_cast<egl::Display*>(dpy);
409 egl::Surface *eglSurface = (egl::Surface*)surface;
411 if (!validateSurface(display, eglSurface))
416 if (surface == EGL_NO_SURFACE)
418 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
423 case EGL_VG_ALPHA_FORMAT:
424 UNIMPLEMENTED(); // FIXME
426 case EGL_VG_COLORSPACE:
427 UNIMPLEMENTED(); // FIXME
430 UNIMPLEMENTED(); // FIXME
433 *value = eglSurface->getHeight();
435 case EGL_HORIZONTAL_RESOLUTION:
436 UNIMPLEMENTED(); // FIXME
438 case EGL_LARGEST_PBUFFER:
439 UNIMPLEMENTED(); // FIXME
441 case EGL_MIPMAP_TEXTURE:
442 UNIMPLEMENTED(); // FIXME
444 case EGL_MIPMAP_LEVEL:
445 UNIMPLEMENTED(); // FIXME
447 case EGL_MULTISAMPLE_RESOLVE:
448 UNIMPLEMENTED(); // FIXME
450 case EGL_PIXEL_ASPECT_RATIO:
451 UNIMPLEMENTED(); // FIXME
453 case EGL_RENDER_BUFFER:
454 UNIMPLEMENTED(); // FIXME
456 case EGL_SWAP_BEHAVIOR:
457 UNIMPLEMENTED(); // FIXME
459 case EGL_TEXTURE_FORMAT:
460 UNIMPLEMENTED(); // FIXME
462 case EGL_TEXTURE_TARGET:
463 UNIMPLEMENTED(); // FIXME
465 case EGL_VERTICAL_RESOLUTION:
466 UNIMPLEMENTED(); // FIXME
469 *value = eglSurface->getWidth();
471 case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
472 *value = eglSurface->isPostSubBufferSupported();
474 case EGL_FIXED_SIZE_ANGLE:
475 *value = eglSurface->isFixedSize();
478 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
481 return egl::success(EGL_TRUE);
483 catch(std::bad_alloc&)
485 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
489 EGLBoolean __stdcall eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value)
491 TRACE("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, void **value = 0x%0.8p)",
492 dpy, surface, attribute, value);
496 egl::Display *display = static_cast<egl::Display*>(dpy);
497 egl::Surface *eglSurface = (egl::Surface*)surface;
499 if (!validateSurface(display, eglSurface))
504 if (surface == EGL_NO_SURFACE)
506 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
511 case EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE:
513 rx::SwapChain *swapchain = eglSurface->getSwapChain();
514 *value = (void*) (swapchain ? swapchain->getShareHandle() : NULL);
518 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
521 return egl::success(EGL_TRUE);
523 catch(std::bad_alloc&)
525 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
529 EGLBoolean __stdcall eglBindAPI(EGLenum api)
531 EVENT("(EGLenum api = 0x%X)", api);
539 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE); // Not supported by this implementation
540 case EGL_OPENGL_ES_API:
543 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
546 egl::setCurrentAPI(api);
548 return egl::success(EGL_TRUE);
550 catch(std::bad_alloc&)
552 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
556 EGLenum __stdcall eglQueryAPI(void)
562 EGLenum API = egl::getCurrentAPI();
564 return egl::success(API);
566 catch(std::bad_alloc&)
568 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
572 EGLBoolean __stdcall eglWaitClient(void)
578 UNIMPLEMENTED(); // FIXME
580 return egl::success(0);
582 catch(std::bad_alloc&)
584 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
588 EGLBoolean __stdcall eglReleaseThread(void)
594 eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
596 return egl::success(EGL_TRUE);
598 catch(std::bad_alloc&)
600 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
604 EGLSurface __stdcall eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
606 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLenum buftype = 0x%X, EGLClientBuffer buffer = 0x%0.8p, "
607 "EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
608 dpy, buftype, buffer, config, attrib_list);
612 egl::Display *display = static_cast<egl::Display*>(dpy);
614 if (!validateConfig(display, config))
616 return EGL_NO_SURFACE;
619 if (buftype != EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE || !buffer)
621 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
624 return display->createOffscreenSurface(config, (HANDLE)buffer, attrib_list);
626 catch(std::bad_alloc&)
628 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
632 EGLBoolean __stdcall eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
634 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint value = %d)",
635 dpy, surface, attribute, value);
639 egl::Display *display = static_cast<egl::Display*>(dpy);
640 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
642 if (!validateSurface(display, eglSurface))
647 UNIMPLEMENTED(); // FIXME
649 return egl::success(EGL_TRUE);
651 catch(std::bad_alloc&)
653 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
657 EGLBoolean __stdcall eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
659 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
663 egl::Display *display = static_cast<egl::Display*>(dpy);
664 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
666 if (!validateSurface(display, eglSurface))
671 if (buffer != EGL_BACK_BUFFER)
673 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
676 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
678 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
681 if (eglSurface->getBoundTexture())
683 return egl::error(EGL_BAD_ACCESS, EGL_FALSE);
686 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
688 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
691 if (!glBindTexImage(eglSurface))
693 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
696 return egl::success(EGL_TRUE);
698 catch(std::bad_alloc&)
700 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
704 EGLBoolean __stdcall eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
706 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
710 egl::Display *display = static_cast<egl::Display*>(dpy);
711 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
713 if (!validateSurface(display, eglSurface))
718 if (buffer != EGL_BACK_BUFFER)
720 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
723 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
725 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
728 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
730 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
733 gl::Texture2D *texture = eglSurface->getBoundTexture();
737 texture->releaseTexImage();
740 return egl::success(EGL_TRUE);
742 catch(std::bad_alloc&)
744 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
748 EGLBoolean __stdcall eglSwapInterval(EGLDisplay dpy, EGLint interval)
750 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint interval = %d)", dpy, interval);
754 egl::Display *display = static_cast<egl::Display*>(dpy);
756 if (!validateDisplay(display))
761 egl::Surface *draw_surface = static_cast<egl::Surface*>(egl::getCurrentDrawSurface());
763 if (draw_surface == NULL)
765 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
768 draw_surface->setSwapInterval(interval);
770 return egl::success(EGL_TRUE);
772 catch(std::bad_alloc&)
774 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
778 EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
780 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLContext share_context = 0x%0.8p, "
781 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, share_context, attrib_list);
785 // Get the requested client version (default is 1) and check it is two.
786 EGLint client_version = 1;
787 bool reset_notification = false;
788 bool robust_access = false;
792 for (const EGLint* attribute = attrib_list; attribute[0] != EGL_NONE; attribute += 2)
794 switch (attribute[0])
796 case EGL_CONTEXT_CLIENT_VERSION:
797 client_version = attribute[1];
799 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
800 if (attribute[1] == EGL_TRUE)
802 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT); // Unimplemented
803 // robust_access = true;
805 else if (attribute[1] != EGL_FALSE)
806 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
808 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
809 if (attribute[1] == EGL_LOSE_CONTEXT_ON_RESET_EXT)
810 reset_notification = true;
811 else if (attribute[1] != EGL_NO_RESET_NOTIFICATION_EXT)
812 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
815 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
820 if (client_version != 2)
822 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
825 gl::Context *sharedContextPtr = (share_context != EGL_NO_CONTEXT ? static_cast<gl::Context*>(share_context) : NULL);
827 if (sharedContextPtr != NULL && sharedContextPtr->isResetNotificationEnabled() != reset_notification)
829 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
832 egl::Display *display = static_cast<egl::Display*>(dpy);
834 // Can not share contexts between displays
835 if (sharedContextPtr != NULL && sharedContextPtr->getRenderer() != display->getRenderer())
837 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
840 if (!validateConfig(display, config))
842 return EGL_NO_CONTEXT;
845 EGLContext context = display->createContext(config, static_cast<gl::Context*>(share_context), reset_notification, robust_access);
848 return egl::success(context);
850 return egl::error(EGL_CONTEXT_LOST, EGL_NO_CONTEXT);
852 catch(std::bad_alloc&)
854 return egl::error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
858 EGLBoolean __stdcall eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
860 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p)", dpy, ctx);
864 egl::Display *display = static_cast<egl::Display*>(dpy);
865 gl::Context *context = static_cast<gl::Context*>(ctx);
867 if (!validateContext(display, context))
872 if (ctx == EGL_NO_CONTEXT)
874 return egl::error(EGL_BAD_CONTEXT, EGL_FALSE);
877 display->destroyContext(context);
879 return egl::success(EGL_TRUE);
881 catch(std::bad_alloc&)
883 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
887 EGLBoolean __stdcall eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
889 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
890 dpy, draw, read, ctx);
894 egl::Display *display = static_cast<egl::Display*>(dpy);
895 gl::Context *context = static_cast<gl::Context*>(ctx);
897 if (ctx != EGL_NO_CONTEXT && !validateContext(display, context))
902 if (dpy != EGL_NO_DISPLAY)
904 rx::Renderer *renderer = display->getRenderer();
905 if (renderer->testDeviceLost(true))
910 if (renderer->isDeviceLost())
912 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
916 if ((draw != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(draw))) ||
917 (read != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(read))))
924 UNIMPLEMENTED(); // FIXME
927 egl::setCurrentDisplay(dpy);
928 egl::setCurrentDrawSurface(draw);
929 egl::setCurrentReadSurface(read);
931 glMakeCurrent(context, display, static_cast<egl::Surface*>(draw));
933 return egl::success(EGL_TRUE);
935 catch(std::bad_alloc&)
937 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
941 EGLContext __stdcall eglGetCurrentContext(void)
947 EGLContext context = glGetCurrentContext();
949 return egl::success(context);
951 catch(std::bad_alloc&)
953 return egl::error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
957 EGLSurface __stdcall eglGetCurrentSurface(EGLint readdraw)
959 EVENT("(EGLint readdraw = %d)", readdraw);
963 if (readdraw == EGL_READ)
965 EGLSurface read = egl::getCurrentReadSurface();
966 return egl::success(read);
968 else if (readdraw == EGL_DRAW)
970 EGLSurface draw = egl::getCurrentDrawSurface();
971 return egl::success(draw);
975 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
978 catch(std::bad_alloc&)
980 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
984 EGLDisplay __stdcall eglGetCurrentDisplay(void)
990 EGLDisplay dpy = egl::getCurrentDisplay();
992 return egl::success(dpy);
994 catch(std::bad_alloc&)
996 return egl::error(EGL_BAD_ALLOC, EGL_NO_DISPLAY);
1000 EGLBoolean __stdcall eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
1002 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
1003 dpy, ctx, attribute, value);
1007 egl::Display *display = static_cast<egl::Display*>(dpy);
1008 gl::Context *context = static_cast<gl::Context*>(ctx);
1010 if (!validateContext(display, context))
1015 UNIMPLEMENTED(); // FIXME
1017 return egl::success(0);
1019 catch(std::bad_alloc&)
1021 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1025 EGLBoolean __stdcall eglWaitGL(void)
1031 UNIMPLEMENTED(); // FIXME
1033 return egl::success(0);
1035 catch(std::bad_alloc&)
1037 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1041 EGLBoolean __stdcall eglWaitNative(EGLint engine)
1043 EVENT("(EGLint engine = %d)", engine);
1047 UNIMPLEMENTED(); // FIXME
1049 return egl::success(0);
1051 catch(std::bad_alloc&)
1053 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1057 EGLBoolean __stdcall eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1059 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
1063 egl::Display *display = static_cast<egl::Display*>(dpy);
1064 egl::Surface *eglSurface = (egl::Surface*)surface;
1066 if (!validateSurface(display, eglSurface))
1071 if (display->getRenderer()->isDeviceLost())
1073 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1076 if (surface == EGL_NO_SURFACE)
1078 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
1081 if (eglSurface->swap())
1083 return egl::success(EGL_TRUE);
1086 catch(std::bad_alloc&)
1088 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1094 EGLBoolean __stdcall eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1096 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLNativePixmapType target = 0x%0.8p)", dpy, surface, target);
1100 egl::Display *display = static_cast<egl::Display*>(dpy);
1101 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
1103 if (!validateSurface(display, eglSurface))
1108 if (display->getRenderer()->isDeviceLost())
1110 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1113 UNIMPLEMENTED(); // FIXME
1115 return egl::success(0);
1117 catch(std::bad_alloc&)
1119 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1123 EGLBoolean __stdcall eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height)
1125 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint x = %d, EGLint y = %d, EGLint width = %d, EGLint height = %d)", dpy, surface, x, y, width, height);
1129 if (x < 0 || y < 0 || width < 0 || height < 0)
1131 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
1134 egl::Display *display = static_cast<egl::Display*>(dpy);
1135 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
1137 if (!validateSurface(display, eglSurface))
1142 if (display->getRenderer()->isDeviceLost())
1144 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1147 if (surface == EGL_NO_SURFACE)
1149 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
1152 if (eglSurface->postSubBuffer(x, y, width, height))
1154 return egl::success(EGL_TRUE);
1157 catch(std::bad_alloc&)
1159 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1165 __eglMustCastToProperFunctionPointerType __stdcall eglGetProcAddress(const char *procname)
1167 EVENT("(const char *procname = \"%s\")", procname);
1174 __eglMustCastToProperFunctionPointerType address;
1177 static const Extension eglExtensions[] =
1179 {"eglQuerySurfacePointerANGLE", (__eglMustCastToProperFunctionPointerType)eglQuerySurfacePointerANGLE},
1180 {"eglPostSubBufferNV", (__eglMustCastToProperFunctionPointerType)eglPostSubBufferNV},
1184 for (unsigned int ext = 0; ext < ArraySize(eglExtensions); ext++)
1186 if (strcmp(procname, eglExtensions[ext].name) == 0)
1188 return (__eglMustCastToProperFunctionPointerType)eglExtensions[ext].address;
1192 return glGetProcAddress(procname);
1194 catch(std::bad_alloc&)
1196 return egl::error(EGL_BAD_ALLOC, (__eglMustCastToProperFunctionPointerType)NULL);