mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
c/main: Constify target factories
This commit is contained in:
parent
3058f1c149
commit
9cf124254e
|
@ -1,3 +1,6 @@
|
|||
---
|
||||
- mr.1684
|
||||
---
|
||||
main: Introduce `comp_target_factory`. This struct allows us to remove long and
|
||||
cumbersome switch statements for each type. Instead the code is generic and
|
||||
tweaks for specific target types can be reused for others more easily with this
|
||||
|
|
|
@ -760,7 +760,7 @@ compositor_init_vulkan(struct comp_compositor *c)
|
|||
*
|
||||
*/
|
||||
|
||||
struct comp_target_factory *ctfs[] = {
|
||||
const struct comp_target_factory *ctfs[] = {
|
||||
#if defined VK_USE_PLATFORM_WAYLAND_KHR && defined XRT_HAVE_WAYLAND_DIRECT
|
||||
&comp_target_factory_direct_wayland,
|
||||
#endif
|
||||
|
@ -801,7 +801,7 @@ error_msg_with_list(struct comp_compositor *c, const char *msg)
|
|||
}
|
||||
|
||||
static bool
|
||||
compositor_check_deferred(struct comp_compositor *c, struct comp_target_factory *ctf)
|
||||
compositor_check_deferred(struct comp_compositor *c, const struct comp_target_factory *ctf)
|
||||
{
|
||||
if (debug_get_bool_option_disable_deferred()) {
|
||||
COMP_DEBUG(c, "Deferred window initialization globally disabled!");
|
||||
|
@ -821,7 +821,7 @@ compositor_check_deferred(struct comp_compositor *c, struct comp_target_factory
|
|||
}
|
||||
|
||||
static bool
|
||||
compositor_try_window(struct comp_compositor *c, struct comp_target_factory *ctf)
|
||||
compositor_try_window(struct comp_compositor *c, const struct comp_target_factory *ctf)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
|
||||
|
@ -845,7 +845,7 @@ compositor_try_window(struct comp_compositor *c, struct comp_target_factory *ctf
|
|||
}
|
||||
|
||||
static bool
|
||||
select_target_factory_from_settings(struct comp_compositor *c, struct comp_target_factory **out_ctf)
|
||||
select_target_factory_from_settings(struct comp_compositor *c, const struct comp_target_factory **out_ctf)
|
||||
{
|
||||
const char *identifier = c->settings.target_identifier;
|
||||
|
||||
|
@ -854,7 +854,7 @@ select_target_factory_from_settings(struct comp_compositor *c, struct comp_targe
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) {
|
||||
struct comp_target_factory *ctf = ctfs[i];
|
||||
const struct comp_target_factory *ctf = ctfs[i];
|
||||
|
||||
if (strcmp(ctf->identifier, identifier) == 0) {
|
||||
*out_ctf = ctf;
|
||||
|
@ -870,10 +870,10 @@ select_target_factory_from_settings(struct comp_compositor *c, struct comp_targe
|
|||
}
|
||||
|
||||
static bool
|
||||
select_target_factory_by_detecting(struct comp_compositor *c, struct comp_target_factory **out_ctf)
|
||||
select_target_factory_by_detecting(struct comp_compositor *c, const struct comp_target_factory **out_ctf)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) {
|
||||
struct comp_target_factory *ctf = ctfs[i];
|
||||
const struct comp_target_factory *ctf = ctfs[i];
|
||||
|
||||
if (comp_target_factory_detect(ctf, c)) {
|
||||
*out_ctf = ctf;
|
||||
|
@ -885,7 +885,7 @@ select_target_factory_by_detecting(struct comp_compositor *c, struct comp_target
|
|||
}
|
||||
|
||||
static bool
|
||||
compositor_init_window_pre_vulkan(struct comp_compositor *c, struct comp_target_factory *selected_ctf)
|
||||
compositor_init_window_pre_vulkan(struct comp_compositor *c, const struct comp_target_factory *selected_ctf)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
|
||||
|
@ -918,7 +918,7 @@ compositor_init_window_pre_vulkan(struct comp_compositor *c, struct comp_target_
|
|||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(ctfs); i++) {
|
||||
struct comp_target_factory *ctf = ctfs[i];
|
||||
const struct comp_target_factory *ctf = ctfs[i];
|
||||
|
||||
// Skip targets that requires Vulkan.
|
||||
if (ctf->requires_vulkan_for_create) {
|
||||
|
@ -1011,7 +1011,7 @@ compositor_init_renderer(struct comp_compositor *c)
|
|||
|
||||
xrt_result_t
|
||||
comp_main_create_system_compositor(struct xrt_device *xdev,
|
||||
struct comp_target_factory *ctf,
|
||||
const struct comp_target_factory *ctf,
|
||||
struct xrt_system_compositor **out_xsysc)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
|
|
|
@ -109,7 +109,7 @@ struct comp_compositor
|
|||
struct render_resources nr;
|
||||
|
||||
//! The selected target factory that we create our target from.
|
||||
struct comp_target_factory *target_factory;
|
||||
const struct comp_target_factory *target_factory;
|
||||
|
||||
//! The target we are displaying to.
|
||||
struct comp_target *target;
|
||||
|
|
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
*/
|
||||
xrt_result_t
|
||||
comp_main_create_system_compositor(struct xrt_device *xdev,
|
||||
struct comp_target_factory *ctf,
|
||||
const struct comp_target_factory *ctf,
|
||||
struct xrt_system_compositor **out_xsysc);
|
||||
|
||||
|
||||
|
|
|
@ -555,13 +555,15 @@ struct comp_target_factory
|
|||
* This is needed for NVIDIA direct mode which window must be created
|
||||
* after vulkan has initialized.
|
||||
*/
|
||||
bool (*detect)(struct comp_target_factory *ctf, struct comp_compositor *c);
|
||||
bool (*detect)(const struct comp_target_factory *ctf, struct comp_compositor *c);
|
||||
|
||||
/*!
|
||||
* Create a target from this factory, some targets requires Vulkan to
|
||||
* have been initialised, see @ref requires_vulkan_for_create.
|
||||
*/
|
||||
bool (*create_target)(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct);
|
||||
bool (*create_target)(const struct comp_target_factory *ctf,
|
||||
struct comp_compositor *c,
|
||||
struct comp_target **out_ct);
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -571,7 +573,7 @@ struct comp_target_factory
|
|||
* @ingroup comp_main
|
||||
*/
|
||||
static inline bool
|
||||
comp_target_factory_detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
comp_target_factory_detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
|
||||
|
@ -585,7 +587,7 @@ comp_target_factory_detect(struct comp_target_factory *ctf, struct comp_composit
|
|||
* @ingroup comp_main
|
||||
*/
|
||||
static inline bool
|
||||
comp_target_factory_create_target(struct comp_target_factory *ctf,
|
||||
comp_target_factory_create_target(const struct comp_target_factory *ctf,
|
||||
struct comp_compositor *c,
|
||||
struct comp_target **out_ct)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ extern "C" {
|
|||
struct comp_target *
|
||||
comp_window_xcb_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_xcb;
|
||||
extern const struct comp_target_factory comp_target_factory_xcb;
|
||||
|
||||
#endif // VK_USE_PLATFORM_XCB_KHR
|
||||
|
||||
|
@ -52,7 +52,7 @@ extern struct comp_target_factory comp_target_factory_xcb;
|
|||
struct comp_target *
|
||||
comp_window_wayland_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_wayland;
|
||||
extern const struct comp_target_factory comp_target_factory_wayland;
|
||||
|
||||
/*!
|
||||
* Create a direct surface to a HMD using Wayland.
|
||||
|
@ -62,7 +62,7 @@ extern struct comp_target_factory comp_target_factory_wayland;
|
|||
struct comp_target *
|
||||
comp_window_direct_wayland_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_direct_wayland;
|
||||
extern const struct comp_target_factory comp_target_factory_direct_wayland;
|
||||
|
||||
#endif // VK_USE_PLATFORM_WAYLAND_KHR
|
||||
|
||||
|
@ -76,7 +76,7 @@ extern struct comp_target_factory comp_target_factory_direct_wayland;
|
|||
struct comp_target *
|
||||
comp_window_direct_randr_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_direct_randr;
|
||||
extern const struct comp_target_factory comp_target_factory_direct_randr;
|
||||
|
||||
/*!
|
||||
* Create a direct surface to an HMD on NVIDIA.
|
||||
|
@ -87,7 +87,7 @@ extern struct comp_target_factory comp_target_factory_direct_randr;
|
|||
struct comp_target *
|
||||
comp_window_direct_nvidia_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_direct_nvidia;
|
||||
extern const struct comp_target_factory comp_target_factory_direct_nvidia;
|
||||
#endif // VK_USE_PLATFORM_XLIB_XRANDR_EXT
|
||||
|
||||
#if 1
|
||||
|
@ -100,7 +100,7 @@ extern struct comp_target_factory comp_target_factory_direct_nvidia;
|
|||
struct comp_target *
|
||||
comp_window_vk_display_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_vk_display;
|
||||
extern const struct comp_target_factory comp_target_factory_vk_display;
|
||||
#endif // 1
|
||||
|
||||
#ifdef XRT_OS_ANDROID
|
||||
|
@ -113,7 +113,7 @@ extern struct comp_target_factory comp_target_factory_vk_display;
|
|||
struct comp_target *
|
||||
comp_window_android_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_android;
|
||||
extern const struct comp_target_factory comp_target_factory_android;
|
||||
#endif // XRT_OS_ANDROID
|
||||
|
||||
#ifdef XRT_OS_WINDOWS
|
||||
|
@ -127,7 +127,7 @@ extern struct comp_target_factory comp_target_factory_android;
|
|||
struct comp_target *
|
||||
comp_window_mswin_create(struct comp_compositor *c);
|
||||
|
||||
extern struct comp_target_factory comp_target_factory_mswin;
|
||||
extern const struct comp_target_factory comp_target_factory_mswin;
|
||||
#endif // XRT_OS_WINDOWS
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -202,13 +202,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_android_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -220,7 +220,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_android = {
|
||||
const struct comp_target_factory comp_target_factory_android = {
|
||||
.name = "Android",
|
||||
.identifier = "android",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
|
@ -413,7 +413,7 @@ check_vulkan_caps(struct comp_compositor *c, bool *out_detected)
|
|||
}
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
bool detected = false;
|
||||
|
||||
|
@ -425,7 +425,7 @@ detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
|||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_direct_nvidia_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -437,7 +437,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_direct_nvidia = {
|
||||
const struct comp_target_factory comp_target_factory_direct_nvidia = {
|
||||
.name = "NVIDIA Direct-Mode",
|
||||
.identifier = "x11_direct_nvidia",
|
||||
.requires_vulkan_for_create = true,
|
||||
|
|
|
@ -466,13 +466,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_direct_randr_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -484,7 +484,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_direct_randr = {
|
||||
const struct comp_target_factory comp_target_factory_direct_randr = {
|
||||
.name = "X11(RandR) Direct-Mode",
|
||||
.identifier = "x11_direct",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
|
@ -483,13 +483,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_direct_wayland_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -501,7 +501,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_direct_wayland = {
|
||||
const struct comp_target_factory comp_target_factory_direct_wayland = {
|
||||
.name = "Wayland Direct-Mode",
|
||||
.identifier = "direct_wayland",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
|
@ -406,13 +406,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_mswin_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -424,7 +424,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_mswin = {
|
||||
const struct comp_target_factory comp_target_factory_mswin = {
|
||||
.name = "Microsoft Windows(TM)",
|
||||
.identifier = "mswin",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
|
@ -267,13 +267,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_vk_display_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -285,7 +285,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_vk_display = {
|
||||
const struct comp_target_factory comp_target_factory_vk_display = {
|
||||
.name = "Vulkan Display Direct-Mode",
|
||||
.identifier = "vk_display",
|
||||
.requires_vulkan_for_create = true,
|
||||
|
|
|
@ -353,13 +353,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_wayland_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -371,7 +371,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_wayland = {
|
||||
const struct comp_target_factory comp_target_factory_wayland = {
|
||||
.name = "Wayland Windowed",
|
||||
.identifier = "wayland",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
|
@ -442,13 +442,13 @@ static const char *instance_extensions[] = {
|
|||
};
|
||||
|
||||
static bool
|
||||
detect(struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
detect(const struct comp_target_factory *ctf, struct comp_compositor *c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
create_target(const struct comp_target_factory *ctf, struct comp_compositor *c, struct comp_target **out_ct)
|
||||
{
|
||||
struct comp_target *ct = comp_window_xcb_create(c);
|
||||
if (ct == NULL) {
|
||||
|
@ -463,7 +463,7 @@ create_target(struct comp_target_factory *ctf, struct comp_compositor *c, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
struct comp_target_factory comp_target_factory_xcb = {
|
||||
const struct comp_target_factory comp_target_factory_xcb = {
|
||||
.name = "X11(XCB) Windowed",
|
||||
.identifier = "x11",
|
||||
.requires_vulkan_for_create = false,
|
||||
|
|
Loading…
Reference in a new issue