From e3c546a1edb893539094fff6284ee0ebce269a64 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 17 Sep 2023 17:20:58 -0400 Subject: [PATCH 1/5] android: Export PiP receiver on API 33 and later Could cause crashes on API 33+ devices --- .../org/yuzu/yuzu_emu/activities/EmulationActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index d4ae39661f..e96a2059b1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt @@ -3,6 +3,7 @@ package org.yuzu.yuzu_emu.activities +import android.annotation.SuppressLint import android.app.Activity import android.app.PendingIntent import android.app.PictureInPictureParams @@ -397,6 +398,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") override fun onPictureInPictureModeChanged( isInPictureInPictureMode: Boolean, newConfig: Configuration @@ -409,7 +411,11 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { addAction(actionMute) addAction(actionUnmute) }.also { - registerReceiver(pictureInPictureReceiver, it) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(pictureInPictureReceiver, it, RECEIVER_EXPORTED) + } else { + registerReceiver(pictureInPictureReceiver, it) + } } } else { try { From 32d65fc8de61407b53eb894dcf26375ea0c982ea Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 17 Sep 2023 17:27:31 -0400 Subject: [PATCH 2/5] android: Properly update emulation surface Previously the emulation surface wasn't being updated during configuration changes and only during specific view events. This would break input and the screen dimensions after each orientation/aspect ratio change. Now a new surface is provided every time and the display dimensions are updated as needed. --- .../yuzu_emu/fragments/EmulationFragment.kt | 22 ++++--------------- .../src/main/jni/emu_window/emu_window.cpp | 14 ++++++------ 2 files changed, 11 insertions(+), 25 deletions(-) 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 3e6c157c7f..43d1d23649 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 @@ -15,7 +15,6 @@ import android.net.Uri import android.os.Bundle import android.os.Handler import android.os.Looper -import android.util.Rational import android.view.* import android.widget.TextView import androidx.activity.OnBackPressedCallback @@ -287,6 +286,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) + updateScreenLayout() if (emulationActivity?.isInPictureInPictureMode == true) { if (binding.drawerLayout.isOpen) { binding.drawerLayout.close() @@ -394,16 +394,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } private fun updateScreenLayout() { - binding.surfaceEmulation.setAspectRatio( - when (IntSetting.RENDERER_ASPECT_RATIO.int) { - 0 -> Rational(16, 9) - 1 -> Rational(4, 3) - 2 -> Rational(21, 9) - 3 -> Rational(16, 10) - 4 -> null // Stretch - else -> Rational(16, 9) - } - ) + binding.surfaceEmulation.setAspectRatio(null) emulationActivity?.buildPictureInPictureParams() updateOrientation() } @@ -693,7 +684,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { private class EmulationState(private val gamePath: String) { private var state: State private var surface: Surface? = null - private var runWhenSurfaceIsValid = false init { // Starting state is stopped. @@ -751,8 +741,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { // If the surface is set, run now. Otherwise, wait for it to get set. if (surface != null) { runWithValidSurface() - } else { - runWhenSurfaceIsValid = true } } @@ -760,7 +748,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { @Synchronized fun newSurface(surface: Surface?) { this.surface = surface - if (runWhenSurfaceIsValid) { + if (this.surface != null) { runWithValidSurface() } } @@ -788,10 +776,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } private fun runWithValidSurface() { - runWhenSurfaceIsValid = false + NativeLibrary.surfaceChanged(surface) when (state) { State.STOPPED -> { - NativeLibrary.surfaceChanged(surface) val emulationThread = Thread({ Log.debug("[EmulationFragment] Starting emulation thread.") NativeLibrary.run(gamePath) @@ -801,7 +788,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { State.PAUSED -> { Log.debug("[EmulationFragment] Resuming emulation.") - NativeLibrary.surfaceChanged(surface) NativeLibrary.unpauseEmulation() } diff --git a/src/android/app/src/main/jni/emu_window/emu_window.cpp b/src/android/app/src/main/jni/emu_window/emu_window.cpp index a890c66042..a7e414b815 100644 --- a/src/android/app/src/main/jni/emu_window/emu_window.cpp +++ b/src/android/app/src/main/jni/emu_window/emu_window.cpp @@ -11,6 +11,12 @@ #include "jni/emu_window/emu_window.h" void EmuWindow_Android::OnSurfaceChanged(ANativeWindow* surface) { + m_window_width = ANativeWindow_getWidth(surface); + m_window_height = ANativeWindow_getHeight(surface); + + // Ensures that we emulate with the correct aspect ratio. + UpdateCurrentFramebufferLayout(m_window_width, m_window_height); + window_info.render_surface = reinterpret_cast(surface); } @@ -62,14 +68,8 @@ EmuWindow_Android::EmuWindow_Android(InputCommon::InputSubsystem* input_subsyste return; } - m_window_width = ANativeWindow_getWidth(surface); - m_window_height = ANativeWindow_getHeight(surface); - - // Ensures that we emulate with the correct aspect ratio. - UpdateCurrentFramebufferLayout(m_window_width, m_window_height); - + OnSurfaceChanged(surface); window_info.type = Core::Frontend::WindowSystemType::Android; - window_info.render_surface = reinterpret_cast(surface); m_input_subsystem->Initialize(); } From 3b612cff288323ecfbbdfca38c5bde3bf4aeec47 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 17 Sep 2023 17:33:13 -0400 Subject: [PATCH 3/5] android: Fix showing input overlay in PiP --- .../main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 43d1d23649..dbc799dae6 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 @@ -293,7 +293,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } if (EmulationMenuSettings.showOverlay) { binding.surfaceInputOverlay.post { - binding.surfaceInputOverlay.visibility = View.VISIBLE + binding.surfaceInputOverlay.visibility = View.INVISIBLE } } } else { From fd097842316ca836c03c9d90131de6e85b2bae39 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 17 Sep 2023 17:41:06 -0400 Subject: [PATCH 4/5] android: Don't pause emulation when entering PiP --- .../main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dbc799dae6..750638bc9f 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 @@ -328,7 +328,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } override fun onPause() { - if (emulationState.isRunning) { + if (emulationState.isRunning && emulationActivity?.isInPictureInPictureMode != true) { emulationState.pause() } super.onPause() From 7dd3d1b8ad3e4bedb03e17c8bee738fc8b67106d Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 17 Sep 2023 17:43:13 -0400 Subject: [PATCH 5/5] android: Ignore validation layers library in git --- src/android/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/android/.gitignore b/src/android/.gitignore index 121cc84843..ff7121acd1 100644 --- a/src/android/.gitignore +++ b/src/android/.gitignore @@ -63,3 +63,6 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md + +# Autogenerated library for vulkan validation layers +libVkLayer_khronos_validation.so