From 9e1916bcad3cc33a870bdbff5bd01b39e523492d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 30 Jun 2009 07:30:57 +0000 Subject: 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. svn-id: r41972 --- backends/platform/sdl/graphics.cpp | 23 +++++++++++++---------- backends/platform/sdl/sdl.h | 4 ++-- common/system.h | 16 +++++++++++++--- engines/engine.cpp | 4 ++-- engines/engine.h | 2 +- graphics/cursorman.cpp | 14 +++++++------- graphics/cursorman.h | 27 ++++++++++++++++----------- 7 files changed, 54 insertions(+), 36 deletions(-) diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a45f31108b..27f32ee8d2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -125,7 +125,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _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 @@ int OSystem_SDL::getGraphicsMode() const { 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::warpMouse(int x, int y) { } } -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 diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index befb82cc89..68dfe64d53 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -123,7 +123,7 @@ public: // 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 @@ public: 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); diff --git a/common/system.h b/common/system.h index 4e8be5024c..4695ece4a4 100644 --- a/common/system.h +++ b/common/system.h @@ -373,6 +373,16 @@ public: * in RGB color order, even if hardware uses BGR or some other color order. */ virtual Common::List getSupportedFormats() const = 0; +#else + inline Graphics::PixelFormat getScreenFormat() const { + return Graphics::PixelFormat::createFormatCLUT8(); + }; + + inline Common::List getSupportedFormats() const { + Common::List list; + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + return list; + }; #endif /** @@ -401,7 +411,7 @@ public: * @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 @@ public: 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 @@ public: * @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. diff --git a/engines/engine.cpp b/engines/engine.cpp index 198bfceaed..8769219c2b 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -124,7 +124,7 @@ void initCommonGFX(bool defaultTo1XScaler) { 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 @@ void initGraphics(int width, int height, bool defaultTo1xScaler, Graphics::Pixel // 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); diff --git a/engines/engine.h b/engines/engine.h index 67454629e7..d59e8ed9bd 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -60,7 +60,7 @@ void initCommonGFX(bool defaultTo1XScaler); * 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. diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index bf6de44fbf..b35bbe73ae 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -57,7 +57,7 @@ bool CursorManager::showMouse(bool visible) { 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 @@ void CursorManager::popCursor() { 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 @@ void CursorManager::popAllCursors() { 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 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, 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 @@ void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, 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); diff --git a/graphics/cursorman.h b/graphics/cursorman.h index 2b2f34f952..044a787e71 100644 --- a/graphics/cursorman.h +++ b/graphics/cursorman.h @@ -61,7 +61,7 @@ public: * 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 @@ public: * @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 @@ private: 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) -- cgit v1.2.3