diff options
author | Norbert Lange | 2009-08-11 22:35:56 +0000 |
---|---|---|
committer | Norbert Lange | 2009-08-11 22:35:56 +0000 |
commit | 0836cf6d9b9222255273a9c6f9d91203b13c3bd9 (patch) | |
tree | 714c59161aaf7dbc36d7cb6b4e8fcaa9c467e8f9 /backends/platform/sdl | |
parent | 8cb42dd6896925106282abd23ce23812d6031989 (diff) | |
parent | 65e9ae163ff757ca15af78da4a753a7ee1d25a16 (diff) | |
download | scummvm-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')
-rw-r--r-- | backends/platform/sdl/graphics.cpp | 60 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 26 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 14 |
3 files changed, 93 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) { diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 8972234f9e..7b3cf4eaa1 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -85,6 +85,31 @@ static Uint32 timer_handler(Uint32 interval, void *param) { return interval; } +AspectRatio::AspectRatio(int w, int h) { + // TODO : Validation and so on... + // Currently, we just ensure the program don't instantiate non-supported aspect ratios + _kw = w; + _kh = h; +} + +static const size_t AR_COUNT = 4; +static const char* desiredAspectRatioAsStrings[AR_COUNT] = { "auto", "4/3", "16/9", "16/10" }; +static const AspectRatio desiredAspectRatios[AR_COUNT] = { AspectRatio(0, 0), AspectRatio(4,3), AspectRatio(16,9), AspectRatio(16,10) }; +static AspectRatio getDesiredAspectRatio() { + //TODO : We could parse an arbitrary string, if we code enough proper validation + Common::String desiredAspectRatio = ConfMan.get("desired_screen_aspect_ratio"); + + for (size_t i = 0; i < AR_COUNT; i++) { + assert(desiredAspectRatioAsStrings[i] != NULL); + + if (!scumm_stricmp(desiredAspectRatio.c_str(), desiredAspectRatioAsStrings[i])) { + return desiredAspectRatios[i]; + } + } + // TODO : Report a warning + return AspectRatio(0, 0); +} + void OSystem_SDL::initBackend() { assert(!_inited); @@ -124,6 +149,7 @@ void OSystem_SDL::initBackend() { _videoMode.mode = GFX_DOUBLESIZE; _videoMode.scaleFactor = 2; _videoMode.aspectRatioCorrection = ConfMan.getBool("aspect_ratio"); + _videoMode.desiredAspectRatio = getDesiredAspectRatio(); _scalerProc = Normal2x; #else // for small screen platforms _videoMode.mode = GFX_NORMAL; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 7498f48b08..2a5fda30bd 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -70,6 +70,18 @@ enum { GFX_DOTMATRIX = 11 }; +class AspectRatio { + int _kw, _kh; +public: + AspectRatio() { _kw = _kh = 0; } + AspectRatio(int w, int h); + + bool isAuto() const { return (_kw | _kh) == 0; } + + int kw() const { return _kw; } + int kh() const { return _kh; } +}; + class OSystem_SDL : public BaseBackend { public: @@ -268,12 +280,14 @@ protected: bool fullscreen; bool aspectRatioCorrection; + AspectRatio desiredAspectRatio; int mode; int scaleFactor; int screenWidth, screenHeight; int overlayWidth, overlayHeight; + int hardwareWidth, hardwareHeight; }; VideoState _videoMode, _oldVideoMode; |