Windows: Start at a sensible window size if high-DPI. Avoids the worst of #9437 but does not fix it.

This commit is contained in:
Henrik Rydgård 2017-03-17 13:22:00 +01:00
parent 6dcbed6659
commit aefad893f8
4 changed files with 25 additions and 20 deletions

View file

@ -130,21 +130,6 @@ bool Core_GetPowerSaving() {
return powerSaving; return powerSaving;
} }
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
static int ScreenDPI() {
return 96; // TODO UWP
}
#else
static int ScreenDPI() {
HDC screenDC = GetDC(nullptr);
int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
ReleaseDC(nullptr, screenDC);
return dotsPerInch;
}
#endif
#endif
static bool IsWindowSmall(int pixelWidth, int pixelHeight) { static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
// Can't take this from config as it will not be set if windows is maximized. // Can't take this from config as it will not be set if windows is maximized.
int w = (int)(pixelWidth * g_dpi_scale); int w = (int)(pixelWidth * g_dpi_scale);
@ -156,10 +141,7 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
bool UpdateScreenScale(int width, int height) { bool UpdateScreenScale(int width, int height) {
bool smallWindow; bool smallWindow;
#ifdef _WIN32 #ifdef _WIN32
// Use legacy DPI handling, because we still compile as XP compatible we don't get the new SDK, unless g_dpi = System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
// we do unholy tricks.
g_dpi = ScreenDPI();
g_dpi_scale = 96.0f / g_dpi; g_dpi_scale = 96.0f / g_dpi;
#else #else
g_dpi = 96; g_dpi = 96;

View file

@ -394,7 +394,12 @@ namespace MainWindow
if (g_Config.iWindowWidth <= 0 || g_Config.iWindowHeight <= 0) { if (g_Config.iWindowWidth <= 0 || g_Config.iWindowHeight <= 0) {
RECT rcInner = rc, rcOuter; RECT rcInner = rc, rcOuter;
bool portrait = g_Config.IsPortrait(); bool portrait = g_Config.IsPortrait();
GetWindowRectAtResolution(2 * (portrait ? 272 : 480), 2 * (portrait ? 480 : 272), rcInner, rcOuter);
// We want to adjust for DPI but still get an integer pixel scaling ratio.
double dpi_scale = 96.0 / System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
int scale = (int)ceil(2.0 / dpi_scale);
GetWindowRectAtResolution(scale * (portrait ? 272 : 480), scale * (portrait ? 480 : 272), rcInner, rcOuter);
rc.right = rc.left + (rcOuter.right - rcOuter.left); rc.right = rc.left + (rcOuter.right - rcOuter.left);
rc.bottom = rc.top + (rcOuter.bottom - rcOuter.top); rc.bottom = rc.top + (rcOuter.bottom - rcOuter.top);
g_Config.iWindowWidth = rc.right - rc.left; g_Config.iWindowWidth = rc.right - rc.left;

View file

@ -187,6 +187,21 @@ std::string System_GetProperty(SystemProperty prop) {
// Ugly! // Ugly!
extern WindowsAudioBackend *winAudioBackend; extern WindowsAudioBackend *winAudioBackend;
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
static int ScreenDPI() {
return 96; // TODO UWP
}
#else
static int ScreenDPI() {
HDC screenDC = GetDC(nullptr);
int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
ReleaseDC(nullptr, screenDC);
return dotsPerInch;
}
#endif
#endif
int System_GetPropertyInt(SystemProperty prop) { int System_GetPropertyInt(SystemProperty prop) {
switch (prop) { switch (prop) {
case SYSPROP_AUDIO_SAMPLE_RATE: case SYSPROP_AUDIO_SAMPLE_RATE:
@ -195,6 +210,8 @@ int System_GetPropertyInt(SystemProperty prop) {
return 60000; return 60000;
case SYSPROP_DEVICE_TYPE: case SYSPROP_DEVICE_TYPE:
return DEVICE_TYPE_DESKTOP; return DEVICE_TYPE_DESKTOP;
case SYSPROP_DISPLAY_DPI:
return ScreenDPI();
default: default:
return -1; return -1;
} }

View file

@ -157,6 +157,7 @@ enum SystemProperty {
SYSPROP_DISPLAY_XRES, SYSPROP_DISPLAY_XRES,
SYSPROP_DISPLAY_YRES, SYSPROP_DISPLAY_YRES,
SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer
SYSPROP_DISPLAY_DPI,
SYSPROP_MOGA_VERSION, SYSPROP_MOGA_VERSION,
SYSPROP_DEVICE_TYPE, SYSPROP_DEVICE_TYPE,