[Scummvm-git-logs] scummvm master -> c4699cb280e2aa55f0044b29cef59a1543e812e2
criezy
criezy at scummvm.org
Sat Aug 14 18:09:35 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c4699cb280 SDL: Move getDisplayDpiFromSdl and getDpiScalingFactor into the SdlWindow class
Commit: c4699cb280e2aa55f0044b29cef59a1543e812e2
https://github.com/scummvm/scummvm/commit/c4699cb280e2aa55f0044b29cef59a1543e812e2
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2021-08-14T19:09:33+01:00
Commit Message:
SDL: Move getDisplayDpiFromSdl and getDpiScalingFactor into the SdlWindow class
Changed paths:
A backends/platform/sdl/macosx/macosx-window.h
A backends/platform/sdl/macosx/macosx-window.mm
R backends/graphics/sdl/sdl-graphics-osx.mm
backends/graphics/openglsdl/openglsdl-graphics.cpp
backends/graphics/sdl/sdl-graphics.h
backends/module.mk
backends/platform/sdl/macosx/macosx.cpp
backends/platform/sdl/module.mk
backends/platform/sdl/sdl-window.cpp
backends/platform/sdl/sdl-window.h
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 22ac859cf4..495e4166d9 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -250,7 +250,7 @@ bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
}
float OpenGLSdlGraphicsManager::getHiDPIScreenFactor() const {
- return getDpiScalingFactor();
+ return _window->getDpiScalingFactor();
}
void OpenGLSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
@@ -290,7 +290,7 @@ void OpenGLSdlGraphicsManager::notifyResize(const int width, const int height) {
// event is processed after recreating the window at the new resolution.
int currentWidth, currentHeight;
getWindowSizeFromSdl(¤tWidth, ¤tHeight);
- float scale = getDpiScalingFactor();
+ float scale = _window->getDpiScalingFactor();
debug(3, "req: %d x %d cur: %d x %d, scale: %f", width, height, currentWidth, currentHeight, scale);
handleResize(currentWidth, currentHeight);
@@ -644,7 +644,7 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
getWindowSizeFromSdl(&windowWidth, &windowHeight);
// FIXME HACK. I don't like this at all, but macOS requires window size in LoDPI
#ifdef __APPLE__
- float scale = getDpiScalingFactor();
+ float scale = _window->getDpiScalingFactor();
windowWidth /= scale;
windowHeight /= scale;
#endif
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 1df94ad534..d15dfa8a01 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -180,51 +180,6 @@ protected:
#endif
}
- void getDisplayDpiFromSdl(float *dpi, float *defaultDpi) const {
- const float systemDpi =
-#ifdef __APPLE__
- 72.0f;
-#elif defined(_WIN32)
- 96.0f;
-#else
- 90.0f; // ScummVM default
-#endif
- if (defaultDpi)
- *defaultDpi = systemDpi;
-
- if (dpi) {
-#if SDL_VERSION_ATLEAST(2, 0, 4)
- if (SDL_GetDisplayDPI(_window->getDisplayIndex(), NULL, dpi, NULL) != 0) {
- *dpi = systemDpi;
- }
-#else
- *dpi = systemDpi;
-#endif
- }
- }
-
- /**
- * Returns the scaling mode based on the display DPI
- */
- float getDpiScalingFactor() const {
-#ifdef MACOSX
- float scale;
- if (getMacWindowScaling(scale)) {
- debug(4, "NSWindow HiDPI scaling: %f", scale);
- return scale;
- }
-#endif
-
- float dpi, defaultDpi;
- getDisplayDpiFromSdl(&dpi, &defaultDpi);
- debug(4, "dpi: %g default: %g", dpi, defaultDpi);
- float ratio = dpi / defaultDpi;
- if (ratio >= 1.5f)
- return 2.f;
- else
- return 1.f;
- }
-
virtual void setSystemMousePosition(const int x, const int y) override;
virtual void handleResizeImpl(const int width, const int height) override;
@@ -251,10 +206,6 @@ protected:
private:
void toggleFullScreen();
-
-#ifdef MACOSX
- bool getMacWindowScaling(float &) const;
-#endif
};
#endif
diff --git a/backends/module.mk b/backends/module.mk
index c26cfdb8e2..02082f30c7 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -149,11 +149,6 @@ MODULE_OBJS += \
plugins/sdl/sdl-provider.o \
timer/sdl/sdl-timer.o
-ifdef MACOSX
-MODULE_OBJS += \
- graphics/sdl/sdl-graphics-osx.o
-endif
-
# SDL 2 removed audio CD support
ifndef USE_SDL2
MODULE_OBJS += \
diff --git a/backends/platform/sdl/macosx/macosx-window.h b/backends/platform/sdl/macosx/macosx-window.h
new file mode 100644
index 0000000000..c696eae11f
--- /dev/null
+++ b/backends/platform/sdl/macosx/macosx-window.h
@@ -0,0 +1,39 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_PLATFORM_SDL_MACOSX_MACOSX_WINDOW_H
+#define BACKENDS_PLATFORM_SDL_MACOSX_MACOSX_WINDOW_H
+
+#ifdef MACOSX
+
+#include "backends/platform/sdl/sdl-window.h"
+
+class SdlWindow_MacOSX final : public SdlWindow {
+public:
+ // Use an iconless window on OS X, as we use a nicer external icon there.
+ virtual void setupIcon() override {}
+ virtual float getDpiScalingFactor() const override;
+};
+
+#endif
+
+#endif
diff --git a/backends/graphics/sdl/sdl-graphics-osx.mm b/backends/platform/sdl/macosx/macosx-window.mm
similarity index 72%
rename from backends/graphics/sdl/sdl-graphics-osx.mm
rename to backends/platform/sdl/macosx/macosx-window.mm
index baac2238e3..88e87880c3 100644
--- a/backends/graphics/sdl/sdl-graphics-osx.mm
+++ b/backends/platform/sdl/macosx/macosx-window.mm
@@ -23,23 +23,18 @@
// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
-#include "SDL_syswm.h"
-#include "backends/graphics/sdl/sdl-graphics.h"
+#include "backends/platform/sdl/macosx/macosx-window.h"
#include <AppKit/NSWindow.h>
-bool SdlGraphicsManager::getMacWindowScaling(float &scale) const {
+float SdlWindow_MacOSX::getDpiScalingFactor() const {
#if SDL_VERSION_ATLEAST(2, 0, 0) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
SDL_SysWMinfo wmInfo;
- SDL_VERSION(&wmInfo.version); /* initialize info structure with SDL version info */
- if (!SDL_GetWindowWMInfo(_window->getSDLWindow(), &wmInfo))
- return false;
-
- NSWindow *nswindow = wmInfo.info.cocoa.window;
- if (!nswindow)
- return false;
- scale = [nswindow backingScaleFactor];
- return true;
-#else
- return false;
+ if (getSDLWMInformation(&wmInfo)) {
+ NSWindow *nswindow = wmInfo.info.cocoa.window;
+ if (nswindow)
+ return [nswindow backingScaleFactor];
+ }
#endif
+
+ return SdlWindow::getDpiScalingFactor();
}
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index 281bdbc2ec..483ba4570d 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -30,6 +30,7 @@
#include "backends/audiocd/macosx/macosx-audiocd.h"
#include "backends/platform/sdl/macosx/appmenu_osx.h"
#include "backends/platform/sdl/macosx/macosx.h"
+#include "backends/platform/sdl/macosx/macosx-window.h"
#include "backends/updates/macosx/macosx-updates.h"
#include "backends/taskbar/macosx/macosx-taskbar.h"
#include "backends/text-to-speech/macosx/macosx-text-to-speech.h"
@@ -62,9 +63,8 @@ OSystem_MacOSX::~OSystem_MacOSX() {
}
void OSystem_MacOSX::init() {
- // Use an iconless window on OS X, as we use a nicer external icon there.
initSDL();
- _window = new SdlIconlessWindow();
+ _window = new SdlWindow_MacOSX();
#if defined(USE_TASKBAR)
// Initialize taskbar manager
diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk
index 410fb4a355..18e8bd8457 100644
--- a/backends/platform/sdl/module.mk
+++ b/backends/platform/sdl/module.mk
@@ -14,6 +14,7 @@ ifdef MACOSX
MODULE_OBJS += \
macosx/macosx-main.o \
macosx/macosx.o \
+ macosx/macosx-window.o \
macosx/macosx_wrapper.o \
macosx/appmenu_osx.o
endif
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 2a53429c6e..7e3cd6db0e 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -241,6 +241,40 @@ Common::Rect SdlWindow::getDesktopResolution() {
return _desktopRes;
}
+void SdlWindow::getDisplayDpi(float *dpi, float *defaultDpi) const {
+ const float systemDpi =
+#ifdef __APPLE__
+ 72.0f;
+#elif defined(_WIN32)
+ 96.0f;
+#else
+ 90.0f; // ScummVM default
+#endif
+ if (defaultDpi)
+ *defaultDpi = systemDpi;
+
+ if (dpi) {
+#if SDL_VERSION_ATLEAST(2, 0, 4)
+ if (SDL_GetDisplayDPI(getDisplayIndex(), NULL, dpi, NULL) != 0) {
+ *dpi = systemDpi;
+ }
+#else
+ *dpi = systemDpi;
+#endif
+ }
+}
+
+float SdlWindow::getDpiScalingFactor() const {
+ float dpi, defaultDpi;
+ getDisplayDpi(&dpi, &defaultDpi);
+ debug(4, "dpi: %g default: %g", dpi, defaultDpi);
+ float ratio = dpi / defaultDpi;
+ if (ratio >= 1.5f)
+ return 2.f;
+ else
+ return 1.f;
+}
+
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Surface *copySDLSurface(SDL_Surface *src) {
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index 29fe7f43f2..abab0b57a4 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -87,6 +87,13 @@ public:
*/
Common::Rect getDesktopResolution();
+ void getDisplayDpi(float *dpi, float *defaultDpi) const;
+
+ /**
+ * Returns the scaling mode based on the display DPI
+ */
+ virtual float getDpiScalingFactor() const;
+
bool mouseIsGrabbed() const {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
More information about the Scummvm-git-logs
mailing list