Commit 20eea3cd by Alexis Hetu Committed by Alexis Hétu

Allow Linux build without X11 dependency

ChromeOS runs tests on some bots which run on Linux, but do not support X11. In order to allow SwiftShader to successfully build on these bots, all X11 dependencies are #ifdefed behind the USE_X11 flag, which is already supplied by the Chromium build system. Change-Id: I6b914b1e662d9fbf101eb7caea7ac59e43cc7b56 Reviewed-on: https://swiftshader-review.googlesource.com/19488Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 964dde93
...@@ -174,6 +174,9 @@ else() ...@@ -174,6 +174,9 @@ else()
set_cpp_flag("-march=x86-64") set_cpp_flag("-march=x86-64")
set_cpp_flag("-mtune=generic") set_cpp_flag("-mtune=generic")
endif() endif()
if(LINUX)
set_cpp_flag("-DUSE_X11=1")
endif()
# Use -g3 to have even more debug info # Use -g3 to have even more debug info
set_cpp_flag("-g -g3" DEBUG) set_cpp_flag("-g -g3" DEBUG)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import("//ui/ozone/ozone.gni") import("//build/config/ui.gni")
import("../swiftshader.gni") import("../swiftshader.gni")
# Need a separate config to ensure the warnings are added to the end. # Need a separate config to ensure the warnings are added to the end.
...@@ -50,10 +50,12 @@ swiftshader_source_set("swiftshader_main") { ...@@ -50,10 +50,12 @@ swiftshader_source_set("swiftshader_main") {
if (use_ozone && !is_win) { if (use_ozone && !is_win) {
sources += [ "FrameBufferOzone.cpp" ] sources += [ "FrameBufferOzone.cpp" ]
} else if (is_linux) { } else if (is_linux) {
sources += [ if (use_x11) {
"FrameBufferX11.cpp", sources += [
"libX11.cpp", "FrameBufferX11.cpp",
] "libX11.cpp",
]
}
} else if (is_mac) { } else if (is_mac) {
sources += [ "FrameBufferOSX.mm" ] sources += [ "FrameBufferOSX.mm" ]
} else if (is_win) { } else if (is_win) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import("//build/config/ui.gni")
import("../../swiftshader.gni") import("../../swiftshader.gni")
# Need a separate config to ensure the warnings are added to the end. # Need a separate config to ensure the warnings are added to the end.
...@@ -70,7 +71,9 @@ swiftshader_shared_library("swiftshader_libEGL") { ...@@ -70,7 +71,9 @@ swiftshader_shared_library("swiftshader_libEGL") {
} else if (is_win) { } else if (is_win) {
ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ] ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ]
} else if (is_linux) { } else if (is_linux) {
sources += [ "../../Main/libX11.cpp" ] if (use_x11) {
sources += [ "../../Main/libX11.cpp" ]
}
ldflags = ldflags =
[ "-Wl,--version-script=" + rebase_path("libEGL.lds", root_build_dir) ] [ "-Wl,--version-script=" + rebase_path("libEGL.lds", root_build_dir) ]
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <fcntl.h> #include <fcntl.h>
#elif defined(__linux__) #elif defined(USE_X11)
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include "OSXUtils.hpp" #include "OSXUtils.hpp"
...@@ -66,7 +66,7 @@ Display *Display::get(EGLDisplay dpy) ...@@ -66,7 +66,7 @@ Display *Display::get(EGLDisplay dpy)
static void *nativeDisplay = nullptr; static void *nativeDisplay = nullptr;
#if defined(__linux__) && !defined(__ANDROID__) #if defined(USE_X11)
// 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 && dpy != HEADLESS_DISPLAY && libX11 && libX11->XOpenDisplay) if(!nativeDisplay && dpy != HEADLESS_DISPLAY && libX11 && libX11->XOpenDisplay)
{ {
...@@ -89,7 +89,7 @@ Display::~Display() ...@@ -89,7 +89,7 @@ Display::~Display()
{ {
terminate(); terminate();
#if defined(__linux__) && !defined(__ANDROID__) #if defined(USE_X11)
if(nativeDisplay && libX11->XCloseDisplay) if(nativeDisplay && libX11->XCloseDisplay)
{ {
libX11->XCloseDisplay((::Display*)nativeDisplay); libX11->XCloseDisplay((::Display*)nativeDisplay);
...@@ -677,7 +677,7 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -677,7 +677,7 @@ bool Display::isValidWindow(EGLNativeWindowType window)
return false; return false;
} }
return true; return true;
#elif defined(__linux__) #elif defined(USE_X11)
if(nativeDisplay) if(nativeDisplay)
{ {
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
...@@ -686,6 +686,8 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -686,6 +686,8 @@ bool Display::isValidWindow(EGLNativeWindowType window)
return status != 0; return status != 0;
} }
return false; return false;
#elif defined(__linux__)
return false; // Non X11 linux is headless only
#elif defined(__APPLE__) #elif defined(__APPLE__)
return sw::OSX::IsValidWindow(window); return sw::OSX::IsValidWindow(window);
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
...@@ -843,7 +845,7 @@ sw::Format Display::getDisplayFormat() const ...@@ -843,7 +845,7 @@ sw::Format Display::getDisplayFormat() const
// No framebuffer device found, or we're in user space // No framebuffer device found, or we're in user space
return sw::FORMAT_X8B8G8R8; return sw::FORMAT_X8B8G8R8;
#elif defined(__linux__) #elif defined(USE_X11)
if(nativeDisplay) if(nativeDisplay)
{ {
Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay); Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay);
...@@ -861,6 +863,8 @@ sw::Format Display::getDisplayFormat() const ...@@ -861,6 +863,8 @@ sw::Format Display::getDisplayFormat() const
{ {
return sw::FORMAT_X8R8G8B8; return sw::FORMAT_X8R8G8B8;
} }
#elif defined(__linux__) // Non X11 linux is headless only
return sw::FORMAT_A8B8G8R8;
#elif defined(__APPLE__) #elif defined(__APPLE__)
return sw::FORMAT_A8B8G8R8; return sw::FORMAT_A8B8G8R8;
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "Main/FrameBuffer.hpp" #include "Main/FrameBuffer.hpp"
#if defined(__linux__) && !defined(__ANDROID__) #if defined(USE_X11)
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
#elif defined(_WIN32) #elif defined(_WIN32)
#include <tchar.h> #include <tchar.h>
...@@ -341,7 +341,7 @@ bool WindowSurface::checkForResize() ...@@ -341,7 +341,7 @@ bool WindowSurface::checkForResize()
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth); int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth);
int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight); int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight);
#elif defined(__linux__) #elif defined(USE_X11)
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
...@@ -352,6 +352,10 @@ bool WindowSurface::checkForResize() ...@@ -352,6 +352,10 @@ bool WindowSurface::checkForResize()
int windowWidth = windowAttributes.width; int windowWidth = windowAttributes.width;
int windowHeight = windowAttributes.height; int windowHeight = windowAttributes.height;
#elif defined(__linux__)
// Non X11 linux is headless only
int windowWidth = 100;
int windowHeight = 100;
#elif defined(__APPLE__) #elif defined(__APPLE__)
int windowWidth; int windowWidth;
int windowHeight; int windowHeight;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include <system/window.h> #include <system/window.h>
#elif defined(__linux__) #elif defined(USE_X11)
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
#endif #endif
...@@ -120,7 +120,9 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id) ...@@ -120,7 +120,9 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id)
} }
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
#if defined(USE_X11)
if(!libX11) if(!libX11)
#endif // Non X11 linux is headless only
{ {
return success(HEADLESS_DISPLAY); return success(HEADLESS_DISPLAY);
} }
...@@ -178,6 +180,8 @@ const char *QueryString(EGLDisplay dpy, EGLint name) ...@@ -178,6 +180,8 @@ const char *QueryString(EGLDisplay dpy, EGLint name)
"EGL_KHR_client_get_all_proc_addresses " "EGL_KHR_client_get_all_proc_addresses "
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
"EGL_KHR_platform_gbm " "EGL_KHR_platform_gbm "
#endif
#if defined(USE_X11)
"EGL_KHR_platform_x11 " "EGL_KHR_platform_x11 "
#endif #endif
"EGL_EXT_client_extensions " "EGL_EXT_client_extensions "
...@@ -1002,7 +1006,7 @@ EGLBoolean WaitNative(EGLint engine) ...@@ -1002,7 +1006,7 @@ EGLBoolean WaitNative(EGLint engine)
if(context) if(context)
{ {
#if defined(__linux__) && !defined(__ANDROID__) #if defined(USE_X11)
egl::Display *display = context->getDisplay(); egl::Display *display = context->getDisplay();
if(!display) if(!display)
...@@ -1171,33 +1175,37 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E ...@@ -1171,33 +1175,37 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
switch(platform) switch(platform)
{ {
#if defined(USE_X11)
case EGL_PLATFORM_X11_EXT: break; case EGL_PLATFORM_X11_EXT: break;
#endif
case EGL_PLATFORM_GBM_KHR: break; case EGL_PLATFORM_GBM_KHR: break;
default: default:
return error(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); return error(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
} }
if(platform == EGL_PLATFORM_X11_EXT) if(platform == EGL_PLATFORM_GBM_KHR)
{ {
if(!libX11)
{
return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY);
}
if(native_display != (void*)EGL_DEFAULT_DISPLAY || attrib_list != NULL) if(native_display != (void*)EGL_DEFAULT_DISPLAY || attrib_list != NULL)
{ {
return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY); // Unimplemented return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY); // Unimplemented
} }
return success(HEADLESS_DISPLAY);
} }
else if(platform == EGL_PLATFORM_GBM_KHR) #if defined(USE_X11)
else if(platform == EGL_PLATFORM_X11_EXT)
{ {
if(!libX11)
{
return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY);
}
if(native_display != (void*)EGL_DEFAULT_DISPLAY || attrib_list != NULL) if(native_display != (void*)EGL_DEFAULT_DISPLAY || attrib_list != NULL)
{ {
return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY); // Unimplemented return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY); // Unimplemented
} }
return success(HEADLESS_DISPLAY);
} }
#endif
return success(PRIMARY_DISPLAY); // We only support the default display return success(PRIMARY_DISPLAY); // We only support the default display
#else #else
......
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