aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl/graphics.cpp
diff options
context:
space:
mode:
authorNorbert Lange2009-08-11 22:35:56 +0000
committerNorbert Lange2009-08-11 22:35:56 +0000
commit0836cf6d9b9222255273a9c6f9d91203b13c3bd9 (patch)
tree714c59161aaf7dbc36d7cb6b4e8fcaa9c467e8f9 /backends/platform/sdl/graphics.cpp
parent8cb42dd6896925106282abd23ce23812d6031989 (diff)
parent65e9ae163ff757ca15af78da4a753a7ee1d25a16 (diff)
downloadscummvm-rg350-0836cf6d9b9222255273a9c6f9d91203b13c3bd9.tar.gz
scummvm-rg350-0836cf6d9b9222255273a9c6f9d91203b13c3bd9.tar.bz2
scummvm-rg350-0836cf6d9b9222255273a9c6f9d91203b13c3bd9.zip
merged from trunk (Amiga LoK supposedly completeable!)
fixed a bug I introduced in one of the last cleanups svn-id: r43291
Diffstat (limited to 'backends/platform/sdl/graphics.cpp')
-rw-r--r--backends/platform/sdl/graphics.cpp60
1 files changed, 53 insertions, 7 deletions
diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp
index ffdcd675e6..1192c1abff 100644
--- a/backends/platform/sdl/graphics.cpp
+++ b/backends/platform/sdl/graphics.cpp
@@ -358,12 +358,54 @@ void OSystem_SDL::initSize(uint w, uint h) {
_dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32));
}
+
+static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &width, int &height) {
+ assert(&width != &height);
+
+ if (desiredAspectRatio.isAuto())
+ return;
+
+ int kw = desiredAspectRatio.kw();
+ int kh = desiredAspectRatio.kh();
+
+ const int w = width;
+ const int h = height;
+
+ SDL_Rect const* const*availableModes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE); //TODO : Maybe specify a pixel format
+ assert(availableModes);
+
+ const SDL_Rect *bestMode = NULL;
+ uint bestMetric = (uint)-1; // Metric is wasted space
+ while (const SDL_Rect *mode = *availableModes++) {
+ if (mode->w < w)
+ continue;
+ if (mode->h < h)
+ continue;
+ if (mode->h * kw != mode->w * kh)
+ continue;
+ //printf("%d %d\n", mode->w, mode->h);
+
+ uint metric = mode->w * mode->h - w * h;
+ if (metric > bestMetric)
+ continue;
+
+ bestMetric = metric;
+ bestMode = mode;
+ }
+
+ if (!bestMode) {
+ warning("Unable to enforce the desired aspect ratio!");
+ return;
+ }
+ //printf("%d %d\n", bestMode->w, bestMode->h);
+ width = bestMode->w;
+ height = bestMode->h;
+}
+
bool OSystem_SDL::loadGFXMode() {
assert(_inited);
_forceFull = true;
- int hwW, hwH;
-
#if !defined(__MAEMO__) && !defined(GP2XWIZ)
_videoMode.overlayWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
_videoMode.overlayHeight = _videoMode.screenHeight * _videoMode.scaleFactor;
@@ -374,11 +416,11 @@ bool OSystem_SDL::loadGFXMode() {
if (_videoMode.aspectRatioCorrection)
_videoMode.overlayHeight = real2Aspect(_videoMode.overlayHeight);
- hwW = _videoMode.screenWidth * _videoMode.scaleFactor;
- hwH = effectiveScreenHeight();
+ _videoMode.hardwareWidth = _videoMode.screenWidth * _videoMode.scaleFactor;
+ _videoMode.hardwareHeight = effectiveScreenHeight();
#else
- hwW = _videoMode.overlayWidth;
- hwH = _videoMode.overlayHeight;
+ _videoMode.hardwareWidth = _videoMode.overlayWidth;
+ _videoMode.hardwareHeight = _videoMode.overlayHeight;
#endif
//
@@ -392,7 +434,11 @@ bool OSystem_SDL::loadGFXMode() {
// Create the surface that contains the scaled graphics in 16 bit mode
//
- _hwscreen = SDL_SetVideoMode(hwW, hwH, 16,
+ if(_videoMode.fullscreen) {
+ fixupResolutionForAspectRatio(_videoMode.desiredAspectRatio, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
+ }
+
+ _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16,
_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
);
if (_hwscreen == NULL) {