From bf49a421ba3b41fb606052a0fbeff62c33472534 Mon Sep 17 00:00:00 2001 From: Lubosz Sarnecki Date: Wed, 8 Apr 2020 18:22:09 +0200 Subject: [PATCH] c/direct: Use common init swapchain function. Simplify and add error messages. --- src/xrt/compositor/main/comp_window_direct.c | 27 ++++++++++++ src/xrt/compositor/main/comp_window_direct.h | 7 +++ .../main/comp_window_direct_nvidia.c | 30 +++---------- .../main/comp_window_direct_randr.c | 43 ++++++------------- 4 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/xrt/compositor/main/comp_window_direct.c b/src/xrt/compositor/main/comp_window_direct.c index 98d8c9f11..2aaefe365 100644 --- a/src/xrt/compositor/main/comp_window_direct.c +++ b/src/xrt/compositor/main/comp_window_direct.c @@ -260,3 +260,30 @@ comp_window_direct_acquire_xlib_display(struct comp_window *w, } return ret; } + +bool +comp_window_direct_init_swapchain(struct comp_window *w, + Display *dpy, + VkDisplayKHR display, + uint32_t width, + uint32_t height) +{ + VkResult ret; + ret = comp_window_direct_acquire_xlib_display(w, dpy, display); + + if (ret != VK_SUCCESS) { + return false; + } + + ret = comp_window_direct_create_surface(w, display, width, height); + if (ret != VK_SUCCESS) { + COMP_ERROR(w->c, "Failed to create surface!"); + return false; + } + + vk_swapchain_create( + &w->swapchain, width, height, w->c->settings.color_format, + w->c->settings.color_space, w->c->settings.present_mode); + + return true; +} diff --git a/src/xrt/compositor/main/comp_window_direct.h b/src/xrt/compositor/main/comp_window_direct.h index ae74387b3..f8bf7a985 100644 --- a/src/xrt/compositor/main/comp_window_direct.h +++ b/src/xrt/compositor/main/comp_window_direct.h @@ -34,6 +34,13 @@ comp_window_direct_acquire_xlib_display(struct comp_window *w, Display *dpy, VkDisplayKHR display); +bool +comp_window_direct_init_swapchain(struct comp_window *w, + Display *dpy, + VkDisplayKHR display, + uint32_t width, + uint32_t height); + #ifdef __cplusplus } #endif diff --git a/src/xrt/compositor/main/comp_window_direct_nvidia.c b/src/xrt/compositor/main/comp_window_direct_nvidia.c index 42421c70c..779b8960c 100644 --- a/src/xrt/compositor/main/comp_window_direct_nvidia.c +++ b/src/xrt/compositor/main/comp_window_direct_nvidia.c @@ -250,33 +250,15 @@ comp_window_direct_nvidia_init_swapchain(struct comp_window *w, struct comp_window_direct_nvidia *w_direct = (struct comp_window_direct_nvidia *)w; - struct comp_window_direct_nvidia_display *nvd = + struct comp_window_direct_nvidia_display *d = comp_window_direct_nvidia_current_display(w_direct); - - VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR; - - VkDisplayKHR _display = VK_NULL_HANDLE; - - if (nvd) { - COMP_DEBUG(w->c, "Will use display: %s", nvd->name); - ret = comp_window_direct_acquire_xlib_display(w, w_direct->dpy, - nvd->display); - _display = nvd->display; - } - - if (ret != VK_SUCCESS) { - return ret; - } - - ret = comp_window_direct_create_surface(w, _display, width, height); - if (ret != VK_SUCCESS) { - COMP_ERROR(w->c, "Failed to create surface!"); + if (!d) { + COMP_ERROR(w->c, "NVIDIA could not find any HMDs."); return false; } - vk_swapchain_create( - &w->swapchain, width, height, w->c->settings.color_format, - w->c->settings.color_space, w->c->settings.present_mode); + COMP_DEBUG(w->c, "Will use display: %s", d->name); - return true; + return comp_window_direct_init_swapchain(w, w_direct->dpy, d->display, + width, height); } diff --git a/src/xrt/compositor/main/comp_window_direct_randr.c b/src/xrt/compositor/main/comp_window_direct_randr.c index 9cff5495e..2af98ecd5 100644 --- a/src/xrt/compositor/main/comp_window_direct_randr.c +++ b/src/xrt/compositor/main/comp_window_direct_randr.c @@ -241,40 +241,23 @@ comp_window_direct_randr_init_swapchain(struct comp_window *w, struct comp_window_direct_randr_display *d = comp_window_direct_randr_current_display(w_direct); - VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR; - VkDisplayKHR _display = VK_NULL_HANDLE; - if (d) { - COMP_DEBUG( - w->c, "Will use display: %s %dx%d@%.2f", d->name, - d->primary_mode.width, d->primary_mode.height, - (double)d->primary_mode.dot_clock / - (d->primary_mode.htotal * d->primary_mode.vtotal)); - - d->display = - comp_window_direct_randr_get_output(w_direct, d->output); - if (d->display == VK_NULL_HANDLE) { - return VK_ERROR_INITIALIZATION_FAILED; - } - ret = comp_window_direct_acquire_xlib_display(w, w_direct->dpy, - d->display); - _display = d->display; - } - - if (ret != VK_SUCCESS) { - return ret; - } - - ret = comp_window_direct_create_surface(w, _display, width, height); - if (ret != VK_SUCCESS) { - COMP_ERROR(w->c, "Failed to create surface!"); + if (!d) { + COMP_ERROR(w->c, "RandR could not find any HMDs."); return false; } - vk_swapchain_create( - &w->swapchain, width, height, w->c->settings.color_format, - w->c->settings.color_space, w->c->settings.present_mode); + COMP_DEBUG(w->c, "Will use display: %s %dx%d@%.2f", d->name, + d->primary_mode.width, d->primary_mode.height, + (double)d->primary_mode.dot_clock / + (d->primary_mode.htotal * d->primary_mode.vtotal)); - return true; + d->display = comp_window_direct_randr_get_output(w_direct, d->output); + if (d->display == VK_NULL_HANDLE) { + return false; + } + + return comp_window_direct_init_swapchain(w, w_direct->dpy, d->display, + width, height); } static VkDisplayKHR