[Scummvm-cvs-logs] scummvm master -> 366e164705a920ccd5de9dc606399f9c5b54913c

lordhoto lordhoto at gmail.com
Fri Dec 18 19:13:36 CET 2015


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:
366e164705 SDL: Implement initial support for resizable window with SDL2.


Commit: 366e164705a920ccd5de9dc606399f9c5b54913c
    https://github.com/scummvm/scummvm/commit/366e164705a920ccd5de9dc606399f9c5b54913c
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-18T19:12:11+01:00

Commit Message:
SDL: Implement initial support for resizable window with SDL2.

The code is disabled for now.

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h



diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index b2da471..2b9d3aa 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -2367,6 +2367,14 @@ void SurfaceSdlGraphicsManager::notifyVideoExpose() {
 	_forceFull = true;
 }
 
+#ifdef USE_SDL_RESIZABLE_WINDOW
+void SurfaceSdlGraphicsManager::notifyResize(const uint width, const uint height) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+	setWindowResolution(width, height);
+#endif
+}
+#endif
+
 void SurfaceSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) {
 #if SDL_VERSION_ATLEAST(2, 0, 0)
 	// In SDL2 the actual output resolution might be different from what we
@@ -2402,21 +2410,10 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() {
 	_window->destroyWindow();
 }
 
-SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
-	deinitializeRenderer();
-
-	const bool isFullscreen = (flags & SDL_FULLSCREEN) != 0;
-	if (!_window->createWindow(width, height, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
-		return nullptr;
-	}
+void SurfaceSdlGraphicsManager::setWindowResolution(int width, int height) {
+	_windowWidth  = width;
+	_windowHeight = height;
 
-	_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0);
-	if (!_renderer) {
-		deinitializeRenderer();
-		return nullptr;
-	}
-
-	SDL_GetWindowSize(_window->getSDLWindow(), &_windowWidth, &_windowHeight);
 	// We expect full screen resolution as inputs coming from the event system.
 	_eventSource->resetKeyboadEmulation(_windowWidth - 1, _windowHeight - 1);
 
@@ -2425,7 +2422,7 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
 	// this case, we add black bars if necessary to assure the aspect ratio
 	// is preserved.
 	const frac_t outputAspect  = intToFrac(_windowWidth) / _windowHeight;
-	const frac_t desiredAspect = intToFrac(width) / height;
+	const frac_t desiredAspect = intToFrac(_videoMode.hardwareWidth) / _videoMode.hardwareHeight;
 
 	_viewport.w = _windowWidth;
 	_viewport.h = _windowHeight;
@@ -2433,15 +2430,43 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
 	// Adjust one dimension for mantaining the aspect ratio.
 	if (abs(outputAspect - desiredAspect) >= (int)(FRAC_ONE / 1000)) {
 		if (outputAspect < desiredAspect) {
-			_viewport.h = height * _windowWidth / width;
+			_viewport.h = _videoMode.hardwareHeight * _windowWidth / _videoMode.hardwareWidth;
 		} else if (outputAspect > desiredAspect) {
-			_viewport.w = width * _windowHeight / height;
+			_viewport.w = _videoMode.hardwareWidth * _windowHeight / _videoMode.hardwareHeight;
 		}
 	}
 
 	_viewport.x = (_windowWidth  - _viewport.w) / 2;
 	_viewport.y = (_windowHeight - _viewport.h) / 2;
 
+	// Force a full redraw because we changed the viewport.
+	_forceFull = true;
+}
+
+SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
+	deinitializeRenderer();
+
+	uint32 createWindowFlags = 0;
+#ifdef USE_SDL_RESIZABLE_WINDOW
+	createWindowFlags |= SDL_WINDOW_RESIZABLE;
+#endif
+	if ((flags & SDL_FULLSCREEN) != 0) {
+		createWindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+	}
+
+	if (!_window->createWindow(width, height, createWindowFlags)) {
+		return nullptr;
+	}
+
+	_renderer = SDL_CreateRenderer(_window->getSDLWindow(), -1, 0);
+	if (!_renderer) {
+		deinitializeRenderer();
+		return nullptr;
+	}
+
+	SDL_GetWindowSize(_window->getSDLWindow(), &_windowWidth, &_windowHeight);
+	setWindowResolution(_windowWidth, _windowHeight);
+
 	_screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height);
 	if (!_screenTexture) {
 		deinitializeRenderer();
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index ac9844c..c4f7346 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -39,6 +39,15 @@
 #define USE_SDL_DEBUG_FOCUSRECT
 #endif
 
+// We have (some) support for resizable windows when SDL2 is used. However
+// the overlay still uses the resolution setup with SDL_SetVideoMode. This
+// makes the GUI look subpar when the user resizes the window. In addition
+// we do not adapt the scale factor right now. Thus, we disable this code
+// path for now.
+#if SDL_VERSION_ATLEAST(2, 0, 0) && 0
+#define USE_SDL_RESIZABLE_WINDOW
+#endif
+
 #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
 // Uncomment this to enable the 'on screen display' code.
 #define USE_OSD	1
@@ -143,6 +152,9 @@ public:
 
 	// SdlGraphicsManager interface
 	virtual void notifyVideoExpose();
+#ifdef USE_SDL_RESIZABLE_WINDOW
+	virtual void notifyResize(const uint width, const uint height);
+#endif
 	virtual void transformMouseCoordinates(Common::Point &point);
 	virtual void notifyMousePos(Common::Point mouse);
 
@@ -174,6 +186,7 @@ protected:
 	SDL_Rect _viewport;
 	int _windowWidth, _windowHeight;
 	void deinitializeRenderer();
+	void setWindowResolution(int width, int height);
 
 	SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
 	void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);






More information about the Scummvm-git-logs mailing list