22#include " JNILog.h"
33
44extern " C" {
5- using UnityRenderEvent = void (*)(int );
5+ using UnityRenderEvent = void (*)(int );
66
77UnityRenderEvent UpdateSurfaceFunc ();
88
@@ -19,15 +19,15 @@ bool GetSharedBufferUpdateFlag(int);
1919void 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
117124void 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
130136long 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
136142void 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
148155bool 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
154161void 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}
0 commit comments