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