mirror of
https://github.com/yuzu-emu/yuzu-mainline
synced 2024-11-26 04:57:42 +00:00
Merge pull request #10703 from bunnei/fix-android-layout
android: Fix screen orientation & blurriness.
This commit is contained in:
commit
b6f2490288
4 changed files with 5 additions and 95 deletions
|
@ -6,15 +6,12 @@ package org.yuzu.yuzu_emu.activities
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.hardware.Sensor
|
import android.hardware.Sensor
|
||||||
import android.hardware.SensorEvent
|
import android.hardware.SensorEvent
|
||||||
import android.hardware.SensorEventListener
|
import android.hardware.SensorEventListener
|
||||||
import android.hardware.SensorManager
|
import android.hardware.SensorManager
|
||||||
import android.hardware.display.DisplayManager
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Display
|
|
||||||
import android.view.InputDevice
|
import android.view.InputDevice
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
@ -23,7 +20,6 @@ import android.view.View
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
|
@ -39,7 +35,6 @@ import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel
|
||||||
import org.yuzu.yuzu_emu.fragments.EmulationFragment
|
import org.yuzu.yuzu_emu.fragments.EmulationFragment
|
||||||
import org.yuzu.yuzu_emu.model.Game
|
import org.yuzu.yuzu_emu.model.Game
|
||||||
import org.yuzu.yuzu_emu.utils.ControllerMappingHelper
|
import org.yuzu.yuzu_emu.utils.ControllerMappingHelper
|
||||||
import org.yuzu.yuzu_emu.utils.EmulationMenuSettings
|
|
||||||
import org.yuzu.yuzu_emu.utils.ForegroundService
|
import org.yuzu.yuzu_emu.utils.ForegroundService
|
||||||
import org.yuzu.yuzu_emu.utils.InputHandler
|
import org.yuzu.yuzu_emu.utils.InputHandler
|
||||||
import org.yuzu.yuzu_emu.utils.NfcReader
|
import org.yuzu.yuzu_emu.utils.NfcReader
|
||||||
|
@ -148,11 +143,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
nfcReader.startScanning()
|
nfcReader.startScanning()
|
||||||
startMotionSensorListener()
|
startMotionSensorListener()
|
||||||
|
|
||||||
NativeLibrary.notifyOrientationChange(
|
|
||||||
EmulationMenuSettings.landscapeScreenLayout,
|
|
||||||
getAdjustedRotation()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -258,24 +248,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
||||||
|
|
||||||
override fun onAccuracyChanged(sensor: Sensor, i: Int) {}
|
override fun onAccuracyChanged(sensor: Sensor, i: Int) {}
|
||||||
|
|
||||||
private fun getAdjustedRotation():Int {
|
|
||||||
val rotation = getSystemService<DisplayManager>()!!.getDisplay(Display.DEFAULT_DISPLAY).rotation
|
|
||||||
val config: Configuration = resources.configuration
|
|
||||||
|
|
||||||
if ((config.screenLayout and Configuration.SCREENLAYOUT_LONG_YES) != 0 ||
|
|
||||||
(config.screenLayout and Configuration.SCREENLAYOUT_LONG_NO) == 0 ||
|
|
||||||
(config.screenLayout and Configuration.SCREENLAYOUT_SIZE_SMALL) != 0) {
|
|
||||||
return rotation
|
|
||||||
}
|
|
||||||
when (rotation) {
|
|
||||||
Surface.ROTATION_0 -> return Surface.ROTATION_90
|
|
||||||
Surface.ROTATION_90 -> return Surface.ROTATION_0
|
|
||||||
Surface.ROTATION_180 -> return Surface.ROTATION_270
|
|
||||||
Surface.ROTATION_270 -> return Surface.ROTATION_180
|
|
||||||
}
|
|
||||||
return rotation
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun restoreState(savedInstanceState: Bundle) {
|
private fun restoreState(savedInstanceState: Bundle) {
|
||||||
game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!!
|
game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!!
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,14 +94,6 @@ public:
|
||||||
m_native_window = native_window;
|
m_native_window = native_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ScreenRotation() const {
|
|
||||||
return m_screen_rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetScreenRotation(u32 screen_rotation) {
|
|
||||||
m_screen_rotation = screen_rotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir,
|
void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir,
|
||||||
const std::string& custom_driver_name,
|
const std::string& custom_driver_name,
|
||||||
const std::string& file_redirect_dir) {
|
const std::string& file_redirect_dir) {
|
||||||
|
@ -400,7 +392,6 @@ private:
|
||||||
// Window management
|
// Window management
|
||||||
std::unique_ptr<EmuWindow_Android> m_window;
|
std::unique_ptr<EmuWindow_Android> m_window;
|
||||||
ANativeWindow* m_native_window{};
|
ANativeWindow* m_native_window{};
|
||||||
u32 m_screen_rotation{};
|
|
||||||
|
|
||||||
// Core emulation
|
// Core emulation
|
||||||
Core::System m_system;
|
Core::System m_system;
|
||||||
|
@ -426,10 +417,6 @@ private:
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
u32 GetAndroidScreenRotation() {
|
|
||||||
return EmulationSession::GetInstance().ScreenRotation();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Core::SystemResultStatus RunEmulation(const std::string& filepath) {
|
static Core::SystemResultStatus RunEmulation(const std::string& filepath) {
|
||||||
Common::Log::Initialize();
|
Common::Log::Initialize();
|
||||||
Common::Log::SetColorConsoleBackendEnabled(true);
|
Common::Log::SetColorConsoleBackendEnabled(true);
|
||||||
|
@ -473,13 +460,6 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_surfaceDestroyed(JNIEnv* env,
|
||||||
EmulationSession::GetInstance().SurfaceChanged();
|
EmulationSession::GetInstance().SurfaceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_notifyOrientationChange(JNIEnv* env,
|
|
||||||
[[maybe_unused]] jclass clazz,
|
|
||||||
jint layout_option,
|
|
||||||
jint rotation) {
|
|
||||||
return EmulationSession::GetInstance().SetScreenRotation(static_cast<u32>(rotation));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env,
|
void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env,
|
||||||
[[maybe_unused]] jclass clazz,
|
[[maybe_unused]] jclass clazz,
|
||||||
jstring j_directory) {
|
jstring j_directory) {
|
||||||
|
|
|
@ -37,10 +37,6 @@
|
||||||
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
||||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
extern u32 GetAndroidScreenRotation();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -78,47 +74,6 @@ struct ScreenRectVertex {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
|
|
||||||
std::array<f32, 4 * 4> MakeOrthographicMatrix(f32 width, f32 height) {
|
|
||||||
constexpr u32 ROTATION_0 = 0;
|
|
||||||
constexpr u32 ROTATION_90 = 1;
|
|
||||||
constexpr u32 ROTATION_180 = 2;
|
|
||||||
constexpr u32 ROTATION_270 = 3;
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
switch (GetAndroidScreenRotation()) {
|
|
||||||
case ROTATION_0:
|
|
||||||
// Desktop
|
|
||||||
return { 2.f / width, 0.f, 0.f, 0.f,
|
|
||||||
0.f, 2.f / height, 0.f, 0.f,
|
|
||||||
0.f, 0.f, 1.f, 0.f,
|
|
||||||
-1.f, -1.f, 0.f, 1.f};
|
|
||||||
case ROTATION_180:
|
|
||||||
// Reverse desktop
|
|
||||||
return {-2.f / width, 0.f, 0.f, 0.f,
|
|
||||||
0.f, -2.f / height, 0.f, 0.f,
|
|
||||||
0.f, 0.f, 1.f, 0.f,
|
|
||||||
1.f, 1.f, 0.f, 1.f};
|
|
||||||
case ROTATION_270:
|
|
||||||
// Reverse landscape
|
|
||||||
return { 0.f, -2.f / width, 0.f, 0.f,
|
|
||||||
2.f / height, 0.f, 0.f, 0.f,
|
|
||||||
0.f, 0.f, 1.f, 0.f,
|
|
||||||
-1.f, 1.f, 0.f, 1.f};
|
|
||||||
case ROTATION_90:
|
|
||||||
default:
|
|
||||||
// Landscape
|
|
||||||
return { 0.f, 2.f / width, 0.f, 0.f,
|
|
||||||
-2.f / height, 0.f, 0.f, 0.f,
|
|
||||||
0.f, 0.f, 1.f, 0.f,
|
|
||||||
1.f, -1.f, 0.f, 1.f};
|
|
||||||
}
|
|
||||||
// clang-format on
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
std::array<f32, 4 * 4> MakeOrthographicMatrix(f32 width, f32 height) {
|
std::array<f32, 4 * 4> MakeOrthographicMatrix(f32 width, f32 height) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return { 2.f / width, 0.f, 0.f, 0.f,
|
return { 2.f / width, 0.f, 0.f, 0.f,
|
||||||
|
@ -128,8 +83,6 @@ std::array<f32, 4 * 4> MakeOrthographicMatrix(f32 width, f32 height) {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
u32 GetBytesPerPixel(const Tegra::FramebufferConfig& framebuffer) {
|
u32 GetBytesPerPixel(const Tegra::FramebufferConfig& framebuffer) {
|
||||||
using namespace VideoCore::Surface;
|
using namespace VideoCore::Surface;
|
||||||
return BytesPerBlock(PixelFormatFromGPUPixelFormat(framebuffer.pixel_format));
|
return BytesPerBlock(PixelFormatFromGPUPixelFormat(framebuffer.pixel_format));
|
||||||
|
|
|
@ -231,7 +231,12 @@ void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bo
|
||||||
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
.queueFamilyIndexCount = 0,
|
.queueFamilyIndexCount = 0,
|
||||||
.pQueueFamilyIndices = nullptr,
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
#ifdef ANDROID
|
||||||
|
// On Android, do not allow surface rotation to deviate from the frontend.
|
||||||
|
.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
|
||||||
|
#else
|
||||||
.preTransform = capabilities.currentTransform,
|
.preTransform = capabilities.currentTransform,
|
||||||
|
#endif
|
||||||
.compositeAlpha = alpha_flags,
|
.compositeAlpha = alpha_flags,
|
||||||
.presentMode = present_mode,
|
.presentMode = present_mode,
|
||||||
.clipped = VK_FALSE,
|
.clipped = VK_FALSE,
|
||||||
|
|
Loading…
Reference in a new issue