OSDN Git Service

Allow Linux build without X11 dependency
authorAlexis Hetu <sugoi@google.com>
Tue, 19 Jun 2018 18:50:41 +0000 (14:50 -0400)
committerAlexis Hétu <sugoi@google.com>
Wed, 20 Jun 2018 15:50:48 +0000 (15:50 +0000)
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/19488
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
CMakeLists.txt
src/Main/BUILD.gn
src/OpenGL/libEGL/BUILD.gn
src/OpenGL/libEGL/Display.cpp
src/OpenGL/libEGL/Surface.cpp
src/OpenGL/libEGL/libEGL.cpp

index f526116..eb03feb 100644 (file)
@@ -174,6 +174,9 @@ else()
         set_cpp_flag("-march=x86-64")
         set_cpp_flag("-mtune=generic")
     endif()
+    if(LINUX)
+        set_cpp_flag("-DUSE_X11=1")
+    endif()
 
     # Use -g3 to have even more debug info
     set_cpp_flag("-g -g3" DEBUG)
index 3641a76..ee76067 100644 (file)
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import("//ui/ozone/ozone.gni")
+import("//build/config/ui.gni")
 import("../swiftshader.gni")
 
 # Need a separate config to ensure the warnings are added to the end.
@@ -50,10 +50,12 @@ swiftshader_source_set("swiftshader_main") {
   if (use_ozone && !is_win) {
     sources += [ "FrameBufferOzone.cpp" ]
   } else if (is_linux) {
-    sources += [
-      "FrameBufferX11.cpp",
-      "libX11.cpp",
-    ]
+    if (use_x11) {
+      sources += [
+        "FrameBufferX11.cpp",
+        "libX11.cpp",
+      ]
+    }
   } else if (is_mac) {
     sources += [ "FrameBufferOSX.mm" ]
   } else if (is_win) {
index 1694381..6c2d803 100644 (file)
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build/config/ui.gni")
 import("../../swiftshader.gni")
 
 # Need a separate config to ensure the warnings are added to the end.
@@ -70,7 +71,9 @@ swiftshader_shared_library("swiftshader_libEGL") {
   } else if (is_win) {
     ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ]
   } else if (is_linux) {
-    sources += [ "../../Main/libX11.cpp" ]
+    if (use_x11) {
+      sources += [ "../../Main/libX11.cpp" ]
+    }
     ldflags =
         [ "-Wl,--version-script=" + rebase_path("libEGL.lds", root_build_dir) ]
   }
index 1f6b37f..343e4ce 100644 (file)
@@ -30,7 +30,7 @@
 #include <sys/ioctl.h>
 #include <linux/fb.h>
 #include <fcntl.h>
-#elif defined(__linux__)
+#elif defined(USE_X11)
 #include "Main/libX11.hpp"
 #elif defined(__APPLE__)
 #include "OSXUtils.hpp"
@@ -66,7 +66,7 @@ Display *Display::get(EGLDisplay dpy)
 
        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
                if(!nativeDisplay && dpy != HEADLESS_DISPLAY && libX11 && libX11->XOpenDisplay)
                {
@@ -89,7 +89,7 @@ Display::~Display()
 {
        terminate();
 
-       #if defined(__linux__) && !defined(__ANDROID__)
+       #if defined(USE_X11)
                if(nativeDisplay && libX11->XCloseDisplay)
                {
                        libX11->XCloseDisplay((::Display*)nativeDisplay);
@@ -677,7 +677,7 @@ bool Display::isValidWindow(EGLNativeWindowType window)
                        return false;
                }
                return true;
-       #elif defined(__linux__)
+       #elif defined(USE_X11)
                if(nativeDisplay)
                {
                        XWindowAttributes windowAttributes;
@@ -686,6 +686,8 @@ bool Display::isValidWindow(EGLNativeWindowType window)
                        return status != 0;
                }
                return false;
+       #elif defined(__linux__)
+               return false;  // Non X11 linux is headless only
        #elif defined(__APPLE__)
                return sw::OSX::IsValidWindow(window);
        #elif defined(__Fuchsia__)
@@ -843,7 +845,7 @@ sw::Format Display::getDisplayFormat() const
 
                // No framebuffer device found, or we're in user space
                return sw::FORMAT_X8B8G8R8;
-       #elif defined(__linux__)
+       #elif defined(USE_X11)
                if(nativeDisplay)
                {
                        Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay);
@@ -861,6 +863,8 @@ sw::Format Display::getDisplayFormat() const
                {
                        return sw::FORMAT_X8R8G8B8;
                }
+       #elif defined(__linux__)  // Non X11 linux is headless only
+               return sw::FORMAT_A8B8G8R8;
        #elif defined(__APPLE__)
                return sw::FORMAT_A8B8G8R8;
        #elif defined(__Fuchsia__)
index 237804b..b8bba5f 100644 (file)
@@ -26,7 +26,7 @@
 #include "common/debug.h"
 #include "Main/FrameBuffer.hpp"
 
-#if defined(__linux__) && !defined(__ANDROID__)
+#if defined(USE_X11)
 #include "Main/libX11.hpp"
 #elif defined(_WIN32)
 #include <tchar.h>
@@ -341,7 +341,7 @@ bool WindowSurface::checkForResize()
        #elif defined(__ANDROID__)
                int windowWidth;  window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth);
                int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight);
-       #elif defined(__linux__)
+       #elif defined(USE_X11)
                XWindowAttributes windowAttributes;
                Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
 
@@ -352,6 +352,10 @@ bool WindowSurface::checkForResize()
 
                int windowWidth = windowAttributes.width;
                int windowHeight = windowAttributes.height;
+       #elif defined(__linux__)
+               // Non X11 linux is headless only
+               int windowWidth = 100;
+               int windowHeight = 100;
        #elif defined(__APPLE__)
                int windowWidth;
                int windowHeight;
index 8e0be66..952fb88 100644 (file)
@@ -25,7 +25,7 @@
 
 #if defined(__ANDROID__)
 #include <system/window.h>
-#elif defined(__linux__)
+#elif defined(USE_X11)
 #include "Main/libX11.hpp"
 #endif
 
@@ -120,7 +120,9 @@ EGLDisplay GetDisplay(EGLNativeDisplayType display_id)
        }
 
        #if defined(__linux__) && !defined(__ANDROID__)
+               #if defined(USE_X11)
                if(!libX11)
+               #endif  // Non X11 linux is headless only
                {
                        return success(HEADLESS_DISPLAY);
                }
@@ -178,6 +180,8 @@ const char *QueryString(EGLDisplay dpy, EGLint name)
                        "EGL_KHR_client_get_all_proc_addresses "
 #if defined(__linux__) && !defined(__ANDROID__)
                        "EGL_KHR_platform_gbm "
+#endif
+#if defined(USE_X11)
                        "EGL_KHR_platform_x11 "
 #endif
                        "EGL_EXT_client_extensions "
@@ -1002,7 +1006,7 @@ EGLBoolean WaitNative(EGLint engine)
 
        if(context)
        {
-               #if defined(__linux__) && !defined(__ANDROID__)
+               #if defined(USE_X11)
                        egl::Display *display = context->getDisplay();
 
                        if(!display)
@@ -1171,33 +1175,37 @@ EGLDisplay GetPlatformDisplayEXT(EGLenum platform, void *native_display, const E
        #if defined(__linux__) && !defined(__ANDROID__)
                switch(platform)
                {
+               #if defined(USE_X11)
                case EGL_PLATFORM_X11_EXT: break;
+               #endif
                case EGL_PLATFORM_GBM_KHR: break;
                default:
                        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)
                        {
                                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)
                        {
                                return error(EGL_BAD_ATTRIBUTE, EGL_NO_DISPLAY);   // Unimplemented
                        }
-
-                       return success(HEADLESS_DISPLAY);
                }
+               #endif
 
                return success(PRIMARY_DISPLAY);   // We only support the default display
        #else