[Scummvm-cvs-logs] SF.net SVN: scummvm:[41972] scummvm/branches/gsoc2009-16bit

upthorn at users.sourceforge.net upthorn at users.sourceforge.net
Tue Jun 30 09:30:57 CEST 2009


Revision: 41972
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41972&view=rev
Author:   upthorn
Date:     2009-06-30 07:30:57 +0000 (Tue, 30 Jun 2009)

Log Message:
-----------
renamed kTransactionPixelFormatNotSupported to kTransactionFormatNotSupported, retyped all Graphics::PixelFormat * parameters to const Graphics::PixelFormat *, (hopefully) repaired all memory leaks on screen and cursor format changes, provided OSystem::getScreenFormat and OSystem::getSupportedFormats methods for when ENABLE_RGB_COLOR is not set, completely forgot the "commit early, commit often" mantra.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp
    scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h
    scummvm/branches/gsoc2009-16bit/common/system.h
    scummvm/branches/gsoc2009-16bit/engines/engine.cpp
    scummvm/branches/gsoc2009-16bit/engines/engine.h
    scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp
    scummvm/branches/gsoc2009-16bit/graphics/cursorman.h

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/graphics.cpp	2009-06-30 07:30:57 UTC (rev 41972)
@@ -125,7 +125,7 @@
 			_videoMode.scaleFactor = _oldVideoMode.scaleFactor;
 #ifdef ENABLE_RGB_COLOR
 		} else if (_videoMode.format != _oldVideoMode.format) {
-			errors |= kTransactionPixelFormatNotSupported;
+			errors |= kTransactionFormatNotSupported;
 
 			_videoMode.format = _oldVideoMode.format;
 			_screenFormat = _videoMode.format;
@@ -354,21 +354,24 @@
 	return _videoMode.mode;
 }
 
-void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat *format) {
+void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
 	assert(_transactionMode == kTransactionActive);
 
 #ifdef ENABLE_RGB_COLOR
 	//avoid redundant format changes
+	Graphics::PixelFormat newFormat;
 	if (!format)
-		format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0);
+		newFormat = Graphics::PixelFormat::createFormatCLUT8();
+	else
+		newFormat = *format;
 
-	assert(format->bytesPerPixel > 0);
+	assert(newFormat.bytesPerPixel > 0);
 
-	if (*format != _videoMode.format)
+	if (newFormat != _videoMode.format)
 	{
-		_videoMode.format = *format;
+		_videoMode.format = newFormat;
 		_transactionDetails.formatChanged = true;
-		_screenFormat = *format;
+		_screenFormat = newFormat;
 	}
 #endif
 
@@ -1373,11 +1376,11 @@
 	}
 }
 
-void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format) {
+void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
 #ifdef ENABLE_RGB_COLOR
 	if (!format)
-		format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0);
-	if (format->bytesPerPixel <= _screenFormat.bytesPerPixel)
+		_cursorFormat = Graphics::PixelFormat(1,8,8,8,8,0,0,0,0);
+	else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel)
 		_cursorFormat = *format;
 	keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1;
 #else

Modified: scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/backends/platform/sdl/sdl.h	2009-06-30 07:30:57 UTC (rev 41972)
@@ -123,7 +123,7 @@
 
 	// Set the size and format of the video bitmap.
 	// Typically, 320x200 CLUT8
-	virtual void initSize(uint w, uint h, Graphics::PixelFormat *format); // overloaded by CE backend
+	virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend
 
 	virtual int getScreenChangeID() const { return _screenChangeCount; }
 
@@ -152,7 +152,7 @@
 	virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME)
 
 	// Set the bitmap that's used when drawing the cursor.
-	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format); // overloaded by CE backend (FIXME)
+	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // overloaded by CE backend (FIXME)
 
 	// Set colors of cursor palette
 	void setCursorPalette(const byte *colors, uint start, uint num);

Modified: scummvm/branches/gsoc2009-16bit/common/system.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/common/system.h	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/common/system.h	2009-06-30 07:30:57 UTC (rev 41972)
@@ -373,6 +373,16 @@
 	 *       in RGB color order, even if hardware uses BGR or some other color order.
 	 */
 	virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const = 0;
+#else
+	inline Graphics::PixelFormat getScreenFormat() const {
+		return Graphics::PixelFormat::createFormatCLUT8();
+	};
+
+	inline Common::List<Graphics::PixelFormat> getSupportedFormats() const {
+		Common::List<Graphics::PixelFormat> list;
+		list.push_back(Graphics::PixelFormat::createFormatCLUT8());
+		return list;
+	};
 #endif
 
 	/**
@@ -401,7 +411,7 @@
 	 * @param height	the new virtual screen height
 	 * @param format	the new virtual screen pixel format
 	 */
-	virtual void initSize(uint width, uint height, Graphics::PixelFormat *format = NULL) = 0;
+	virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) = 0;
 
 	/**
 	 * Return an int value which is changed whenever any screen
@@ -451,7 +461,7 @@
 		kTransactionFullscreenFailed = (1 << 1),	/**< Failed switchting fullscreen mode */
 		kTransactionModeSwitchFailed = (1 << 2),	/**< Failed switchting the GFX graphics mode (setGraphicsMode) */
 #ifdef ENABLE_RGB_COLOR
-		kTransactionPixelFormatNotSupported = (1 << 4), /**< Failed setting the color format (function not yet implemented) */
+		kTransactionFormatNotSupported = (1 << 4), /**< Failed setting the color format (function not yet implemented) */
 #endif
 		kTransactionSizeChangeFailed = (1 << 3)		/**< Failed switchting the screen dimensions (initSize) */
 	};
@@ -734,7 +744,7 @@
 	 * @param cursorTargetScale	scale factor which cursor is designed for
 	 * @param format			pointer to the pixel format which cursor graphic uses
 	 */
-	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int cursorTargetScale = 1, Graphics::PixelFormat *format = NULL) = 0;
+	virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL) = 0;
 
 	/**
 	 * Replace the specified range of cursor the palette with new colors.

Modified: scummvm/branches/gsoc2009-16bit/engines/engine.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/engine.cpp	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/engines/engine.cpp	2009-06-30 07:30:57 UTC (rev 41972)
@@ -124,7 +124,7 @@
 	if (gameDomain && gameDomain->contains("fullscreen"))
 		g_system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen"));
 }
-void initGraphics(int width, int height, bool defaultTo1xScaler, Graphics::PixelFormat *format) {
+void initGraphics(int width, int height, bool defaultTo1xScaler, const Graphics::PixelFormat *format) {
 
 	g_system->beginGFXTransaction();
 
@@ -155,7 +155,7 @@
 
 	// Just show warnings then these occur:
 #ifdef ENABLE_RGB_COLOR
-	if (gfxError & OSystem::kTransactionPixelFormatNotSupported) {
+	if (gfxError & OSystem::kTransactionFormatNotSupported) {
 		Common::String message = "Could not initialize color format.";
 
 		GUI::MessageDialog dialog(message);

Modified: scummvm/branches/gsoc2009-16bit/engines/engine.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/engines/engine.h	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/engines/engine.h	2009-06-30 07:30:57 UTC (rev 41972)
@@ -60,7 +60,7 @@
  * Errors out when backend is not able to switch to the specified
  * mode.
  */
-void initGraphics(int width, int height, bool defaultTo1xScaler, Graphics::PixelFormat *format = NULL);
+void initGraphics(int width, int height, bool defaultTo1xScaler, const Graphics::PixelFormat *format = NULL);
 
 /**
  * Initializes graphics and shows error message.

Modified: scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/graphics/cursorman.cpp	2009-06-30 07:30:57 UTC (rev 41972)
@@ -57,7 +57,7 @@
 	return g_system->showMouse(visible);
 }
 
-void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, Graphics::PixelFormat *format) {
+void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, const Graphics::PixelFormat *format) {
 	Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, format);
 
 	cur->_visible = isVisible();
@@ -77,7 +77,7 @@
 
 	if (!_cursorStack.empty()) {
 		cur = _cursorStack.top();
-		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale, &(cur->_format));
+		g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale, cur->_format);
 	}
 
 	g_system->showMouse(isVisible());
@@ -100,7 +100,7 @@
 	g_system->showMouse(isVisible());
 }
 
-void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, Graphics::PixelFormat *format) {
+void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int targetScale, const Graphics::PixelFormat *format) {
 
 	if (_cursorStack.empty()) {
 		pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale, format);
@@ -110,10 +110,10 @@
 	Cursor *cur = _cursorStack.top();
 
 #ifdef ENABLE_RGB_COLOR
+	uint size;
 	if (!format)
-		format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0);
-
-	uint size = w * h * format->bytesPerPixel;
+		size = w * h;
+	else size = w * h * format->bytesPerPixel;
 #else
 	uint size = w * h;
 #endif
@@ -134,7 +134,7 @@
 	cur->_keycolor = keycolor;
 	cur->_targetScale = targetScale;
 #ifdef ENABLE_RGB_COLOR
-	cur->_format = *format;
+	cur->_format = format;
 #endif
 
 	g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale, format);

Modified: scummvm/branches/gsoc2009-16bit/graphics/cursorman.h
===================================================================
--- scummvm/branches/gsoc2009-16bit/graphics/cursorman.h	2009-06-30 01:13:21 UTC (rev 41971)
+++ scummvm/branches/gsoc2009-16bit/graphics/cursorman.h	2009-06-30 07:30:57 UTC (rev 41972)
@@ -61,7 +61,7 @@
 	 *       useful to push a "dummy" cursor and modify it later. The
 	 *       cursor will be added to the stack, but not to the backend.
 	 */
-	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, Graphics::PixelFormat *format = NULL);
+	void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL);
 
 	/**
 	 * Pop a cursor from the stack, and restore the previous one to the
@@ -83,7 +83,7 @@
 	 * @param targetScale	the scale for which the cursor is designed
 	 * @param format	the pixel format which the cursor graphic uses
 	 */
-	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, Graphics::PixelFormat *format = NULL);
+	void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL);
 
 	/**
 	 * Pop all of the cursors and cursor palettes from their respective stacks.
@@ -148,22 +148,27 @@
 		int _hotspotX;
 		int _hotspotY;
 		uint32 _keycolor;
-#ifdef ENABLE_RGB_COLOR
-		Graphics::PixelFormat _format;
-#endif
+		const Graphics::PixelFormat *_format;
 		byte _targetScale;
 
 		uint _size;
-		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, Graphics::PixelFormat *format = NULL) {
+		Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 0xFFFFFFFF, int targetScale = 1, const Graphics::PixelFormat *format = NULL) {
 #ifdef ENABLE_RGB_COLOR
 			if (!format)
-				format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0);
-			_size = w * h * format->bytesPerPixel;
-			_keycolor &= ((1 << (format->bytesPerPixel << 3)) - 1);
-			_format = *format;
+			{
+				_size = w * h;
+				_keycolor &= 0xFF;
+			}
+			else
+			{
+				_size = w * h * format->bytesPerPixel;
+				_keycolor &= ((1 << (format->bytesPerPixel << 3)) - 1);
+			}
+			_format = format;
 #else
+			_format = NULL;
 			_size = w * h;
-			_keycolor = keycolor & 0xFF;
+			_keycolor &= 0xFF;
 #endif
 			_data = new byte[_size];
 			if (data && _data)


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