@@ -8,12 +8,14 @@ UnityRenderEvent UpdateSurfaceFunc();
88
99void UpdateSurface (int );
1010
11- long GetBindedPlatformTextureID (int );
11+ long GetPlatformTextureID (int );
1212
1313void SetUnityTextureID (int , long );
1414
1515void ReleaseSharedTexture (int );
1616
17+ bool ContentExists (int );
18+
1719bool GetSharedBufferUpdateFlag (int );
1820
1921void SetHardwareBufferUpdateFlag (int , bool );
@@ -22,7 +24,7 @@ void SetHardwareBufferUpdateFlag(int, bool);
2224JavaVM *g_jvm;
2325
2426JNIEnv *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() {
5153jint 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() {
124134void 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
142152void 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
149159void 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+
155171bool 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
161177void 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}
0 commit comments