MainAndroid: Resolve -Wmissing-variable-declarations warnings

This commit is contained in:
Lioncash 2017-05-18 19:33:44 -04:00
parent 35a8771e68
commit 35aa55931f
1 changed files with 46 additions and 40 deletions

View File

@ -11,6 +11,7 @@
#include <jni.h>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include "ButtonManager.h"
@ -44,16 +45,27 @@
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"
ANativeWindow* surf;
std::string g_filename;
std::string g_set_userpath = "";
#define DOLPHIN_TAG "DolphinEmuNative"
JavaVM* g_java_vm;
jclass g_jni_class;
jmethodID g_jni_method_alert;
jmethodID g_jni_method_end;
#define DOLPHIN_TAG "DolphinEmuNative"
namespace
{
ANativeWindow* s_surf;
std::string s_filename;
std::string s_set_userpath;
jclass s_jni_class;
jmethodID s_jni_method_alert;
jmethodID s_jni_method_end;
// The Core only supports using a single Host thread.
// If multiple threads want to call host functions then they need to queue
// sequentially for access.
std::mutex s_host_identity_lock;
Common::Event s_update_main_frame_event;
bool s_have_wm_user_stop = false;
} // Anonymous namespace
/*
* Cache the JavaVM so that we can call into it later.
@ -72,17 +84,11 @@ void Host_RefreshDSPDebuggerWindow()
{
}
// The Core only supports using a single Host thread.
// If multiple threads want to call host functions then they need to queue
// sequentially for access.
static std::mutex s_host_identity_lock;
Common::Event updateMainFrameEvent;
static bool s_have_wm_user_stop = false;
void Host_Message(int Id)
{
if (Id == WM_USER_JOB_DISPATCH)
{
updateMainFrameEvent.Set();
s_update_main_frame_event.Set();
}
else if (Id == WM_USER_STOP)
{
@ -94,7 +100,7 @@ void Host_Message(int Id)
void* Host_GetRenderHandle()
{
return surf;
return s_surf;
}
void Host_UpdateTitle(const std::string& title)
@ -158,7 +164,7 @@ static bool MsgAlert(const char* caption, const char* text, bool yes_no, int /*S
g_java_vm->AttachCurrentThread(&env, NULL);
// Execute the Java method.
env->CallStaticVoidMethod(g_jni_class, g_jni_method_alert, env->NewStringUTF(text));
env->CallStaticVoidMethod(s_jni_class, s_jni_method_alert, env->NewStringUTF(text));
// Must be called before the current thread exits; might as well do it here.
g_java_vm->DetachCurrentThread();
@ -466,7 +472,7 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env,
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
jobject obj,
jobject _surf);
jobject surf);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
jobject obj);
@ -489,7 +495,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio
std::lock_guard<std::mutex> guard(s_host_identity_lock);
Core::SaveScreenShot("thumb", true);
Core::Stop();
updateMainFrameEvent.Set(); // Kick the waiting event
s_update_main_frame_event.Set(); // Kick the waiting event
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action)
@ -634,7 +640,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetFilename(
jobject obj,
jstring jFile)
{
g_filename = GetJString(env, jFile);
s_filename = GetJString(env, jFile);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
@ -682,7 +688,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirec
{
std::lock_guard<std::mutex> guard(s_host_identity_lock);
std::string directory = GetJString(env, jDirectory);
g_set_userpath = directory;
s_set_userpath = directory;
UICommon::SetUserDirectory(directory);
}
@ -725,30 +731,30 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env,
jclass localClass = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
// This reference, however, is valid until we delete it.
g_jni_class = reinterpret_cast<jclass>(env->NewGlobalRef(localClass));
s_jni_class = reinterpret_cast<jclass>(env->NewGlobalRef(localClass));
// TODO Find a place for this.
// So we don't leak a reference to NativeLibrary.class.
// env->DeleteGlobalRef(g_jni_class);
// env->DeleteGlobalRef(s_jni_class);
// Method signature taken from javap -s
// Source/Android/app/build/intermediates/classes/arm/debug/org/dolphinemu/dolphinemu/NativeLibrary.class
g_jni_method_alert =
env->GetStaticMethodID(g_jni_class, "displayAlertMsg", "(Ljava/lang/String;)V");
g_jni_method_end = env->GetStaticMethodID(g_jni_class, "endEmulationActivity", "()V");
s_jni_method_alert =
env->GetStaticMethodID(s_jni_class, "displayAlertMsg", "(Ljava/lang/String;)V");
s_jni_method_end = env->GetStaticMethodID(s_jni_class, "endEmulationActivity", "()V");
}
// Surface Handling
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
jobject obj,
jobject _surf)
jobject surf)
{
surf = ANativeWindow_fromSurface(env, _surf);
if (surf == nullptr)
s_surf = ANativeWindow_fromSurface(env, surf);
if (s_surf == nullptr)
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
if (g_renderer)
g_renderer->ChangeSurface(surf);
g_renderer->ChangeSurface(s_surf);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
@ -757,10 +763,10 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr
if (g_renderer)
g_renderer->ChangeSurface(nullptr);
if (surf)
if (s_surf)
{
ANativeWindow_release(surf);
surf = nullptr;
ANativeWindow_release(s_surf);
s_surf = nullptr;
}
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv* env,
@ -772,7 +778,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv* env, jobject obj)
{
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", g_filename.c_str());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", s_filename.c_str());
// Install our callbacks
OSD::AddCallback(OSD::CallbackType::Initialization, ButtonManager::Init);
@ -781,14 +787,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv*
RegisterMsgAlertHandler(&MsgAlert);
std::unique_lock<std::mutex> guard(s_host_identity_lock);
UICommon::SetUserDirectory(g_set_userpath);
UICommon::SetUserDirectory(s_set_userpath);
UICommon::Init();
WiimoteReal::InitAdapterClass();
// No use running the loop when booting fails
s_have_wm_user_stop = false;
if (BootManager::BootCore(g_filename.c_str()))
if (BootManager::BootCore(s_filename.c_str()))
{
static constexpr int TIMEOUT = 10000;
static constexpr int WAIT_STEP = 25;
@ -802,7 +808,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv*
while (Core::IsRunning())
{
guard.unlock();
updateMainFrameEvent.Wait();
s_update_main_frame_event.Wait();
guard.lock();
Core::HostDispatchJobs();
}
@ -812,14 +818,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv*
UICommon::Shutdown();
guard.unlock();
if (surf)
if (s_surf)
{
ANativeWindow_release(surf);
surf = nullptr;
ANativeWindow_release(s_surf);
s_surf = nullptr;
}
// Execute the Java method.
env->CallStaticVoidMethod(g_jni_class, g_jni_method_end);
env->CallStaticVoidMethod(s_jni_class, s_jni_method_end);
}
#ifdef __cplusplus