Skip to content

Commit 4e6e742

Browse files
committed
add support for html5 input with custom widget, update resize process
1 parent 8ba23df commit 4e6e742

18 files changed

Lines changed: 1484 additions & 695 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Java_com_robot9_shared_SharedTexture_getHeight(JNIEnv *env, jobject /* this */,
112112

113113
extern "C"
114114
JNIEXPORT jlong JNICALL
115-
Java_com_robot9_shared_SharedTexture_getBindedPlatformTexture(JNIEnv *env, jobject /* this */,
116-
jlong ctx) {
115+
Java_com_robot9_shared_SharedTexture_getPlatformTexture(JNIEnv *env, jobject /* this */,
116+
jlong ctx) {
117117
if (ctx == 0) {
118118
return 0;
119119
}
@@ -122,7 +122,7 @@ Java_com_robot9_shared_SharedTexture_getBindedPlatformTexture(JNIEnv *env, jobje
122122
if (!_ctx->buffer) {
123123
return 0;
124124
}
125-
return static_cast<jlong>(_ctx->buffer->getBindedPlatformTexture());
125+
return static_cast<jlong>(_ctx->buffer->getPlatformTexture());
126126
}
127127

128128
extern "C"

libwebview/src/main/cpp/SharedTexture/RenderAPI_Vulkan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,4 @@ namespace tlab {
453453
}
454454
}
455455

456-
#endif // #if SUPPORT_VULKANa
456+
#endif // #if SUPPORT_VULKAN

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ namespace robot9 {
166166
DEVLOGE("[sharedtex-jni] [SharedTexture] render api is null");
167167
}
168168

169-
m_bindedPlatformTexID = m_renderAPI->RegistHWBufferConnectedTexture(m_width, m_height,
170-
m_buffer);
169+
m_platformTexID = m_renderAPI->RegistHWBufferConnectedTexture(m_width, m_height,
170+
m_buffer);
171171

172-
if (m_bindedPlatformTexID == 0) {
172+
if (m_platformTexID == 0) {
173173
LOGE("constructor failed: m_bindTextureId");
174174
return;
175175
}
@@ -180,11 +180,11 @@ namespace robot9 {
180180
SharedTexture::~SharedTexture() {
181181
LOGD("~SharedTexture");
182182

183-
if (m_bindedPlatformTexID != 0) {
184-
m_renderAPI->UnRegistHWBufferConnectedTexture(m_bindedPlatformTexID);
183+
if (m_platformTexID != 0) {
184+
m_renderAPI->UnRegistHWBufferConnectedTexture(m_platformTexID);
185185
}
186186

187-
m_bindedPlatformTexID = NULL;
187+
m_platformTexID = NULL;
188188
m_unityTexID = NULL;
189189
m_unityPlatformTexID = NULL;
190190

@@ -206,8 +206,8 @@ namespace robot9 {
206206
}
207207

208208
void SharedTexture::downloadBuffer() const {
209-
if (m_renderAPI && m_bindedPlatformTexID != 0) {
210-
m_renderAPI->DownloadHardwareBuffer(m_bindedPlatformTexID);
209+
if (m_renderAPI && m_platformTexID != 0) {
210+
m_renderAPI->DownloadHardwareBuffer(m_platformTexID);
211211
}
212212
}
213213

@@ -219,8 +219,8 @@ namespace robot9 {
219219
return m_height;
220220
}
221221

222-
long SharedTexture::getBindedPlatformTexture() const {
223-
return m_bindedPlatformTexID;
222+
long SharedTexture::getPlatformTexture() const {
223+
return m_platformTexID;
224224
}
225225

226226
void SharedTexture::setUnityTexture(long unityTexID) {
@@ -231,8 +231,8 @@ namespace robot9 {
231231
}
232232

233233
void SharedTexture::updateUnityTexture() {
234-
if (m_renderAPI && m_unityPlatformTexID && m_bindedPlatformTexID) {
235-
m_renderAPI->UpdateUnityTexture(m_unityPlatformTexID, m_bindedPlatformTexID);
234+
if (m_renderAPI && m_unityPlatformTexID && m_platformTexID) {
235+
m_renderAPI->UpdateUnityTexture(m_unityPlatformTexID, m_platformTexID);
236236
}
237237
}
238238
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace robot9 {
3939

4040
int getHeight() const;
4141

42-
long getBindedPlatformTexture() const;
42+
long getPlatformTexture() const;
4343

4444
void setUnityTexture(long unityTexID);
4545

@@ -56,7 +56,7 @@ namespace robot9 {
5656
AHardwareBuffer *m_buffer = nullptr;
5757
int m_width = 0;
5858
int m_height = 0;
59-
long m_bindedPlatformTexID = 0;
59+
long m_platformTexID = 0;
6060
long m_unityTexID = 0;
6161
long m_unityPlatformTexID = 0;
6262
};

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

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ UnityRenderEvent UpdateSurfaceFunc();
88

99
void UpdateSurface(int);
1010

11-
long GetBindedPlatformTextureID(int);
11+
long GetPlatformTextureID(int);
1212

1313
void SetUnityTextureID(int, long);
1414

1515
void ReleaseSharedTexture(int);
1616

17+
bool ContentExists(int);
18+
1719
bool GetSharedBufferUpdateFlag(int);
1820

1921
void SetHardwareBufferUpdateFlag(int, bool);
@@ -22,7 +24,7 @@ void SetHardwareBufferUpdateFlag(int, bool);
2224
JavaVM *g_jvm;
2325

2426
JNIEnv *GetEnv() {
25-
void *env = NULL;
27+
void *env = nullptr;
2628
jint status = g_jvm->GetEnv(&env, JNI_VERSION_1_6);
2729
return reinterpret_cast<JNIEnv *>(env);
2830
}
@@ -36,7 +38,7 @@ static void ThreadDestructor(void *prev_jni_ptr) {
3638
if (GetEnv() == prev_jni_ptr) {
3739
jint status = g_jvm->DetachCurrentThread();
3840

39-
if (!(status == JNI_OK)) {
41+
if (status != JNI_OK) {
4042
LOGE("JNI filed to detach env from this thread");
4143
}
4244
}
@@ -51,46 +53,54 @@ static void CreateJNIPtrKey() {
5153
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
5254
g_jvm = vm;
5355

54-
g_jvm->AttachCurrentThread(&g_main_thread_env, NULL);
56+
g_jvm->AttachCurrentThread(&g_main_thread_env, nullptr);
5557

5658
g_class_unity_connect = (jclass) g_main_thread_env->NewGlobalRef(
5759
g_main_thread_env->FindClass("com/tlab/libwebview/UnityConnect"));
5860

59-
if (g_class_unity_connect == NULL) {
61+
if (g_class_unity_connect == nullptr) {
6062
LOGE("JNI Class 'UnityConnect' not found");
6163
}
6264

6365
g_func_update_surface = g_main_thread_env->GetMethodID(g_class_unity_connect, "updateSurface",
6466
"()V");
6567

66-
if (g_func_update_surface == NULL) {
68+
if (g_func_update_surface == nullptr) {
6769
LOGE("JNI Function 'updateSurface' not found");
6870
}
6971

70-
g_func_get_binded_platform_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
71-
"getBindedPlatformTextureID",
72-
"()J");
72+
g_func_get_platform_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
73+
"getPlatformTextureID",
74+
"()J");
7375

74-
if (g_func_get_binded_platform_texture_id == NULL) {
75-
LOGE("JNI Function 'GetBindedPlatformTextureID' not found");
76+
if (g_func_get_platform_texture_id == nullptr) {
77+
LOGE("JNI Function 'GetPlatformTextureID' not found");
7678
}
7779

7880
g_func_release_shared_texture = g_main_thread_env->GetMethodID(g_class_unity_connect,
7981
"releaseSharedTexture", "()V");
8082

81-
if (g_func_release_shared_texture == NULL) {
83+
if (g_func_release_shared_texture == nullptr) {
8284
LOGE("JNI Function 'setUnityTextureID' not found");
8385
}
8486

8587
g_func_set_unity_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
8688
"setUnityTextureID", "(J)V");
8789

88-
if (g_func_set_unity_texture_id == NULL) {
90+
if (g_func_content_exists == nullptr) {
91+
LOGE("JNI Function 'contentExists' not found");
92+
}
93+
94+
g_func_content_exists = g_main_thread_env->GetMethodID(g_class_unity_connect,
95+
"contentExists", "()Z");
96+
97+
if (g_func_set_unity_texture_id == nullptr) {
8998
LOGE("JNI Function 'setUnityTextureID' not found");
9099
}
91100

92-
g_field_is_shared_buffer_updated = g_main_thread_env->GetFieldID(g_class_unity_connect,
93-
"mSharedBufferUpdated", "Z");
101+
g_field_is_shared_buffer_exchanged = g_main_thread_env->GetFieldID(g_class_unity_connect,
102+
"m_isSharedBufferExchanged",
103+
"Z");
94104

95105
return JNI_VERSION_1_6;
96106
}
@@ -102,9 +112,9 @@ JNIEnv *AttachCurrentThreadIfNeeded() {
102112
return jni;
103113
}
104114

105-
JNIEnv *env = NULL;
115+
JNIEnv *env = nullptr;
106116

107-
int status = g_jvm->AttachCurrentThread(&env, NULL);
117+
int status = g_jvm->AttachCurrentThread(&env, nullptr);
108118

109119
if (status != JNI_OK) {
110120
LOGE("JNIEnv Filed to attach current thread: %d", status);
@@ -124,7 +134,7 @@ JNIEnv *AttachCurrentThreadIfNeeded() {
124134
void UpdateSurface(int instance_ptr) {
125135
JNIEnv *env = AttachCurrentThreadIfNeeded();
126136

127-
jobject instance = (jobject) ((long) instance_ptr);
137+
auto instance = (jobject) ((long) instance_ptr);
128138

129139
env->CallVoidMethod(instance, g_func_update_surface);
130140
}
@@ -133,33 +143,39 @@ UnityRenderEvent UpdateSurfaceFunc() {
133143
return UpdateSurface;
134144
}
135145

136-
long GetBindedPlatformTextureID(int instance_ptr) {
137-
jobject instance = (jobject) ((long) instance_ptr);
146+
long GetPlatformTextureID(int instance_ptr) {
147+
auto instance = (jobject) ((long) instance_ptr);
138148

139-
return g_main_thread_env->CallLongMethod(instance, g_func_get_binded_platform_texture_id);
149+
return g_main_thread_env->CallLongMethod(instance, g_func_get_platform_texture_id);
140150
}
141151

142152
void SetUnityTextureID(int instance_ptr, long unity_texture_id) {
143-
jobject instance = (jobject) ((long) instance_ptr);
153+
auto instance = (jobject) ((long) instance_ptr);
144154

145155
return g_main_thread_env->CallVoidMethod(instance, g_func_set_unity_texture_id,
146156
(jlong) unity_texture_id);
147157
}
148158

149159
void ReleaseSharedTexture(int instance_ptr) {
150-
jobject instance = (jobject) ((long) instance_ptr);
160+
auto instance = (jobject) ((long) instance_ptr);
151161

152162
g_main_thread_env->CallVoidMethod(instance, g_func_release_shared_texture);
153163
}
154164

165+
bool ContentExists(int instance_ptr) {
166+
auto instance = (jobject) ((long) instance_ptr);
167+
168+
return g_main_thread_env->CallBooleanMethod(instance, g_func_content_exists);
169+
}
170+
155171
bool GetSharedBufferUpdateFlag(int instance_ptr) {
156-
jobject instance = (jobject) ((long) instance_ptr);
172+
auto instance = (jobject) ((long) instance_ptr);
157173

158-
return g_main_thread_env->GetBooleanField(instance, g_field_is_shared_buffer_updated);
174+
return g_main_thread_env->GetBooleanField(instance, g_field_is_shared_buffer_exchanged);
159175
}
160176

161177
void SetHardwareBufferUpdateFlag(int instance_ptr, bool value) {
162-
jobject instance = (jobject) ((long) instance_ptr);
178+
auto instance = (jobject) ((long) instance_ptr);
163179

164-
g_main_thread_env->SetBooleanField(instance, g_field_is_shared_buffer_updated, value);
180+
g_main_thread_env->SetBooleanField(instance, g_field_is_shared_buffer_exchanged, value);
165181
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ namespace {
1010

1111
jmethodID g_func_update_surface = nullptr;
1212

13-
jmethodID g_func_get_binded_platform_texture_id = nullptr;
13+
jmethodID g_func_get_platform_texture_id = nullptr;
1414

1515
jmethodID g_func_set_unity_texture_id = nullptr;
1616

1717
jmethodID g_func_release_shared_texture = nullptr;
1818

19-
jfieldID g_field_is_shared_buffer_updated = nullptr;
19+
jmethodID g_func_content_exists = nullptr;
20+
21+
jfieldID g_field_is_shared_buffer_exchanged = nullptr;
2022

2123
// https://stackoverflow.com/questions/7096350/can-you-cache-jnienv
2224
JNIEnv *g_main_thread_env = nullptr;

libwebview/src/main/java/com/robot9/shared/SharedTexture.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public int getBufferHeight() {
8484
return 0;
8585
}
8686

87-
public long getBindedPlatformTexture() {
87+
public long getPlatformTexture() {
8888
if (mNativeContext != 0) {
89-
return getBindedPlatformTexture(mNativeContext);
89+
return getPlatformTexture(mNativeContext);
9090
}
9191
return 0;
9292
}
@@ -165,7 +165,7 @@ protected void finalize() throws Throwable {
165165

166166
private native int getHeight(long ctx);
167167

168-
private native long getBindedPlatformTexture(long ctx);
168+
private native long getPlatformTexture(long ctx);
169169

170170
private native void setUnityTexture(long ctx, long unityTexID);
171171

0 commit comments

Comments
 (0)