mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
t/gui: Add st/prober code
This commit is contained in:
parent
44d58037b7
commit
968952aa9e
|
@ -16,6 +16,7 @@ include_directories(
|
|||
set(SOURCE_FILES
|
||||
gui_common.h
|
||||
gui_main.c
|
||||
gui_prober.c
|
||||
gui_sdl2.c
|
||||
../../../external/glad/gl.h
|
||||
../../../external/glad/gl.c
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NUM_XDEVS 8
|
||||
struct xrt_device;
|
||||
struct xrt_prober;
|
||||
struct time_state;
|
||||
|
||||
/*!
|
||||
* Common struct holding state for the GUI interface.
|
||||
*
|
||||
|
@ -46,6 +51,10 @@ struct program
|
|||
uint32_t height;
|
||||
bool own_buffer;
|
||||
} blit;
|
||||
|
||||
struct time_state *timekeeping;
|
||||
struct xrt_device *xdevs[NUM_XDEVS];
|
||||
struct xrt_prober *xp;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -85,6 +94,30 @@ gui_sdl2_display_R8G8B8(struct program *p,
|
|||
void
|
||||
gui_sdl2_quit(struct program *p);
|
||||
|
||||
/*!
|
||||
* Initialize the prober and open all devices found.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
int
|
||||
gui_prober_init(struct program *p);
|
||||
|
||||
/*!
|
||||
* Update all devices.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
void
|
||||
gui_prober_update(struct program *p);
|
||||
|
||||
/*!
|
||||
* Destroy all opened devices and destroy the prober.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
void
|
||||
gui_prober_teardown(struct program *p);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
123
src/xrt/targets/gui/gui_prober.c
Normal file
123
src/xrt/targets/gui/gui_prober.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
// Copyright 2019, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Enable the use of the prober in the gui application.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
*/
|
||||
|
||||
#include "util/u_time.h"
|
||||
#include "target_lists.h"
|
||||
#include "gui_common.h"
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Helper functions.
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
do_exit(struct program *p, int ret)
|
||||
{
|
||||
gui_prober_teardown(p);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* 'Exported' functions.
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
gui_prober_init(struct program *p)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
p->timekeeping = time_state_create();
|
||||
|
||||
// Initialize the prober.
|
||||
printf(" :: Creating prober!\n");
|
||||
|
||||
ret = xrt_prober_create(&p->xp);
|
||||
if (ret != 0) {
|
||||
return do_exit(p, ret);
|
||||
}
|
||||
|
||||
// Need to prime the prober with devices before dumping and listing.
|
||||
printf(" :: Probing!\n");
|
||||
|
||||
ret = xrt_prober_probe(p->xp);
|
||||
if (ret != 0) {
|
||||
return do_exit(p, ret);
|
||||
}
|
||||
|
||||
// Multiple devices can be found.
|
||||
printf(" :: Selecting devices!\n");
|
||||
|
||||
ret = xrt_prober_select(p->xp, p->xdevs, NUM_XDEVS);
|
||||
if (ret != 0) {
|
||||
do_exit(p, ret);
|
||||
}
|
||||
if (p->xdevs[0] == NULL) {
|
||||
printf("\tNo HMD found! :(\n");
|
||||
return do_exit(p, -1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
||||
if (p->xdevs[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\tFound '%s'\n", p->xdevs[i]->str);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
gui_prober_update(struct program *p)
|
||||
{
|
||||
// We haven't been initialized
|
||||
if (p->timekeeping == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
time_state_get_now_and_update(p->timekeeping);
|
||||
|
||||
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
||||
if (p->xdevs[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
p->xdevs[i]->update_inputs(p->xdevs[i], p->timekeeping);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gui_prober_teardown(struct program *p)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
||||
if (p->xdevs[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
p->xdevs[i]->destroy(p->xdevs[i]);
|
||||
p->xdevs[i] = NULL;
|
||||
}
|
||||
|
||||
if (p->timekeeping != NULL) {
|
||||
time_state_destroy(p->timekeeping);
|
||||
p->timekeeping = NULL;
|
||||
}
|
||||
|
||||
xrt_prober_destroy(&p->xp);
|
||||
}
|
||||
|
||||
int
|
||||
xrt_prober_create(struct xrt_prober **out_xp)
|
||||
{
|
||||
return xrt_prober_create_with_lists(out_xp, &target_lists);
|
||||
}
|
Loading…
Reference in a new issue