1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/*
* gxr
* Copyright 2018 Collabora Ltd.
* Author: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
* SPDX-License-Identifier: MIT
*/
#include <glib.h>
#include <gulkan.h>
#include "gxr.h"
#define ENUM_TO_STR(r) case r: return #r
static void
_test_scene_available (void)
{
GxrContext* gxr_context = gxr_context_new_headless ("Test Context", 1);
gboolean scene_available =
!gxr_context_is_another_scene_running (gxr_context);
g_print ("Scene available: %d\n", scene_available);
g_object_unref (gxr_context);
}
static const gchar*
gxr_api_string (GxrApi v)
{
switch (v)
{
ENUM_TO_STR(GXR_API_OPENXR);
ENUM_TO_STR(GXR_API_OPENVR);
default:
return "UNKNOWN API";
}
}
static void
_test_init_context (GxrAppType type)
{
GxrContext *context = gxr_context_new (type, "Test Context", 1);
g_assert_nonnull (context);
GxrApi api = gxr_context_get_api (context);
g_print ("Using API: %s\n", gxr_api_string (api));
g_object_unref (context);
}
static void
_system_quit_cb (GxrContext *context,
GxrQuitEvent *event,
gboolean *quit_completed)
{
g_print ("Acknowledging VR quit event %d\n", event->reason);
gxr_context_acknowledge_quit (context);
*quit_completed = TRUE;
g_free (event);
}
static void
_test_quit_event (GxrAppType type)
{
GxrContext *context = gxr_context_new (type, "Test Context", 1);
g_assert_nonnull (context);
gboolean quit_completed = FALSE;
g_signal_connect (context, "quit-event",
(GCallback) _system_quit_cb, &quit_completed);
g_print ("Requesting exit\n");
gxr_context_request_quit (context);
while (!quit_completed)
{
gxr_context_poll_event (context);
g_usleep (100000);
}
g_object_unref (context);
g_print ("Exit completed\n");
}
int
main ()
{
_test_scene_available ();
_test_init_context (GXR_APP_SCENE);
_test_init_context (GXR_APP_OVERLAY);
_test_quit_event (GXR_APP_SCENE);
gxr_backend_shutdown ();
return 0;
}
|