c/direct_mode: Create append_nvidia_entry_on_match function.

This commit is contained in:
Lubosz Sarnecki 2020-04-01 16:56:05 +02:00
parent f8c99b0230
commit a449ed174a

View file

@ -271,6 +271,31 @@ comp_window_direct_init_randr(struct comp_window *w)
return true; 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 static bool
comp_window_direct_init_nvidia(struct comp_window *w) 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? // TODO: what if we have multiple whitelisted HMD displays connected?
for (uint32_t i = 0; i < display_count; i++) { for (uint32_t i = 0; i < display_count; i++) {
struct VkDisplayPropertiesKHR disp = *(display_props + i); struct VkDisplayPropertiesKHR disp = *(display_props + i);
// check this display against our whitelist // check this display against our whitelist
for (uint32_t j = 0; j < ARRAY_SIZE(NV_DIRECT_WHITELIST); j++) { for (uint32_t j = 0; j < ARRAY_SIZE(NV_DIRECT_WHITELIST); j++)
unsigned long wl_entry_length = if (append_nvidia_entry_on_match(
strlen(NV_DIRECT_WHITELIST[j]); w_direct, NV_DIRECT_WHITELIST[j], &disp))
unsigned long disp_entry_length = break;
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;
}
}
}
} }
free(display_props); free(display_props);