[Scummvm-cvs-logs] SF.net SVN: scummvm:[43214] scummvm/trunk

tramboi at users.sourceforge.net tramboi at users.sourceforge.net
Mon Aug 10 20:03:54 CEST 2009


Revision: 43214
          http://scummvm.svn.sourceforge.net/scummvm/?rev=43214&view=rev
Author:   tramboi
Date:     2009-08-10 18:03:54 +0000 (Mon, 10 Aug 2009)

Log Message:
-----------
Option "desired_screen_aspect_ratio" for fullscreen mode in the SDL backend
Shortcoming: the picture is not centered

Modified Paths:
--------------
    scummvm/trunk/backends/platform/sdl/graphics.cpp
    scummvm/trunk/backends/platform/sdl/sdl.cpp
    scummvm/trunk/backends/platform/sdl/sdl.h
    scummvm/trunk/base/commandLine.cpp

Modified: scummvm/trunk/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/graphics.cpp	2009-08-10 18:03:37 UTC (rev 43213)
+++ scummvm/trunk/backends/platform/sdl/graphics.cpp	2009-08-10 18:03:54 UTC (rev 43214)
@@ -358,6 +358,50 @@
 	_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;
@@ -374,11 +418,11 @@
 	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 +436,11 @@
 	// 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) {

Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp	2009-08-10 18:03:37 UTC (rev 43213)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp	2009-08-10 18:03:54 UTC (rev 43214)
@@ -85,6 +85,31 @@
 	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 @@
 	_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;

Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h	2009-08-10 18:03:37 UTC (rev 43213)
+++ scummvm/trunk/backends/platform/sdl/sdl.h	2009-08-10 18:03:54 UTC (rev 43214)
@@ -70,7 +70,19 @@
 	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:
 	OSystem_SDL();
@@ -268,12 +280,14 @@
 
 		bool fullscreen;
 		bool aspectRatioCorrection;
+		AspectRatio desiredAspectRatio;
 
 		int mode;
 		int scaleFactor;
 
 		int screenWidth, screenHeight;
 		int overlayWidth, overlayHeight;
+		int hardwareWidth, hardwareHeight;
 	};
 	VideoState _videoMode, _oldVideoMode;
 

Modified: scummvm/trunk/base/commandLine.cpp
===================================================================
--- scummvm/trunk/base/commandLine.cpp	2009-08-10 18:03:37 UTC (rev 43213)
+++ scummvm/trunk/base/commandLine.cpp	2009-08-10 18:03:54 UTC (rev 43214)
@@ -157,6 +157,7 @@
 	ConfMan.registerDefault("aspect_ratio", false);
 	ConfMan.registerDefault("gfx_mode", "normal");
 	ConfMan.registerDefault("render_mode", "default");
+	ConfMan.registerDefault("desired_screen_aspect_ratio", "auto");
 
 	// Sound & Music
 	ConfMan.registerDefault("music_volume", 192);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list