The open source OpenXR runtime
0
fork

Configure Feed

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

c/main: Constify target factories

authored by

Ryan Pavlik and committed by
Jakob Bornecrantz
9cf12425 3058f1c1

+53 -48
+3
doc/changes/compositor/mr.1570.md
··· 1 + --- 2 + - mr.1684 3 + --- 1 4 main: Introduce `comp_target_factory`. This struct allows us to remove long and 2 5 cumbersome switch statements for each type. Instead the code is generic and 3 6 tweaks for specific target types can be reused for others more easily with this
+10 -10
src/xrt/compositor/main/comp_compositor.c
··· 760 760 * 761 761 */ 762 762 763 - struct comp_target_factory *ctfs[] = { 763 + const struct comp_target_factory *ctfs[] = { 764 764 #if defined VK_USE_PLATFORM_WAYLAND_KHR && defined XRT_HAVE_WAYLAND_DIRECT 765 765 &comp_target_factory_direct_wayland, 766 766 #endif ··· 801 801 } 802 802 803 803 static bool 804 - compositor_check_deferred(struct comp_compositor *c, struct comp_target_factory *ctf) 804 + compositor_check_deferred(struct comp_compositor *c, const struct comp_target_factory *ctf) 805 805 { 806 806 if (debug_get_bool_option_disable_deferred()) { 807 807 COMP_DEBUG(c, "Deferred window initialization globally disabled!"); ··· 821 821 } 822 822 823 823 static bool 824 - compositor_try_window(struct comp_compositor *c, struct comp_target_factory *ctf) 824 + compositor_try_window(struct comp_compositor *c, const struct comp_target_factory *ctf) 825 825 { 826 826 COMP_TRACE_MARKER(); 827 827 ··· 845 845 } 846 846 847 847 static bool 848 - select_target_factory_from_settings(struct comp_compositor *c, struct comp_target_factory **out_ctf) 848 + select_target_factory_from_settings(struct comp_compositor *c, const struct comp_target_factory **out_ctf) 849 849 { 850 850 const char *identifier = c->settings.target_identifier; 851 851 ··· 854 854 } 855 855 856 856 for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) { 857 - struct comp_target_factory *ctf = ctfs[i]; 857 + const struct comp_target_factory *ctf = ctfs[i]; 858 858 859 859 if (strcmp(ctf->identifier, identifier) == 0) { 860 860 *out_ctf = ctf; ··· 870 870 } 871 871 872 872 static bool 873 - select_target_factory_by_detecting(struct comp_compositor *c, struct comp_target_factory **out_ctf) 873 + select_target_factory_by_detecting(struct comp_compositor *c, const struct comp_target_factory **out_ctf) 874 874 { 875 875 for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) { 876 - struct comp_target_factory *ctf = ctfs[i]; 876 + const struct comp_target_factory *ctf = ctfs[i]; 877 877 878 878 if (comp_target_factory_detect(ctf, c)) { 879 879 *out_ctf = ctf; ··· 885 885 } 886 886 887 887 static bool 888 - compositor_init_window_pre_vulkan(struct comp_compositor *c, struct comp_target_factory *selected_ctf) 888 + compositor_init_window_pre_vulkan(struct comp_compositor *c, const struct comp_target_factory *selected_ctf) 889 889 { 890 890 COMP_TRACE_MARKER(); 891 891 ··· 918 918 } 919 919 920 920 for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) { 921 - struct comp_target_factory *ctf = ctfs[i]; 921 + const struct comp_target_factory *ctf = ctfs[i]; 922 922 923 923 // Skip targets that requires Vulkan. 924 924 if (ctf->requires_vulkan_for_create) { ··· 1011 1011 1012 1012 xrt_result_t 1013 1013 comp_main_create_system_compositor(struct xrt_device *xdev, 1014 - struct comp_target_factory *ctf, 1014 + const struct comp_target_factory *ctf, 1015 1015 struct xrt_system_compositor **out_xsysc) 1016 1016 { 1017 1017 COMP_TRACE_MARKER();
+1 -1
src/xrt/compositor/main/comp_compositor.h
··· 109 109 struct render_resources nr; 110 110 111 111 //! The selected target factory that we create our target from. 112 - struct comp_target_factory *target_factory; 112 + const struct comp_target_factory *target_factory; 113 113 114 114 //! The target we are displaying to. 115 115 struct comp_target *target;
+1 -1
src/xrt/compositor/main/comp_main_interface.h
··· 35 35 */ 36 36 xrt_result_t 37 37 comp_main_create_system_compositor(struct xrt_device *xdev, 38 - struct comp_target_factory *ctf, 38 + const struct comp_target_factory *ctf, 39 39 struct xrt_system_compositor **out_xsysc); 40 40 41 41
+6 -4
src/xrt/compositor/main/comp_target.h
··· 555 555 * This is needed for NVIDIA direct mode which window must be created 556 556 * after vulkan has initialized. 557 557 */ 558 - bool (*detect)(struct comp_target_factory *ctf, struct comp_compositor *c); 558 + bool (*detect)(const struct comp_target_factory *ctf, struct comp_compositor *c); 559 559 560 560 /*! 561 561 * Create a target from this factory, some targets requires Vulkan to 562 562 * have been initialised, see @ref requires_vulkan_for_create. 563 563 */ 564 - bool (*create_target)(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct); 564 + bool (*create_target)(const struct comp_target_factory *ctf, 565 + struct comp_compositor *c, 566 + struct comp_target **out_ct); 565 567 }; 566 568 567 569 /*! ··· 571 573 * @ingroup comp_main 572 574 */ 573 575 static inline bool 574 - comp_target_factory_detect(struct comp_target_factory *ctf, struct comp_compositor *c) 576 + comp_target_factory_detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 575 577 { 576 578 COMP_TRACE_MARKER(); 577 579 ··· 585 587 * @ingroup comp_main 586 588 */ 587 589 static inline bool 588 - comp_target_factory_create_target(struct comp_target_factory *ctf, 590 + comp_target_factory_create_target(const struct comp_target_factory *ctf, 589 591 struct comp_compositor *c, 590 592 struct comp_target **out_ct) 591 593 {
+8 -8
src/xrt/compositor/main/comp_window.h
··· 37 37 struct comp_target * 38 38 comp_window_xcb_create(struct comp_compositor *c); 39 39 40 - extern struct comp_target_factory comp_target_factory_xcb; 40 + extern const struct comp_target_factory comp_target_factory_xcb; 41 41 42 42 #endif // VK_USE_PLATFORM_XCB_KHR 43 43 ··· 52 52 struct comp_target * 53 53 comp_window_wayland_create(struct comp_compositor *c); 54 54 55 - extern struct comp_target_factory comp_target_factory_wayland; 55 + extern const struct comp_target_factory comp_target_factory_wayland; 56 56 57 57 /*! 58 58 * Create a direct surface to a HMD using Wayland. ··· 62 62 struct comp_target * 63 63 comp_window_direct_wayland_create(struct comp_compositor *c); 64 64 65 - extern struct comp_target_factory comp_target_factory_direct_wayland; 65 + extern const struct comp_target_factory comp_target_factory_direct_wayland; 66 66 67 67 #endif // VK_USE_PLATFORM_WAYLAND_KHR 68 68 ··· 76 76 struct comp_target * 77 77 comp_window_direct_randr_create(struct comp_compositor *c); 78 78 79 - extern struct comp_target_factory comp_target_factory_direct_randr; 79 + extern const struct comp_target_factory comp_target_factory_direct_randr; 80 80 81 81 /*! 82 82 * Create a direct surface to an HMD on NVIDIA. ··· 87 87 struct comp_target * 88 88 comp_window_direct_nvidia_create(struct comp_compositor *c); 89 89 90 - extern struct comp_target_factory comp_target_factory_direct_nvidia; 90 + extern const struct comp_target_factory comp_target_factory_direct_nvidia; 91 91 #endif // VK_USE_PLATFORM_XLIB_XRANDR_EXT 92 92 93 93 #if 1 ··· 100 100 struct comp_target * 101 101 comp_window_vk_display_create(struct comp_compositor *c); 102 102 103 - extern struct comp_target_factory comp_target_factory_vk_display; 103 + extern const struct comp_target_factory comp_target_factory_vk_display; 104 104 #endif // 1 105 105 106 106 #ifdef XRT_OS_ANDROID ··· 113 113 struct comp_target * 114 114 comp_window_android_create(struct comp_compositor *c); 115 115 116 - extern struct comp_target_factory comp_target_factory_android; 116 + extern const struct comp_target_factory comp_target_factory_android; 117 117 #endif // XRT_OS_ANDROID 118 118 119 119 #ifdef XRT_OS_WINDOWS ··· 127 127 struct comp_target * 128 128 comp_window_mswin_create(struct comp_compositor *c); 129 129 130 - extern struct comp_target_factory comp_target_factory_mswin; 130 + extern const struct comp_target_factory comp_target_factory_mswin; 131 131 #endif // XRT_OS_WINDOWS 132 132 133 133 #ifdef __cplusplus
+3 -3
src/xrt/compositor/main/comp_window_android.c
··· 202 202 }; 203 203 204 204 static bool 205 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 205 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 206 206 { 207 207 return false; 208 208 } 209 209 210 210 static bool 211 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 211 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 212 212 { 213 213 struct comp_target *ct = comp_window_android_create(c); 214 214 if (ct == NULL) { ··· 220 220 return true; 221 221 } 222 222 223 - struct comp_target_factory comp_target_factory_android = { 223 + const struct comp_target_factory comp_target_factory_android = { 224 224 .name = "Android", 225 225 .identifier = "android", 226 226 .requires_vulkan_for_create = false,
+3 -3
src/xrt/compositor/main/comp_window_direct_nvidia.c
··· 413 413 } 414 414 415 415 static bool 416 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 416 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 417 417 { 418 418 bool detected = false; 419 419 ··· 425 425 } 426 426 427 427 static bool 428 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 428 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 429 429 { 430 430 struct comp_target *ct = comp_window_direct_nvidia_create(c); 431 431 if (ct == NULL) { ··· 437 437 return true; 438 438 } 439 439 440 - struct comp_target_factory comp_target_factory_direct_nvidia = { 440 + const struct comp_target_factory comp_target_factory_direct_nvidia = { 441 441 .name = "NVIDIA Direct-Mode", 442 442 .identifier = "x11_direct_nvidia", 443 443 .requires_vulkan_for_create = true,
+3 -3
src/xrt/compositor/main/comp_window_direct_randr.c
··· 466 466 }; 467 467 468 468 static bool 469 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 469 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 470 470 { 471 471 return false; 472 472 } 473 473 474 474 static bool 475 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 475 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 476 476 { 477 477 struct comp_target *ct = comp_window_direct_randr_create(c); 478 478 if (ct == NULL) { ··· 484 484 return true; 485 485 } 486 486 487 - struct comp_target_factory comp_target_factory_direct_randr = { 487 + const struct comp_target_factory comp_target_factory_direct_randr = { 488 488 .name = "X11(RandR) Direct-Mode", 489 489 .identifier = "x11_direct", 490 490 .requires_vulkan_for_create = false,
+3 -3
src/xrt/compositor/main/comp_window_direct_wayland.c
··· 483 483 }; 484 484 485 485 static bool 486 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 486 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 487 487 { 488 488 return false; 489 489 } 490 490 491 491 static bool 492 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 492 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 493 493 { 494 494 struct comp_target *ct = comp_window_direct_wayland_create(c); 495 495 if (ct == NULL) { ··· 501 501 return true; 502 502 } 503 503 504 - struct comp_target_factory comp_target_factory_direct_wayland = { 504 + const struct comp_target_factory comp_target_factory_direct_wayland = { 505 505 .name = "Wayland Direct-Mode", 506 506 .identifier = "direct_wayland", 507 507 .requires_vulkan_for_create = false,
+3 -3
src/xrt/compositor/main/comp_window_mswin.c
··· 406 406 }; 407 407 408 408 static bool 409 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 409 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 410 410 { 411 411 return false; 412 412 } 413 413 414 414 static bool 415 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 415 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 416 416 { 417 417 struct comp_target *ct = comp_window_mswin_create(c); 418 418 if (ct == NULL) { ··· 424 424 return true; 425 425 } 426 426 427 - struct comp_target_factory comp_target_factory_mswin = { 427 + const struct comp_target_factory comp_target_factory_mswin = { 428 428 .name = "Microsoft Windows(TM)", 429 429 .identifier = "mswin", 430 430 .requires_vulkan_for_create = false,
+3 -3
src/xrt/compositor/main/comp_window_vk_display.c
··· 267 267 }; 268 268 269 269 static bool 270 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 270 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 271 271 { 272 272 return false; 273 273 } 274 274 275 275 static bool 276 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 276 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 277 277 { 278 278 struct comp_target *ct = comp_window_vk_display_create(c); 279 279 if (ct == NULL) { ··· 285 285 return true; 286 286 } 287 287 288 - struct comp_target_factory comp_target_factory_vk_display = { 288 + const struct comp_target_factory comp_target_factory_vk_display = { 289 289 .name = "Vulkan Display Direct-Mode", 290 290 .identifier = "vk_display", 291 291 .requires_vulkan_for_create = true,
+3 -3
src/xrt/compositor/main/comp_window_wayland.c
··· 353 353 }; 354 354 355 355 static bool 356 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 356 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 357 357 { 358 358 return false; 359 359 } 360 360 361 361 static bool 362 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 362 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 363 363 { 364 364 struct comp_target *ct = comp_window_wayland_create(c); 365 365 if (ct == NULL) { ··· 371 371 return true; 372 372 } 373 373 374 - struct comp_target_factory comp_target_factory_wayland = { 374 + const struct comp_target_factory comp_target_factory_wayland = { 375 375 .name = "Wayland Windowed", 376 376 .identifier = "wayland", 377 377 .requires_vulkan_for_create = false,
+3 -3
src/xrt/compositor/main/comp_window_xcb.c
··· 442 442 }; 443 443 444 444 static bool 445 - detect(struct comp_target_factory *ctf, struct comp_compositor *c) 445 + detect(const struct comp_target_factory *ctf, struct comp_compositor *c) 446 446 { 447 447 return false; 448 448 } 449 449 450 450 static bool 451 - create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 451 + create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct) 452 452 { 453 453 struct comp_target *ct = comp_window_xcb_create(c); 454 454 if (ct == NULL) { ··· 463 463 return true; 464 464 } 465 465 466 - struct comp_target_factory comp_target_factory_xcb = { 466 + const struct comp_target_factory comp_target_factory_xcb = { 467 467 .name = "X11(XCB) Windowed", 468 468 .identifier = "x11", 469 469 .requires_vulkan_for_create = false,