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.
This commit is contained in:
Lubosz Sarnecki 2020-04-07 15:31:36 +02:00
parent 48a51ddb23
commit 7da70568be

View file

@ -399,44 +399,42 @@ choose_best_vk_mode_auto(struct comp_window_direct *w,
VkDisplayModePropertiesKHR *mode_properties, VkDisplayModePropertiesKHR *mode_properties,
int mode_count) int mode_count)
{ {
struct if (mode_count == 1)
{ return 0;
uint16_t width;
uint16_t height; int best_index = 0;
float refresh;
int index;
} best_mode;
// First priority: choose mode that maximizes rendered pixels. // First priority: choose mode that maximizes rendered pixels.
// Second priority: choose mode with highest refresh rate. // Second priority: choose mode with highest refresh rate.
for (int i = 0; i < mode_count; i++) { for (int i = 1; i < mode_count; i++) {
VkDisplayModePropertiesKHR props = mode_properties[i]; VkDisplayModeParametersKHR current =
uint16_t width = props.parameters.visibleRegion.width; mode_properties[i].parameters;
uint16_t height = props.parameters.visibleRegion.height;
float refresh = (float)props.parameters.refreshRate / 1000.;
COMP_DEBUG(w->base.c, "Available Vk direct mode %d: %dx%d@%.2f", 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; VkDisplayModeParametersKHR best =
if (pixels > max_pixels) { mode_properties[best_index].parameters;
best_mode.index = i;
best_mode.width = width; int best_pixels =
best_mode.height = height; best.visibleRegion.width * best.visibleRegion.height;
best_mode.refresh = refresh; int pixels =
} else if (pixels == max_pixels && current.visibleRegion.width * current.visibleRegion.height;
refresh > best_mode.refresh) { if (pixels > best_pixels) {
best_mode.index = i; best_index = i;
/* update dims because it might be rotated */ } else if (pixels == best_pixels &&
best_mode.width = width; current.refreshRate > best.refreshRate) {
best_mode.height = height; best_index = i;
best_mode.refresh = refresh;
} }
} }
VkDisplayModeParametersKHR best =
mode_properties[best_index].parameters;
COMP_DEBUG(w->base.c, "Auto choosing Vk direct mode %d: %dx%d@%.2f", COMP_DEBUG(w->base.c, "Auto choosing Vk direct mode %d: %dx%d@%.2f",
best_mode.index, best_mode.width, best_mode.height, best_index, best.visibleRegion.width,
best_mode.refresh); best.visibleRegion.width, (float)best.refreshRate / 1000.);
return best_mode.index; return best_index;
} }
static void static void