From 78d6b57e312769a82ab3cf115fee6cb5ee709723 Mon Sep 17 00:00:00 2001 From: Tony Barbour Date: Mon, 14 Nov 2016 14:46:33 -0700 Subject: demos: Enable building combinations of xcb and xlib Change-Id: I055c12e8c93d05db747239df46611386eb8b8278 --- demos/CMakeLists.txt | 6 ++++-- demos/cube.c | 11 +++++++++-- demos/cube.cpp | 53 +++++++++++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 29196f11..802e85b5 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -127,8 +127,10 @@ else() target_link_libraries(cubepp ${LIBRARIES}) endif() -if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) - add_subdirectory(smoke) +if ((${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})) + if (BUILD_WSI_XCB_SUPPORT OR BUILD_WSI_WAYLAND_SUPPORT OR WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Android")) + add_subdirectory(smoke) + endif() endif() if(UNIX) diff --git a/demos/cube.c b/demos/cube.c index 078b6245..fb8b7c1f 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -293,13 +293,16 @@ struct demo { POINT minsize; // minimum window size #elif defined(VK_USE_PLATFORM_XLIB_KHR) | defined(VK_USE_PLATFORM_XCB_KHR) Display* display; +#if defined(VK_USE_PLATFORM_XLIB_KHR) Window xlib_window; Atom xlib_wm_delete_window; - +#endif +#if defined(VK_USE_PLATFORM_XCB_KHR) xcb_connection_t *connection; xcb_screen_t *screen; xcb_window_t xcb_window; xcb_intern_atom_reply_t *atom_wm_delete_window; +#endif #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) struct wl_display *display; struct wl_registry *registry; @@ -2070,7 +2073,7 @@ static void demo_cleanup(struct demo *demo) { vkDestroySurfaceKHR(demo->inst, demo->surface, NULL); vkDestroyInstance(demo->inst, NULL); -#if defined(VK_USE_PLATFORM_XLIB_KHR) +#if defined(VK_USE_PLATFORM_XLIB_KHR) && defined(VK_USE_PLATFORM_XCB_KHR) if (demo->use_xlib) { XDestroyWindow(demo->display, demo->xlib_window); XCloseDisplay(demo->display); @@ -2079,6 +2082,9 @@ static void demo_cleanup(struct demo *demo) { xcb_disconnect(demo->connection); } free(demo->atom_wm_delete_window); +#elif defined(VK_USE_PLATFORM_XLIB_KHR) + XDestroyWindow(demo->display, demo->xlib_window); + XCloseDisplay(demo->display); #elif defined(VK_USE_PLATFORM_XCB_KHR) xcb_destroy_window(demo->connection, demo->xcb_window); xcb_disconnect(demo->connection); @@ -3487,6 +3493,7 @@ int main(int argc, char **argv) { #elif defined(VK_USE_PLATFORM_XCB_KHR) demo_create_xcb_window(&demo); #elif defined(VK_USE_PLATFORM_XLIB_KHR) + demo.use_xlib = true; demo_create_xlib_window(&demo); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo_create_window(&demo); diff --git a/demos/cube.cpp b/demos/cube.cpp index 9fc04c9d..e91b0c3f 100644 --- a/demos/cube.cpp +++ b/demos/cube.cpp @@ -212,17 +212,19 @@ struct Demo { window{nullptr}, minsize(POINT{ 0, 0}), // Use explicit construction to avoid MSVC error C2797. -#elif defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) - display{nullptr}, - xlib_window{0}, xlib_wm_delete_window{0}, connection{nullptr}, - screen{nullptr}, xcb_window{0}, atom_wm_delete_window{nullptr}, -#elif defined(VK_USE_PLATFORM_WAYLAND_KHR) - display{nullptr}, - registry{nullptr}, compositor{nullptr}, window{nullptr}, - shell{nullptr}, shell_surface{nullptr}, #endif - prepared{false}, - use_staging_buffer{false}, use_xlib{false}, +#if defined(VK_USE_PLATFORM_XLIB_KHR) + xlib_window{0}, + xlib_wm_delete_window{0}, display{nullptr}, +#endif +#if defined(VK_USE_PLATFORM_XCB_KHR) + xcb_window{0}, screen{nullptr}, connection{nullptr}, +#endif +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) + display{nullptr}, registry{nullptr}, compositor{nullptr}, + window{nullptr}, shell{nullptr}, shell_surface{nullptr}, +#endif + prepared{false}, use_staging_buffer{false}, use_xlib{false}, graphics_queue_family_index{0}, present_queue_family_index{0}, enabled_extension_count{0}, enabled_layer_count{0}, width{0}, height{0}, swapchainImageCount{0}, frame_index{0}, spin_angle{0.0f}, @@ -231,8 +233,6 @@ struct Demo { suppress_popups{false}, current_buffer{0}, queue_family_count{0} { #if defined(VK_USE_PLATFORM_WIN32_KHR) memset(name, '\0', APP_NAME_STR_LEN); -#elif defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) -#elif defined(VK_USE_PLATFORM_WAYLAND_KHR) #endif memset(projection_matrix, 0, sizeof(projection_matrix)); memset(view_matrix, 0, sizeof(view_matrix)); @@ -342,7 +342,7 @@ struct Demo { inst.destroySurfaceKHR(surface, nullptr); inst.destroy(nullptr); -#if defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) +#if defined(VK_USE_PLATFORM_XLIB_KHR) && defined(VK_USE_PLATFORM_XCB_KHR) if (use_xlib) { XDestroyWindow(display, xlib_window); XCloseDisplay(display); @@ -351,6 +351,13 @@ struct Demo { xcb_disconnect(connection); } free(atom_wm_delete_window); +#elif defined(VK_USE_PLATFORM_XLIB_KHR) + XDestroyWindow(display, xlib_window); + XCloseDisplay(display); +#elif defined(VK_USE_PLATFORM_XCB_KHR) + xcb_destroy_window(connection, xcb_window); + xcb_disconnect(connection); + free(atom_wm_delete_window); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) wl_shell_surface_destroy(shell_surface); wl_surface_destroy(window); @@ -2581,16 +2588,19 @@ struct Demo { HWND window; // hWnd - window handle POINT minsize; // minimum window size char name[APP_NAME_STR_LEN]; // Name to put on the window/icon -#elif defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) - Display *display; +#endif +#if defined(VK_USE_PLATFORM_XLIB_KHR) Window xlib_window; Atom xlib_wm_delete_window; - - xcb_connection_t *connection; - xcb_screen_t *screen; + Display *display; +#endif +#if defined(VK_USE_PLATFORM_XCB_KHR) xcb_window_t xcb_window; + xcb_screen_t *screen; + xcb_connection_t *connection; xcb_intern_atom_reply_t *atom_wm_delete_window; -#elif defined(VK_USE_PLATFORM_WAYLAND_KHR) +#endif +#if defined(VK_USE_PLATFORM_WAYLAND_KHR) wl_display *display; wl_registry *registry; wl_compositor *compositor; @@ -2834,14 +2844,15 @@ int main(int argc, char **argv) { demo.create_xlib_window(); } else { demo.create_xcb_window(); + } #elif defined(VK_USE_PLATFORM_XCB_KHR) demo.create_xcb_window(); #elif defined(VK_USE_PLATFORM_XLIB_KHR) + demo.use_xlib = true; demo.create_xlib_window(); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo.create_window(); #endif - } demo.init_vk_swapchain(); @@ -2852,6 +2863,7 @@ int main(int argc, char **argv) { demo.run_xlib(); } else { demo.run_xcb(); + } #elif defined(VK_USE_PLATFORM_XCB_KHR) demo.run_xcb(); #elif defined(VK_USE_PLATFORM_XLIB_KHR) @@ -2859,7 +2871,6 @@ demo.run_xlib(); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo.run(); #endif - } demo.cleanup(); -- cgit v1.2.3