Skip to content

Commit 85a3478

Browse files
committed
added a view-based dialog (alert only) in order to display a custom dialog on the meta-quest
1 parent e93bd37 commit 85a3478

22 files changed

Lines changed: 579 additions & 381 deletions

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
3-
id 'com.android.application' version '7.3.0-rc01' apply false
4-
id 'com.android.library' version '7.3.0-rc01' apply false
3+
id 'com.android.application' version '7.3.1' apply false
4+
id 'com.android.library' version '7.3.1' apply false
55
}

libwebview/build.gradle

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,17 @@ android {
4545
sourceCompatibility JavaVersion.VERSION_1_8
4646
targetCompatibility JavaVersion.VERSION_1_8
4747
}
48-
externalNativeBuild{
49-
cmake{
50-
path="src/main/cpp/CMakeLists.txt"
51-
//version "3.24.0"
48+
externalNativeBuild {
49+
cmake {
50+
path = "src/main/cpp/CMakeLists.txt"
5251
}
5352
}
5453
}
5554

5655
dependencies {
5756
compileOnly fileTree(dir: 'libs', include: 'classes.jar')
58-
implementation 'androidx.appcompat:appcompat:1.7.0' // api level 33 ~ 34
59-
//implementation 'androidx.appcompat:appcompat:1.6.1' // api level 31 ~ 32
60-
//implementation 'androidx.appcompat:appcompat:1.3.1' // api level 30
6157
}
6258

63-
// android.libraryVariants.all { variant ->
6459
android.libraryVariants.configureEach { variant ->
6560
variant.outputs.each { output ->
6661
output.packageLibrary.exclude('libs/classes.jar')

libwebview/src/main/cpp/JNIUtil/JNIUtil.cpp

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "JNILog.h"
33

44
extern "C" {
5-
using UnityRenderEvent = void(*)(int);
5+
using UnityRenderEvent = void (*)(int);
66

77
UnityRenderEvent UpdateSurfaceFunc();
88

@@ -19,15 +19,15 @@ bool GetSharedBufferUpdateFlag(int);
1919
void SetHardwareBufferUpdateFlag(int, bool);
2020
}
2121

22-
JavaVM* g_jvm;
22+
JavaVM *g_jvm;
2323

24-
JNIEnv* GetEnv() {
25-
void* env = NULL;
24+
JNIEnv *GetEnv() {
25+
void *env = NULL;
2626
jint status = g_jvm->GetEnv(&env, JNI_VERSION_1_6);
27-
return reinterpret_cast<JNIEnv*>(env);
27+
return reinterpret_cast<JNIEnv *>(env);
2828
}
2929

30-
static void ThreadDestructor(void* prev_jni_ptr) {
30+
static void ThreadDestructor(void *prev_jni_ptr) {
3131
if (!GetEnv()) {
3232
LOGD("JNI env already detach from this thread");
3333
return;
@@ -48,62 +48,69 @@ static void CreateJNIPtrKey() {
4848
pthread_key_create(&g_jni_ptr, &ThreadDestructor);
4949
}
5050

51-
jint JNI_OnLoad(JavaVM *vm, void* reserved) {
51+
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
5252
g_jvm = vm;
5353

5454
g_jvm->AttachCurrentThread(&g_main_thread_env, NULL);
5555

56-
g_class_unity_connect = (jclass)g_main_thread_env->NewGlobalRef(g_main_thread_env->FindClass("com/tlab/libwebview/UnityConnect"));
56+
g_class_unity_connect = (jclass) g_main_thread_env->NewGlobalRef(
57+
g_main_thread_env->FindClass("com/tlab/libwebview/UnityConnect"));
5758

5859
if (g_class_unity_connect == NULL) {
5960
LOGE("JNI Class 'UnityConnect' not found");
6061
}
6162

62-
g_func_update_surface = g_main_thread_env->GetMethodID(g_class_unity_connect, "updateSurface", "()V");
63+
g_func_update_surface = g_main_thread_env->GetMethodID(g_class_unity_connect, "updateSurface",
64+
"()V");
6365

6466
if (g_func_update_surface == NULL) {
6567
LOGE("JNI Function 'updateSurface' not found");
6668
}
6769

68-
g_func_get_binded_platform_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect, "getBindedPlatformTextureID", "()J");
70+
g_func_get_binded_platform_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
71+
"getBindedPlatformTextureID",
72+
"()J");
6973

7074
if (g_func_get_binded_platform_texture_id == NULL) {
7175
LOGE("JNI Function 'GetBindedPlatformTextureID' not found");
7276
}
7377

74-
g_func_release_shared_texture = g_main_thread_env->GetMethodID(g_class_unity_connect, "releaseSharedTexture", "()V");
78+
g_func_release_shared_texture = g_main_thread_env->GetMethodID(g_class_unity_connect,
79+
"releaseSharedTexture", "()V");
7580

7681
if (g_func_release_shared_texture == NULL) {
7782
LOGE("JNI Function 'setUnityTextureID' not found");
7883
}
7984

80-
g_func_set_unity_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect, "setUnityTextureID", "(J)V");
85+
g_func_set_unity_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
86+
"setUnityTextureID", "(J)V");
8187

8288
if (g_func_set_unity_texture_id == NULL) {
8389
LOGE("JNI Function 'setUnityTextureID' not found");
8490
}
8591

86-
g_field_is_shared_buffer_updated = g_main_thread_env->GetFieldID(g_class_unity_connect, "mSharedBufferUpdated","Z");
92+
g_field_is_shared_buffer_updated = g_main_thread_env->GetFieldID(g_class_unity_connect,
93+
"mSharedBufferUpdated", "Z");
8794

8895
return JNI_VERSION_1_6;
8996
}
9097

91-
JNIEnv* AttachCurrentThreadIfNeeded() {
92-
JNIEnv* jni = GetEnv();
98+
JNIEnv *AttachCurrentThreadIfNeeded() {
99+
JNIEnv *jni = GetEnv();
93100

94101
if (jni) {
95102
return jni;
96103
}
97104

98-
JNIEnv* env = NULL;
105+
JNIEnv *env = NULL;
99106

100107
int status = g_jvm->AttachCurrentThread(&env, NULL);
101108

102-
if (status != JNI_OK ) {
109+
if (status != JNI_OK) {
103110
LOGE("JNIEnv Filed to attach current thread: %d", status);
104111
}
105112

106-
jni = reinterpret_cast<JNIEnv*>(env);
113+
jni = reinterpret_cast<JNIEnv *>(env);
107114

108115
CreateJNIPtrKey();
109116

@@ -115,44 +122,44 @@ JNIEnv* AttachCurrentThreadIfNeeded() {
115122
}
116123

117124
void UpdateSurface(int instance_ptr) {
118-
JNIEnv* env = AttachCurrentThreadIfNeeded();
125+
JNIEnv *env = AttachCurrentThreadIfNeeded();
119126

120-
jobject instance = (jobject)((long)instance_ptr);
127+
jobject instance = (jobject) ((long) instance_ptr);
121128

122129
env->CallVoidMethod(instance, g_func_update_surface);
123130
}
124131

125-
UnityRenderEvent UpdateSurfaceFunc()
126-
{
132+
UnityRenderEvent UpdateSurfaceFunc() {
127133
return UpdateSurface;
128134
}
129135

130136
long GetBindedPlatformTextureID(int instance_ptr) {
131-
jobject instance = (jobject)((long)instance_ptr);
137+
jobject instance = (jobject) ((long) instance_ptr);
132138

133139
return g_main_thread_env->CallLongMethod(instance, g_func_get_binded_platform_texture_id);
134140
}
135141

136142
void SetUnityTextureID(int instance_ptr, long unity_texture_id) {
137-
jobject instance = (jobject)((long)instance_ptr);
143+
jobject instance = (jobject) ((long) instance_ptr);
138144

139-
return g_main_thread_env->CallVoidMethod(instance, g_func_set_unity_texture_id, (jlong)unity_texture_id);
145+
return g_main_thread_env->CallVoidMethod(instance, g_func_set_unity_texture_id,
146+
(jlong) unity_texture_id);
140147
}
141148

142-
void ReleaseSharedTexture(int instance_ptr){
143-
jobject instance = (jobject)((long)instance_ptr);
149+
void ReleaseSharedTexture(int instance_ptr) {
150+
jobject instance = (jobject) ((long) instance_ptr);
144151

145152
g_main_thread_env->CallVoidMethod(instance, g_func_release_shared_texture);
146153
}
147154

148155
bool GetSharedBufferUpdateFlag(int instance_ptr) {
149-
jobject instance = (jobject)((long)instance_ptr);
156+
jobject instance = (jobject) ((long) instance_ptr);
150157

151158
return g_main_thread_env->GetBooleanField(instance, g_field_is_shared_buffer_updated);
152159
}
153160

154161
void SetHardwareBufferUpdateFlag(int instance_ptr, bool value) {
155-
jobject instance = (jobject)((long)instance_ptr);
162+
jobject instance = (jobject) ((long) instance_ptr);
156163

157164
g_main_thread_env->SetBooleanField(instance, g_field_is_shared_buffer_updated, value);
158165
}

libwebview/src/main/cpp/JNIUtil/JNIUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace {
1919
jfieldID g_field_is_shared_buffer_updated = nullptr;
2020

2121
// https://stackoverflow.com/questions/7096350/can-you-cache-jnienv
22-
JNIEnv* g_main_thread_env = nullptr;
22+
JNIEnv *g_main_thread_env = nullptr;
2323

2424
pthread_key_t g_jni_ptr;
2525
}

libwebview/src/main/cpp/SharedTexture/JSharedTexture.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Java_com_robot9_shared_SharedTexture_getBindedPlatformTexture(JNIEnv *env, jobje
127127

128128
extern "C"
129129
JNIEXPORT void JNICALL
130-
Java_com_robot9_shared_SharedTexture_setUnityTexture(JNIEnv* env, jobject /* this */,
130+
Java_com_robot9_shared_SharedTexture_setUnityTexture(JNIEnv *env, jobject /* this */,
131131
jlong ctx, jlong unityTexID) {
132132
if (ctx == 0) {
133133
return;
@@ -143,7 +143,7 @@ Java_com_robot9_shared_SharedTexture_setUnityTexture(JNIEnv* env, jobject /* thi
143143

144144
extern "C"
145145
JNIEXPORT void JNICALL
146-
Java_com_robot9_shared_SharedTexture_updateUnityTexture(JNIEnv* env, jobject /* this */,
146+
Java_com_robot9_shared_SharedTexture_updateUnityTexture(JNIEnv *env, jobject /* this */,
147147
jlong ctx) {
148148
if (ctx == 0) {
149149
return;

libwebview/src/main/cpp/SharedTexture/RenderAPI.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33

44
namespace tlab {
55

6-
RenderAPI* CreateRenderAPI(UnityGfxRenderer apiType)
7-
{
6+
RenderAPI *CreateRenderAPI(UnityGfxRenderer apiType) {
87
DEVLOGD("[sharedtex-jni] [CreateRenderAPI] pass 0 (start)");
98

109
# if SUPPORT_OPENGL_UNIFIED
11-
extern RenderAPI* CreateRenderAPI_OpenGLCoreES(UnityGfxRenderer apiType);
10+
extern RenderAPI *CreateRenderAPI_OpenGLCoreES(UnityGfxRenderer apiType);
1211
m_glesAPI = CreateRenderAPI_OpenGLCoreES(apiType);
1312
# endif // if SUPPORT_OPENGL_UNIFIED
1413

1514
# if SUPPORT_VULKAN
16-
if (apiType == kUnityGfxRendererVulkan)
17-
{
18-
extern RenderAPI* CreateRenderAPI_Vulkan();
15+
if (apiType == kUnityGfxRendererVulkan) {
16+
extern RenderAPI *CreateRenderAPI_Vulkan();
1917
m_vulkanAPI = CreateRenderAPI_Vulkan();
2018
}
2119
# endif // if SUPPORT_VULKAN

libwebview/src/main/cpp/SharedTexture/RenderAPI.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ namespace tlab {
1919
// and "modify a texture" at this point.
2020
//
2121
// There are implementations of this base class for D3D9, D3D11, OpenGL etc.; see individual RenderAPI_* files.
22-
class RenderAPI
23-
{
22+
class RenderAPI {
2423
public:
25-
virtual ~RenderAPI() { }
24+
virtual ~RenderAPI() {}
2625

2726
// Process general event like initialization, shutdown, device loss/reset etc.
28-
virtual void ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces* interfaces) = 0;
27+
virtual void
28+
ProcessDeviceEvent(UnityGfxDeviceEventType type, IUnityInterfaces *interfaces) = 0;
2929

30-
virtual long RegistHWBufferConnectedTexture(uint32_t width, uint32_t height, AHardwareBuffer* hwBuffer) = 0;
30+
virtual long RegistHWBufferConnectedTexture(uint32_t width, uint32_t height,
31+
AHardwareBuffer *hwBuffer) = 0;
3132

3233
virtual void UnRegistHWBufferConnectedTexture(long platformTexID) = 0;
3334

@@ -39,13 +40,13 @@ namespace tlab {
3940
};
4041

4142
// Create a graphics API implementation instance for the given API type.
42-
RenderAPI* CreateRenderAPI(UnityGfxRenderer apiType);
43+
RenderAPI *CreateRenderAPI(UnityGfxRenderer apiType);
4344

4445
#if SUPPORT_OPENGL_UNIFIED
45-
inline RenderAPI* m_glesAPI;
46+
inline RenderAPI *m_glesAPI;
4647
#endif
4748

4849
#if SUPPORT_VULKAN
49-
inline RenderAPI* m_vulkanAPI;
50+
inline RenderAPI *m_vulkanAPI;
5051
#endif
5152
}

0 commit comments

Comments
 (0)