diff options
| author | 2023-09-19 09:25:09 -0400 | |
|---|---|---|
| committer | 2023-09-19 09:25:09 -0400 | |
| commit | df56ecc318c55897e3de8c60ba9b74a3c29323e8 (patch) | |
| tree | 445eed88c91ce53fa8198ab7bc0b9d14f5e6be7a /src | |
| parent | Merge pull request #11526 from german77/mii_service_v2 (diff) | |
| parent | android: Ignore validation layers library in git (diff) | |
| download | yuzu-df56ecc318c55897e3de8c60ba9b74a3c29323e8.tar.gz yuzu-df56ecc318c55897e3de8c60ba9b74a3c29323e8.tar.xz yuzu-df56ecc318c55897e3de8c60ba9b74a3c29323e8.zip | |
Merge pull request #11542 from t895/touch-offset-fix
android: Screen orientation and aspect ratio fixes
Diffstat (limited to 'src')
4 files changed, 23 insertions, 28 deletions
diff --git a/src/android/.gitignore b/src/android/.gitignore index 121cc8484..ff7121acd 100644 --- a/src/android/.gitignore +++ b/src/android/.gitignore | |||
| @@ -63,3 +63,6 @@ fastlane/Preview.html | |||
| 63 | fastlane/screenshots | 63 | fastlane/screenshots |
| 64 | fastlane/test_output | 64 | fastlane/test_output |
| 65 | fastlane/readme.md | 65 | fastlane/readme.md |
| 66 | |||
| 67 | # Autogenerated library for vulkan validation layers | ||
| 68 | libVkLayer_khronos_validation.so | ||
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 d4ae39661..e96a2059b 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 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.activities | 4 | package org.yuzu.yuzu_emu.activities |
| 5 | 5 | ||
| 6 | import android.annotation.SuppressLint | ||
| 6 | import android.app.Activity | 7 | import android.app.Activity |
| 7 | import android.app.PendingIntent | 8 | import android.app.PendingIntent |
| 8 | import android.app.PictureInPictureParams | 9 | import android.app.PictureInPictureParams |
| @@ -397,6 +398,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { | |||
| 397 | } | 398 | } |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 401 | @SuppressLint("UnspecifiedRegisterReceiverFlag") | ||
| 400 | override fun onPictureInPictureModeChanged( | 402 | override fun onPictureInPictureModeChanged( |
| 401 | isInPictureInPictureMode: Boolean, | 403 | isInPictureInPictureMode: Boolean, |
| 402 | newConfig: Configuration | 404 | newConfig: Configuration |
| @@ -409,7 +411,11 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { | |||
| 409 | addAction(actionMute) | 411 | addAction(actionMute) |
| 410 | addAction(actionUnmute) | 412 | addAction(actionUnmute) |
| 411 | }.also { | 413 | }.also { |
| 412 | registerReceiver(pictureInPictureReceiver, it) | 414 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { |
| 415 | registerReceiver(pictureInPictureReceiver, it, RECEIVER_EXPORTED) | ||
| 416 | } else { | ||
| 417 | registerReceiver(pictureInPictureReceiver, it) | ||
| 418 | } | ||
| 413 | } | 419 | } |
| 414 | } else { | 420 | } else { |
| 415 | try { | 421 | try { |
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 3e6c157c7..750638bc9 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 | |||
| 15 | import android.os.Bundle | 15 | import android.os.Bundle |
| 16 | import android.os.Handler | 16 | import android.os.Handler |
| 17 | import android.os.Looper | 17 | import android.os.Looper |
| 18 | import android.util.Rational | ||
| 19 | import android.view.* | 18 | import android.view.* |
| 20 | import android.widget.TextView | 19 | import android.widget.TextView |
| 21 | import androidx.activity.OnBackPressedCallback | 20 | import androidx.activity.OnBackPressedCallback |
| @@ -287,13 +286,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 287 | 286 | ||
| 288 | override fun onConfigurationChanged(newConfig: Configuration) { | 287 | override fun onConfigurationChanged(newConfig: Configuration) { |
| 289 | super.onConfigurationChanged(newConfig) | 288 | super.onConfigurationChanged(newConfig) |
| 289 | updateScreenLayout() | ||
| 290 | if (emulationActivity?.isInPictureInPictureMode == true) { | 290 | if (emulationActivity?.isInPictureInPictureMode == true) { |
| 291 | if (binding.drawerLayout.isOpen) { | 291 | if (binding.drawerLayout.isOpen) { |
| 292 | binding.drawerLayout.close() | 292 | binding.drawerLayout.close() |
| 293 | } | 293 | } |
| 294 | if (EmulationMenuSettings.showOverlay) { | 294 | if (EmulationMenuSettings.showOverlay) { |
| 295 | binding.surfaceInputOverlay.post { | 295 | binding.surfaceInputOverlay.post { |
| 296 | binding.surfaceInputOverlay.visibility = View.VISIBLE | 296 | binding.surfaceInputOverlay.visibility = View.INVISIBLE |
| 297 | } | 297 | } |
| 298 | } | 298 | } |
| 299 | } else { | 299 | } else { |
| @@ -328,7 +328,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | override fun onPause() { | 330 | override fun onPause() { |
| 331 | if (emulationState.isRunning) { | 331 | if (emulationState.isRunning && emulationActivity?.isInPictureInPictureMode != true) { |
| 332 | emulationState.pause() | 332 | emulationState.pause() |
| 333 | } | 333 | } |
| 334 | super.onPause() | 334 | super.onPause() |
| @@ -394,16 +394,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | private fun updateScreenLayout() { | 396 | private fun updateScreenLayout() { |
| 397 | binding.surfaceEmulation.setAspectRatio( | 397 | binding.surfaceEmulation.setAspectRatio(null) |
| 398 | when (IntSetting.RENDERER_ASPECT_RATIO.int) { | ||
| 399 | 0 -> Rational(16, 9) | ||
| 400 | 1 -> Rational(4, 3) | ||
| 401 | 2 -> Rational(21, 9) | ||
| 402 | 3 -> Rational(16, 10) | ||
| 403 | 4 -> null // Stretch | ||
| 404 | else -> Rational(16, 9) | ||
| 405 | } | ||
| 406 | ) | ||
| 407 | emulationActivity?.buildPictureInPictureParams() | 398 | emulationActivity?.buildPictureInPictureParams() |
| 408 | updateOrientation() | 399 | updateOrientation() |
| 409 | } | 400 | } |
| @@ -693,7 +684,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 693 | private class EmulationState(private val gamePath: String) { | 684 | private class EmulationState(private val gamePath: String) { |
| 694 | private var state: State | 685 | private var state: State |
| 695 | private var surface: Surface? = null | 686 | private var surface: Surface? = null |
| 696 | private var runWhenSurfaceIsValid = false | ||
| 697 | 687 | ||
| 698 | init { | 688 | init { |
| 699 | // Starting state is stopped. | 689 | // Starting state is stopped. |
| @@ -751,8 +741,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 751 | // If the surface is set, run now. Otherwise, wait for it to get set. | 741 | // If the surface is set, run now. Otherwise, wait for it to get set. |
| 752 | if (surface != null) { | 742 | if (surface != null) { |
| 753 | runWithValidSurface() | 743 | runWithValidSurface() |
| 754 | } else { | ||
| 755 | runWhenSurfaceIsValid = true | ||
| 756 | } | 744 | } |
| 757 | } | 745 | } |
| 758 | 746 | ||
| @@ -760,7 +748,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 760 | @Synchronized | 748 | @Synchronized |
| 761 | fun newSurface(surface: Surface?) { | 749 | fun newSurface(surface: Surface?) { |
| 762 | this.surface = surface | 750 | this.surface = surface |
| 763 | if (runWhenSurfaceIsValid) { | 751 | if (this.surface != null) { |
| 764 | runWithValidSurface() | 752 | runWithValidSurface() |
| 765 | } | 753 | } |
| 766 | } | 754 | } |
| @@ -788,10 +776,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 788 | } | 776 | } |
| 789 | 777 | ||
| 790 | private fun runWithValidSurface() { | 778 | private fun runWithValidSurface() { |
| 791 | runWhenSurfaceIsValid = false | 779 | NativeLibrary.surfaceChanged(surface) |
| 792 | when (state) { | 780 | when (state) { |
| 793 | State.STOPPED -> { | 781 | State.STOPPED -> { |
| 794 | NativeLibrary.surfaceChanged(surface) | ||
| 795 | val emulationThread = Thread({ | 782 | val emulationThread = Thread({ |
| 796 | Log.debug("[EmulationFragment] Starting emulation thread.") | 783 | Log.debug("[EmulationFragment] Starting emulation thread.") |
| 797 | NativeLibrary.run(gamePath) | 784 | NativeLibrary.run(gamePath) |
| @@ -801,7 +788,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 801 | 788 | ||
| 802 | State.PAUSED -> { | 789 | State.PAUSED -> { |
| 803 | Log.debug("[EmulationFragment] Resuming emulation.") | 790 | Log.debug("[EmulationFragment] Resuming emulation.") |
| 804 | NativeLibrary.surfaceChanged(surface) | ||
| 805 | NativeLibrary.unpauseEmulation() | 791 | NativeLibrary.unpauseEmulation() |
| 806 | } | 792 | } |
| 807 | 793 | ||
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 a890c6604..a7e414b81 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 @@ | |||
| 11 | #include "jni/emu_window/emu_window.h" | 11 | #include "jni/emu_window/emu_window.h" |
| 12 | 12 | ||
| 13 | void EmuWindow_Android::OnSurfaceChanged(ANativeWindow* surface) { | 13 | void EmuWindow_Android::OnSurfaceChanged(ANativeWindow* surface) { |
| 14 | m_window_width = ANativeWindow_getWidth(surface); | ||
| 15 | m_window_height = ANativeWindow_getHeight(surface); | ||
| 16 | |||
| 17 | // Ensures that we emulate with the correct aspect ratio. | ||
| 18 | UpdateCurrentFramebufferLayout(m_window_width, m_window_height); | ||
| 19 | |||
| 14 | window_info.render_surface = reinterpret_cast<void*>(surface); | 20 | window_info.render_surface = reinterpret_cast<void*>(surface); |
| 15 | } | 21 | } |
| 16 | 22 | ||
| @@ -62,14 +68,8 @@ EmuWindow_Android::EmuWindow_Android(InputCommon::InputSubsystem* input_subsyste | |||
| 62 | return; | 68 | return; |
| 63 | } | 69 | } |
| 64 | 70 | ||
| 65 | m_window_width = ANativeWindow_getWidth(surface); | 71 | OnSurfaceChanged(surface); |
| 66 | m_window_height = ANativeWindow_getHeight(surface); | ||
| 67 | |||
| 68 | // Ensures that we emulate with the correct aspect ratio. | ||
| 69 | UpdateCurrentFramebufferLayout(m_window_width, m_window_height); | ||
| 70 | |||
| 71 | window_info.type = Core::Frontend::WindowSystemType::Android; | 72 | window_info.type = Core::Frontend::WindowSystemType::Android; |
| 72 | window_info.render_surface = reinterpret_cast<void*>(surface); | ||
| 73 | 73 | ||
| 74 | m_input_subsystem->Initialize(); | 74 | m_input_subsystem->Initialize(); |
| 75 | } | 75 | } |