From a449ed174ae2ef4f1dc9ad22cd7f4ef59daf8874 Mon Sep 17 00:00:00 2001 From: Lubosz Sarnecki Date: Wed, 1 Apr 2020 16:56:05 +0200 Subject: [PATCH] c/direct_mode: Create append_nvidia_entry_on_match function. --- .../main/comp_window_direct_mode.cpp | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/xrt/compositor/main/comp_window_direct_mode.cpp b/src/xrt/compositor/main/comp_window_direct_mode.cpp index 15fd7866c..2b9f760f7 100644 --- a/src/xrt/compositor/main/comp_window_direct_mode.cpp +++ b/src/xrt/compositor/main/comp_window_direct_mode.cpp @@ -271,6 +271,31 @@ comp_window_direct_init_randr(struct comp_window *w) return true; } +static bool +append_nvidia_entry_on_match(struct comp_window_direct *w, + const char *wl_entry, + struct VkDisplayPropertiesKHR *disp) +{ + unsigned long wl_entry_length = strlen(wl_entry); + unsigned long disp_entry_length = strlen(disp->displayName); + if (disp_entry_length < wl_entry_length) + return false; + + if (strncmp(wl_entry, disp->displayName, wl_entry_length) != 0) + return false; + + // we have a match with this whitelist entry. + w->base.c->settings.width = disp->physicalResolution.width; + w->base.c->settings.height = disp->physicalResolution.height; + comp_window_direct_nvidia_display d = { + .name = std::string(disp->displayName), + .display_properties = *disp, + .display = disp->display}; + w->nv_displays.push_back(d); + + return true; +} + static bool comp_window_direct_init_nvidia(struct comp_window *w) { @@ -310,35 +335,13 @@ comp_window_direct_init_nvidia(struct comp_window *w) } // TODO: what if we have multiple whitelisted HMD displays connected? - for (uint32_t i = 0; i < display_count; i++) { struct VkDisplayPropertiesKHR disp = *(display_props + i); // check this display against our whitelist - for (uint32_t j = 0; j < ARRAY_SIZE(NV_DIRECT_WHITELIST); j++) { - unsigned long wl_entry_length = - strlen(NV_DIRECT_WHITELIST[j]); - unsigned long disp_entry_length = - strlen(disp.displayName); - if (disp_entry_length >= wl_entry_length) { - if (strncmp(NV_DIRECT_WHITELIST[j], - disp.displayName, - wl_entry_length) == 0) { - // we have a match with this whitelist - // entry. - w->c->settings.width = - disp.physicalResolution.width; - w->c->settings.height = - disp.physicalResolution.height; - comp_window_direct_nvidia_display d = { - .name = - std::string(disp.displayName), - .display_properties = disp, - .display = disp.display}; - w_direct->nv_displays.push_back(d); - break; - } - } - } + for (uint32_t j = 0; j < ARRAY_SIZE(NV_DIRECT_WHITELIST); j++) + if (append_nvidia_entry_on_match( + w_direct, NV_DIRECT_WHITELIST[j], &disp)) + break; } free(display_props);