2 // Copyright (c) 2002-2014 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 #include "common/NativeWindow.h"
24 bool validateDisplay(egl::Display *display)
26 if (display == EGL_NO_DISPLAY)
28 return egl::error(EGL_BAD_DISPLAY, false);
31 if (!display->isInitialized())
33 return egl::error(EGL_NOT_INITIALIZED, false);
39 bool validateConfig(egl::Display *display, EGLConfig config)
41 if (!validateDisplay(display))
46 if (!display->isValidConfig(config))
48 return egl::error(EGL_BAD_CONFIG, false);
54 bool validateContext(egl::Display *display, gl::Context *context)
56 if (!validateDisplay(display))
61 if (!display->isValidContext(context))
63 return egl::error(EGL_BAD_CONTEXT, false);
69 bool validateSurface(egl::Display *display, egl::Surface *surface)
71 if (!validateDisplay(display))
76 if (!display->isValidSurface(surface))
78 return egl::error(EGL_BAD_SURFACE, false);
86 EGLint __stdcall eglGetError(void)
90 EGLint error = egl::getCurrentError();
92 if (error != EGL_SUCCESS)
94 egl::setCurrentError(EGL_SUCCESS);
100 EGLDisplay __stdcall eglGetDisplay(EGLNativeDisplayType display_id)
102 EVENT("(EGLNativeDisplayType display_id = 0x%0.8p)", display_id);
104 return egl::Display::getDisplay(display_id, EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE);
107 EGLDisplay __stdcall eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list)
109 EVENT("(EGLenum platform = %d, void* native_display = 0x%0.8p, const EGLint* attrib_list = 0x%0.8p)",
110 platform, native_display, attrib_list);
114 case EGL_PLATFORM_ANGLE_ANGLE:
118 return egl::error(EGL_BAD_CONFIG, EGL_NO_DISPLAY);
121 EGLNativeDisplayType displayId = static_cast<EGLNativeDisplayType>(native_display);
123 #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
124 // Validate the display device context
125 if (WindowFromDC(displayId) == NULL)
127 return egl::success(EGL_NO_DISPLAY);
131 EGLint requestedDisplayType = EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE;
134 for (const EGLint *curAttrib = attrib_list; curAttrib[0] != EGL_NONE; curAttrib += 2)
136 switch (curAttrib[0])
138 case EGL_PLATFORM_ANGLE_TYPE_ANGLE:
139 requestedDisplayType = curAttrib[1];
148 switch (requestedDisplayType)
150 case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE:
153 case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE:
154 case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
155 case EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE:
156 if (!egl::Display::supportsPlatformD3D())
158 return egl::success(EGL_NO_DISPLAY);
162 case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
163 case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
164 if (!egl::Display::supportsPlatformOpenGL())
166 return egl::success(EGL_NO_DISPLAY);
171 return egl::success(EGL_NO_DISPLAY);
174 return egl::Display::getDisplay(displayId, requestedDisplayType);
177 EGLBoolean __stdcall eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
179 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint *major = 0x%0.8p, EGLint *minor = 0x%0.8p)",
182 if (dpy == EGL_NO_DISPLAY)
184 return egl::error(EGL_BAD_DISPLAY, EGL_FALSE);
187 egl::Display *display = static_cast<egl::Display*>(dpy);
189 if (!display->initialize())
191 return egl::error(EGL_NOT_INITIALIZED, EGL_FALSE);
194 if (major) *major = 1;
195 if (minor) *minor = 4;
197 return egl::success(EGL_TRUE);
200 EGLBoolean __stdcall eglTerminate(EGLDisplay dpy)
202 EVENT("(EGLDisplay dpy = 0x%0.8p)", dpy);
204 if (dpy == EGL_NO_DISPLAY)
206 return egl::error(EGL_BAD_DISPLAY, EGL_FALSE);
209 egl::Display *display = static_cast<egl::Display*>(dpy);
211 display->terminate();
213 return egl::success(EGL_TRUE);
216 const char *__stdcall eglQueryString(EGLDisplay dpy, EGLint name)
218 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint name = %d)", dpy, name);
220 egl::Display *display = static_cast<egl::Display*>(dpy);
221 if (!(display == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) && !validateDisplay(display))
228 case EGL_CLIENT_APIS:
229 return egl::success("OpenGL_ES");
231 return egl::success(egl::Display::getExtensionString(display));
233 return egl::success(display->getVendorString());
235 return egl::success("1.4 (ANGLE " ANGLE_VERSION_STRING ")");
237 return egl::error(EGL_BAD_PARAMETER, (const char*)NULL);
241 EGLBoolean __stdcall eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
243 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig *configs = 0x%0.8p, "
244 "EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
245 dpy, configs, config_size, num_config);
247 egl::Display *display = static_cast<egl::Display*>(dpy);
249 if (!validateDisplay(display))
256 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
259 const EGLint attribList[] = {EGL_NONE};
261 if (!display->getConfigs(configs, attribList, config_size, num_config))
263 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
266 return egl::success(EGL_TRUE);
269 EGLBoolean __stdcall eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
271 EVENT("(EGLDisplay dpy = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p, "
272 "EGLConfig *configs = 0x%0.8p, EGLint config_size = %d, EGLint *num_config = 0x%0.8p)",
273 dpy, attrib_list, configs, config_size, num_config);
275 egl::Display *display = static_cast<egl::Display*>(dpy);
277 if (!validateDisplay(display))
284 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
287 const EGLint attribList[] = {EGL_NONE};
291 attrib_list = attribList;
294 display->getConfigs(configs, attrib_list, config_size, num_config);
296 return egl::success(EGL_TRUE);
299 EGLBoolean __stdcall eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
301 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
302 dpy, config, attribute, value);
304 egl::Display *display = static_cast<egl::Display*>(dpy);
306 if (!validateConfig(display, config))
311 if (!display->getConfigAttrib(config, attribute, value))
313 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
316 return egl::success(EGL_TRUE);
319 EGLSurface __stdcall eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
321 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativeWindowType win = 0x%0.8p, "
322 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, win, attrib_list);
324 egl::Display *display = static_cast<egl::Display*>(dpy);
326 if (!validateConfig(display, config))
328 return EGL_NO_SURFACE;
331 if (!isValidEGLNativeWindowType(win))
333 return egl::error(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
336 return display->createWindowSurface(win, config, attrib_list);
339 EGLSurface __stdcall eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
341 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
342 dpy, config, attrib_list);
344 egl::Display *display = static_cast<egl::Display*>(dpy);
346 if (!validateConfig(display, config))
348 return EGL_NO_SURFACE;
351 return display->createOffscreenSurface(config, NULL, attrib_list);
354 EGLSurface __stdcall eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
356 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLNativePixmapType pixmap = 0x%0.8p, "
357 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, pixmap, attrib_list);
359 egl::Display *display = static_cast<egl::Display*>(dpy);
361 if (!validateConfig(display, config))
363 return EGL_NO_SURFACE;
366 UNIMPLEMENTED(); // FIXME
368 return egl::success(EGL_NO_SURFACE);
371 EGLBoolean __stdcall eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
373 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
375 egl::Display *display = static_cast<egl::Display*>(dpy);
376 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
378 if (!validateSurface(display, eglSurface))
383 if (surface == EGL_NO_SURFACE)
385 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
388 display->destroySurface((egl::Surface*)surface);
390 return egl::success(EGL_TRUE);
393 EGLBoolean __stdcall eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
395 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
396 dpy, surface, attribute, value);
398 egl::Display *display = static_cast<egl::Display*>(dpy);
399 egl::Surface *eglSurface = (egl::Surface*)surface;
401 if (!validateSurface(display, eglSurface))
406 if (surface == EGL_NO_SURFACE)
408 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
413 case EGL_VG_ALPHA_FORMAT:
414 UNIMPLEMENTED(); // FIXME
416 case EGL_VG_COLORSPACE:
417 UNIMPLEMENTED(); // FIXME
420 *value = eglSurface->getConfigID();
423 *value = eglSurface->getHeight();
425 case EGL_HORIZONTAL_RESOLUTION:
426 UNIMPLEMENTED(); // FIXME
428 case EGL_LARGEST_PBUFFER:
429 UNIMPLEMENTED(); // FIXME
431 case EGL_MIPMAP_TEXTURE:
432 UNIMPLEMENTED(); // FIXME
434 case EGL_MIPMAP_LEVEL:
435 UNIMPLEMENTED(); // FIXME
437 case EGL_MULTISAMPLE_RESOLVE:
438 UNIMPLEMENTED(); // FIXME
440 case EGL_PIXEL_ASPECT_RATIO:
441 *value = eglSurface->getPixelAspectRatio();
443 case EGL_RENDER_BUFFER:
444 *value = eglSurface->getRenderBuffer();
446 case EGL_SWAP_BEHAVIOR:
447 *value = eglSurface->getSwapBehavior();
449 case EGL_TEXTURE_FORMAT:
450 *value = eglSurface->getTextureFormat();
452 case EGL_TEXTURE_TARGET:
453 *value = eglSurface->getTextureTarget();
455 case EGL_VERTICAL_RESOLUTION:
456 UNIMPLEMENTED(); // FIXME
459 *value = eglSurface->getWidth();
461 case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
462 *value = eglSurface->isPostSubBufferSupported();
464 case EGL_FIXED_SIZE_ANGLE:
465 *value = eglSurface->isFixedSize();
468 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
471 return egl::success(EGL_TRUE);
474 EGLBoolean __stdcall eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value)
476 TRACE("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, void **value = 0x%0.8p)",
477 dpy, surface, attribute, value);
479 egl::Display *display = static_cast<egl::Display*>(dpy);
480 egl::Surface *eglSurface = (egl::Surface*)surface;
482 if (!validateSurface(display, eglSurface))
487 if (surface == EGL_NO_SURFACE)
489 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
494 case EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE:
496 rx::SwapChain *swapchain = eglSurface->getSwapChain();
497 *value = (void*) (swapchain ? swapchain->getShareHandle() : NULL);
501 return egl::error(EGL_BAD_ATTRIBUTE, EGL_FALSE);
504 return egl::success(EGL_TRUE);
507 EGLBoolean __stdcall eglBindAPI(EGLenum api)
509 EVENT("(EGLenum api = 0x%X)", api);
515 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE); // Not supported by this implementation
516 case EGL_OPENGL_ES_API:
519 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
522 egl::setCurrentAPI(api);
524 return egl::success(EGL_TRUE);
527 EGLenum __stdcall eglQueryAPI(void)
531 EGLenum API = egl::getCurrentAPI();
533 return egl::success(API);
536 EGLBoolean __stdcall eglWaitClient(void)
540 UNIMPLEMENTED(); // FIXME
542 return egl::success(0);
545 EGLBoolean __stdcall eglReleaseThread(void)
549 eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE);
551 return egl::success(EGL_TRUE);
554 EGLSurface __stdcall eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
556 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLenum buftype = 0x%X, EGLClientBuffer buffer = 0x%0.8p, "
557 "EGLConfig config = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)",
558 dpy, buftype, buffer, config, attrib_list);
560 egl::Display *display = static_cast<egl::Display*>(dpy);
562 if (!validateConfig(display, config))
564 return EGL_NO_SURFACE;
567 if (buftype != EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE || !buffer)
569 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
572 return display->createOffscreenSurface(config, (HANDLE)buffer, attrib_list);
575 EGLBoolean __stdcall eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
577 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint attribute = %d, EGLint value = %d)",
578 dpy, surface, attribute, value);
580 egl::Display *display = static_cast<egl::Display*>(dpy);
581 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
583 if (!validateSurface(display, eglSurface))
588 UNIMPLEMENTED(); // FIXME
590 return egl::success(EGL_TRUE);
593 EGLBoolean __stdcall eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
595 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
597 egl::Display *display = static_cast<egl::Display*>(dpy);
598 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
600 if (!validateSurface(display, eglSurface))
605 if (buffer != EGL_BACK_BUFFER)
607 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
610 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
612 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
615 if (eglSurface->getBoundTexture())
617 return egl::error(EGL_BAD_ACCESS, EGL_FALSE);
620 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
622 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
625 if (!glBindTexImage(eglSurface))
627 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
630 return egl::success(EGL_TRUE);
633 EGLBoolean __stdcall eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
635 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);
637 egl::Display *display = static_cast<egl::Display*>(dpy);
638 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
640 if (!validateSurface(display, eglSurface))
645 if (buffer != EGL_BACK_BUFFER)
647 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
650 if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
652 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
655 if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
657 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
660 gl::Texture2D *texture = eglSurface->getBoundTexture();
664 texture->releaseTexImage();
667 return egl::success(EGL_TRUE);
670 EGLBoolean __stdcall eglSwapInterval(EGLDisplay dpy, EGLint interval)
672 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLint interval = %d)", dpy, interval);
674 egl::Display *display = static_cast<egl::Display*>(dpy);
676 if (!validateDisplay(display))
681 egl::Surface *draw_surface = static_cast<egl::Surface*>(egl::getCurrentDrawSurface());
683 if (draw_surface == NULL)
685 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
688 draw_surface->setSwapInterval(interval);
690 return egl::success(EGL_TRUE);
693 EGLContext __stdcall eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
695 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLConfig config = 0x%0.8p, EGLContext share_context = 0x%0.8p, "
696 "const EGLint *attrib_list = 0x%0.8p)", dpy, config, share_context, attrib_list);
698 // Get the requested client version (default is 1) and check it is 2 or 3.
699 EGLint client_version = 1;
700 bool reset_notification = false;
701 bool robust_access = false;
705 for (const EGLint* attribute = attrib_list; attribute[0] != EGL_NONE; attribute += 2)
707 switch (attribute[0])
709 case EGL_CONTEXT_CLIENT_VERSION:
710 client_version = attribute[1];
712 case EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT:
713 if (attribute[1] == EGL_TRUE)
715 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT); // Unimplemented
716 // robust_access = true;
718 else if (attribute[1] != EGL_FALSE)
719 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
721 case EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT:
722 if (attribute[1] == EGL_LOSE_CONTEXT_ON_RESET_EXT)
723 reset_notification = true;
724 else if (attribute[1] != EGL_NO_RESET_NOTIFICATION_EXT)
725 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
728 return egl::error(EGL_BAD_ATTRIBUTE, EGL_NO_CONTEXT);
733 if (client_version != 2 && client_version != 3)
735 return egl::error(EGL_BAD_CONFIG, EGL_NO_CONTEXT);
738 egl::Display *display = static_cast<egl::Display*>(dpy);
742 gl::Context* sharedGLContext = static_cast<gl::Context*>(share_context);
744 if (sharedGLContext->isResetNotificationEnabled() != reset_notification)
746 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
749 if (sharedGLContext->getClientVersion() != client_version)
751 return egl::error(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
754 // Can not share contexts between displays
755 if (sharedGLContext->getRenderer() != display->getRenderer())
757 return egl::error(EGL_BAD_MATCH, EGL_NO_CONTEXT);
761 if (!validateConfig(display, config))
763 return EGL_NO_CONTEXT;
766 return display->createContext(config, client_version, static_cast<gl::Context*>(share_context), reset_notification, robust_access);
769 EGLBoolean __stdcall eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
771 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p)", dpy, ctx);
773 egl::Display *display = static_cast<egl::Display*>(dpy);
774 gl::Context *context = static_cast<gl::Context*>(ctx);
776 if (!validateContext(display, context))
781 if (ctx == EGL_NO_CONTEXT)
783 return egl::error(EGL_BAD_CONTEXT, EGL_FALSE);
786 display->destroyContext(context);
788 return egl::success(EGL_TRUE);
791 EGLBoolean __stdcall eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
793 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
794 dpy, draw, read, ctx);
796 egl::Display *display = static_cast<egl::Display*>(dpy);
797 gl::Context *context = static_cast<gl::Context*>(ctx);
799 bool noContext = (ctx == EGL_NO_CONTEXT);
800 bool noSurface = (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE);
801 if (noContext != noSurface)
803 return egl::error(EGL_BAD_MATCH, EGL_FALSE);
806 if (ctx != EGL_NO_CONTEXT && !validateContext(display, context))
811 if (dpy != EGL_NO_DISPLAY && display->isInitialized())
813 rx::Renderer *renderer = display->getRenderer();
814 if (renderer->testDeviceLost(true))
819 if (renderer->isDeviceLost())
821 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
825 if ((draw != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(draw))) ||
826 (read != EGL_NO_SURFACE && !validateSurface(display, static_cast<egl::Surface*>(read))))
833 UNIMPLEMENTED(); // FIXME
836 egl::setCurrentDisplay(dpy);
837 egl::setCurrentDrawSurface(draw);
838 egl::setCurrentReadSurface(read);
840 glMakeCurrent(context, display, static_cast<egl::Surface*>(draw));
842 return egl::success(EGL_TRUE);
845 EGLContext __stdcall eglGetCurrentContext(void)
849 EGLContext context = glGetCurrentContext();
851 return egl::success(context);
854 EGLSurface __stdcall eglGetCurrentSurface(EGLint readdraw)
856 EVENT("(EGLint readdraw = %d)", readdraw);
858 if (readdraw == EGL_READ)
860 EGLSurface read = egl::getCurrentReadSurface();
861 return egl::success(read);
863 else if (readdraw == EGL_DRAW)
865 EGLSurface draw = egl::getCurrentDrawSurface();
866 return egl::success(draw);
870 return egl::error(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
874 EGLDisplay __stdcall eglGetCurrentDisplay(void)
878 EGLDisplay dpy = egl::getCurrentDisplay();
880 return egl::success(dpy);
883 EGLBoolean __stdcall eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
885 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p, EGLint attribute = %d, EGLint *value = 0x%0.8p)",
886 dpy, ctx, attribute, value);
888 egl::Display *display = static_cast<egl::Display*>(dpy);
889 gl::Context *context = static_cast<gl::Context*>(ctx);
891 if (!validateContext(display, context))
896 UNIMPLEMENTED(); // FIXME
898 return egl::success(0);
901 EGLBoolean __stdcall eglWaitGL(void)
905 UNIMPLEMENTED(); // FIXME
907 return egl::success(0);
910 EGLBoolean __stdcall eglWaitNative(EGLint engine)
912 EVENT("(EGLint engine = %d)", engine);
914 UNIMPLEMENTED(); // FIXME
916 return egl::success(0);
919 EGLBoolean __stdcall eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
921 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p)", dpy, surface);
923 egl::Display *display = static_cast<egl::Display*>(dpy);
924 egl::Surface *eglSurface = (egl::Surface*)surface;
926 if (!validateSurface(display, eglSurface))
931 if (display->getRenderer()->isDeviceLost())
933 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
936 if (surface == EGL_NO_SURFACE)
938 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
941 if (eglSurface->swap())
943 return egl::success(EGL_TRUE);
949 EGLBoolean __stdcall eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
951 EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLNativePixmapType target = 0x%0.8p)", dpy, surface, target);
953 egl::Display *display = static_cast<egl::Display*>(dpy);
954 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
956 if (!validateSurface(display, eglSurface))
961 if (display->getRenderer()->isDeviceLost())
963 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
966 UNIMPLEMENTED(); // FIXME
968 return egl::success(0);
971 EGLBoolean __stdcall eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height)
973 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);
975 if (x < 0 || y < 0 || width < 0 || height < 0)
977 return egl::error(EGL_BAD_PARAMETER, EGL_FALSE);
980 egl::Display *display = static_cast<egl::Display*>(dpy);
981 egl::Surface *eglSurface = static_cast<egl::Surface*>(surface);
983 if (!validateSurface(display, eglSurface))
988 if (display->getRenderer()->isDeviceLost())
990 return egl::error(EGL_CONTEXT_LOST, EGL_FALSE);
993 if (surface == EGL_NO_SURFACE)
995 return egl::error(EGL_BAD_SURFACE, EGL_FALSE);
998 if (eglSurface->postSubBuffer(x, y, width, height))
1000 return egl::success(EGL_TRUE);
1006 __eglMustCastToProperFunctionPointerType __stdcall eglGetProcAddress(const char *procname)
1008 EVENT("(const char *procname = \"%s\")", procname);
1013 __eglMustCastToProperFunctionPointerType address;
1016 static const Extension eglExtensions[] =
1018 { "eglQuerySurfacePointerANGLE", (__eglMustCastToProperFunctionPointerType)eglQuerySurfacePointerANGLE },
1019 { "eglPostSubBufferNV", (__eglMustCastToProperFunctionPointerType)eglPostSubBufferNV },
1020 { "eglGetPlatformDisplayEXT", (__eglMustCastToProperFunctionPointerType)eglGetPlatformDisplayEXT },
1024 for (unsigned int ext = 0; ext < ArraySize(eglExtensions); ext++)
1026 if (strcmp(procname, eglExtensions[ext].name) == 0)
1028 return (__eglMustCastToProperFunctionPointerType)eglExtensions[ext].address;
1032 return glGetProcAddress(procname);