demos: Add support for headless XCB
authorAndreas Bergmeier <abergmeier@gmx.net>
Wed, 13 Sep 2017 13:55:16 +0000 (15:55 +0200)
committerMark Lobodzinski <mark@lunarg.com>
Wed, 13 Sep 2017 14:48:05 +0000 (08:48 -0600)
For headless XCB we cannot create a surface. Simply ignore XCB if
connection could not be established or any other error occured.

Change-Id: I32db6aa3fc14887658d4290dcabbe8a1930cd8b3

demos/vulkaninfo.c

index cfd0e0c..949bd00 100644 (file)
@@ -930,9 +930,9 @@ static void AppCreateXcbWindow(struct AppInstance *inst) {
     inst->xcb_connection = xcb_connect(NULL, &scr);
     int conn_error = xcb_connection_has_error(inst->xcb_connection);
     if (conn_error) {
-        fprintf(stderr, "XCB failed to connect to the X server due to error:%d.\nExiting ...\n", conn_error);
+        fprintf(stderr, "XCB failed to connect to the X server due to error:%d.\n", conn_error);
         fflush(stderr);
-        exit(1);
+        inst->xcb_connection = NULL;
     }
 
     setup = xcb_get_setup(inst->xcb_connection);
@@ -956,6 +956,10 @@ static void AppCreateXcbWindow(struct AppInstance *inst) {
 }
 
 static void AppCreateXcbSurface(struct AppInstance *inst) {
+    if (!inst->xcb_connection) {
+        return;
+    }
+
     VkResult U_ASSERT_ONLY err;
     VkXcbSurfaceCreateInfoKHR xcb_createInfo;
     xcb_createInfo.sType      = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
@@ -968,6 +972,10 @@ static void AppCreateXcbSurface(struct AppInstance *inst) {
 }
 
 static void AppDestroyXcbWindow(struct AppInstance *inst) {
+    if (!inst->xcb_connection) {
+        return; // Nothing to destroy
+    }
+
     xcb_destroy_window(inst->xcb_connection, inst->xcb_window);
     xcb_disconnect(inst->xcb_connection);
 }