The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/direct: Use common init swapchain function.

Simplify and add error messages.

authored by

Lubosz Sarnecki and committed by
Jakob Bornecrantz
bf49a421 77207ed5

+51 -52
+27
src/xrt/compositor/main/comp_window_direct.c
··· 260 260 } 261 261 return ret; 262 262 } 263 + 264 + bool 265 + comp_window_direct_init_swapchain(struct comp_window *w, 266 + Display *dpy, 267 + VkDisplayKHR display, 268 + uint32_t width, 269 + uint32_t height) 270 + { 271 + VkResult ret; 272 + ret = comp_window_direct_acquire_xlib_display(w, dpy, display); 273 + 274 + if (ret != VK_SUCCESS) { 275 + return false; 276 + } 277 + 278 + ret = comp_window_direct_create_surface(w, display, width, height); 279 + if (ret != VK_SUCCESS) { 280 + COMP_ERROR(w->c, "Failed to create surface!"); 281 + return false; 282 + } 283 + 284 + vk_swapchain_create( 285 + &w->swapchain, width, height, w->c->settings.color_format, 286 + w->c->settings.color_space, w->c->settings.present_mode); 287 + 288 + return true; 289 + }
+7
src/xrt/compositor/main/comp_window_direct.h
··· 34 34 Display *dpy, 35 35 VkDisplayKHR display); 36 36 37 + bool 38 + comp_window_direct_init_swapchain(struct comp_window *w, 39 + Display *dpy, 40 + VkDisplayKHR display, 41 + uint32_t width, 42 + uint32_t height); 43 + 37 44 #ifdef __cplusplus 38 45 } 39 46 #endif
+6 -24
src/xrt/compositor/main/comp_window_direct_nvidia.c
··· 250 250 struct comp_window_direct_nvidia *w_direct = 251 251 (struct comp_window_direct_nvidia *)w; 252 252 253 - struct comp_window_direct_nvidia_display *nvd = 253 + struct comp_window_direct_nvidia_display *d = 254 254 comp_window_direct_nvidia_current_display(w_direct); 255 - 256 - VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR; 257 - 258 - VkDisplayKHR _display = VK_NULL_HANDLE; 259 - 260 - if (nvd) { 261 - COMP_DEBUG(w->c, "Will use display: %s", nvd->name); 262 - ret = comp_window_direct_acquire_xlib_display(w, w_direct->dpy, 263 - nvd->display); 264 - _display = nvd->display; 265 - } 266 - 267 - if (ret != VK_SUCCESS) { 268 - return ret; 269 - } 270 - 271 - ret = comp_window_direct_create_surface(w, _display, width, height); 272 - if (ret != VK_SUCCESS) { 273 - COMP_ERROR(w->c, "Failed to create surface!"); 255 + if (!d) { 256 + COMP_ERROR(w->c, "NVIDIA could not find any HMDs."); 274 257 return false; 275 258 } 276 259 277 - vk_swapchain_create( 278 - &w->swapchain, width, height, w->c->settings.color_format, 279 - w->c->settings.color_space, w->c->settings.present_mode); 260 + COMP_DEBUG(w->c, "Will use display: %s", d->name); 280 261 281 - return true; 262 + return comp_window_direct_init_swapchain(w, w_direct->dpy, d->display, 263 + width, height); 282 264 }
+11 -28
src/xrt/compositor/main/comp_window_direct_randr.c
··· 241 241 struct comp_window_direct_randr_display *d = 242 242 comp_window_direct_randr_current_display(w_direct); 243 243 244 - VkResult ret = VK_ERROR_INCOMPATIBLE_DISPLAY_KHR; 245 - VkDisplayKHR _display = VK_NULL_HANDLE; 246 - if (d) { 247 - COMP_DEBUG( 248 - w->c, "Will use display: %s %dx%d@%.2f", d->name, 249 - d->primary_mode.width, d->primary_mode.height, 250 - (double)d->primary_mode.dot_clock / 251 - (d->primary_mode.htotal * d->primary_mode.vtotal)); 252 - 253 - d->display = 254 - comp_window_direct_randr_get_output(w_direct, d->output); 255 - if (d->display == VK_NULL_HANDLE) { 256 - return VK_ERROR_INITIALIZATION_FAILED; 257 - } 258 - ret = comp_window_direct_acquire_xlib_display(w, w_direct->dpy, 259 - d->display); 260 - _display = d->display; 244 + if (!d) { 245 + COMP_ERROR(w->c, "RandR could not find any HMDs."); 246 + return false; 261 247 } 262 248 263 - if (ret != VK_SUCCESS) { 264 - return ret; 265 - } 249 + COMP_DEBUG(w->c, "Will use display: %s %dx%d@%.2f", d->name, 250 + d->primary_mode.width, d->primary_mode.height, 251 + (double)d->primary_mode.dot_clock / 252 + (d->primary_mode.htotal * d->primary_mode.vtotal)); 266 253 267 - ret = comp_window_direct_create_surface(w, _display, width, height); 268 - if (ret != VK_SUCCESS) { 269 - COMP_ERROR(w->c, "Failed to create surface!"); 254 + d->display = comp_window_direct_randr_get_output(w_direct, d->output); 255 + if (d->display == VK_NULL_HANDLE) { 270 256 return false; 271 257 } 272 258 273 - vk_swapchain_create( 274 - &w->swapchain, width, height, w->c->settings.color_format, 275 - w->c->settings.color_space, w->c->settings.present_mode); 276 - 277 - return true; 259 + return comp_window_direct_init_swapchain(w, w_direct->dpy, d->display, 260 + width, height); 278 261 } 279 262 280 263 static VkDisplayKHR