diff options
4 files changed, 39 insertions, 15 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt index c408485c6..5b9f553f7 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | |||
| @@ -303,6 +303,11 @@ object NativeLibrary { | |||
| 303 | */ | 303 | */ |
| 304 | external fun getCpuBackend(): String | 304 | external fun getCpuBackend(): String |
| 305 | 305 | ||
| 306 | /** | ||
| 307 | * Returns the current GPU Driver. | ||
| 308 | */ | ||
| 309 | external fun getGpuDriver(): String | ||
| 310 | |||
| 306 | external fun applySettings() | 311 | external fun applySettings() |
| 307 | 312 | ||
| 308 | external fun logSettings() | 313 | external fun logSettings() |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 2a97ae14d..d17e087fe 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | |||
| @@ -38,7 +38,6 @@ import androidx.window.layout.WindowLayoutInfo | |||
| 38 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 38 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 39 | import com.google.android.material.slider.Slider | 39 | import com.google.android.material.slider.Slider |
| 40 | import kotlinx.coroutines.Dispatchers | 40 | import kotlinx.coroutines.Dispatchers |
| 41 | import kotlinx.coroutines.flow.collect | ||
| 42 | import kotlinx.coroutines.flow.collectLatest | 41 | import kotlinx.coroutines.flow.collectLatest |
| 43 | import kotlinx.coroutines.launch | 42 | import kotlinx.coroutines.launch |
| 44 | import org.yuzu.yuzu_emu.HomeNavigationDirections | 43 | import org.yuzu.yuzu_emu.HomeNavigationDirections |
| @@ -141,7 +140,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 141 | 140 | ||
| 142 | // So this fragment doesn't restart on configuration changes; i.e. rotation. | 141 | // So this fragment doesn't restart on configuration changes; i.e. rotation. |
| 143 | retainInstance = true | 142 | retainInstance = true |
| 144 | emulationState = EmulationState(game.path) | 143 | emulationState = EmulationState(game.path) { |
| 144 | return@EmulationState driverViewModel.isInteractionAllowed.value | ||
| 145 | } | ||
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | /** | 148 | /** |
| @@ -371,6 +372,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 371 | } | 372 | } |
| 372 | } | 373 | } |
| 373 | launch { | 374 | launch { |
| 375 | repeatOnLifecycle(Lifecycle.State.RESUMED) { | ||
| 376 | driverViewModel.isInteractionAllowed.collect { | ||
| 377 | if (it) { | ||
| 378 | startEmulation() | ||
| 379 | } | ||
| 380 | } | ||
| 381 | } | ||
| 382 | } | ||
| 383 | launch { | ||
| 374 | repeatOnLifecycle(Lifecycle.State.CREATED) { | 384 | repeatOnLifecycle(Lifecycle.State.CREATED) { |
| 375 | emulationViewModel.emulationStarted.collectLatest { | 385 | emulationViewModel.emulationStarted.collectLatest { |
| 376 | if (it) { | 386 | if (it) { |
| @@ -398,19 +408,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 398 | } | 408 | } |
| 399 | } | 409 | } |
| 400 | } | 410 | } |
| 401 | launch { | ||
| 402 | repeatOnLifecycle(Lifecycle.State.RESUMED) { | ||
| 403 | driverViewModel.isInteractionAllowed.collect { | ||
| 404 | if (it) { | ||
| 405 | onEmulationStart() | ||
| 406 | } | ||
| 407 | } | ||
| 408 | } | ||
| 409 | } | ||
| 410 | } | 411 | } |
| 411 | } | 412 | } |
| 412 | 413 | ||
| 413 | private fun onEmulationStart() { | 414 | private fun startEmulation() { |
| 414 | if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { | 415 | if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { |
| 415 | if (!DirectoryInitialization.areDirectoriesReady) { | 416 | if (!DirectoryInitialization.areDirectoriesReady) { |
| 416 | DirectoryInitialization.start() | 417 | DirectoryInitialization.start() |
| @@ -485,12 +486,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 485 | val FRAMETIME = 2 | 486 | val FRAMETIME = 2 |
| 486 | val SPEED = 3 | 487 | val SPEED = 3 |
| 487 | perfStatsUpdater = { | 488 | perfStatsUpdater = { |
| 488 | if (emulationViewModel.emulationStarted.value) { | 489 | if (emulationViewModel.emulationStarted.value && |
| 490 | !emulationViewModel.isEmulationStopping.value | ||
| 491 | ) { | ||
| 489 | val perfStats = NativeLibrary.getPerfStats() | 492 | val perfStats = NativeLibrary.getPerfStats() |
| 490 | val cpuBackend = NativeLibrary.getCpuBackend() | 493 | val cpuBackend = NativeLibrary.getCpuBackend() |
| 494 | val gpuDriver = NativeLibrary.getGpuDriver() | ||
| 491 | if (_binding != null) { | 495 | if (_binding != null) { |
| 492 | binding.showFpsText.text = | 496 | binding.showFpsText.text = |
| 493 | String.format("FPS: %.1f\n%s", perfStats[FPS], cpuBackend) | 497 | String.format("FPS: %.1f\n%s/%s", perfStats[FPS], cpuBackend, gpuDriver) |
| 494 | } | 498 | } |
| 495 | perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 800) | 499 | perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 800) |
| 496 | } | 500 | } |
| @@ -807,7 +811,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 807 | } | 811 | } |
| 808 | } | 812 | } |
| 809 | 813 | ||
| 810 | private class EmulationState(private val gamePath: String) { | 814 | private class EmulationState( |
| 815 | private val gamePath: String, | ||
| 816 | private val emulationCanStart: () -> Boolean | ||
| 817 | ) { | ||
| 811 | private var state: State | 818 | private var state: State |
| 812 | private var surface: Surface? = null | 819 | private var surface: Surface? = null |
| 813 | 820 | ||
| @@ -901,6 +908,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 901 | State.PAUSED -> Log.warning( | 908 | State.PAUSED -> Log.warning( |
| 902 | "[EmulationFragment] Surface cleared while emulation paused." | 909 | "[EmulationFragment] Surface cleared while emulation paused." |
| 903 | ) | 910 | ) |
| 911 | |||
| 904 | else -> Log.warning( | 912 | else -> Log.warning( |
| 905 | "[EmulationFragment] Surface cleared while emulation stopped." | 913 | "[EmulationFragment] Surface cleared while emulation stopped." |
| 906 | ) | 914 | ) |
| @@ -910,6 +918,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 910 | 918 | ||
| 911 | private fun runWithValidSurface() { | 919 | private fun runWithValidSurface() { |
| 912 | NativeLibrary.surfaceChanged(surface) | 920 | NativeLibrary.surfaceChanged(surface) |
| 921 | if (!emulationCanStart.invoke()) { | ||
| 922 | return | ||
| 923 | } | ||
| 924 | |||
| 913 | when (state) { | 925 | when (state) { |
| 914 | State.STOPPED -> { | 926 | State.STOPPED -> { |
| 915 | val emulationThread = Thread({ | 927 | val emulationThread = Thread({ |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt index 15ae3a42b..5ed754c96 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt | |||
| @@ -144,6 +144,7 @@ class DriverViewModel : ViewModel() { | |||
| 144 | val selectedDriverFile = File(StringSetting.DRIVER_PATH.getString()) | 144 | val selectedDriverFile = File(StringSetting.DRIVER_PATH.getString()) |
| 145 | val selectedDriverMetadata = GpuDriverHelper.customDriverSettingData | 145 | val selectedDriverMetadata = GpuDriverHelper.customDriverSettingData |
| 146 | if (GpuDriverHelper.installedCustomDriverData == selectedDriverMetadata) { | 146 | if (GpuDriverHelper.installedCustomDriverData == selectedDriverMetadata) { |
| 147 | setDriverReady() | ||
| 147 | return | 148 | return |
| 148 | } | 149 | } |
| 149 | 150 | ||
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 963f57380..c20c2d2b8 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -247,6 +247,7 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string | |||
| 247 | m_system.GetCpuManager().OnGpuReady(); | 247 | m_system.GetCpuManager().OnGpuReady(); |
| 248 | m_system.RegisterExitCallback([&] { HaltEmulation(); }); | 248 | m_system.RegisterExitCallback([&] { HaltEmulation(); }); |
| 249 | 249 | ||
| 250 | OnEmulationStarted(); | ||
| 250 | return Core::SystemResultStatus::Success; | 251 | return Core::SystemResultStatus::Success; |
| 251 | } | 252 | } |
| 252 | 253 | ||
| @@ -674,6 +675,11 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getCpuBackend(JNIEnv* env, jclass | |||
| 674 | return ToJString(env, "JIT"); | 675 | return ToJString(env, "JIT"); |
| 675 | } | 676 | } |
| 676 | 677 | ||
| 678 | jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getGpuDriver(JNIEnv* env, jobject jobj) { | ||
| 679 | return ToJString(env, | ||
| 680 | EmulationSession::GetInstance().System().GPU().Renderer().GetDeviceVendor()); | ||
| 681 | } | ||
| 682 | |||
| 677 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_applySettings(JNIEnv* env, jobject jobj) { | 683 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_applySettings(JNIEnv* env, jobject jobj) { |
| 678 | EmulationSession::GetInstance().System().ApplySettings(); | 684 | EmulationSession::GetInstance().System().ApplySettings(); |
| 679 | } | 685 | } |