Commit 3f1ab0c8 by Nicolas Capens

Fix attempting to load libX11 when rendering headless.

Bug 26776258 Change-Id: I326e76d2650b3992835d74baea159b13f14b2e3e Reviewed-on: https://swiftshader-review.googlesource.com/4720Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent cbda6264
#define MAJOR_VERSION 3
#define MINOR_VERSION 2
#define BUILD_VERSION 10
#define BUILD_REVISION 47663
#define BUILD_REVISION 47664
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -41,7 +41,7 @@ namespace egl
Display *Display::get(EGLDisplay dpy)
{
if(dpy != (EGLDisplay)1) // We only support the default display
if(dpy != PRIMARY_DISPLAY && dpy != HEADLESS_DISPLAY) // We only support the default display
{
return nullptr;
}
......@@ -50,7 +50,7 @@ Display *Display::get(EGLDisplay dpy)
#if defined(__linux__) && !defined(__ANDROID__)
// Even if the application provides a native display handle, we open (and close) our own connection
if(!nativeDisplay && libX11->XOpenDisplay)
if(!nativeDisplay && dpy != HEADLESS_DISPLAY && libX11 && libX11->XOpenDisplay)
{
nativeDisplay = libX11->XOpenDisplay(NULL);
}
......@@ -193,11 +193,6 @@ void Display::terminate()
{
destroyContext(*mContextSet.begin());
}
if(this == getCurrentDisplay())
{
setCurrentDisplay(nullptr);
}
}
bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
......
......@@ -25,6 +25,9 @@ namespace egl
class Surface;
class Context;
const EGLDisplay PRIMARY_DISPLAY = (EGLDisplay)1;
const EGLDisplay HEADLESS_DISPLAY = (EGLDisplay)0xFACE1E55;
class Display
{
public:
......
......@@ -115,7 +115,14 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id)
// FIXME: Check if display_id is the default display
}
return success((EGLDisplay)1); // We only support the default display
#if defined(__linux__) && !defined(__ANDROID__)
if(!libX11)
{
return success(HEADLESS_DISPLAY);
}
#endif
return success(PRIMARY_DISPLAY); // We only support the default display
}
EGLBoolean Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
......@@ -731,7 +738,7 @@ EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLCont
UNIMPLEMENTED(); // FIXME
}
egl::setCurrentDisplay(display);
egl::setCurrentDisplay(dpy);
egl::setCurrentDrawSurface(drawSurface);
egl::setCurrentReadSurface(readSurface);
egl::setCurrentContext(context);
......@@ -777,10 +784,7 @@ EGLDisplay GetCurrentDisplay(void)
{
TRACE("()");
egl::Display *display = egl::getCurrentDisplay();
// We don't return the actual object pointer. We only support the default display, represented by '1'
return success(display ? (EGLDisplay)1 : EGL_NO_DISPLAY);
return success(egl::getCurrentDisplay());
}
EGLBoolean QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
......@@ -995,10 +999,12 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E
{
return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY); // Unimplemented
}
return success(HEADLESS_DISPLAY);
}
#endif
return success((EGLDisplay)1); // We only support the default display
return success(PRIMARY_DISPLAY); // We only support the default display
}
EGLSurface CreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list)
......
......@@ -54,7 +54,6 @@ public:
// Functions that don't change the error code, for use by client APIs
egl::Context *(*clientGetCurrentContext)();
egl::Display *(*clientGetCurrentDisplay)();
};
class LibEGL
......
......@@ -46,7 +46,7 @@ static void eglAttachThread()
current->error = EGL_SUCCESS;
current->API = EGL_OPENGL_ES_API;
current->display = nullptr;
current->display = EGL_NO_DISPLAY;
current->context = nullptr;
current->drawSurface = nullptr;
current->readSurface = nullptr;
......@@ -205,14 +205,14 @@ EGLenum getCurrentAPI()
return current->API;
}
void setCurrentDisplay(egl::Display *dpy)
void setCurrentDisplay(EGLDisplay dpy)
{
Current *current = eglGetCurrent();
current->display = dpy;
}
egl::Display *getCurrentDisplay()
EGLDisplay getCurrentDisplay()
{
Current *current = eglGetCurrent();
......@@ -628,7 +628,6 @@ LibEGLexports::LibEGLexports()
this->eglGetSyncAttribKHR = egl::GetSyncAttribKHR;
this->clientGetCurrentContext = egl::getCurrentContext;
this->clientGetCurrentDisplay = egl::getCurrentDisplay;
}
extern "C" EGLAPI LibEGLexports *libEGL_swiftshader()
......
......@@ -30,7 +30,7 @@ namespace egl
{
EGLint error;
EGLenum API;
Display *display;
EGLDisplay display;
Context *context;
Surface *drawSurface;
Surface *readSurface;
......@@ -42,8 +42,8 @@ namespace egl
void setCurrentAPI(EGLenum API);
EGLenum getCurrentAPI();
void setCurrentDisplay(Display *dpy);
Display *getCurrentDisplay();
void setCurrentDisplay(EGLDisplay dpy);
EGLDisplay getCurrentDisplay();
void setCurrentContext(Context *ctx);
Context *getCurrentContext();
......@@ -55,7 +55,7 @@ namespace egl
Surface *getCurrentReadSurface();
void error(EGLint errorCode);
template<class T>
const T &error(EGLint errorCode, const T &returnValue)
{
......
......@@ -94,11 +94,6 @@ es1::Context *getContext()
return 0;
}
egl::Display *getDisplay()
{
return libEGL->clientGetCurrentDisplay();
}
Device *getDevice()
{
Context *context = getContext();
......
......@@ -26,7 +26,6 @@
namespace es1
{
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
void error(GLenum errorCode);
......
......@@ -94,11 +94,6 @@ es2::Context *getContext()
return 0;
}
egl::Display *getDisplay()
{
return libEGL->clientGetCurrentDisplay();
}
Device *getDevice()
{
Context *context = getContext();
......
......@@ -28,7 +28,6 @@
namespace es2
{
Context *getContext();
egl::Display *getDisplay();
Device *getDevice();
void error(GLenum errorCode);
......
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