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 " 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();
475 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
478 return egl::success(EGL_TRUE);
480 catch(std::bad_alloc&)
482 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
486 EGLBoolean __stdcall eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value)
488 TRACE("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, void **value = 0x%0.8p)",
489 dpy, surface, attribute, value);
493 egl::Display *display = static_cast<egl::Display*>(dpy);
494 egl::Surface *eglSurface = (egl::Surface*)surface;
496 if (!validateSurface(display, eglSurface))
501 if (surface == EGL_NO_SURFACE)
503 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
508 case EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE:
510 rx::SwapChain *swapchain = eglSurface->getSwapChain();
511 *value = (void*) (swapchain ? swapchain->getShareHandle() : NULL);
515 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
518 return egl::success(EGL_TRUE);
520 catch(std::bad_alloc&)
522 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
526 EGLBoolean __stdcall eglBindAPI(EGLenum api)
528 EVENT("(EGLenum api = 0x%X)", api);
536 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE); // Not supported by this implementation
537 case EGL_OPENGL_ES_API:
540 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
543 egl::setCurrentAPI(api);
545 return egl::success(EGL_TRUE);
547 catch(std::bad_alloc&)
549 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
553 EGLenum __stdcall eglQueryAPI(void)
559 EGLenum API = egl::getCurrentAPI();
561 return egl::success(API);
563 catch(std::bad_alloc&)
565 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
569 EGLBoolean __stdcall eglWaitClient(void)
575 UNIMPLEMENTED(); // FIXME
577 return egl::success(0);
579 catch(std::bad_alloc&)
581 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
585 EGLBoolean __stdcall eglReleaseThread(void)
591 eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
593 return egl::success(EGL_TRUE);
595 catch(std::bad_alloc&)
597 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
601 EGLSurface __stdcall eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
603 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLenum buftype = 0x%X, EGLClientBuffer buffer = 0x%0.8p, "
604 "EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
605 dpy, buftype, buffer, config, attrib_list);
609 egl::Display *display = static_cast<egl::Display*>(dpy);
611 if (!validateConfig(display, config))
613 return EGL_NO_SURFACE;
616 if (buftype != EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE || !buffer)
618 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
621 return display->createOffscreenSurface(config, (HANDLE)buffer, attrib_list);
623 catch(std::bad_alloc&)
625 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
629 EGLBoolean __stdcall eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
631 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint value = %d)",
632 dpy, surface, attribute, value);
636 egl::Display *display = static_cast<egl::Display*>(dpy);
637 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
639 if (!validateSurface(display, eglSurface))
644 UNIMPLEMENTED(); // FIXME
646 return egl::success(EGL_TRUE);
648 catch(std::bad_alloc&)
650 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
654 EGLBoolean __stdcall eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
656 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
660 egl::Display *display = static_cast<egl::Display*>(dpy);
661 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
663 if (!validateSurface(display, eglSurface))
668 if (buffer != EGL_BACK_BUFFER)
670 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
673 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
675 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
678 if (eglSurface->getBoundTexture())
680 return egl::error(EGL_BAD_ACCESS, EGL_FALSE);
683 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
685 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
688 if (!glBindTexImage(eglSurface))
690 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
693 return egl::success(EGL_TRUE);
695 catch(std::bad_alloc&)
697 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
701 EGLBoolean __stdcall eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
703 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
707 egl::Display *display = static_cast<egl::Display*>(dpy);
708 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
710 if (!validateSurface(display, eglSurface))
715 if (buffer != EGL_BACK_BUFFER)
717 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
720 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
722 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
725 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
727 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
730 gl::Texture2D *texture = eglSurface->getBoundTexture();
734 texture->releaseTexImage();
737 return egl::success(EGL_TRUE);
739 catch(std::bad_alloc&)
741 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
745 EGLBoolean __stdcall eglSwapInterval(EGLDisplay dpy, EGLint interval)
747 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint interval = %d)", dpy, interval);
751 egl::Display *display = static_cast<egl::Display*>(dpy);
753 if (!validateDisplay(display))
758 egl::Surface *draw_surface = static_cast<egl::Surface*>(egl::getCurrentDrawSurface());
760 if (draw_surface == NULL)
762 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
765 draw_surface->setSwapInterval(interval);
767 return egl::success(EGL_TRUE);
769 catch(std::bad_alloc&)
771 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
775 EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
777 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLContext share_context = 0x%0.8p, "
778 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, share_context, attrib_list);
782 // Get the requested client version (default is 1) and check it is two.
783 EGLint client_version = 1;
784 bool reset_notification = false;
785 bool robust_access = false;
789 for (const EGLint* attribute = attrib_list; attribute[0] != EGL_NONE; attribute += 2)
791 switch (attribute[0])
793 case EGL_CONTEXT_CLIENT_VERSION:
794 client_version = attribute[1];
796 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
797 if (attribute[1] == EGL_TRUE)
799 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT); // Unimplemented
800 // robust_access = true;
802 else if (attribute[1] != EGL_FALSE)
803 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
805 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
806 if (attribute[1] == EGL_LOSE_CONTEXT_ON_RESET_EXT)
807 reset_notification = true;
808 else if (attribute[1] != EGL_NO_RESET_NOTIFICATION_EXT)
809 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
812 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
817 if (client_version != 2)
819 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
822 gl::Context *sharedContextPtr = (share_context != EGL_NO_CONTEXT ? static_cast<gl::Context*>(share_context) : NULL);
824 if (sharedContextPtr != NULL && sharedContextPtr->isResetNotificationEnabled() != reset_notification)
826 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
829 egl::Display *display = static_cast<egl::Display*>(dpy);
831 // Can not share contexts between displays
832 if (sharedContextPtr != NULL && sharedContextPtr->getRenderer() != display->getRenderer())
834 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
837 if (!validateConfig(display, config))
839 return EGL_NO_CONTEXT;
842 EGLContext context = display->createContext(config, static_cast<gl::Context*>(share_context), reset_notification, robust_access);
845 return egl::success(context);
847 return egl::error(EGL_CONTEXT_LOST, EGL_NO_CONTEXT);
849 catch(std::bad_alloc&)
851 return egl::error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
855 EGLBoolean __stdcall eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
857 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p)", dpy, ctx);
861 egl::Display *display = static_cast<egl::Display*>(dpy);
862 gl::Context *context = static_cast<gl::Context*>(ctx);
864 if (!validateContext(display, context))
869 if (ctx == EGL_NO_CONTEXT)
871 return egl::error(EGL_BAD_CONTEXT, EGL_FALSE);
874 display->destroyContext(context);
876 return egl::success(EGL_TRUE);
878 catch(std::bad_alloc&)
880 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
884 EGLBoolean __stdcall eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
886 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
887 dpy, draw, read, ctx);
891 egl::Display *display = static_cast<egl::Display*>(dpy);
892 gl::Context *context = static_cast<gl::Context*>(ctx);
894 if (ctx != EGL_NO_CONTEXT && !validateContext(display, context))
899 if (dpy != EGL_NO_DISPLAY)
901 rx::Renderer *renderer = display->getRenderer();
902 if (renderer->testDeviceLost(true))
907 if (renderer->isDeviceLost())
909 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
913 if ((draw != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(draw))) ||
914 (read != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(read))))
921 UNIMPLEMENTED(); // FIXME
924 egl::setCurrentDisplay(dpy);
925 egl::setCurrentDrawSurface(draw);
926 egl::setCurrentReadSurface(read);
928 glMakeCurrent(context, display, static_cast<egl::Surface*>(draw));
930 return egl::success(EGL_TRUE);
932 catch(std::bad_alloc&)
934 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
938 EGLContext __stdcall eglGetCurrentContext(void)
944 EGLContext context = glGetCurrentContext();
946 return egl::success(context);
948 catch(std::bad_alloc&)
950 return egl::error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
954 EGLSurface __stdcall eglGetCurrentSurface(EGLint readdraw)
956 EVENT("(EGLint readdraw = %d)", readdraw);
960 if (readdraw == EGL_READ)
962 EGLSurface read = egl::getCurrentReadSurface();
963 return egl::success(read);
965 else if (readdraw == EGL_DRAW)
967 EGLSurface draw = egl::getCurrentDrawSurface();
968 return egl::success(draw);
972 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
975 catch(std::bad_alloc&)
977 return egl::error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
981 EGLDisplay __stdcall eglGetCurrentDisplay(void)
987 EGLDisplay dpy = egl::getCurrentDisplay();
989 return egl::success(dpy);
991 catch(std::bad_alloc&)
993 return egl::error(EGL_BAD_ALLOC, EGL_NO_DISPLAY);
997 EGLBoolean __stdcall eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
999 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
1000 dpy, ctx, attribute, value);
1004 egl::Display *display = static_cast<egl::Display*>(dpy);
1005 gl::Context *context = static_cast<gl::Context*>(ctx);
1007 if (!validateContext(display, context))
1012 UNIMPLEMENTED(); // FIXME
1014 return egl::success(0);
1016 catch(std::bad_alloc&)
1018 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1022 EGLBoolean __stdcall eglWaitGL(void)
1028 UNIMPLEMENTED(); // FIXME
1030 return egl::success(0);
1032 catch(std::bad_alloc&)
1034 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1038 EGLBoolean __stdcall eglWaitNative(EGLint engine)
1040 EVENT("(EGLint engine = %d)", engine);
1044 UNIMPLEMENTED(); // FIXME
1046 return egl::success(0);
1048 catch(std::bad_alloc&)
1050 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1054 EGLBoolean __stdcall eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1056 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
1060 egl::Display *display = static_cast<egl::Display*>(dpy);
1061 egl::Surface *eglSurface = (egl::Surface*)surface;
1063 if (!validateSurface(display, eglSurface))
1068 if (display->getRenderer()->isDeviceLost())
1070 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1073 if (surface == EGL_NO_SURFACE)
1075 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
1078 if (eglSurface->swap())
1080 return egl::success(EGL_TRUE);
1083 catch(std::bad_alloc&)
1085 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1091 EGLBoolean __stdcall eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
1093 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLNativePixmapType target = 0x%0.8p)", dpy, surface, target);
1097 egl::Display *display = static_cast<egl::Display*>(dpy);
1098 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
1100 if (!validateSurface(display, eglSurface))
1105 if (display->getRenderer()->isDeviceLost())
1107 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1110 UNIMPLEMENTED(); // FIXME
1112 return egl::success(0);
1114 catch(std::bad_alloc&)
1116 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1120 EGLBoolean __stdcall eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height)
1122 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);
1126 if (x < 0 || y < 0 || width < 0 || height < 0)
1128 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
1131 egl::Display *display = static_cast<egl::Display*>(dpy);
1132 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
1134 if (!validateSurface(display, eglSurface))
1139 if (display->getRenderer()->isDeviceLost())
1141 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
1144 if (surface == EGL_NO_SURFACE)
1146 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
1149 if (eglSurface->postSubBuffer(x, y, width, height))
1151 return egl::success(EGL_TRUE);
1154 catch(std::bad_alloc&)
1156 return egl::error(EGL_BAD_ALLOC, EGL_FALSE);
1162 __eglMustCastToProperFunctionPointerType __stdcall eglGetProcAddress(const char *procname)
1164 EVENT("(const char *procname = \"%s\")", procname);
1171 __eglMustCastToProperFunctionPointerType address;
1174 static const Extension eglExtensions[] =
1176 {"eglQuerySurfacePointerANGLE", (__eglMustCastToProperFunctionPointerType)eglQuerySurfacePointerANGLE},
1177 {"eglPostSubBufferNV", (__eglMustCastToProperFunctionPointerType)eglPostSubBufferNV},
1181 for (unsigned int ext = 0; ext < ArraySize(eglExtensions); ext++)
1183 if (strcmp(procname, eglExtensions[ext].name) == 0)
1185 return (__eglMustCastToProperFunctionPointerType)eglExtensions[ext].address;
1189 return glGetProcAddress(procname);
1191 catch(std::bad_alloc&)
1193 return egl::error(EGL_BAD_ALLOC, (__eglMustCastToProperFunctionPointerType)NULL);