[Scummvm-git-logs] scummvm window-display -> f5233f1c8d59beb407920c53cff1b6f27246c415

SupSuper supsuper at gmail.com
Thu Apr 29 04:20:32 UTC 2021


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5219b1ea57 SDL: Get the window decoration size from the backend
f5233f1c8d SDL: Use the window display index when querying display modes


Commit: 5219b1ea57c32f16d4d9dac4ceb8a6246376e23a
    https://github.com/scummvm/scummvm/commit/5219b1ea57c32f16d4d9dac4ceb8a6246376e23a
Author: SupSuper (supsuper at gmail.com)
Date: 2021-04-29T04:44:55+01:00

Commit Message:
SDL: Get the window decoration size from the backend

It's been 5 years since SDL 2.0.5, I think it's safe to use

Changed paths:
    backends/platform/sdl/sdl-window.cpp


diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 1799948513..2ec160ddb4 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -296,19 +296,26 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
 	// the documentation says it only works on X11 anyway, which means it is
 	// basically worthless. So we'll just try to keep things closeish to the
 	// maximum for now.
-	SDL_DisplayMode displayMode;
-	SDL_GetDesktopDisplayMode(0, &displayMode);
+	Common::Rect desktopRes = getDesktopResolution();
 	if (!fullscreenFlags) {
-		displayMode.w -= 20;
-		displayMode.h -= 30;
+		int top, left, bottom, right;
+#if SDL_VERSION_ATLEAST(2, 0, 5)
+		if (!_window || SDL_GetWindowBordersSize(_window, &top, &left, &bottom, &right) < 0)
+#endif
+		{
+			left = right = 10;
+			top = bottom = 15;
+		}
+		desktopRes.right -= (left + right);
+		desktopRes.bottom -= (top + bottom);
 	}
 
-	if (width > displayMode.w) {
-		width = displayMode.w;
+	if (width > desktopRes.right) {
+		width = desktopRes.right;
 	}
 
-	if (height > displayMode.h) {
-		height = displayMode.h;
+	if (height > desktopRes.bottom) {
+		height = desktopRes.bottom;
 	}
 
 	if (!_window || oldNonUpdateableFlags != newNonUpdateableFlags) {


Commit: f5233f1c8d59beb407920c53cff1b6f27246c415
    https://github.com/scummvm/scummvm/commit/f5233f1c8d59beb407920c53cff1b6f27246c415
Author: SupSuper (supsuper at gmail.com)
Date: 2021-04-29T05:18:37+01:00

Commit Message:
SDL: Use the window display index when querying display modes

Changed paths:
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/sdl/sdl-graphics.h
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h
    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 b793962d0d..09f86495ed 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -140,10 +140,11 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(SdlEventSource *eventSource,
 
 	// Retrieve a list of working fullscreen modes
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	const int numModes = SDL_GetNumDisplayModes(0);
+	const int display = _window->getDisplayIndex();
+	const int numModes = SDL_GetNumDisplayModes(display);
 	for (int i = 0; i < numModes; ++i) {
 		SDL_DisplayMode mode;
-		if (SDL_GetDisplayMode(0, i, &mode)) {
+		if (SDL_GetDisplayMode(display, i, &mode)) {
 			continue;
 		}
 
diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h
index 256e8bec79..acac7ffb74 100644
--- a/backends/graphics/sdl/sdl-graphics.h
+++ b/backends/graphics/sdl/sdl-graphics.h
@@ -179,17 +179,6 @@ protected:
 		}
 #endif
 	}
-	/**
-	 * Gets the display index that the ScummVM window is on
-	 */
-	void getWindowDisplayIndexFromSdl(int *index) const {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-		assert(_window);
-		*index = SDL_GetWindowDisplayIndex(_window->getSDLWindow());
-#else
-		*index = 0;
-#endif
-	}
 
 	void getDisplayDpiFromSdl(float *dpi, float *defaultDpi) const {
 		const float systemDpi =
@@ -205,10 +194,7 @@ protected:
 
 		if (dpi) {
 #if SDL_VERSION_ATLEAST(2, 0, 4)
-			int displayIndex = 0;
-			getWindowDisplayIndexFromSdl(&displayIndex);
-
-			if (SDL_GetDisplayDPI(displayIndex, NULL, dpi, NULL) != 0) {
+			if (SDL_GetDisplayDPI(_window->getDisplayIndex(), NULL, dpi, NULL) != 0) {
 				*dpi = systemDpi;
 			}
 #else
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index bf36ca8339..8f0be68ba4 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -521,18 +521,8 @@ void SurfaceSdlGraphicsManager::detectSupportedFormats() {
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	{
-		SDL_Window *window = _window->getSDLWindow();
-		if (window == nullptr) {
-			error("Could not find ScummVM window for retrieving default display mode");
-		}
-
-		const int displayIndex = SDL_GetWindowDisplayIndex(window);
-		if (displayIndex < 0) {
-			error("Could not find ScummVM window display index");
-		}
-
 		SDL_DisplayMode defaultMode;
-		if (SDL_GetDesktopDisplayMode(displayIndex, &defaultMode) != 0) {
+		if (SDL_GetDesktopDisplayMode(_window->getDisplayIndex(), &defaultMode) != 0) {
 			error("Could not get default system display mode");
 		}
 
@@ -805,7 +795,7 @@ void SurfaceSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFo
 	_transactionDetails.sizeChanged = true;
 }
 
-static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &width, int &height) {
+void SurfaceSdlGraphicsManager::fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &width, int &height) const {
 	assert(&width != &height);
 
 	if (desiredAspectRatio.isAuto())
@@ -821,10 +811,11 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w
 	uint bestMetric = (uint)-1; // Metric is wasted space
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	const int numModes = SDL_GetNumDisplayModes(0);
+	const int display = _window->getDisplayIndex();
+	const int numModes = SDL_GetNumDisplayModes(display);
 	SDL_DisplayMode modeData, *mode = &modeData;
 	for (int i = 0; i < numModes; ++i) {
-		if (SDL_GetDisplayMode(0, i, &modeData)) {
+		if (SDL_GetDisplayMode(display, i, &modeData)) {
 			continue;
 		}
 #else
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index da4ed8a8ff..628a55740d 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -171,6 +171,8 @@ protected:
 
 	virtual void setupHardwareSize();
 
+	void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &width, int &height) const;
+
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	/* SDL2 features a different API for 2D graphics. We create a wrapper
 	 * around this API to keep the code paths as close as possible. */
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index 2ec160ddb4..ffc7e9eb30 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -232,9 +232,8 @@ bool SdlWindow::getSDLWMInformation(SDL_SysWMinfo *info) const {
 
 Common::Rect SdlWindow::getDesktopResolution() {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
-	int displayIndex = _window ? SDL_GetWindowDisplayIndex(_window) : 0;
 	SDL_DisplayMode displayMode;
-	if (!SDL_GetDesktopDisplayMode(displayIndex, &displayMode)) {
+	if (!SDL_GetDesktopDisplayMode(getDisplayIndex(), &displayMode)) {
 		_desktopRes = Common::Rect(displayMode.w, displayMode.h);
 	}
 #endif
@@ -265,6 +264,18 @@ SDL_Surface *copySDLSurface(SDL_Surface *src) {
 	return res;
 }
 
+int SdlWindow::getDisplayIndex() const {
+	if (_window) {
+		int displayIndex = SDL_GetWindowDisplayIndex(_window);
+		// Default to primary monitor
+		if (displayIndex < 0)
+			return 0;
+		else
+			return displayIndex;
+	}
+	return 0;
+}
+
 bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
 	if (_inputGrabState) {
 		flags |= SDL_WINDOW_INPUT_GRABBED;
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index b84cbd6039..29fe7f43f2 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -115,6 +115,11 @@ public:
 	 */
 	SDL_Window *getSDLWindow() const { return _window; }
 
+	/**
+	 * @return The display containing the ScummVM window.
+	 */
+	int getDisplayIndex() const;
+
 	/**
 	 * Creates or updates the SDL window.
 	 *




More information about the Scummvm-git-logs mailing list