[Scummvm-cvs-logs] SF.net SVN: scummvm:[50832] scummvm/trunk/backends/platform/sdl

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jul 13 01:18:44 CEST 2010


Revision: 50832
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50832&view=rev
Author:   fingolfin
Date:     2010-07-12 23:18:44 +0000 (Mon, 12 Jul 2010)

Log Message:
-----------
SDL: Overhaul OSystem_SDL::getSupportedFormats

* Do not use global constructor for the RGBList and BGRList
  tables anymore, by moving them inside a function.
* Update the list of supported formats if the hardware
  screen surface changes. Previously, the list of supported
  pixel formats (and its order) was computed only once and
  then never changed.

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

Modified: scummvm/trunk/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/graphics.cpp	2010-07-12 22:26:48 UTC (rev 50831)
+++ scummvm/trunk/backends/platform/sdl/graphics.cpp	2010-07-12 23:18:44 UTC (rev 50832)
@@ -214,43 +214,55 @@
 }
 
 #ifdef USE_RGB_COLOR
-const Graphics::PixelFormat RGBList[] = {
+
+Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() const {
+	assert(!_supportedFormats.empty());
+	return _supportedFormats;
+}
+
+void OSystem_SDL::detectSupportedFormats() {
+
+	// Clear old list
+	_supportedFormats.clear();
+
+	// Some tables with standard formats that we always list
+	// as "supported". If frontend code tries to use one of
+	// these, we will perform the necessary format
+	// conversion in the background. Of course this incurs a
+	// performance hit, but on desktop ports this should not
+	// matter. We still push the currently active format to
+	// the front, so if frontend code just uses the first
+	// available format, it will get one that is "cheap" to
+	// use.
+	const Graphics::PixelFormat RGBList[] = {
 #ifdef ENABLE_32BIT
-	// RGBA8888, ARGB8888, RGB888
-	Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0),
-	Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24),
-	Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),
+		// RGBA8888, ARGB8888, RGB888
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0),
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24),
+		Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),
 #endif
-	// RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444
-	Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),
-	Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15),
-	Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0),
-	Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),
-	Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)
-};
-const Graphics::PixelFormat BGRList[] = {
+		// RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444
+		Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),
+		Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15),
+		Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0),
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)
+	};
+	const Graphics::PixelFormat BGRList[] = {
 #ifdef ENABLE_32BIT
-	// ABGR8888, BGRA8888, BGR888
-	Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24),
-	Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0),
-	Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),
+		// ABGR8888, BGRA8888, BGR888
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24),
+		Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0),
+		Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),
 #endif
-	// BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444
-	Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0),
-	Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15),
-	Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0),
-	Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12),
-	Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)
-};
+		// BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444
+		Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0),
+		Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15),
+		Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0),
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12),
+		Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)
+	};
 
-// TODO: prioritize matching alpha masks
-Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() const {
-	static Common::List<Graphics::PixelFormat> list;
-	static bool inited = false;
-
-	if (inited)
-		return list;
-
 	bool BGR = false;
 	int listLength = ARRAYSIZE(RGBList);
 
@@ -268,31 +280,29 @@
 			format.aLoss = 8;
 
 		// Push it first, as the prefered format.
-		list.push_back(format);
+		_supportedFormats.push_back(format);
 
 		if (format.bShift > format.rShift)
 			BGR = true;
-
-		// Mark that we don't need to do this any more.
-		inited = true;
 	}
 
+	// TODO: prioritize matching alpha masks
 	for (int i = 0; i < listLength; i++) {
-		if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
+		if (_hwscreen && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
 			continue;
 		if (BGR) {
 			if (BGRList[i] != format)
-				list.push_back(BGRList[i]);
-			list.push_back(RGBList[i]);
+				_supportedFormats.push_back(BGRList[i]);
+			_supportedFormats.push_back(RGBList[i]);
 		} else {
 			if (RGBList[i] != format)
-				list.push_back(RGBList[i]);
-			list.push_back(BGRList[i]);
+				_supportedFormats.push_back(RGBList[i]);
+			_supportedFormats.push_back(BGRList[i]);
 		}
 	}
-	list.push_back(Graphics::PixelFormat::createFormatCLUT8());
-	return list;
+	_supportedFormats.push_back(Graphics::PixelFormat::createFormatCLUT8());
 }
+
 #endif
 
 bool OSystem_SDL::setGraphicsMode(int mode) {
@@ -574,6 +584,10 @@
 	_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16,
 		_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
 	);
+#ifdef USE_RGB_COLOR
+	detectSupportedFormats();
+#endif
+
 	if (_hwscreen == NULL) {
 		// DON'T use error(), as this tries to bring up the debug
 		// console, which WON'T WORK now that _hwscreen is hosed.

Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h	2010-07-12 22:26:48 UTC (rev 50831)
+++ scummvm/trunk/backends/platform/sdl/sdl.h	2010-07-12 23:18:44 UTC (rev 50832)
@@ -274,6 +274,13 @@
 #ifdef USE_RGB_COLOR
 	Graphics::PixelFormat _screenFormat;
 	Graphics::PixelFormat _cursorFormat;
+	Common::List<Graphics::PixelFormat> _supportedFormats;
+
+	/**
+	 * Update the list of supported pixel formats.
+	 * This method is invoked by loadGFXMode().
+	 */
+	void detectSupportedFormats();
 #endif
 
 	// temporary screen (for scalers)


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