android: frontend: Track screen layout separately for orientation.

This commit is contained in:
bunnei 2019-07-22 14:58:54 -04:00
parent eb094e377f
commit 2952363549
10 changed files with 44 additions and 18 deletions

View File

@ -278,12 +278,17 @@ public final class NativeLibrary {
/** /**
* Switches the screen layout. * Switches the screen layout.
*/ */
public static native void SwitchScreenLayout(); public static native void SwitchScreenLayout(boolean is_portrait_mode);
/**
* Notifies the core emulation that the orientation has changed.
*/
public static native void NotifyOrientationChange(boolean is_portrait_mode);
/** /**
* Swaps the top and bottom screens. * Swaps the top and bottom screens.
*/ */
public static native void SwapScreens(); public static native void SwapScreens(boolean is_portrait_mode);
public static boolean displayAlertMsg(final String caption, final String text, public static boolean displayAlertMsg(final String caption, final String text,
final boolean yesNo) { final boolean yesNo) {

View File

@ -3,6 +3,7 @@ package org.citra.citra_android.activities;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -366,12 +367,12 @@ public final class EmulationActivity extends AppCompatActivity {
// Switch the layout of the screens // Switch the layout of the screens
case MENU_ACTION_SWITCH_SCREEN_LAYOUT: case MENU_ACTION_SWITCH_SCREEN_LAYOUT:
NativeLibrary.SwitchScreenLayout(); NativeLibrary.SwitchScreenLayout(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
return; return;
// Swap the top and bottom screen locations // Swap the top and bottom screen locations
case MENU_ACTION_SWAP_SCREENS: case MENU_ACTION_SWAP_SCREENS:
NativeLibrary.SwapScreens(); NativeLibrary.SwapScreens(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
return; return;
// Reset overlay placement // Reset overlay placement

View File

@ -343,6 +343,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
joystick.draw(canvas); joystick.draw(canvas);
} }
NativeLibrary.NotifyOrientationChange(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
} }
@Override @Override

View File

@ -119,7 +119,7 @@ void Config::ReadValues() {
// Layout // Layout
Settings::values.layout_option = static_cast<Settings::LayoutOption>(sdl2_config->GetInteger( Settings::values.layout_option = static_cast<Settings::LayoutOption>(sdl2_config->GetInteger(
"Layout", "layout_option", static_cast<int>(Settings::LayoutOption::MobilePortrait))); "Layout", "layout_option", static_cast<int>(Settings::LayoutOption::MobileLandscape)));
Settings::values.swap_screen = sdl2_config->GetBoolean("Layout", "swap_screen", false); Settings::values.swap_screen = sdl2_config->GetBoolean("Layout", "swap_screen", false);
Settings::values.custom_layout = sdl2_config->GetBoolean("Layout", "custom_layout", false); Settings::values.custom_layout = sdl2_config->GetBoolean("Layout", "custom_layout", false);
Settings::values.custom_top_left = Settings::values.custom_top_left =

View File

@ -192,7 +192,8 @@ void Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv*
"(Ljava/lang/String;Ljava/lang/String;Z)Z"); "(Ljava/lang/String;Ljava/lang/String;Z)Z");
} }
void Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env, jobject obj) { void Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env, jobject obj,
jboolean is_portrait_mode) {
if (Settings::values.layout_option == Settings::LayoutOption::MobilePortrait) { if (Settings::values.layout_option == Settings::LayoutOption::MobilePortrait) {
Settings::values.layout_option = Settings::LayoutOption::MobileLandscape; Settings::values.layout_option = Settings::LayoutOption::MobileLandscape;
} else if (Settings::values.layout_option == Settings::LayoutOption::MobileLandscape) { } else if (Settings::values.layout_option == Settings::LayoutOption::MobileLandscape) {
@ -204,12 +205,18 @@ void Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env,
} else { } else {
Settings::values.layout_option = Settings::LayoutOption::MobilePortrait; Settings::values.layout_option = Settings::LayoutOption::MobilePortrait;
} }
VideoCore::g_renderer->UpdateCurrentFramebufferLayout(); VideoCore::g_renderer->UpdateCurrentFramebufferLayout(is_portrait_mode);
} }
void Java_org_citra_citra_1android_NativeLibrary_SwapScreens(JNIEnv* env, jobject obj) { void Java_org_citra_citra_1android_NativeLibrary_NotifyOrientationChange(
JNIEnv* env, jobject obj, jboolean is_portrait_mode) {
VideoCore::g_renderer->UpdateCurrentFramebufferLayout(is_portrait_mode);
}
void Java_org_citra_citra_1android_NativeLibrary_SwapScreens(JNIEnv* env, jobject obj,
jboolean is_portrait_mode) {
Settings::values.swap_screen = !Settings::values.swap_screen; Settings::values.swap_screen = !Settings::values.swap_screen;
VideoCore::g_renderer->UpdateCurrentFramebufferLayout(); VideoCore::g_renderer->UpdateCurrentFramebufferLayout(is_portrait_mode);
} }
void Java_org_citra_citra_1android_NativeLibrary_SetUserDirectory(JNIEnv* env, jobject obj, void Java_org_citra_citra_1android_NativeLibrary_SetUserDirectory(JNIEnv* env, jobject obj,

View File

@ -139,11 +139,14 @@ JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_WriteProfileR
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj); Java_org_citra_citra_1android_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(JNIEnv* env, JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwitchScreenLayout(
jobject obj); JNIEnv* env, jobject obj, jboolean is_portrait_mode);
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwapScreens(JNIEnv* env, JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_NotifyOrientationChange(
jobject obj); JNIEnv* env, jobject obj, jboolean is_portrait_mode);
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_SwapScreens(
JNIEnv* env, jobject obj, jboolean is_portrait_mode);
JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_Run__Ljava_lang_String_2( JNIEXPORT void JNICALL Java_org_citra_citra_1android_NativeLibrary_Run__Ljava_lang_String_2(
JNIEnv* env, jclass type, jstring path_); JNIEnv* env, jclass type, jstring path_);

View File

@ -145,7 +145,8 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
TouchPressed(framebuffer_x, framebuffer_y); TouchPressed(framebuffer_x, framebuffer_y);
} }
void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
bool is_portrait_mode) {
Layout::FramebufferLayout layout; Layout::FramebufferLayout layout;
const auto layout_option = Settings::values.layout_option; const auto layout_option = Settings::values.layout_option;
const auto min_size = const auto min_size =
@ -156,6 +157,12 @@ void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height)
} else { } else {
width = std::max(width, min_size.first); width = std::max(width, min_size.first);
height = std::max(height, min_size.second); height = std::max(height, min_size.second);
// If in portrait mode, only the MobilePortrait option really makes sense
const Settings::LayoutOption layout_option = is_portrait_mode
? Settings::LayoutOption::MobilePortrait
: Settings::values.layout_option;
switch (layout_option) { switch (layout_option) {
case Settings::LayoutOption::SingleScreen: case Settings::LayoutOption::SingleScreen:
layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen, layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen,

View File

@ -159,7 +159,8 @@ public:
* Convenience method to update the current frame layout * Convenience method to update the current frame layout
* Read from the current settings to determine which layout to use. * Read from the current settings to determine which layout to use.
*/ */
void UpdateCurrentFramebufferLayout(unsigned width, unsigned height); void UpdateCurrentFramebufferLayout(unsigned width, unsigned height,
bool is_portrait_mode = {});
std::unique_ptr<TextureMailbox> mailbox = nullptr; std::unique_ptr<TextureMailbox> mailbox = nullptr;

View File

@ -11,9 +11,9 @@
RendererBase::RendererBase(Frontend::EmuWindow& window) : render_window{window} {} RendererBase::RendererBase(Frontend::EmuWindow& window) : render_window{window} {}
RendererBase::~RendererBase() = default; RendererBase::~RendererBase() = default;
void RendererBase::UpdateCurrentFramebufferLayout() { void RendererBase::UpdateCurrentFramebufferLayout(bool is_portrait_mode) {
const Layout::FramebufferLayout& layout = render_window.GetFramebufferLayout(); const Layout::FramebufferLayout& layout = render_window.GetFramebufferLayout();
render_window.UpdateCurrentFramebufferLayout(layout.width, layout.height); render_window.UpdateCurrentFramebufferLayout(layout.width, layout.height, is_portrait_mode);
} }
void RendererBase::RefreshRasterizerSetting() { void RendererBase::RefreshRasterizerSetting() {

View File

@ -38,7 +38,7 @@ public:
virtual void CleanupVideoDumping() = 0; virtual void CleanupVideoDumping() = 0;
/// Updates the framebuffer layout of the contained render window handle. /// Updates the framebuffer layout of the contained render window handle.
void UpdateCurrentFramebufferLayout(); void UpdateCurrentFramebufferLayout(bool is_portrait_mode = {});
// Getter/setter functions: // Getter/setter functions:
// ------------------------ // ------------------------