src/core/android/SDL_android.c
changeset 12696 3ef8a628853d
parent 12689 d581caf613cd
child 12709 d268ce129edb
equal deleted inserted replaced
12695:0c4d04572622 12696:3ef8a628853d
  1154 
  1154 
  1155 /*******************************************************************************
  1155 /*******************************************************************************
  1156              Functions called by SDL into Java
  1156              Functions called by SDL into Java
  1157 *******************************************************************************/
  1157 *******************************************************************************/
  1158 
  1158 
  1159 static int s_active = 0;
  1159 static SDL_atomic_t s_active;
  1160 struct LocalReferenceHolder
  1160 struct LocalReferenceHolder
  1161 {
  1161 {
  1162     JNIEnv *m_env;
  1162     JNIEnv *m_env;
  1163     const char *m_func;
  1163     const char *m_func;
  1164 };
  1164 };
  1179     const int capacity = 16;
  1179     const int capacity = 16;
  1180     if ((*env)->PushLocalFrame(env, capacity) < 0) {
  1180     if ((*env)->PushLocalFrame(env, capacity) < 0) {
  1181         SDL_SetError("Failed to allocate enough JVM local references");
  1181         SDL_SetError("Failed to allocate enough JVM local references");
  1182         return SDL_FALSE;
  1182         return SDL_FALSE;
  1183     }
  1183     }
  1184     ++s_active;
  1184     SDL_AtomicIncRef(&s_active);
  1185     refholder->m_env = env;
  1185     refholder->m_env = env;
  1186     return SDL_TRUE;
  1186     return SDL_TRUE;
  1187 }
  1187 }
  1188 
  1188 
  1189 static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
  1189 static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
  1192     SDL_Log("Leaving function %s", refholder->m_func);
  1192     SDL_Log("Leaving function %s", refholder->m_func);
  1193 #endif
  1193 #endif
  1194     if (refholder->m_env) {
  1194     if (refholder->m_env) {
  1195         JNIEnv *env = refholder->m_env;
  1195         JNIEnv *env = refholder->m_env;
  1196         (*env)->PopLocalFrame(env, NULL);
  1196         (*env)->PopLocalFrame(env, NULL);
  1197         --s_active;
  1197         SDL_AtomicDecRef(&s_active);
  1198     }
  1198     }
       
  1199 }
       
  1200 
       
  1201 static SDL_bool LocalReferenceHolder_IsActive(void)
       
  1202 {
       
  1203     return (SDL_AtomicGet(&s_active) > 0);
  1199 }
  1204 }
  1200 
  1205 
  1201 ANativeWindow* Android_JNI_GetNativeWindow(void)
  1206 ANativeWindow* Android_JNI_GetNativeWindow(void)
  1202 {
  1207 {
  1203     ANativeWindow *anw = NULL;
  1208     ANativeWindow *anw = NULL;
  1599 {
  1604 {
  1600     JNIEnv *env = Android_JNI_GetEnv();
  1605     JNIEnv *env = Android_JNI_GetEnv();
  1601     jthrowable exception;
  1606     jthrowable exception;
  1602 
  1607 
  1603     /* Detect mismatch LocalReferenceHolder_Init/Cleanup */
  1608     /* Detect mismatch LocalReferenceHolder_Init/Cleanup */
  1604     SDL_assert((s_active > 0));
  1609     SDL_assert(LocalReferenceHolder_IsActive());
  1605 
  1610 
  1606     exception = (*env)->ExceptionOccurred(env);
  1611     exception = (*env)->ExceptionOccurred(env);
  1607     if (exception != NULL) {
  1612     if (exception != NULL) {
  1608         jmethodID mid;
  1613         jmethodID mid;
  1609 
  1614