c/direct: Use common init swapchain function.

Simplify and add error messages.
This commit is contained in:
Lubosz Sarnecki 2020-04-08 18:22:09 +02:00 committed by Jakob Bornecrantz
parent 77207ed585
commit bf49a421ba
4 changed files with 53 additions and 54 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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);
}

View file

@ -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