Merge pull request #16641 from hrydgard/delete-more-dead-code

Delete more dead code in app-android.cpp
This commit is contained in:
Henrik Rydgård 2022-12-22 11:13:11 +01:00 committed by GitHub
commit 976190cd4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 160 deletions

View File

@ -132,13 +132,6 @@ std::string g_extFilesDir; // App private external dir.
std::vector<std::string> g_additionalStorageDirs;
static float left_joystick_x_async;
static float left_joystick_y_async;
static float right_joystick_x_async;
static float right_joystick_y_async;
static float hat_joystick_x_async;
static float hat_joystick_y_async;
static int optimalFramesPerBuffer = 0;
static int optimalSampleRate = 0;
static int sampleRate = 0;
@ -172,22 +165,17 @@ static jmethodID postCommand;
static jmethodID getDebugString;
static jobject nativeActivity;
static volatile bool exitRenderLoop;
static std::atomic<bool> exitRenderLoop;
static bool renderLoopRunning;
static bool renderer_inited = false;
static std::mutex renderLock;
static int inputBoxSequence = 1;
std::map<int, std::function<void(bool, const std::string &)>> inputBoxCallbacks;
static float dp_xscale = 1.0f;
static float dp_yscale = 1.0f;
static bool renderer_inited = false;
static bool sustainedPerfSupported = false;
static std::mutex renderLock;
// See NativeQueryConfig("androidJavaGL") to change this value.
static bool javaGL = true;
static std::string library_path;
static std::map<SystemPermission, PermissionStatus> permissions;
AndroidGraphicsContext *graphicsContext;
@ -277,6 +265,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) {
return JNI_VERSION_1_6;
}
// Only used in OpenGL mode.
static void EmuThreadFunc() {
JNIEnv *env;
gJvm->AttachCurrentThread(&env, nullptr);
@ -291,7 +280,7 @@ static void EmuThreadFunc() {
sleep_ms(20);
}
} else {
INFO_LOG(SYSTEM, "Runloop: Graphics context available! %p", graphicsContext);
INFO_LOG(SYSTEM, "Runloop: Graphics context available!");
}
if (!NativeInitGraphics(graphicsContext)) {
@ -518,16 +507,19 @@ std::string Android_GetInputDeviceDebugString() {
return "(N/A)";
}
auto env = getEnv();
jstring param = env->NewStringUTF("InputDevice");
jstring str = (jstring)env->CallObjectMethod(nativeActivity, getDebugString, param);
if (!str) {
jstring jparam = env->NewStringUTF("InputDevice");
jstring jstr = (jstring)env->CallObjectMethod(nativeActivity, getDebugString, jparam);
if (!jstr) {
env->DeleteLocalRef(jparam);
return "(N/A)";
}
const char *charArray = env->GetStringUTFChars(str, 0);
const char *charArray = env->GetStringUTFChars(jstr, 0);
std::string retVal = charArray;
env->DeleteLocalRef(str);
env->ReleaseStringUTFChars(jstr, charArray);
env->DeleteLocalRef(jstr);
env->DeleteLocalRef(jparam);
return retVal;
}
@ -648,7 +640,7 @@ static void parse_args(std::vector<std::string> &args, const std::string value)
extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
(JNIEnv *env, jclass, jstring jmodel, jint jdeviceType, jstring jlangRegion, jstring japkpath,
jstring jdataDir, jstring jexternalStorageDir, jstring jexternalFilesDir, jstring jadditionalStorageDirs, jstring jlibraryDir, jstring jcacheDir, jstring jshortcutParam,
jstring jdataDir, jstring jexternalStorageDir, jstring jexternalFilesDir, jstring jadditionalStorageDirs, jstring jcacheDir, jstring jshortcutParam,
jint jAndroidVersion, jstring jboard) {
SetCurrentThreadName("androidInit");
@ -663,13 +655,6 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
androidVersion = jAndroidVersion;
deviceType = jdeviceType;
left_joystick_x_async = 0;
left_joystick_y_async = 0;
right_joystick_x_async = 0;
right_joystick_y_async = 0;
hat_joystick_x_async = 0;
hat_joystick_y_async = 0;
std::string apkPath = GetJavaString(env, japkpath);
VFSRegister("", new ZipAssetReader(apkPath.c_str(), "assets/"));
@ -695,7 +680,6 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
std::string user_data_path = GetJavaString(env, jdataDir);
if (user_data_path.size() > 0)
user_data_path += "/";
library_path = GetJavaString(env, jlibraryDir) + "/";
std::string shortcut_param = GetJavaString(env, jshortcutParam);
std::string cacheDir = GetJavaString(env, jcacheDir);
std::string buildBoard = GetJavaString(env, jboard);
@ -737,17 +721,18 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
retry:
switch (g_Config.iGPUBackend) {
case (int)GPUBackend::OPENGL:
javaGL = true;
useCPUThread = true;
INFO_LOG(SYSTEM, "NativeApp.init() -- creating OpenGL context (JavaGL)");
graphicsContext = new AndroidJavaEGLGraphicsContext();
INFO_LOG(SYSTEM, "NativeApp.init() - launching emu thread");
EmuThreadStart();
break;
case (int)GPUBackend::VULKAN:
{
javaGL = false;
INFO_LOG(SYSTEM, "NativeApp.init() -- creating Vulkan context");
useCPUThread = false; // The Vulkan render manager manages its own thread.
// We create and destroy the Vulkan graphics context in the "EGL" thread.
useCPUThread = false;
// The Vulkan render manager manages its own thread.
// We create and destroy the Vulkan graphics context in the app main thread though.
AndroidVulkanContext *ctx = new AndroidVulkanContext();
if (!ctx->InitAPI()) {
INFO_LOG(SYSTEM, "Failed to initialize Vulkan, switching to OpenGL");
@ -765,11 +750,6 @@ retry:
goto retry;
}
if (useCPUThread) {
INFO_LOG(SYSTEM, "NativeApp.init() - launching emu thread");
EmuThreadStart();
}
if (IsVREnabled()) {
Version gitVer(PPSSPP_GIT_VERSION);
InitVROnAndroid(gJvm, nativeActivity, systemName.c_str(), gitVer.ToInteger(), "PPSSPP");
@ -882,15 +862,19 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_shutdown(JNIEnv *, jclass) {
VFSShutdown();
}
std::lock_guard<std::mutex> guard(frameCommandLock);
while (frameCommands.size())
frameCommands.pop();
{
std::lock_guard<std::mutex> guard(frameCommandLock);
while (frameCommands.size())
frameCommands.pop();
}
INFO_LOG(SYSTEM, "NativeApp.shutdown() -- end");
}
// JavaEGL
// JavaEGL. This doesn't get called on the Vulkan path.
extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env, jobject obj) {
_assert_(useCPUThread);
INFO_LOG(G3D, "NativeApp.displayInit()");
bool firstStart = !renderer_inited;
// We should be running on the render thread here.
@ -898,19 +882,16 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
if (renderer_inited) {
// Would be really nice if we could get something on the GL thread immediately when shutting down.
INFO_LOG(G3D, "NativeApp.displayInit() restoring");
if (useCPUThread) {
EmuThreadStop("displayInit");
graphicsContext->BeginAndroidShutdown();
INFO_LOG(G3D, "BeginAndroidShutdown. Looping until emu thread done...");
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
INFO_LOG(G3D, "Joining emu thread");
EmuThreadJoin();
} else {
NativeShutdownGraphics();
EmuThreadStop("displayInit");
graphicsContext->BeginAndroidShutdown();
INFO_LOG(G3D, "BeginAndroidShutdown. Looping until emu thread done...");
// Skipping GL calls here because the old context is lost.
while (graphicsContext->ThreadFrame()) {
continue;
}
INFO_LOG(G3D, "Joining emu thread");
EmuThreadJoin();
graphicsContext->ThreadEnd();
graphicsContext->ShutdownFromRenderThread();
@ -925,17 +906,10 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
host->NotifyUserMessage(details, 5.0, 0xFFFFFFFF, "error_callback");
}, nullptr);
if (useCPUThread) {
EmuThreadStart();
} else {
if (!NativeInitGraphics(graphicsContext)) {
// Gonna be in a weird state here, not good.
System_Toast("Failed to initialize graphics.");
return false;
}
}
EmuThreadStart();
graphicsContext->ThreadStart();
INFO_LOG(G3D, "Restored.");
} else {
INFO_LOG(G3D, "NativeApp.displayInit() first time");
@ -951,12 +925,12 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env,
graphicsContext->ThreadStart();
renderer_inited = true;
}
NativeMessageReceived("recreateviews", "");
if (IsVREnabled()) {
EnterVR(firstStart, graphicsContext->GetAPIContext());
}
return true;
}
@ -970,17 +944,11 @@ static void recalculateDpi() {
dp_xres = display_xres * g_dpi_scale_x;
dp_yres = display_yres * g_dpi_scale_y;
// Touch scaling is from display pixels to dp pixels.
// Wait, doesn't even make sense... this is equal to g_dpi_scale_x. TODO: Figure out what's going on!
dp_xscale = (float)dp_xres / (float)display_xres;
dp_yscale = (float)dp_yres / (float)display_yres;
pixel_in_dps_x = (float)pixel_xres / dp_xres;
pixel_in_dps_y = (float)pixel_yres / dp_yres;
INFO_LOG(G3D, "RecalcDPI: display_xres=%d display_yres=%d", display_xres, display_yres);
INFO_LOG(G3D, "RecalcDPI: g_dpi=%f g_dpi_scale_x=%f g_dpi_scale_y=%f", g_dpi, g_dpi_scale_x, g_dpi_scale_y);
INFO_LOG(G3D, "RecalcDPI: dp_xscale=%f dp_yscale=%f", dp_xscale, dp_yscale);
INFO_LOG(G3D, "RecalcDPI: dp_xres=%d dp_yres=%d", dp_xres, dp_yres);
INFO_LOG(G3D, "RecalcDPI: pixel_xres=%d pixel_yres=%d", pixel_xres, pixel_yres);
}
@ -1056,6 +1024,7 @@ void UpdateRunLoopAndroid(JNIEnv *env) {
std::lock_guard<std::mutex> guard(frameCommandLock);
if (!nativeActivity) {
ERROR_LOG(SYSTEM, "No activity, clearing commands");
while (!frameCommands.empty())
frameCommands.pop();
return;
@ -1075,15 +1044,16 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeRenderer_displayRender(JNIEnv *env,
return;
if (useCPUThread) {
// This is the "GPU thread".
if (!graphicsContext || !graphicsContext->ThreadFrame())
// This is the "GPU thread". Call ThreadFrame.
if (!graphicsContext || !graphicsContext->ThreadFrame()) {
return;
}
} else {
UpdateRunLoopAndroid(env);
}
if (IsVREnabled()) {
UpdateVRInput(g_Config.bHapticFeedback, dp_xscale, dp_yscale);
UpdateVRInput(g_Config.bHapticFeedback, g_dpi_scale_x, g_dpi_scale_y);
FinishVRRender();
}
}
@ -1107,8 +1077,8 @@ PermissionStatus System_GetPermissionStatus(SystemPermission permission) {
extern "C" jboolean JNICALL Java_org_ppsspp_ppsspp_NativeApp_touch
(JNIEnv *, jclass, float x, float y, int code, int pointerId) {
float scaledX = x * dp_xscale;
float scaledY = y * dp_yscale;
float scaledX = x * g_dpi_scale_x;
float scaledY = y * g_dpi_scale_y;
TouchInput touch;
touch.id = pointerId;
@ -1148,26 +1118,6 @@ extern "C" jboolean Java_org_ppsspp_ppsspp_NativeApp_joystickAxis(
JNIEnv *env, jclass, jint deviceId, jint axisId, jfloat value) {
if (!renderer_inited)
return false;
switch (axisId) {
case JOYSTICK_AXIS_X:
left_joystick_x_async = value;
break;
case JOYSTICK_AXIS_Y:
left_joystick_y_async = -value;
break;
case JOYSTICK_AXIS_Z:
right_joystick_x_async = value;
break;
case JOYSTICK_AXIS_RZ:
right_joystick_y_async = -value;
break;
case JOYSTICK_AXIS_HAT_X:
hat_joystick_x_async = value;
break;
case JOYSTICK_AXIS_HAT_Y:
hat_joystick_y_async = -value;
break;
}
AxisInput axis;
axis.axisId = axisId;
@ -1353,7 +1303,7 @@ std::vector<std::string> __cameraGetDeviceList() {
jint arrayListObjectLen = getEnv()->CallIntMethod(deviceListObject, arrayListSize);
std::vector<std::string> deviceListVector;
for (int i=0; i < arrayListObjectLen; i++) {
for (int i = 0; i < arrayListObjectLen; i++) {
jstring dev = static_cast<jstring>(getEnv()->CallObjectMethod(deviceListObject, arrayListGet, i));
const char* cdev = getEnv()->GetStringUTFChars(dev, nullptr);
deviceListVector.push_back(cdev);
@ -1407,63 +1357,47 @@ static void ProcessFrameCommands(JNIEnv *env) {
}
}
// This runs in Vulkan mode only.
extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(JNIEnv *env, jobject obj, jobject _surf) {
_assert_(!useCPUThread);
if (!graphicsContext) {
ERROR_LOG(G3D, "runEGLRenderLoop: Tried to enter without a created graphics context.");
return false;
}
// Needed for Vulkan, even if we're not using the old EGL path.
exitRenderLoop = false;
// This is up here to prevent race conditions, in case we pause during init.
renderLoopRunning = true;
ANativeWindow *wnd = _surf ? ANativeWindow_fromSurface(env, _surf) : nullptr;
WARN_LOG(G3D, "runEGLRenderLoop. display_xres=%d display_yres=%d", display_xres, display_yres);
WARN_LOG(G3D, "runEGLRenderLoop. display_xres=%d display_yres=%d desiredBackbufferSizeX=%d desiredBackbufferSizeY=%d",
display_xres, display_yres, desiredBackbufferSizeX, desiredBackbufferSizeY);
if (wnd == nullptr) {
if (!wnd) {
ERROR_LOG(G3D, "Error: Surface is null.");
renderLoopRunning = false;
return false;
}
auto tryInit = [&]() {
if (graphicsContext->InitFromRenderThread(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) {
return true;
} else {
ERROR_LOG(G3D, "Failed to initialize graphics context.");
System_Toast("Failed to initialize graphics context.");
return false;
}
};
if (!graphicsContext->InitFromRenderThread(wnd, desiredBackbufferSizeX, desiredBackbufferSizeY, backbuffer_format, androidVersion)) {
// On Android, if we get here, really no point in continuing.
// The UI is supposed to render on any device both on OpenGL and Vulkan. If either of those don't work
// on a device, we blacklist it.
ERROR_LOG(G3D, "Failed to initialize graphics context.");
System_Toast("Failed to initialize graphics context.");
bool initSuccess = tryInit();
if (!initSuccess) {
if (!exitRenderLoop && g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
INFO_LOG(G3D, "Trying again, this time with OpenGL.");
SetGPUBackend(GPUBackend::OPENGL);
g_Config.iGPUBackend = (int)GetGPUBackend();
// If we were still supporting EGL for GL, we'd retry here:
//initSuccess = tryInit();
}
if (!initSuccess) {
delete graphicsContext;
graphicsContext = nullptr;
renderLoopRunning = false;
return false;
}
delete graphicsContext;
graphicsContext = nullptr;
renderLoopRunning = false;
return false;
}
if (!exitRenderLoop) {
if (!useCPUThread) {
if (!NativeInitGraphics(graphicsContext)) {
ERROR_LOG(G3D, "Failed to initialize graphics.");
// Gonna be in a weird state here..
}
if (!NativeInitGraphics(graphicsContext)) {
ERROR_LOG(G3D, "Failed to initialize graphics.");
// Gonna be in a weird state here..
}
graphicsContext->ThreadStart();
renderer_inited = true;
@ -1477,33 +1411,17 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
}
}
if (useCPUThread) {
ERROR_LOG(SYSTEM, "Running graphics loop");
while (!exitRenderLoop) {
// This is the "GPU thread".
graphicsContext->ThreadFrame();
graphicsContext->SwapBuffers();
}
} else {
while (!exitRenderLoop) {
LockedNativeUpdateRender();
graphicsContext->SwapBuffers();
while (!exitRenderLoop) {
LockedNativeUpdateRender();
graphicsContext->SwapBuffers();
ProcessFrameCommands(env);
}
ProcessFrameCommands(env);
}
INFO_LOG(G3D, "Leaving EGL/Vulkan render loop.");
if (useCPUThread) {
EmuThreadStop("exitrenderloop");
while (graphicsContext->ThreadFrame()) {
continue;
}
EmuThreadJoin();
} else {
NativeShutdownGraphics();
}
NativeShutdownGraphics();
renderer_inited = false;
graphicsContext->ThreadEnd();
@ -1511,6 +1429,7 @@ extern "C" bool JNICALL Java_org_ppsspp_ppsspp_NativeActivity_runEGLRenderLoop(J
INFO_LOG(G3D, "Shutting down graphics context from render thread...");
graphicsContext->ShutdownFromRenderThread();
renderLoopRunning = false;
WARN_LOG(G3D, "Render loop function exited.");
return true;
}

View File

@ -399,8 +399,6 @@ public abstract class NativeActivity extends Activity {
isXperiaPlay = IsXperiaPlay();
String libraryDir = getApplicationLibraryDir(appInfo);
String extStorageState = Environment.getExternalStorageState();
String extStorageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
File externalFiles = this.getExternalFilesDir(null);
@ -446,7 +444,7 @@ public abstract class NativeActivity extends Activity {
overrideShortcutParam = null;
NativeApp.audioConfig(optimalFramesPerBuffer, optimalSampleRate);
NativeApp.init(model, deviceType, languageRegion, apkFilePath, dataDir, extStorageDir, externalFilesDir, additionalStorageDirs, libraryDir, cacheDir, shortcut, Build.VERSION.SDK_INT, Build.BOARD);
NativeApp.init(model, deviceType, languageRegion, apkFilePath, dataDir, extStorageDir, externalFilesDir, additionalStorageDirs, cacheDir, shortcut, Build.VERSION.SDK_INT, Build.BOARD);
// Allow C++ to tell us to use JavaGL or not.
javaGL = "true".equalsIgnoreCase(NativeApp.queryConfig("androidJavaGL"));

View File

@ -13,7 +13,7 @@ public class NativeApp {
public static final int DEVICE_TYPE_DESKTOP = 2;
public static final int DEVICE_TYPE_VR = 3;
public static native void init(String model, int deviceType, String languageRegion, String apkPath, String dataDir, String externalStorageDir, String extFilesDir, String additionalStorageDirs, String libraryDir, String cacheDir, String shortcutParam, int androidVersion, String board);
public static native void init(String model, int deviceType, String languageRegion, String apkPath, String dataDir, String externalStorageDir, String extFilesDir, String additionalStorageDirs, String cacheDir, String shortcutParam, int androidVersion, String board);
public static native void audioInit();
public static native void audioShutdown();
public static native void audioConfig(int optimalFramesPerBuffer, int optimalSampleRate);