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
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
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(platform == EGL_PLATFORM_X11_EXT)
{
#if defined(__unix__)
displayId = XOpenDisplay(NULL);
#else
return error(EGL_BAD_PARAMETER, (egl::Display*)EGL_NO_DISPLAY);
#endif
}
}
else
{
// FIXME: Check if displayId is a valid display device context for <platform>
}
if(displays.find(displayId) != displays.end())
{
return displays[displayId];
}
// FIXME: Check if displayId is a valid display device context
egl::Display *display = new egl::Display(displayId);
egl::Display *display = new egl::Display(platform, displayId);
displays[displayId] = display;
return display;
}
Display::Display(EGLNativeDisplayType displayId) : displayId(displayId)
Display::Display(EGLenum platform, EGLNativeDisplayType displayId) : platform(platform), displayId(displayId)
{
mMinSwapInterval = 1;
mMaxSwapInterval = 1;
......@@ -452,11 +466,16 @@ bool Display::isValidWindow(EGLNativeWindowType window)
#if defined(_WIN32)
return IsWindow(window) == TRUE;
#else
if(platform == EGL_PLATFORM_X11_EXT)
{
XWindowAttributes windowAttributes;
Status status = XGetWindowAttributes(displayId, window, &windowAttributes);
return status == True;
}
#endif
return false;
}
bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
......@@ -509,6 +528,8 @@ DisplayMode Display::getDisplayMode() const
ReleaseDC(0, deviceContext);
#else
if(platform == EGL_PLATFORM_X11_EXT)
{
Screen *screen = XDefaultScreenOfDisplay(displayId);
displayMode.width = XWidthOfScreen(screen);
displayMode.height = XHeightOfScreen(screen);
......@@ -522,6 +543,14 @@ DisplayMode Display::getDisplayMode() const
default:
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
return displayMode;
......
......@@ -30,7 +30,7 @@ namespace egl
public:
~Display();
static egl::Display *getDisplay(EGLNativeDisplayType displayId);
static egl::Display *getPlatformDisplay(EGLenum platform, EGLNativeDisplayType displayId);
bool initialize();
void terminate();
......@@ -59,10 +59,11 @@ namespace egl
const char *getExtensionString() const;
private:
Display(EGLNativeDisplayType displayId);
Display(EGLenum platform, EGLNativeDisplayType displayId);
DisplayMode getDisplayMode() const;
const EGLenum platform;
const EGLNativeDisplayType displayId;
EGLint mMaxSwapInterval;
......
......@@ -105,7 +105,7 @@ EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
try
{
return egl::Display::getDisplay(display_id);
return egl::Display::getPlatformDisplay(EGL_UNKNOWN, display_id);
}
catch(std::bad_alloc&)
{
......@@ -180,7 +180,10 @@ const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name)
{
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);
......@@ -1191,6 +1194,32 @@ EGLBoolean EGLAPIENTRY eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
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)
{
TRACE("(const char *procname = \"%s\")", procname);
......@@ -1209,6 +1238,9 @@ __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const cha
EXTENSION(eglCreateImageKHR),
EXTENSION(eglDestroyImageKHR),
EXTENSION(eglGetPlatformDisplayEXT),
EXTENSION(eglCreatePlatformWindowSurfaceEXT),
EXTENSION(eglCreatePlatformPixmapSurfaceEXT),
#undef EXTENSION
};
......
......@@ -38,6 +38,9 @@ EXPORTS
; Extensions
eglCreateImageKHR
eglDestroyImageKHR
eglGetPlatformDisplayEXT
eglCreatePlatformWindowSurfaceEXT
eglCreatePlatformPixmapSurfaceEXT
; Functions that don't change the error code, for use by client APIs
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