diff options
| author | Nicolas Caramelli <caramelli.devel@gmail.com> | 2020-07-13 17:22:09 +0200 |
|---|---|---|
| committer | jeremyk-lunarg <jeremyk@lunarg.com> | 2020-08-07 11:59:36 -0600 |
| commit | c8be8c840153dfc736099c10d67abf880722f9e1 (patch) | |
| tree | 4d24efcdd1b6d2cc95ebf602468971799385e287 /cube | |
| parent | a1c21580f50b9d6ead9e5f04b8b8fdc378f49087 (diff) | |
| download | usermoji-c8be8c840153dfc736099c10d67abf880722f9e1.tar.xz | |
Add support for VK_EXT_directfb_surface extension
Diffstat (limited to 'cube')
| -rw-r--r-- | cube/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | cube/cube.c | 108 | ||||
| -rw-r--r-- | cube/cube.cpp | 117 |
3 files changed, 239 insertions, 1 deletions
diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt index 05685ce3..ef05db18 100644 --- a/cube/CMakeLists.txt +++ b/cube/CMakeLists.txt @@ -46,7 +46,8 @@ if(UNIX AND NOT APPLE) # i.e. Linux option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON) option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON) option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON) - set(CUBE_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for vkcube (XCB, XLIB, WAYLAND, DISPLAY)") + option(BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF) + set(CUBE_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for vkcube (XCB, XLIB, WAYLAND, DIRECTFB, DISPLAY)") if(BUILD_WSI_XCB_SUPPORT) find_package(XCB REQUIRED) @@ -60,6 +61,11 @@ if(UNIX AND NOT APPLE) # i.e. Linux find_package(Wayland REQUIRED) include_directories(${WAYLAND_CLIENT_INCLUDE_DIR}) endif() + + if(BUILD_WSI_DIRECTFB_SUPPORT) + find_package(DirectFB REQUIRED) + include_directories(${DIRECTFB_INCLUDE_DIR}) + endif() endif() if(WIN32) @@ -101,6 +107,13 @@ elseif(UNIX AND NOT APPLE) # i.e. Linux set(CUBE_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR} ${CUBE_INCLUDE_DIRS}) link_libraries(${WAYLAND_CLIENT_LIBRARIES}) add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR) + elseif(CUBE_WSI_SELECTION STREQUAL "DIRECTFB") + if(NOT BUILD_WSI_DIRECTFB_SUPPORT) + message(FATAL_ERROR "Selected DIRECTFB for vkcube build but not building DirectFB support") + endif() + set(CUBE_INCLUDE_DIRS ${DIRECTFB_INCLUDE_DIR} ${CUBE_INCLUDE_DIRS}) + link_libraries(${DIRECTFB_LIBRARIES}) + add_definitions(-DVK_USE_PLATFORM_DIRECTFB_EXT) elseif(CUBE_WSI_SELECTION STREQUAL "DISPLAY") add_definitions(-DVK_USE_PLATFORM_DISPLAY_KHR) else() diff --git a/cube/cube.c b/cube/cube.c index 71ad5a40..857056e3 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -327,6 +327,10 @@ struct demo { struct wl_seat *seat; struct wl_pointer *pointer; struct wl_keyboard *keyboard; +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + IDirectFB *dfb; + IDirectFBSurface *window; + IDirectFBEventBuffer *event_buffer; #elif defined(VK_USE_PLATFORM_ANDROID_KHR) struct ANativeWindow *window; #elif defined(VK_USE_PLATFORM_METAL_EXT) @@ -2367,6 +2371,10 @@ static void demo_cleanup(struct demo *demo) { wl_compositor_destroy(demo->compositor); wl_registry_destroy(demo->registry); wl_display_disconnect(demo->display); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + demo->event_buffer->Release(demo->event_buffer); + demo->window->Release(demo->window); + demo->dfb->Release(demo->dfb); #endif vkDestroyInstance(demo->inst, NULL); @@ -2769,6 +2777,82 @@ static void demo_create_window(struct demo *demo) { wl_shell_surface_set_toplevel(demo->shell_surface); wl_shell_surface_set_title(demo->shell_surface, APP_SHORT_NAME); } +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) +static void demo_create_directfb_window(struct demo *demo) { + DFBResult ret; + + ret = DirectFBInit(NULL, NULL); + if (ret) { + printf("DirectFBInit failed to initialize DirectFB!\n"); + fflush(stdout); + exit(1); + } + + ret = DirectFBCreate(&demo->dfb); + if (ret) { + printf("DirectFBCreate failed to create main interface of DirectFB!\n"); + fflush(stdout); + exit(1); + } + + DFBSurfaceDescription desc; + desc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT; + desc.caps = DSCAPS_PRIMARY; + desc.width = demo->width; + desc.height = demo->height; + ret = demo->dfb->CreateSurface(demo->dfb, &desc, &demo->window); + if (ret) { + printf("CreateSurface failed to create DirectFB surface interface!\n"); + fflush(stdout); + exit(1); + } + + ret = demo->dfb->CreateInputEventBuffer(demo->dfb, DICAPS_KEYS, DFB_FALSE, &demo->event_buffer); + if (ret) { + printf("CreateInputEventBuffer failed to create DirectFB event buffer interface!\n"); + fflush(stdout); + exit(1); + } +} + +static void demo_handle_directfb_event(struct demo *demo, const DFBInputEvent *event) { + if (event->type != DIET_KEYPRESS) return; + switch (event->key_symbol) { + case DIKS_ESCAPE: // Escape + demo->quit = true; + break; + case DIKS_CURSOR_LEFT: // left arrow key + demo->spin_angle -= demo->spin_increment; + break; + case DIKS_CURSOR_RIGHT: // right arrow key + demo->spin_angle += demo->spin_increment; + break; + case DIKS_SPACE: // space bar + demo->pause = !demo->pause; + break; + default: + break; + } +} + +static void demo_run_directfb(struct demo *demo) { + while (!demo->quit) { + DFBInputEvent event; + + if (demo->pause) { + demo->event_buffer->WaitForEvent(demo->event_buffer); + if (!demo->event_buffer->GetEvent(demo->event_buffer, DFB_EVENT(&event))) + demo_handle_directfb_event(demo, &event); + } else { + if (!demo->event_buffer->GetEvent(demo->event_buffer, DFB_EVENT(&event))) + demo_handle_directfb_event(demo, &event); + + demo_draw(demo); + demo->curFrame++; + if (demo->frameCount != INT32_MAX && demo->curFrame == demo->frameCount) demo->quit = true; + } + } +} #elif defined(VK_USE_PLATFORM_ANDROID_KHR) static void demo_run(struct demo *demo) { if (!demo->prepared) return; @@ -3031,6 +3115,11 @@ static void demo_init_vk(struct demo *demo) { platformSurfaceExtFound = 1; demo->extension_names[demo->enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; } +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + if (!strcmp(VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME, instance_extensions[i].extensionName)) { + platformSurfaceExtFound = 1; + demo->extension_names[demo->enabled_extension_count++] = VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME; + } #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) if (!strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, instance_extensions[i].extensionName)) { platformSurfaceExtFound = 1; @@ -3108,6 +3197,12 @@ static void demo_init_vk(struct demo *demo) { "Do you have a compatible Vulkan installable client driver (ICD) installed?\n" "Please look at the Getting Started guide for additional information.\n", "vkCreateInstance Failure"); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + ERR_EXIT("vkEnumerateInstanceExtensionProperties failed to find the " VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME + " extension.\n\n" + "Do you have a compatible Vulkan installable client driver (ICD) installed?\n" + "Please look at the Getting Started guide for additional information.\n", + "vkCreateInstance Failure"); #endif } const VkApplicationInfo app = { @@ -3405,6 +3500,15 @@ static void demo_create_surface(struct demo *demo) { createInfo.window = demo->xcb_window; err = vkCreateXcbSurfaceKHR(demo->inst, &createInfo, NULL, &demo->surface); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + VkDirectFBSurfaceCreateInfoEXT createInfo; + createInfo.sType = VK_STRUCTURE_TYPE_DIRECTFB_SURFACE_CREATE_INFO_EXT; + createInfo.pNext = NULL; + createInfo.flags = 0; + createInfo.dfb = demo->dfb; + createInfo.surface = demo->window; + + err = vkCreateDirectFBSurfaceEXT(demo->inst, &createInfo, NULL, &demo->surface); #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) err = demo_create_display_surface(demo); #elif defined(VK_USE_PLATFORM_METAL_EXT) @@ -4014,6 +4118,8 @@ int main(int argc, char **argv) { demo_create_xlib_window(&demo); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo_create_window(&demo); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + demo_create_directfb_window(&demo); #endif demo_init_vk_swapchain(&demo); @@ -4026,6 +4132,8 @@ int main(int argc, char **argv) { demo_run_xlib(&demo); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo_run(&demo); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + demo_run_directfb(&demo); #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) demo_run_display(&demo); #endif diff --git a/cube/cube.cpp b/cube/cube.cpp index fc32c74f..a319b59a 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -263,6 +263,10 @@ struct Demo { #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) void run(); void create_window(); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + void handle_directfb_event(const DFBInputEvent *); + void run_directfb(); + void create_directfb_window(); #elif defined(VK_USE_PLATFORM_METAL_EXT) void run(); #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) @@ -294,6 +298,10 @@ struct Demo { wl_seat *seat; wl_pointer *pointer; wl_keyboard *keyboard; +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + IDirectFB *dfb; + IDirectFBSurface *window; + IDirectFBEventBuffer *event_buffer; #elif defined(VK_USE_PLATFORM_METAL_EXT) void *caMetalLayer; #endif @@ -531,6 +539,10 @@ Demo::Demo() seat{nullptr}, pointer{nullptr}, keyboard{nullptr}, +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + dfb{nullptr}, + window{nullptr}, + event_buffer{nullptr}, #endif prepared{false}, use_staging_buffer{false}, @@ -677,6 +689,10 @@ void Demo::cleanup() { wl_compositor_destroy(compositor); wl_registry_destroy(registry); wl_display_disconnect(display); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + event_buffer->Release(event_buffer); + window->Release(window); + dfb->Release(dfb); #endif inst.destroy(nullptr); @@ -1118,6 +1134,11 @@ void Demo::init_vk() { platformSurfaceExtFound = 1; extension_names[enabled_extension_count++] = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME; } +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + if (!strcmp(VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME, instance_extensions[i].extensionName)) { + platformSurfaceExtFound = 1; + extension_names[enabled_extension_count++] = VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME; + } #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) if (!strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, instance_extensions[i].extensionName)) { platformSurfaceExtFound = 1; @@ -1167,6 +1188,12 @@ void Demo::init_vk() { "Do you have a compatible Vulkan installable client driver (ICD) installed?\n" "Please look at the Getting Started guide for additional information.\n", "vkCreateInstance Failure"); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + ERR_EXIT("vkEnumerateInstanceExtensionProperties failed to find the " VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME + " extension.\n\n" + "Do you have a compatible Vulkan installable client driver (ICD) installed?\n" + "Please look at the Getting Started guide for additional information.\n", + "vkCreateInstance Failure"); #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) ERR_EXIT("vkEnumerateInstanceExtensionProperties failed to find the " VK_KHR_DISPLAY_EXTENSION_NAME " extension.\n\n" @@ -1315,6 +1342,13 @@ void Demo::create_surface() { auto result = inst.createXcbSurfaceKHR(&createInfo, nullptr, &surface); VERIFY(result == vk::Result::eSuccess); } +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + { + auto const createInfo = vk::DirectFBSurfaceCreateInfoEXT().setDfb(dfb).setSurface(window); + + auto result = inst.createDirectFBSurfaceEXT(&createInfo, nullptr, &surface); + VERIFY(result == vk::Result::eSuccess); + } #elif defined(VK_USE_PLATFORM_METAL_EXT) { auto const createInfo = vk::MetalSurfaceCreateInfoEXT().setPLayer(static_cast<CAMetalLayer *>(caMetalLayer)); @@ -2711,6 +2745,85 @@ void Demo::create_window() { wl_shell_surface_set_toplevel(shell_surface); wl_shell_surface_set_title(shell_surface, APP_SHORT_NAME); } +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + +void Demo::handle_directfb_event(const DFBInputEvent *event) { + if (event->type != DIET_KEYPRESS) return; + switch (event->key_symbol) { + case DIKS_ESCAPE: // Escape + quit = true; + break; + case DIKS_CURSOR_LEFT: // left arrow key + spin_angle -= spin_increment; + break; + case DIKS_CURSOR_RIGHT: // right arrow key + spin_angle += spin_increment; + break; + case DIKS_SPACE: // space bar + pause = !pause; + break; + default: + break; + } +} + +void Demo::run_directfb() { + while (!quit) { + DFBInputEvent event; + + if (pause) { + event_buffer->WaitForEvent(event_buffer); + if (!event_buffer->GetEvent(event_buffer, DFB_EVENT(&event))) + handle_directfb_event(&event); + } else { + if (!event_buffer->GetEvent(event_buffer, DFB_EVENT(&event))) + handle_directfb_event(&event); + + draw(); + curFrame++; + if (frameCount != UINT32_MAX && curFrame == frameCount) { + quit = true; + } + } + } +} + +void Demo::create_directfb_window() { + DFBResult ret; + + ret = DirectFBInit(NULL, NULL); + if (ret) { + printf("DirectFBInit failed to initialize DirectFB!\n"); + fflush(stdout); + exit(1); + } + + ret = DirectFBCreate(&dfb); + if (ret) { + printf("DirectFBCreate failed to create main interface of DirectFB!\n"); + fflush(stdout); + exit(1); + } + + DFBSurfaceDescription desc; + desc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT); + desc.caps = DSCAPS_PRIMARY; + desc.width = -1; //width; + desc.height = height; + ret = dfb->CreateSurface(dfb, &desc, &window); + if (ret) { + printf("CreateSurface failed to create DirectFB surface interface!\n"); + fflush(stdout); + exit(1); + } + + ret = dfb->CreateInputEventBuffer(dfb, DICAPS_KEYS, DFB_FALSE, &event_buffer); + if (ret) { + printf("CreateInputEventBuffer failed to create DirectFB event buffer interface!\n"); + fflush(stdout); + exit(1); + } +} #elif defined(VK_USE_PLATFORM_METAL_EXT) void Demo::run() { draw(); @@ -3024,6 +3137,8 @@ int main(int argc, char **argv) { demo.create_xlib_window(); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo.create_window(); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + demo.create_directfb_window(); #endif demo.init_vk_swapchain(); @@ -3036,6 +3151,8 @@ int main(int argc, char **argv) { demo.run_xlib(); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) demo.run(); +#elif defined(VK_USE_PLATFORM_DIRECTFB_EXT) + demo.run_directfb(); #elif defined(VK_USE_PLATFORM_DISPLAY_KHR) demo.run_display(); #endif |
