Commit 43989208 by Nicolas Capens Committed by Nicolas Capens

Implemented EGL_EXT_platform_base and EGL_KHR_platform_gbm.

BUG=18314459 Change-Id: I361dba91a2fec3d9c923c660e64b5cc25beeb72b Reviewed-on: https://swiftshader-review.googlesource.com/1421Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 1b4f08b8
...@@ -29,29 +29,43 @@ namespace egl ...@@ -29,29 +29,43 @@ namespace egl
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
DisplayMap displays; DisplayMap displays;
egl::Display *Display::getDisplay(EGLNativeDisplayType displayId) egl::Display *Display::getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId)
{ {
if(platform == EGL_UNKNOWN) // Default
{
#if defined(__unix__)
platform = EGL_PLATFORM_X11_EXT;
#endif
}
if(displayId == EGL_DEFAULT_DISPLAY) if(displayId == EGL_DEFAULT_DISPLAY)
{ {
if(platform == EGL_PLATFORM_X11_EXT)
{
#if defined(__unix__) #if defined(__unix__)
displayId = XOpenDisplay(NULL); displayId = XOpenDisplay(NULL);
#else
return error(EGL_BAD_PARAMETER, (egl::Display*)EGL_NO_DISPLAY);
#endif #endif
} }
}
else
{
// FIXME: Check if displayId is a valid display device context for <platform>
}
if(displays.find(displayId) != displays.end()) if(displays.find(displayId) != displays.end())
{ {
return displays[displayId]; return displays[displayId];
} }
// FIXME: Check if displayId is a valid display device context egl::Display *display = new egl::Display(platform, displayId);
egl::Display *display = new egl::Display(displayId);
displays[displayId] = display; displays[displayId] = display;
return display; return display;
} }
Display::Display(EGLNativeDisplayType displayId) : displayId(displayId) Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(platform), displayId(displayId)
{ {
mMinSwapInterval = 1; mMinSwapInterval = 1;
mMaxSwapInterval = 1; mMaxSwapInterval = 1;
...@@ -452,11 +466,16 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -452,11 +466,16 @@ bool Display::isValidWindow(EGLNativeWindowType window)
#if defined(_WIN32) #if defined(_WIN32)
return IsWindow(window) == TRUE; return IsWindow(window) == TRUE;
#else #else
if(platform == EGL_PLATFORM_X11_EXT)
{
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
Status status = XGetWindowAttributes(displayId, window, &windowAttributes); Status status = XGetWindowAttributes(displayId, window, &windowAttributes);
return status == True; return status == True;
}
#endif #endif
return false;
} }
bool Display::hasExistingWindowSurface(EGLNativeWindowType window) bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
...@@ -509,6 +528,8 @@ DisplayMode Display::getDisplayMode() const ...@@ -509,6 +528,8 @@ DisplayMode Display::getDisplayMode() const
ReleaseDC(0, deviceContext); ReleaseDC(0, deviceContext);
#else #else
if(platform == EGL_PLATFORM_X11_EXT)
{
Screen *screen = XDefaultScreenOfDisplay(displayId); Screen *screen = XDefaultScreenOfDisplay(displayId);
displayMode.width = XWidthOfScreen(screen); displayMode.width = XWidthOfScreen(screen);
displayMode.height = XHeightOfScreen(screen); displayMode.height = XHeightOfScreen(screen);
...@@ -522,6 +543,14 @@ DisplayMode Display::getDisplayMode() const ...@@ -522,6 +543,14 @@ DisplayMode Display::getDisplayMode() const
default: default:
ASSERT(false); // Unexpected display mode color depth ASSERT(false); // Unexpected display mode color depth
} }
}
else if(platform == EGL_PLATFORM_GBM_MESA)
{
displayMode.width = 0;
displayMode.height = 0;
displayMode.format = sw::FORMAT_X8R8G8B8;
}
else UNREACHABLE();
#endif #endif
return displayMode; return displayMode;
......
...@@ -30,7 +30,7 @@ namespace egl ...@@ -30,7 +30,7 @@ namespace egl
public: public:
~Display(); ~Display();
static egl::Display *getDisplay(EGLNativeDisplayType displayId); static egl::Display *getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId);
bool initialize(); bool initialize();
void terminate(); void terminate();
...@@ -59,10 +59,11 @@ namespace egl ...@@ -59,10 +59,11 @@ namespace egl
const char *getExtensionString() const; const char *getExtensionString() const;
private: private:
Display(EGLNativeDisplayType displayId); Display(EGLenum platform, EGLNativeDisplayType displayId);
DisplayMode getDisplayMode() const; DisplayMode getDisplayMode() const;
const EGLenum platform;
const EGLNativeDisplayType displayId; const EGLNativeDisplayType displayId;
EGLint mMaxSwapInterval; EGLint mMaxSwapInterval;
......
...@@ -105,7 +105,7 @@ EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id) ...@@ -105,7 +105,7 @@ EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
try try
{ {
return egl::Display::getDisplay(display_id); return egl::Display::getPlatformDisplay(EGL_UNKNOWN, display_id);
} }
catch(std::bad_alloc&) catch(std::bad_alloc&)
{ {
...@@ -180,7 +180,10 @@ const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) ...@@ -180,7 +180,10 @@ const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name)
{ {
if(dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) if(dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
{ {
return success("EGL_EXT_client_extensions"); return success("EGL_KHR_platform_gbm "
"EGL_KHR_platform_x11 "
"EGL_EXT_client_extensions "
"EGL_EXT_platform_base");
} }
egl::Display *display = static_cast<egl::Display*>(dpy); egl::Display *display = static_cast<egl::Display*>(dpy);
...@@ -1191,6 +1194,32 @@ EGLBoolean EGLAPIENTRY eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) ...@@ -1191,6 +1194,32 @@ EGLBoolean EGLAPIENTRY eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
return EGL_FALSE; return EGL_FALSE;
} }
EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list)
{
TRACE("(EGLenum platform = 0x%X, void *native_display = 0x%0.8p, const EGLint *attrib_list = 0x%0.8p)", platform, native_display, attrib_list);
try
{
return egl::Display::getPlatformDisplay(platform, (EGLNativeDisplayType)native_display);
}
catch(std::bad_alloc&)
{
return error(EGL_BAD_ALLOC, EGL_NO_DISPLAY);
}
return EGL_NO_DISPLAY;
}
EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list)
{
return eglCreateWindowSurface(dpy, config, (EGLNativeWindowType)native_window, attrib_list);
}
EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list)
{
return eglCreatePixmapSurface(dpy, config, (EGLNativePixmapType)native_pixmap, attrib_list);
}
__eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname) __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
{ {
TRACE("(const char *procname = \"%s\")", procname); TRACE("(const char *procname = \"%s\")", procname);
...@@ -1209,6 +1238,9 @@ __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const cha ...@@ -1209,6 +1238,9 @@ __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const cha
EXTENSION(eglCreateImageKHR), EXTENSION(eglCreateImageKHR),
EXTENSION(eglDestroyImageKHR), EXTENSION(eglDestroyImageKHR),
EXTENSION(eglGetPlatformDisplayEXT),
EXTENSION(eglCreatePlatformWindowSurfaceEXT),
EXTENSION(eglCreatePlatformPixmapSurfaceEXT),
#undef EXTENSION #undef EXTENSION
}; };
......
...@@ -38,6 +38,9 @@ EXPORTS ...@@ -38,6 +38,9 @@ EXPORTS
; Extensions ; Extensions
eglCreateImageKHR eglCreateImageKHR
eglDestroyImageKHR eglDestroyImageKHR
eglGetPlatformDisplayEXT
eglCreatePlatformWindowSurfaceEXT
eglCreatePlatformPixmapSurfaceEXT
; Functions that don't change the error code, for use by client APIs ; Functions that don't change the error code, for use by client APIs
clientGetCurrentContext clientGetCurrentContext
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment