targets: Move xrt_instance implementation into targets

This commit is contained in:
Jakob Bornecrantz 2020-04-11 11:09:24 +01:00
parent b5354c4d83
commit 945f2c82ed
10 changed files with 167 additions and 138 deletions

View file

@ -6,7 +6,6 @@ set(PROBER_INCLUDES)
set(PROBER_SOURCE_FILES
p_documentation.h
p_dump.c
p_instance.c
p_json.c
p_prober.c
p_prober.h

View file

@ -4,7 +4,6 @@
prober_sources = [
'p_documentation.h',
'p_dump.c',
'p_instance.c',
'p_json.c',
'p_prober.c',
'p_prober.h',

View file

@ -1,114 +0,0 @@
#include "xrt/xrt_prober.h"
#include "xrt/xrt_instance.h"
#include "xrt/xrt_gfx_fd.h"
#include "util/u_misc.h"
/*
*
* Struct and helpers.
*
*/
struct p_instance
{
struct xrt_instance base;
struct xrt_prober *xp;
};
static inline struct p_instance *
p_instance(struct xrt_instance *xinst)
{
return (struct p_instance *)xinst;
}
/*
*
* Member functions.
*
*/
static int
p_instance_select(struct xrt_instance *xinst,
struct xrt_device **xdevs,
size_t num_xdevs)
{
struct p_instance *pinst = p_instance(xinst);
int ret = xrt_prober_probe(pinst->xp);
if (ret < 0) {
return ret;
}
return xrt_prober_select(pinst->xp, xdevs, num_xdevs);
}
static int
p_instance_create_fd_compositor(struct xrt_instance *xinst,
struct xrt_device *xdev,
bool flip_y,
struct xrt_compositor_fd **out_xcfd)
{
struct xrt_compositor_fd *xcfd =
xrt_gfx_provider_create_fd(xdev, flip_y);
if (xcfd == NULL) {
return -1;
}
*out_xcfd = xcfd;
return 0;
}
static int
p_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
{
struct p_instance *pinst = p_instance(xinst);
*out_xp = pinst->xp;
return 0;
}
static void
p_instance_destroy(struct xrt_instance *xinst)
{
struct p_instance *pinst = p_instance(xinst);
xrt_prober_destroy(&pinst->xp);
free(pinst);
}
/*
*
* Exported function(s).
*
*/
int
xrt_instance_create(struct xrt_instance **out_xinst)
{
struct xrt_prober *xp = NULL;
int ret = xrt_prober_create(&xp);
if (ret < 0) {
return ret;
}
struct p_instance *pinst = U_TYPED_CALLOC(struct p_instance);
pinst->base.select = p_instance_select;
pinst->base.create_fd_compositor = p_instance_create_fd_compositor;
pinst->base.get_prober = p_instance_get_prober;
pinst->base.destroy = p_instance_destroy;
pinst->xp = xp;
*out_xinst = &pinst->base;
return 0;
}

View file

@ -51,10 +51,3 @@ main(int argc, const char **argv)
}
return cli_print_help(argc, argv);
}
//! Needed to support st/prober.
int
xrt_gfx_provider_create_fd()
{
return -1;
}

View file

@ -1,14 +1,23 @@
# Copyright 2019-2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
set(SOURCE_FILES
####
# Lists
#
add_library(target_lists STATIC
target_lists.c
)
add_library(target_lists STATIC ${SOURCE_FILES})
target_link_libraries(target_lists PRIVATE xrt-interfaces)
target_include_directories(target_lists PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../drivers)
target_include_directories(target_lists PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(target_lists PRIVATE
xrt-interfaces
)
target_include_directories(target_lists PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../drivers
)
target_include_directories(target_lists PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
if(BUILD_DRIVER_ARDUINO)
target_link_libraries(target_lists PRIVATE drv_arduino)
@ -57,3 +66,22 @@ endif()
if(BUILD_DRIVER_VIVE)
target_link_libraries(target_lists PRIVATE drv_vive)
endif()
####
# Instance
#
add_library(target_instance STATIC
target_instance.c
)
target_link_libraries(target_instance PRIVATE
xrt-interfaces
aux_util
)
target_include_directories(target_instance PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../drivers
)
target_include_directories(target_instance PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

View file

@ -1,4 +1,4 @@
# Copyright 2019, Collabora, Ltd.
# Copyright 2019-2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
common_include = include_directories('.')
@ -11,3 +11,12 @@ lib_target_lists = static_library(
include_directories: [drv_include, xrt_include],
dependencies: [aux, xrt_config_drivers],
)
lib_target_instance = static_library(
'target_instance',
files(
'target_instance.c',
),
include_directories: [xrt_include],
dependencies: [aux],
)

View file

@ -0,0 +1,120 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Shared default implementation of the instance.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include "xrt/xrt_prober.h"
#include "xrt/xrt_instance.h"
#include "xrt/xrt_gfx_fd.h"
#include "util/u_misc.h"
/*
*
* Struct and helpers.
*
*/
struct t_instance
{
struct xrt_instance base;
struct xrt_prober *xp;
};
static inline struct t_instance *
t_instance(struct xrt_instance *xinst)
{
return (struct t_instance *)xinst;
}
/*
*
* Member functions.
*
*/
static int
t_instance_select(struct xrt_instance *xinst,
struct xrt_device **xdevs,
size_t num_xdevs)
{
struct t_instance *tinst = t_instance(xinst);
int ret = xrt_prober_probe(tinst->xp);
if (ret < 0) {
return ret;
}
return xrt_prober_select(tinst->xp, xdevs, num_xdevs);
}
static int
t_instance_create_fd_compositor(struct xrt_instance *xinst,
struct xrt_device *xdev,
bool flip_y,
struct xrt_compositor_fd **out_xcfd)
{
struct xrt_compositor_fd *xcfd =
xrt_gfx_provider_create_fd(xdev, flip_y);
if (xcfd == NULL) {
return -1;
}
*out_xcfd = xcfd;
return 0;
}
static int
t_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
{
struct t_instance *tinst = t_instance(xinst);
*out_xp = tinst->xp;
return 0;
}
static void
t_instance_destroy(struct xrt_instance *xinst)
{
struct t_instance *tinst = t_instance(xinst);
xrt_prober_destroy(&tinst->xp);
free(tinst);
}
/*
*
* Exported function(s).
*
*/
int
xrt_instance_create(struct xrt_instance **out_xinst)
{
struct xrt_prober *xp = NULL;
int ret = xrt_prober_create(&xp);
if (ret < 0) {
return ret;
}
struct t_instance *tinst = U_TYPED_CALLOC(struct t_instance);
tinst->base.select = t_instance_select;
tinst->base.create_fd_compositor = t_instance_create_fd_compositor;
tinst->base.get_prober = t_instance_get_prober;
tinst->base.destroy = t_instance_destroy;
tinst->xp = xp;
*out_xinst = &tinst->base;
return 0;
}

View file

@ -57,10 +57,3 @@ main(int argc, char **argv)
return 0;
}
//! Needed to support st/prober.
int
xrt_gfx_provider_create_fd()
{
return -1;
}

View file

@ -34,9 +34,10 @@ target_link_libraries(${RUNTIME_TARGET} PUBLIC
st_oxr
st_gui
st_prober
target_lists
target_instance
comp_main
comp_client
target_lists
)
if(BUILD_WITH_SDL2)

View file

@ -79,6 +79,7 @@ openxr = library(
lib_st_oxr,
lib_st_prober,
lib_target_lists,
lib_target_instance,
] + driver_libs + hack_libs,
include_directories: [
external_include,