tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
android: Add support for casting Context to Activity
Ryan Pavlik
5 years ago
65a7b490
43e0206a
+25
-7
3 changed files
expand all
collapse all
unified
split
src
xrt
auxiliary
CMakeLists.txt
android
android_globals.cpp
android_globals.h
+1
-1
src/xrt/auxiliary/CMakeLists.txt
···
6
6
android/android_ahardwarebuffer_allocator.h
7
7
android/android_custom_surface.cpp
8
8
android/android_custom_surface.h
9
9
-
android/android_globals.c
9
9
+
android/android_globals.cpp
10
10
android/android_globals.h
11
11
android/android_load_class.cpp
12
12
android/android_load_class.hpp
+17
-6
src/xrt/auxiliary/android/android_globals.c
src/xrt/auxiliary/android/android_globals.cpp
···
10
10
#include "android_globals.h"
11
11
12
12
#include <stddef.h>
13
13
+
#include <wrap/android.app.h>
13
14
14
15
/*!
15
16
* @todo Do we need locking here? Do we need to create global refs for the
···
17
18
*/
18
19
static struct
19
20
{
20
20
-
struct _JavaVM *vm;
21
21
-
void *activity;
22
22
-
void *context;
23
23
-
struct _ANativeWindow *window;
24
24
-
} android_globals = {NULL, NULL, NULL};
21
21
+
struct _JavaVM *vm = nullptr;
22
22
+
void *activity = nullptr;
23
23
+
void *context = nullptr;
24
24
+
struct _ANativeWindow *window = nullptr;
25
25
+
} android_globals;
25
26
26
27
void
27
28
android_globals_store_vm_and_activity(struct _JavaVM *vm, void *activity)
···
33
34
void
34
35
android_globals_store_vm_and_context(struct _JavaVM *vm, void *context)
35
36
{
36
36
-
37
37
android_globals.vm = vm;
38
38
android_globals.context = context;
39
39
+
if (android_globals_is_instance_of_activity(vm, context)) {
40
40
+
android_globals.activity = context;
41
41
+
}
39
42
}
40
43
44
44
+
bool
45
45
+
android_globals_is_instance_of_activity(struct _JavaVM *vm, void *obj)
46
46
+
{
47
47
+
jni::init(vm);
48
48
+
49
49
+
auto activity_cls = jni::Class(wrap::android::app::Activity::getTypeName());
50
50
+
return JNI_TRUE == jni::env()->IsInstanceOf((jobject)obj, activity_cls.getHandle());
51
51
+
}
41
52
void
42
53
android_globals_store_window(struct _ANativeWindow *window)
43
54
{
+7
src/xrt/auxiliary/android/android_globals.h
···
34
34
void
35
35
android_globals_store_vm_and_context(struct _JavaVM *vm, void *context);
36
36
37
37
+
38
38
+
/*!
39
39
+
* Is the provided jobject an instance of android.app.Activity?
40
40
+
*/
41
41
+
bool
42
42
+
android_globals_is_instance_of_activity(struct _JavaVM *vm, void *obj);
43
43
+
37
44
/*!
38
45
* Retrieve the Java VM pointer previously stored, if any.
39
46
*/