From 7da70568be4bb260fa91eaedd5075cb3bc302af8 Mon Sep 17 00:00:00 2001 From: Lubosz Sarnecki Date: Tue, 7 Apr 2020 15:31:36 +0200 Subject: [PATCH] c/direct_mode: Use VkDisplayModeParametersKHR. In favor of own struct to determine best available mode. The loop now also starts as one, as we do not need compare the 0th mode it itself and returns if there is only one mode. --- .../compositor/main/comp_window_direct_mode.c | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/xrt/compositor/main/comp_window_direct_mode.c b/src/xrt/compositor/main/comp_window_direct_mode.c index 443211dfc..b5a87da5b 100644 --- a/src/xrt/compositor/main/comp_window_direct_mode.c +++ b/src/xrt/compositor/main/comp_window_direct_mode.c @@ -399,44 +399,42 @@ choose_best_vk_mode_auto(struct comp_window_direct *w, VkDisplayModePropertiesKHR *mode_properties, int mode_count) { - struct - { - uint16_t width; - uint16_t height; - float refresh; - int index; - } best_mode; + if (mode_count == 1) + return 0; + + int best_index = 0; // First priority: choose mode that maximizes rendered pixels. // Second priority: choose mode with highest refresh rate. - for (int i = 0; i < mode_count; i++) { - VkDisplayModePropertiesKHR props = mode_properties[i]; - uint16_t width = props.parameters.visibleRegion.width; - uint16_t height = props.parameters.visibleRegion.height; - float refresh = (float)props.parameters.refreshRate / 1000.; + for (int i = 1; i < mode_count; i++) { + VkDisplayModeParametersKHR current = + mode_properties[i].parameters; COMP_DEBUG(w->base.c, "Available Vk direct mode %d: %dx%d@%.2f", - i, width, height, refresh); + i, current.visibleRegion.width, + current.visibleRegion.height, + (float)current.refreshRate / 1000.); - int max_pixels = best_mode.width * best_mode.height; - int pixels = width * height; - if (pixels > max_pixels) { - best_mode.index = i; - best_mode.width = width; - best_mode.height = height; - best_mode.refresh = refresh; - } else if (pixels == max_pixels && - refresh > best_mode.refresh) { - best_mode.index = i; - /* update dims because it might be rotated */ - best_mode.width = width; - best_mode.height = height; - best_mode.refresh = refresh; + + VkDisplayModeParametersKHR best = + mode_properties[best_index].parameters; + + int best_pixels = + best.visibleRegion.width * best.visibleRegion.height; + int pixels = + current.visibleRegion.width * current.visibleRegion.height; + if (pixels > best_pixels) { + best_index = i; + } else if (pixels == best_pixels && + current.refreshRate > best.refreshRate) { + best_index = i; } } + VkDisplayModeParametersKHR best = + mode_properties[best_index].parameters; COMP_DEBUG(w->base.c, "Auto choosing Vk direct mode %d: %dx%d@%.2f", - best_mode.index, best_mode.width, best_mode.height, - best_mode.refresh); - return best_mode.index; + best_index, best.visibleRegion.width, + best.visibleRegion.width, (float)best.refreshRate / 1000.); + return best_index; } static void