From 14f4eac6c25a3f231d2d760b164de8980971e4dd Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 27 Apr 2017 20:24:10 +1000 Subject: [PATCH] [Video] Make screen res dynamic on android --- Source/Project64-video/Android.cpp | 5 ++ Source/Project64-video/Main.cpp | 6 +- Source/Project64-video/ScreenResolution.cpp | 70 +++++++++++++-------- Source/Project64-video/ScreenResolution.h | 3 + 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/Source/Project64-video/Android.cpp b/Source/Project64-video/Android.cpp index e20eaa8f3..968f9fbbc 100644 --- a/Source/Project64-video/Android.cpp +++ b/Source/Project64-video/Android.cpp @@ -16,6 +16,11 @@ #define EXPORT extern "C" __attribute__((visibility("default"))) #define CALL +EXPORT void CALL Java_emu_project64_jni_NativeVideo_UpdateScreenRes(JNIEnv* env, jclass cls, int ScreenWidth, int ScreenHeight) +{ + UpdateScreenResolution(ScreenWidth, ScreenHeight); +} + EXPORT jint CALL Java_emu_project64_jni_NativeVideo_getResolutionCount(JNIEnv* env, jclass cls) { return GetScreenResolutionCount(); diff --git a/Source/Project64-video/Main.cpp b/Source/Project64-video/Main.cpp index f83311112..dddfd0405 100644 --- a/Source/Project64-video/Main.cpp +++ b/Source/Project64-video/Main.cpp @@ -42,7 +42,7 @@ #include #ifdef ANDROID -uint32_t g_NativeWidth, g_NativeHeight; +uint32_t g_ScreenWidth, g_ScreenHeight; #endif GFX_INFO gfx; @@ -1605,8 +1605,8 @@ output: none *******************************************************************/ void CALL SurfaceChanged(int width, int height) { - g_NativeWidth = width; - g_NativeHeight = height; + g_ScreenWidth = width; + g_ScreenHeight = height; } void Android_JNI_SwapWindow() diff --git a/Source/Project64-video/ScreenResolution.cpp b/Source/Project64-video/ScreenResolution.cpp index d54fedc74..7e16dfc8c 100644 --- a/Source/Project64-video/ScreenResolution.cpp +++ b/Source/Project64-video/ScreenResolution.cpp @@ -13,13 +13,14 @@ #include "trace.h" #ifdef ANDROID -extern uint32_t g_NativeWidth, g_NativeHeight; +#include +#include #endif struct ResolutionInfo { ResolutionInfo(const char * name = NULL, uint32_t width = 0, uint32_t height = 0, uint32_t frequency = 0, bool default_res = false) : - m_name(name), + m_name(name ? name : ""), m_width(width), m_height(height), m_frequency(frequency), @@ -27,7 +28,7 @@ struct ResolutionInfo { } - const char * Name(void) const { return m_name; } + const char * Name(void) const { return m_name.c_str(); } uint32_t width(void) const { return m_width; } uint32_t height(void) const { return m_height; } uint32_t frequency(void) const { return m_frequency; } @@ -43,21 +44,12 @@ struct ResolutionInfo } private: uint32_t m_width, m_height, m_frequency; - const char * m_name; + std::string m_name; bool m_default_res; }; #ifdef ANDROID -static ResolutionInfo g_resolutions[] = -{ - ResolutionInfo("#3200#", 0, 0, 0, true), - ResolutionInfo("960x720", 960, 720, 0, false), - ResolutionInfo("800x600", 800, 600, 0, false), - ResolutionInfo("640x480", 640, 480, 0, false), - ResolutionInfo("480x360", 480, 360, 0, false), - ResolutionInfo("320x240", 320, 240, 0, false), -}; - +std::vector g_resolutions; #else static ResolutionInfo g_resolutions[] = { @@ -88,9 +80,47 @@ static ResolutionInfo g_resolutions[] = }; #endif +#ifdef ANDROID +void UpdateScreenResolution(int ScreenWidth, int ScreenHeight) +{ + WriteTrace(TraceResolution, TraceError, "aspectmode: %d", g_settings->aspectmode()); + g_resolutions.clear(); + switch (g_settings->aspectmode()) + { + case CSettings::Aspect_4x3: + g_resolutions.push_back(ResolutionInfo(stdstr_f("%dx%d", ScreenHeight * 4/3, ScreenHeight).c_str(), ScreenHeight * 4 / 3, ScreenHeight, 0, true)); + g_resolutions.push_back(ResolutionInfo("960x720", 960, 720, 0, false)); + g_resolutions.push_back(ResolutionInfo("800x600", 800, 600, 0, false)); + g_resolutions.push_back(ResolutionInfo("640x480", 640, 480, 0, false)); + g_resolutions.push_back(ResolutionInfo("480x360", 480, 360, 0, false)); + g_resolutions.push_back(ResolutionInfo("320x240", 320, 240, 0, false)); + break; + case CSettings::Aspect_16x9: + g_resolutions.push_back(ResolutionInfo(stdstr_f("%dx%d", ScreenHeight * 16 / 9, ScreenHeight).c_str(), ScreenHeight * 16 / 9, ScreenHeight, 0, true)); + g_resolutions.push_back(ResolutionInfo("1280x720", 1280, 720, 0, false)); + g_resolutions.push_back(ResolutionInfo("1067x600", 1067, 600, 0, false)); + g_resolutions.push_back(ResolutionInfo("854x480", 854, 480, 0, false)); + g_resolutions.push_back(ResolutionInfo("640x360", 640, 360, 0, false)); + g_resolutions.push_back(ResolutionInfo("426x240", 426, 240, 0, false)); + break; + case CSettings::Aspect_Original: + g_resolutions.push_back(ResolutionInfo("Original", ScreenWidth, ScreenHeight, 0, true)); + break; + case CSettings::Aspect_Stretch: + default: //stretch + g_resolutions.push_back(ResolutionInfo(stdstr_f("%dx%d", ScreenWidth, ScreenHeight).c_str(), ScreenWidth, ScreenHeight, 0, true)); + break; + } +} +#endif + uint32_t GetScreenResolutionCount() { +#ifdef ANDROID + return g_resolutions.size(); +#else return sizeof(g_resolutions) / sizeof(g_resolutions[0]); +#endif } const char * GetScreenResolutionName(uint32_t index) @@ -118,12 +148,6 @@ uint32_t GetScreenResWidth(uint32_t index) { if (index < GetScreenResolutionCount()) { -#ifdef ANDROID - if (g_resolutions[index].width() == 0) - { - return g_NativeWidth; - } -#endif return g_resolutions[index].width(); } return 0; @@ -133,12 +157,6 @@ uint32_t GetScreenResHeight(uint32_t index) { if (index < GetScreenResolutionCount()) { -#ifdef ANDROID - if (g_resolutions[index].height() == 0) - { - return g_NativeHeight; - } -#endif return g_resolutions[index].height(); } return 0; diff --git a/Source/Project64-video/ScreenResolution.h b/Source/Project64-video/ScreenResolution.h index 80a8f2b84..96d23382f 100644 --- a/Source/Project64-video/ScreenResolution.h +++ b/Source/Project64-video/ScreenResolution.h @@ -11,6 +11,9 @@ #pragma once #include +#ifdef ANDROID +void UpdateScreenResolution(int ScreenWidth, int ScreenHeight); +#endif uint32_t GetScreenResolutionCount(); uint32_t GetDefaultScreenRes(); uint32_t GetScreenResWidth(uint32_t index);