[Scummvm-cvs-logs] scummvm master -> 457640a16257be20581080d6d682994cca94ba37
lordhoto
lordhoto at gmail.com
Tue Dec 8 15:48:20 CET 2015
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:
079037b739 SDL: Prevent graphics stretching in fullscreen when using SDL2.
457640a162 SDL: Prevent cursor from leaving screen area in fullscreen with SDL2.
Commit: 079037b73990b6107e59c7f1cd971c3a1cc221d1
https://github.com/scummvm/scummvm/commit/079037b73990b6107e59c7f1cd971c3a1cc221d1
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-08T15:41:10+01:00
Commit Message:
SDL: Prevent graphics stretching in fullscreen when using SDL2.
As a side effect we get better coordinates from mouse move events in
fullscreen, i.e. we do not get actual window coordinates but something close
to actual viewport coordinates. The easily noticable issue is that mouse
coordinates inside black bars are outside of the viewport. For example, the
x coordinate can get negative when there's a black bar at the left side.
Changed paths:
backends/graphics/surfacesdl/surfacesdl-graphics.cpp
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 9cb1452..01afc84 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -2380,7 +2380,8 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() {
SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) {
deinitializeRenderer();
- if (!_window->createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
+ const bool isFullscreen = (flags & SDL_FULLSCREEN) != 0;
+ if (!_window->createWindow(width, height, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) {
return nullptr;
}
@@ -2390,6 +2391,14 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
return nullptr;
}
+ // We set the logical renderer size to the requested resolution in
+ // fullscreen. This assures that SDL2 adds black bars if needed to prevent
+ // stretching.
+ if (isFullscreen && SDL_RenderSetLogicalSize(_renderer, width, height) < 0) {
+ deinitializeRenderer();
+ return nullptr;
+ }
+
_screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height);
if (!_screenTexture) {
deinitializeRenderer();
Commit: 457640a16257be20581080d6d682994cca94ba37
https://github.com/scummvm/scummvm/commit/457640a16257be20581080d6d682994cca94ba37
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2015-12-08T15:43:36+01:00
Commit Message:
SDL: Prevent cursor from leaving screen area in fullscreen with SDL2.
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 01afc84..e45773e 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -125,6 +125,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
_hwscreen(0),
#if SDL_VERSION_ATLEAST(2, 0, 0)
_renderer(nullptr), _screenTexture(nullptr),
+ _viewportX(0), _viewportY(0), _mouseScaleX(1.0f), _mouseScaleY(1.0f),
#else
_originalBitsPerPixel(0),
#endif
@@ -2353,6 +2354,16 @@ void SurfaceSdlGraphicsManager::notifyVideoExpose() {
}
void SurfaceSdlGraphicsManager::transformMouseCoordinates(Common::Point &point) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ // In fullscreen mode we can easily get coordinates outside the actual
+ // screen area. For example, if black bars are added left/right we can end
+ // up with negative x coordinates if the user moves the mouse inside the
+ // black bar. Here, we post process the received cooridnates to give the
+ // user the feeling the black bars do not exist.
+ point.x = (int)((point.x + _viewportX) * _mouseScaleX);
+ point.y = (int)((point.y + _viewportY) * _mouseScaleY);
+#endif
+
if (!_overlayVisible) {
point.x /= _videoMode.scaleFactor;
point.y /= _videoMode.scaleFactor;
@@ -2399,6 +2410,25 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height,
return nullptr;
}
+ // To provide smooth mouse handling in case black borders are added, we
+ // obtain the actual window size and the internal renderer scaling.
+ // Based on this we calculate scale factors to scale received mouse
+ // coordinates into actual screen area coordinates.
+ float scaleX = 0, scaleY = 0;
+ SDL_RenderGetScale(_renderer, &scaleX, &scaleY);
+ int windowWidth = 1, windowHeight = 1;
+ SDL_GetWindowSize(_window->getSDLWindow(), &windowWidth, &windowHeight);
+
+ _mouseScaleX = (width * scaleX) / windowWidth;
+ _mouseScaleY = (height * scaleY) / windowHeight;
+
+ // Obtain viewport top left coordinates to transform received coordinates
+ // into visible area coordinates (i.e. including black borders).
+ SDL_Rect viewport;
+ SDL_RenderGetViewport(_renderer, &viewport);
+ _viewportX = viewport.x;
+ _viewportY = viewport.y;
+
_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 2431ce8..07ff4e5 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -171,6 +171,8 @@ protected:
* around this API to keep the code paths as close as possible. */
SDL_Renderer *_renderer;
SDL_Texture *_screenTexture;
+ int _viewportX, _viewportY;
+ float _mouseScaleX, _mouseScaleY;
void deinitializeRenderer();
SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
More information about the Scummvm-git-logs
mailing list