aux/util: Add u_android for global state.

This commit is contained in:
Ryan Pavlik 2020-08-18 15:46:26 -05:00
parent d11f5cb558
commit 430f79a7ca
3 changed files with 134 additions and 0 deletions

View file

@ -116,6 +116,12 @@ set(UTIL_SOURCE_FILES
util/u_var.cpp
util/u_var.h
)
if(ANDROID)
list(APPEND UTIL_SOURCE_FILES
util/u_android.c
util/u_android.h
)
endif()
set(VK_SOURCE_FILES
vk/vk_documentation.h

View file

@ -0,0 +1,60 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Functions for Android-specific global state.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @ingroup aux_util
*/
#include "u_android.h"
#include <stddef.h>
/*!
* @todo Do we need locking here? Do we need to create global refs for the
* supplied jobjects?
*/
static struct
{
struct _JavaVM *vm;
void *activity;
void *context;
} android_globals = {NULL, NULL, NULL};
void
u_android_store_vm_and_activity(struct _JavaVM *vm, void *activity)
{
android_globals.vm = vm;
android_globals.activity = activity;
}
void
u_android_store_vm_and_context(struct _JavaVM *vm, void *context)
{
android_globals.vm = vm;
android_globals.context = context;
}
struct _JavaVM *
u_android_get_vm()
{
return android_globals.vm;
}
void *
u_android_get_activity()
{
return android_globals.activity;
}
void *
u_android_get_context()
{
void *ret = android_globals.context;
if (ret == NULL) {
ret = android_globals.activity;
}
return ret;
}

View file

@ -0,0 +1,68 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Functions for Android-specific global state.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @ingroup aux_util
*/
#pragma once
#include <xrt/xrt_config_os.h>
#ifdef XRT_OS_ANDROID
#ifdef __cplusplus
extern "C" {
#endif
struct _JNIEnv;
struct _JavaVM;
/*!
* Store the Java VM pointer and the android.app.Activity jobject.
*/
void
u_android_store_vm_and_activity(struct _JavaVM *vm, void *activity);
/*!
* Store the Java VM pointer and the android.content.Context jobject.
*/
void
u_android_store_vm_and_context(struct _JavaVM *vm, void *context);
/*!
* Retrieve the Java VM pointer previously stored, if any.
*/
struct _JavaVM *
u_android_get_vm();
/*!
* Retrieve the android.app.Activity jobject previously stored, if any.
*
* For usage, cast the return value to jobject - a typedef whose definition
* differs between C (a void *) and C++ (a pointer to an empty class)
*/
void *
u_android_get_activity();
/*!
* Retrieve the android.content.Context jobject previously stored, if any.
*
* Since android.app.Activity is a sub-class of android.content.Context, the
* activity jobject will be returned if it has been set but the context has not.
*
* For usage, cast the return value to jobject - a typedef whose definition
* differs between C (a void *) and C++ (a pointer to an empty class)
*/
void *
u_android_get_context();
#ifdef __cplusplus
}
#endif
#endif // XRT_OS_ANDROID