diff options
-rw-r--r-- | backends/graphics/default/default-graphics.cpp | 40 | ||||
-rw-r--r-- | backends/graphics/default/default-graphics.h | 78 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp (renamed from backends/platform/sdl/graphics.cpp) | 280 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 310 | ||||
-rw-r--r-- | backends/module.mk | 4 | ||||
-rw-r--r-- | backends/mutex/default/default-mutex.cpp | 38 | ||||
-rw-r--r-- | backends/mutex/default/default-mutex.h | 48 | ||||
-rw-r--r-- | backends/mutex/sdl/sdl-mutex.cpp | 48 | ||||
-rw-r--r-- | backends/mutex/sdl/sdl-mutex.h | 40 | ||||
-rw-r--r-- | backends/platform/sdl/events.cpp | 33 | ||||
-rw-r--r-- | backends/platform/sdl/module.mk | 1 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 331 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 230 | ||||
-rw-r--r-- | sound/mixer.h | 3 |
14 files changed, 1045 insertions, 439 deletions
diff --git a/backends/graphics/default/default-graphics.cpp b/backends/graphics/default/default-graphics.cpp new file mode 100644 index 0000000000..9683eff9ac --- /dev/null +++ b/backends/graphics/default/default-graphics.cpp @@ -0,0 +1,40 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "backends/graphics/default/default-graphics.h" + +bool DefaultGraphicsManager::hasGraphicsFeature(OSystem::Feature f) { + return false; +} + +bool DefaultGraphicsManager::getGraphicsFeatureState(OSystem::Feature f) { + return false; +} + +static const OSystem::GraphicsMode s_noGraphicsModes[] = { {0, 0, 0} }; + +const OSystem::GraphicsMode *DefaultGraphicsManager::getSupportedGraphicsModes() { + return s_noGraphicsModes; +} diff --git a/backends/graphics/default/default-graphics.h b/backends/graphics/default/default-graphics.h new file mode 100644 index 0000000000..9e1593f0eb --- /dev/null +++ b/backends/graphics/default/default-graphics.h @@ -0,0 +1,78 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_GRAPHICS_DEFAULT_H +#define BACKENDS_GRAPHICS_DEFAULT_H + +#include "common/system.h" +#include "common/noncopyable.h" + +class DefaultGraphicsManager : Common::NonCopyable { +public: + DefaultGraphicsManager() {} + ~DefaultGraphicsManager() {} + + bool hasGraphicsFeature(OSystem::Feature f); + void setGraphicsFeatureState(OSystem::Feature f, bool enable) {} + bool getGraphicsFeatureState(OSystem::Feature f); + + const OSystem::GraphicsMode *getSupportedGraphicsModes(); + int getDefaultGraphicsMode() { return 0; } + bool setGraphicsMode(int mode) { return true; } + int getGraphicsMode() { return 0; } + 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; + }; + void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) {} + int16 getHeight() { return 0; } + int16 getWidth() { return 0; } + void setPalette(const byte *colors, uint start, uint num) {} + void grabPalette(byte *colors, uint start, uint num) {} + void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {} + Graphics::Surface *lockScreen() { return NULL; } + void unlockScreen() {} + void fillScreen(uint32 col) {} + void updateScreen() {} + void setShakePos(int shakeOffset) {} + void showOverlay() {} + void hideOverlay() {} + Graphics::PixelFormat getOverlayFormat() { return Graphics::PixelFormat(); } + void clearOverlay() {} + void grabOverlay(OverlayColor *buf, int pitch) {} + void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {} + int16 getOverlayHeight() { return 0; } + int16 getOverlayWidth() { return 0; } + bool showMouse(bool visible) {} + void warpMouse(int x, int y) {} + void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL) {} +}; + + +#endif diff --git a/backends/platform/sdl/graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 82670cfcb7..5276cbbf30 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -23,7 +23,8 @@ * */ -#include "backends/platform/sdl/sdl.h" +#include "backends/graphics/sdl/sdl-graphics.h" +#include "common/config-manager.h" #include "common/mutex.h" #include "common/util.h" #ifdef USE_RGB_COLOR @@ -34,6 +35,7 @@ #include "graphics/scaler.h" #include "graphics/scaler/aspect.h" #include "graphics/surface.h" +#include "backends/events/default/default-events.h" static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {"1x", "Normal (no scaling)", GFX_NORMAL}, @@ -84,15 +86,158 @@ static const int s_gfxModeSwitchTable[][4] = { static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY); #endif -const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const { +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; +} + +#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS) +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); +} +#endif + +SdlGraphicsManager::SdlGraphicsManager() + : +#ifdef USE_OSD + _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), +#endif + _hwscreen(0), _screen(0), _tmpscreen(0), +#ifdef USE_RGB_COLOR + _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), + _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), +#endif + _overlayVisible(false), + _overlayscreen(0), _tmpscreen2(0), + _scalerProc(0), _modeChanged(false), _screenChangeCount(0), + _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0), + _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true), + _currentShakePos(0), _newShakePos(0), + _paletteDirtyStart(0), _paletteDirtyEnd(0), + _screenIsLocked(false), + _graphicsMutex(0), _transactionMode(kTransactionNone) { + + if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { + error("Could not initialize SDL: %s", SDL_GetError()); + } + + // allocate palette storage + _currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); + _cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); + + _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; + + memset(&_mouseCurState, 0, sizeof(_mouseCurState)); + + _graphicsMutex = g_system->createMutex(); + +#ifdef _WIN32_WCE + if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) { + SDL_VideoInit("windib", 0); + sdlFlags ^= SDL_INIT_VIDEO; + } +#endif + + SDL_ShowCursor(SDL_DISABLE); + + memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); + memset(&_videoMode, 0, sizeof(_videoMode)); + memset(&_transactionDetails, 0, sizeof(_transactionDetails)); + +#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS) + _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; + _videoMode.scaleFactor = 1; + _videoMode.aspectRatioCorrection = false; + _scalerProc = Normal1x; +#endif + _scalerType = 0; + +#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) + _videoMode.fullscreen = ConfMan.getBool("fullscreen"); +#else + _videoMode.fullscreen = true; +#endif +} + +SdlGraphicsManager::~SdlGraphicsManager() { + unloadGFXMode(); + g_system->deleteMutex(_graphicsMutex); + + free(_currentPalette); + free(_cursorPalette); + free(_mouseData); +} + +bool SdlGraphicsManager::hasFeature(OSystem::Feature f) { + return + (f == OSystem::kFeatureFullscreenMode) || + (f == OSystem::kFeatureAspectRatioCorrection) || + (f == OSystem::kFeatureCursorHasPalette) || + (f == OSystem::kFeatureIconifyWindow); +} + +void SdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) { + switch (f) { + case OSystem::kFeatureFullscreenMode: + setFullscreenMode(enable); + break; + case OSystem::kFeatureAspectRatioCorrection: + setAspectRatioCorrection(enable); + break; + case OSystem::kFeatureIconifyWindow: + if (enable) + SDL_WM_IconifyWindow(); + break; + default: + break; + } +} + +bool SdlGraphicsManager::getFeatureState(OSystem::Feature f) { + assert (_transactionMode == kTransactionNone); + + switch (f) { + case OSystem::kFeatureFullscreenMode: + return _videoMode.fullscreen; + case OSystem::kFeatureAspectRatioCorrection: + return _videoMode.aspectRatioCorrection; + default: + return false; + } +} + +const OSystem::GraphicsMode *SdlGraphicsManager::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } -int OSystem_SDL::getDefaultGraphicsMode() const { +int SdlGraphicsManager::getDefaultGraphicsMode() const { return GFX_DOUBLESIZE; } -void OSystem_SDL::beginGFXTransaction() { +void SdlGraphicsManager::beginGFXTransaction() { assert(_transactionMode == kTransactionNone); _transactionMode = kTransactionActive; @@ -110,34 +255,34 @@ void OSystem_SDL::beginGFXTransaction() { _oldVideoMode = _videoMode; } -OSystem::TransactionError OSystem_SDL::endGFXTransaction() { - int errors = kTransactionSuccess; +OSystem::TransactionError SdlGraphicsManager::endGFXTransaction() { + int errors = OSystem::kTransactionSuccess; assert(_transactionMode != kTransactionNone); if (_transactionMode == kTransactionRollback) { if (_videoMode.fullscreen != _oldVideoMode.fullscreen) { - errors |= kTransactionFullscreenFailed; + errors |= OSystem::kTransactionFullscreenFailed; _videoMode.fullscreen = _oldVideoMode.fullscreen; } else if (_videoMode.aspectRatioCorrection != _oldVideoMode.aspectRatioCorrection) { - errors |= kTransactionAspectRatioFailed; + errors |= OSystem::kTransactionAspectRatioFailed; _videoMode.aspectRatioCorrection = _oldVideoMode.aspectRatioCorrection; } else if (_videoMode.mode != _oldVideoMode.mode) { - errors |= kTransactionModeSwitchFailed; + errors |= OSystem::kTransactionModeSwitchFailed; _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; #ifdef USE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { - errors |= kTransactionFormatNotSupported; + errors |= OSystem::kTransactionFormatNotSupported; _videoMode.format = _oldVideoMode.format; _screenFormat = _videoMode.format; #endif } else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) { - errors |= kTransactionSizeChangeFailed; + errors |= OSystem::kTransactionSizeChangeFailed; _videoMode.screenWidth = _oldVideoMode.screenWidth; _videoMode.screenHeight = _oldVideoMode.screenHeight; @@ -209,7 +354,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction() { } _transactionMode = kTransactionNone; - return (TransactionError)errors; + return (OSystem::TransactionError)errors; } #ifdef USE_RGB_COLOR @@ -243,7 +388,7 @@ const Graphics::PixelFormat BGRList[] = { }; // TODO: prioritize matching alpha masks -Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() { +Common::List<Graphics::PixelFormat> SdlGraphicsManager::getSupportedFormats() { static Common::List<Graphics::PixelFormat> list; static bool inited = false; @@ -294,7 +439,7 @@ Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() { } #endif -bool OSystem_SDL::setGraphicsMode(int mode) { +bool SdlGraphicsManager::setGraphicsMode(int mode) { Common::StackLock lock(_graphicsMutex); assert(_transactionMode == kTransactionActive); @@ -364,7 +509,7 @@ bool OSystem_SDL::setGraphicsMode(int mode) { return true; } -void OSystem_SDL::setGraphicsModeIntern() { +void SdlGraphicsManager::setGraphicsModeIntern() { Common::StackLock lock(_graphicsMutex); ScalerProc *newScalerProc = 0; @@ -437,12 +582,12 @@ void OSystem_SDL::setGraphicsModeIntern() { blitCursor(); } -int OSystem_SDL::getGraphicsMode() const { +int SdlGraphicsManager::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void SdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); #ifdef USE_RGB_COLOR @@ -472,7 +617,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) _transactionDetails.sizeChanged = true; } -int OSystem_SDL::effectiveScreenHeight() const { +int SdlGraphicsManager::effectiveScreenHeight() const { return _videoMode.scaleFactor * (_videoMode.aspectRatioCorrection ? real2Aspect(_videoMode.screenHeight) @@ -522,8 +667,7 @@ static void fixupResolutionForAspectRatio(AspectRatio desiredAspectRatio, int &w height = bestMode->h; } -bool OSystem_SDL::loadGFXMode() { - assert(_inited); +bool SdlGraphicsManager::loadGFXMode() { _forceFull = true; #if !defined(__MAEMO__) && !defined(GP2XWIZ) && !defined(LINUXMOTO) @@ -579,7 +723,7 @@ bool OSystem_SDL::loadGFXMode() { if (!_oldVideoMode.setup) { warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); - quit(); + g_system->quit(); } else { return false; } @@ -646,11 +790,11 @@ bool OSystem_SDL::loadGFXMode() { SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey); #endif - // keyboard cursor control, some other better place for it? - _km.x_max = _videoMode.screenWidth * _videoMode.scaleFactor - 1; + // keyboard cursor control, some other better place for it? - FIXME + /*_km.x_max = _videoMode.screenWidth * _videoMode.scaleFactor - 1; _km.y_max = effectiveScreenHeight() - 1; _km.delay_time = 25; - _km.last_time = 0; + _km.last_time = 0;*/ // Distinguish 555 and 565 mode if (_hwscreen->format->Rmask == 0x7C00) @@ -661,7 +805,7 @@ bool OSystem_SDL::loadGFXMode() { return true; } -void OSystem_SDL::unloadGFXMode() { +void SdlGraphicsManager::unloadGFXMode() { if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; @@ -696,7 +840,7 @@ void OSystem_SDL::unloadGFXMode() { DestroyScalers(); } -bool OSystem_SDL::hotswapGFXMode() { +bool SdlGraphicsManager::hotswapGFXMode() { if (!_screen) return false; @@ -748,7 +892,7 @@ bool OSystem_SDL::hotswapGFXMode() { return true; } -void OSystem_SDL::updateScreen() { +void SdlGraphicsManager::updateScreen() { assert (_transactionMode == kTransactionNone); Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends @@ -756,7 +900,7 @@ void OSystem_SDL::updateScreen() { internUpdateScreen(); } -void OSystem_SDL::internUpdateScreen() { +void SdlGraphicsManager::internUpdateScreen() { SDL_Surface *srcSurf, *origSurf; int height, width; ScalerProc *scalerProc; @@ -924,14 +1068,14 @@ void OSystem_SDL::internUpdateScreen() { _mouseNeedsRedraw = false; } -bool OSystem_SDL::saveScreenshot(const char *filename) { +bool SdlGraphicsManager::saveScreenshot(const char *filename) { assert(_hwscreen != NULL); Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends return SDL_SaveBMP(_hwscreen, filename) == 0; } -void OSystem_SDL::setFullscreenMode(bool enable) { +void SdlGraphicsManager::setFullscreenMode(bool enable) { Common::StackLock lock(_graphicsMutex); if (_oldVideoMode.setup && _oldVideoMode.fullscreen == enable) @@ -943,7 +1087,7 @@ void OSystem_SDL::setFullscreenMode(bool enable) { } } -void OSystem_SDL::setAspectRatioCorrection(bool enable) { +void SdlGraphicsManager::setAspectRatioCorrection(bool enable) { Common::StackLock lock(_graphicsMutex); if (_oldVideoMode.setup && _oldVideoMode.aspectRatioCorrection == enable) @@ -955,12 +1099,12 @@ void OSystem_SDL::setAspectRatioCorrection(bool enable) { } } -void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) { +void SdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) { assert (_transactionMode == kTransactionNone); assert(src); if (_screen == NULL) { - warning("OSystem_SDL::copyRectToScreen: _screen == NULL"); + warning("SdlGraphicsManager::copyRectToScreen: _screen == NULL"); return; } @@ -1005,11 +1149,11 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int SDL_UnlockSurface(_screen); } -Graphics::Surface *OSystem_SDL::lockScreen() { +Graphics::Surface *SdlGraphicsManager::lockScreen() { assert (_transactionMode == kTransactionNone); // Lock the graphics mutex - lockMutex(_graphicsMutex); + g_system->lockMutex(_graphicsMutex); // paranoia check assert(!_screenIsLocked); @@ -1032,7 +1176,7 @@ Graphics::Surface *OSystem_SDL::lockScreen() { return &_framebuffer; } -void OSystem_SDL::unlockScreen() { +void SdlGraphicsManager::unlockScreen() { assert (_transactionMode == kTransactionNone); // paranoia check @@ -1046,10 +1190,10 @@ void OSystem_SDL::unlockScreen() { _forceFull = true; // Finally unlock the graphics mutex - unlockMutex(_graphicsMutex); + g_system->unlockMutex(_graphicsMutex); } -void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) { +void SdlGraphicsManager::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) { if (_forceFull) return; @@ -1117,15 +1261,15 @@ void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) } } -int16 OSystem_SDL::getHeight() { +int16 SdlGraphicsManager::getHeight() { return _videoMode.screenHeight; } -int16 OSystem_SDL::getWidth() { +int16 SdlGraphicsManager::getWidth() { return _videoMode.screenWidth; } -void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { +void SdlGraphicsManager::setPalette(const byte *colors, uint start, uint num) { assert(colors); #ifdef USE_RGB_COLOR @@ -1137,7 +1281,7 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // But it could indicate a programming error, so let's warn about it. if (!_screen) - warning("OSystem_SDL::setPalette: _screen == NULL"); + warning("SdlGraphicsManager::setPalette: _screen == NULL"); const byte *b = colors; uint i; @@ -1160,7 +1304,7 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { blitCursor(); } -void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { +void SdlGraphicsManager::grabPalette(byte *colors, uint start, uint num) { assert(colors); #ifdef USE_RGB_COLOR @@ -1177,7 +1321,7 @@ void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { } } -void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { +void SdlGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) { assert(colors); const byte *b = colors; uint i; @@ -1194,7 +1338,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } -void OSystem_SDL::setShakePos(int shake_pos) { +void SdlGraphicsManager::setShakePos(int shake_pos) { assert (_transactionMode == kTransactionNone); _newShakePos = shake_pos; @@ -1205,7 +1349,7 @@ void OSystem_SDL::setShakePos(int shake_pos) { #pragma mark --- Overlays --- #pragma mark - -void OSystem_SDL::showOverlay() { +void SdlGraphicsManager::showOverlay() { assert (_transactionMode == kTransactionNone); int x, y; @@ -1228,7 +1372,7 @@ void OSystem_SDL::showOverlay() { clearOverlay(); } -void OSystem_SDL::hideOverlay() { +void SdlGraphicsManager::hideOverlay() { assert (_transactionMode == kTransactionNone); if (!_overlayVisible) @@ -1252,7 +1396,7 @@ void OSystem_SDL::hideOverlay() { _forceFull = true; } -void OSystem_SDL::clearOverlay() { +void SdlGraphicsManager::clearOverlay() { //assert (_transactionMode == kTransactionNone); Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends @@ -1285,7 +1429,7 @@ void OSystem_SDL::clearOverlay() { _forceFull = true; } -void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) { +void SdlGraphicsManager::grabOverlay(OverlayColor *buf, int pitch) { assert (_transactionMode == kTransactionNone); if (_overlayscreen == NULL) @@ -1305,7 +1449,7 @@ void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) { SDL_UnlockSurface(_overlayscreen); } -void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { +void SdlGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { assert (_transactionMode == kTransactionNone); if (_overlayscreen == NULL) @@ -1355,7 +1499,7 @@ void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, i #pragma mark --- Mouse --- #pragma mark - -bool OSystem_SDL::showMouse(bool visible) { +bool SdlGraphicsManager::showMouse(bool visible) { if (_mouseVisible == visible) return visible; @@ -1366,7 +1510,7 @@ bool OSystem_SDL::showMouse(bool visible) { return last; } -void OSystem_SDL::setMousePos(int x, int y) { +void SdlGraphicsManager::setMousePos(int x, int y) { if (x != _mouseCurState.x || y != _mouseCurState.y) { _mouseNeedsRedraw = true; _mouseCurState.x = x; @@ -1374,7 +1518,7 @@ void OSystem_SDL::setMousePos(int x, int y) { } } -void OSystem_SDL::warpMouse(int x, int y) { +void SdlGraphicsManager::warpMouse(int x, int y) { int y1 = y; if (_videoMode.aspectRatioCorrection && !_overlayVisible) @@ -1397,7 +1541,7 @@ 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, const Graphics::PixelFormat *format) { +void SdlGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef USE_RGB_COLOR if (!format) _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); @@ -1454,7 +1598,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, blitCursor(); } -void OSystem_SDL::blitCursor() { +void SdlGraphicsManager::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; #ifdef USE_RGB_COLOR @@ -1645,14 +1789,7 @@ static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height } #endif -void OSystem_SDL::toggleMouseGrab() { - if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) - SDL_WM_GrabInput(SDL_GRAB_ON); - else - SDL_WM_GrabInput(SDL_GRAB_OFF); -} - -void OSystem_SDL::undrawMouse() { +void SdlGraphicsManager::undrawMouse() { const int x = _mouseBackup.x; const int y = _mouseBackup.y; @@ -1665,7 +1802,7 @@ void OSystem_SDL::undrawMouse() { addDirtyRect(x, y, _mouseBackup.w, _mouseBackup.h); } -void OSystem_SDL::drawMouse() { +void SdlGraphicsManager::drawMouse() { if (!_mouseVisible || !_mouseSurface) { _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; return; @@ -1673,6 +1810,7 @@ void OSystem_SDL::drawMouse() { SDL_Rect dst; int scale; + int width, height; int hotX, hotY; dst.x = _mouseCurState.x; @@ -1680,12 +1818,16 @@ void OSystem_SDL::drawMouse() { if (!_overlayVisible) { scale = _videoMode.scaleFactor; + width = _videoMode.screenWidth; + height = _videoMode.screenHeight; dst.w = _mouseCurState.vW; dst.h = _mouseCurState.vH; hotX = _mouseCurState.vHotX; hotY = _mouseCurState.vHotY; } else { scale = 1; + width = _videoMode.overlayWidth; + height = _videoMode.overlayHeight; dst.w = _mouseCurState.rW; dst.h = _mouseCurState.rH; hotX = _mouseCurState.rHotX; @@ -1732,7 +1874,7 @@ void OSystem_SDL::drawMouse() { #pragma mark - #ifdef USE_OSD -void OSystem_SDL::displayMessageOnOSD(const char *msg) { +void SdlGraphicsManager::displayMessageOnOSD(const char *msg) { assert (_transactionMode == kTransactionNone); assert(msg); @@ -1820,11 +1962,11 @@ void OSystem_SDL::displayMessageOnOSD(const char *msg) { #pragma mark --- Misc --- #pragma mark - -bool OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) { +bool SdlGraphicsManager::handleScalerHotkeys(const SDL_KeyboardEvent &key) { // Ctrl-Alt-a toggles aspect ratio correction if (key.keysym.sym == 'a') { beginGFXTransaction(); - setFeatureState(kFeatureAspectRatioCorrection, !_videoMode.aspectRatioCorrection); + setGraphicsFeatureState(OSystem::kFeatureAspectRatioCorrection, !_videoMode.aspectRatioCorrection); endGFXTransaction(); #ifdef USE_OSD char buffer[128]; @@ -1877,7 +2019,7 @@ bool OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) { #ifdef USE_OSD if (_osdSurface) { const char *newScalerName = 0; - const GraphicsMode *g = getSupportedGraphicsModes(); + const OSystem::GraphicsMode *g = getSupportedGraphicsModes(); while (g->name) { if (g->id == _videoMode.mode) { newScalerName = g->description; @@ -1904,7 +2046,7 @@ bool OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) { } } -bool OSystem_SDL::isScalerHotkey(const Common::Event &event) { +bool SdlGraphicsManager::isScalerHotkey(const Common::Event &event) { if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { const bool isNormalNumber = (Common::KEYCODE_1 <= event.kbd.keycode && event.kbd.keycode <= Common::KEYCODE_9); const bool isKeypadNumber = (Common::KEYCODE_KP1 <= event.kbd.keycode && event.kbd.keycode <= Common::KEYCODE_KP9); diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h new file mode 100644 index 0000000000..13ce5af5dc --- /dev/null +++ b/backends/graphics/sdl/sdl-graphics.h @@ -0,0 +1,310 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_GRAPHICS_SDL_H +#define BACKENDS_GRAPHICS_SDL_H + +#include "backends/graphics/default/default-graphics.h" +#include "common/system.h" +#include "graphics/scaler.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) +// Uncomment this to enable the 'on screen display' code. +#define USE_OSD 1 +#endif + +enum { + GFX_NORMAL = 0, + GFX_DOUBLESIZE = 1, + GFX_TRIPLESIZE = 2, + GFX_2XSAI = 3, + GFX_SUPER2XSAI = 4, + GFX_SUPEREAGLE = 5, + GFX_ADVMAME2X = 6, + GFX_ADVMAME3X = 7, + GFX_HQ2X = 8, + GFX_HQ3X = 9, + GFX_TV2X = 10, + 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 SdlGraphicsManager : public DefaultGraphicsManager { +public: + SdlGraphicsManager(); + ~SdlGraphicsManager(); + + bool hasFeature(OSystem::Feature f); + void setFeatureState(OSystem::Feature f, bool enable); + bool getFeatureState(OSystem::Feature f); + + const OSystem::GraphicsMode *getSupportedGraphicsModes() const; + int getDefaultGraphicsMode() const; + bool setGraphicsMode(int mode); + int getGraphicsMode() const; + +#ifdef USE_RGB_COLOR + // Game screen + virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } + + // Highest supported + virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); +#endif + void beginGFXTransaction(); + OSystem::TransactionError endGFXTransaction(); + virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL); + virtual int16 getHeight(); + virtual int16 getWidth(); + void setPalette(const byte *colors, uint start, uint num); + void grabPalette(byte *colors, uint start, uint num); + virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h); + virtual Graphics::Surface *lockScreen(); + virtual void unlockScreen(); + void fillScreen(uint32 col); + void updateScreen(); + void setShakePos(int shakeOffset); + virtual void showOverlay(); + virtual void hideOverlay(); + virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } + void clearOverlay(); + void grabOverlay(OverlayColor *buf, int pitch); + void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); + virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; } + virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; } + bool showMouse(bool visible); + virtual void warpMouse(int x, int y); + virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL); + void setCursorPalette(const byte *colors, uint start, uint num); + void disableCursorPalette(bool disable) { + _cursorPaletteDisabled = disable; + blitCursor(); + } + virtual int getScreenChangeID() const { return _screenChangeCount; } + +#ifdef USE_OSD + void displayMessageOnOSD(const char *msg); +#endif + + // Accessed from OSystem_SDL::pollEvent for EVENT_SCREEN_CHANGED + // The way this event works should be changed + bool _modeChanged; + + // Accessed from OSystem_SDL::dispatchSDLEvent + // A function here for toggling it should be made for this + bool _forceFull; + + bool handleScalerHotkeys(const SDL_KeyboardEvent &key); // Move this? + bool isScalerHotkey(const Common::Event &event); // Move this? + + void setMousePos(int x, int y); + +protected: +#ifdef USE_OSD + SDL_Surface *_osdSurface; + Uint8 _osdAlpha; // Transparency level of the OSD + uint32 _osdFadeStartTime; // When to start the fade out + enum { + kOSDFadeOutDelay = 2 * 1000, // Delay before the OSD is faded out (in milliseconds) + kOSDFadeOutDuration = 500, // Duration of the OSD fade out (in milliseconds) + kOSDColorKey = 1, + kOSDInitialAlpha = 80 // Initial alpha level, in percent + }; +#endif + + // hardware screen + SDL_Surface *_hwscreen; + + // unseen game screen + SDL_Surface *_screen; +#ifdef USE_RGB_COLOR + Graphics::PixelFormat _screenFormat; + Graphics::PixelFormat _cursorFormat; +#endif + + // temporary screen (for scalers) + SDL_Surface *_tmpscreen; + SDL_Surface *_tmpscreen2; + + // overlay + SDL_Surface *_overlayscreen; + bool _overlayVisible; + Graphics::PixelFormat _overlayFormat; + + enum { + kTransactionNone = 0, + kTransactionActive = 1, + kTransactionRollback = 2 + }; + + struct TransactionDetails { + bool sizeChanged; + bool needHotswap; + bool needUpdatescreen; + bool normal1xScaler; +#ifdef USE_RGB_COLOR + bool formatChanged; +#endif + }; + TransactionDetails _transactionDetails; + + struct VideoState { + bool setup; + + bool fullscreen; + bool aspectRatioCorrection; + AspectRatio desiredAspectRatio; + + int mode; + int scaleFactor; + + int screenWidth, screenHeight; + int overlayWidth, overlayHeight; + int hardwareWidth, hardwareHeight; +#ifdef USE_RGB_COLOR + Graphics::PixelFormat format; +#endif + }; + VideoState _videoMode, _oldVideoMode; + + virtual void setGraphicsModeIntern(); // overloaded by CE backend + + /** Force full redraw on next updateScreen */ + ScalerProc *_scalerProc; + int _scalerType; + int _transactionMode; + + bool _screenIsLocked; + Graphics::Surface _framebuffer; + + int _screenChangeCount; + + enum { + NUM_DIRTY_RECT = 100, + MAX_SCALING = 3 + }; + + // Dirty rect management + SDL_Rect _dirtyRectList[NUM_DIRTY_RECT]; + int _numDirtyRects; + + struct MousePos { + // The mouse position, using either virtual (game) or real + // (overlay) coordinates. + int16 x, y; + + // The size and hotspot of the original cursor image. + int16 w, h; + int16 hotX, hotY; + + // The size and hotspot of the pre-scaled cursor image, in real + // coordinates. + int16 rW, rH; + int16 rHotX, rHotY; + + // The size and hotspot of the pre-scaled cursor image, in game + // coordinates. + int16 vW, vH; + int16 vHotX, vHotY; + + MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0), + rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0), + vHotX(0), vHotY(0) + { } + }; + + bool _mouseVisible; + bool _mouseNeedsRedraw; + byte *_mouseData; + SDL_Rect _mouseBackup; + MousePos _mouseCurState; // Move to events? +#ifdef USE_RGB_COLOR + uint32 _mouseKeyColor; +#else + byte _mouseKeyColor; +#endif + int _cursorTargetScale; + bool _cursorPaletteDisabled; + SDL_Surface *_mouseOrigSurface; + SDL_Surface *_mouseSurface; + enum { + kMouseColorKey = 1 + }; + + // Shake mode + int _currentShakePos; + int _newShakePos; + + // Palette data + SDL_Color *_currentPalette; + uint _paletteDirtyStart, _paletteDirtyEnd; + + // Cursor palette data + SDL_Color *_cursorPalette; + + /** + * Mutex which prevents multiple threads from interfering with each other + * when accessing the screen. + */ + OSystem::MutexRef _graphicsMutex; + + virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); // overloaded by CE backend + + virtual void drawMouse(); // overloaded by CE backend + virtual void undrawMouse(); // overloaded by CE backend (FIXME) + virtual void blitCursor(); // overloaded by CE backend (FIXME) + + virtual void internUpdateScreen(); // overloaded by CE backend + + virtual bool loadGFXMode(); // overloaded by CE backend + virtual void unloadGFXMode(); // overloaded by CE backend + virtual bool hotswapGFXMode(); // overloaded by CE backend + + void setFullscreenMode(bool enable); + void setAspectRatioCorrection(bool enable); + + virtual bool saveScreenshot(const char *filename); // overloaded by CE backend + + int effectiveScreenHeight() const; +}; + + +#endif diff --git a/backends/module.mk b/backends/module.mk index 59df56b468..a76dca2702 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -17,6 +17,8 @@ MODULE_OBJS := \ fs/wii/wii-fs-factory.o \ fs/n64/n64-fs-factory.o \ fs/n64/romfsstream.o \ + graphics/default/default-graphics.o \ + graphics/sdl/sdl-graphics.o \ keymapper/action.o \ keymapper/keymap.o \ keymapper/keymapper.o \ @@ -30,6 +32,8 @@ MODULE_OBJS := \ midi/timidity.o \ midi/dmedia.o \ midi/windows.o \ + mutex/default/default-mutex.o \ + mutex/sdl/sdl-mutex.o \ plugins/dc/dc-provider.o \ plugins/posix/posix-provider.o \ plugins/sdl/sdl-provider.o \ diff --git a/backends/mutex/default/default-mutex.cpp b/backends/mutex/default/default-mutex.cpp new file mode 100644 index 0000000000..936ede197a --- /dev/null +++ b/backends/mutex/default/default-mutex.cpp @@ -0,0 +1,38 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "backends/mutex/default/default-mutex.h" + +OSystem::MutexRef DefaultMutexManager::createMutex() { + return OSystem::MutexRef(); +} + +bool DefaultMutexManager::hasMutexFeature(OSystem::Feature f) { + return false; +} + +bool DefaultMutexManager::getMutexFeatureState(OSystem::Feature f) { + return false; +} diff --git a/backends/mutex/default/default-mutex.h b/backends/mutex/default/default-mutex.h new file mode 100644 index 0000000000..bd667eba5b --- /dev/null +++ b/backends/mutex/default/default-mutex.h @@ -0,0 +1,48 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_MUTEX_DEFAULT_H +#define BACKENDS_MUTEX_DEFAULT_H + +#include "common/system.h" +#include "common/noncopyable.h" + +class DefaultMutexManager : Common::NonCopyable { +public: + DefaultMutexManager() {} + ~DefaultMutexManager() {} + + bool hasMutexFeature(OSystem::Feature f); + void setMutexFeatureState(OSystem::Feature f, bool enable) {} + bool getMutexFeatureState(OSystem::Feature f); + + OSystem::MutexRef createMutex(); + void lockMutex(OSystem::MutexRef mutex) {} + void unlockMutex(OSystem::MutexRef mutex) {} + void deleteMutex(OSystem::MutexRef mutex); +}; + + +#endif diff --git a/backends/mutex/sdl/sdl-mutex.cpp b/backends/mutex/sdl/sdl-mutex.cpp new file mode 100644 index 0000000000..e30d194ca1 --- /dev/null +++ b/backends/mutex/sdl/sdl-mutex.cpp @@ -0,0 +1,48 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "backends/mutex/sdl/sdl-mutex.h" + +#if defined(__SYMBIAN32__) +#include <esdl\SDL.h> +#else +#include <SDL.h> +#endif + +OSystem::MutexRef SdlMutexManager::createMutex() { + return (OSystem::MutexRef) SDL_CreateMutex(); +} + +void SdlMutexManager::lockMutex(OSystem::MutexRef mutex) { + SDL_mutexP((SDL_mutex *) mutex); +} + +void SdlMutexManager::unlockMutex(OSystem::MutexRef mutex) { + SDL_mutexV((SDL_mutex *) mutex); +} + +void SdlMutexManager::deleteMutex(OSystem::MutexRef mutex) { + SDL_DestroyMutex((SDL_mutex *) mutex); +} diff --git a/backends/mutex/sdl/sdl-mutex.h b/backends/mutex/sdl/sdl-mutex.h new file mode 100644 index 0000000000..aad3032315 --- /dev/null +++ b/backends/mutex/sdl/sdl-mutex.h @@ -0,0 +1,40 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_MUTEX_SDL_H +#define BACKENDS_MUTEX_SDL_H + +#include "backends/mutex/default/default-mutex.h" + +class SdlMutexManager : public DefaultMutexManager { +public: + OSystem::MutexRef createMutex(); + void lockMutex(OSystem::MutexRef mutex); + void unlockMutex(OSystem::MutexRef mutex); + void deleteMutex(OSystem::MutexRef mutex); +}; + + +#endif diff --git a/backends/platform/sdl/events.cpp b/backends/platform/sdl/events.cpp index 1965cb3031..9f80557c0c 100644 --- a/backends/platform/sdl/events.cpp +++ b/backends/platform/sdl/events.cpp @@ -76,12 +76,12 @@ void OSystem_SDL::fillMouseEvent(Common::Event &event, int x, int y) { _km.y = y; // Adjust for the screen scaling - if (!_overlayVisible) { + /*if (!_overlayVisible) { // FIXME event.mouse.x /= _videoMode.scaleFactor; event.mouse.y /= _videoMode.scaleFactor; if (_videoMode.aspectRatioCorrection) event.mouse.y = aspect2Real(event.mouse.y); - } + }*/ } void OSystem_SDL::handleKbdMouse() { @@ -184,8 +184,8 @@ bool OSystem_SDL::pollEvent(Common::Event &event) { handleKbdMouse(); // If the screen mode changed, send an Common::EVENT_SCREEN_CHANGED - if (_modeChanged) { - _modeChanged = false; + if (_graphicsManager->_modeChanged) { + _graphicsManager->_modeChanged = false; event.type = Common::EVENT_SCREEN_CHANGED; return true; } @@ -218,7 +218,7 @@ bool OSystem_SDL::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) { return handleJoyAxisMotion(ev, event); case SDL_VIDEOEXPOSE: - _forceFull = true; + _graphicsManager->_forceFull = true; break; case SDL_QUIT: @@ -243,7 +243,8 @@ bool OSystem_SDL::handleKeyDown(SDL_Event &ev, Common::Event &event) { event.kbd.flags |= Common::KBD_SCRL; // Alt-Return and Alt-Enter toggle full screen mode - if (event.kbd.hasFlags(Common::KBD_ALT) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) { + // TODO: make a function in graphics manager for this + /*if (event.kbd.hasFlags(Common::KBD_ALT) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) { beginGFXTransaction(); setFullscreenMode(!_videoMode.fullscreen); endGFXTransaction(); @@ -255,10 +256,11 @@ bool OSystem_SDL::handleKeyDown(SDL_Event &ev, Common::Event &event) { #endif return false; - } + }*/ // Alt-S: Create a screenshot - if (event.kbd.hasFlags(Common::KBD_ALT) && ev.key.keysym.sym == 's') { + // TODO: make a function in graphics manager for this + /*if (event.kbd.hasFlags(Common::KBD_ALT) && ev.key.keysym.sym == 's') { char filename[20]; for (int n = 0;; n++) { @@ -275,7 +277,7 @@ bool OSystem_SDL::handleKeyDown(SDL_Event &ev, Common::Event &event) { else printf("Could not save screenshot!\n"); return false; - } + }*/ // Ctrl-m toggles mouse capture if (event.kbd.hasFlags(Common::KBD_CTRL) && ev.key.keysym.sym == 'm') { @@ -310,7 +312,7 @@ bool OSystem_SDL::handleKeyDown(SDL_Event &ev, Common::Event &event) { // Ctrl-Alt-<key> will change the GFX mode if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) { - if (handleScalerHotkeys(ev.key)) + if (_graphicsManager->handleScalerHotkeys(ev.key)) return false; } @@ -339,7 +341,7 @@ bool OSystem_SDL::handleKeyUp(SDL_Event &ev, Common::Event &event) { if (_scrollLock) event.kbd.flags |= Common::KBD_SCRL; - if (isScalerHotkey(event)) + if (_graphicsManager->isScalerHotkey(event)) // Swallow these key up events return false; @@ -350,7 +352,7 @@ bool OSystem_SDL::handleMouseMotion(SDL_Event &ev, Common::Event &event) { event.type = Common::EVENT_MOUSEMOVE; fillMouseEvent(event, ev.motion.x, ev.motion.y); - setMousePos(event.mouse.x, event.mouse.y); + _graphicsManager->setMousePos(event.mouse.x, event.mouse.y); return true; } @@ -570,3 +572,10 @@ bool OSystem_SDL::remapKey(SDL_Event &ev, Common::Event &event) { #endif return false; } + +void OSystem_SDL::toggleMouseGrab() { + if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) + SDL_WM_GrabInput(SDL_GRAB_ON); + else + SDL_WM_GrabInput(SDL_GRAB_OFF); +} diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk index f6ec769253..a9cce272aa 100644 --- a/backends/platform/sdl/module.mk +++ b/backends/platform/sdl/module.mk @@ -2,7 +2,6 @@ MODULE := backends/platform/sdl MODULE_OBJS := \ events.o \ - graphics.o \ hardwarekeys.o \ main.o \ sdl.o diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index f8ae824acf..6f82ede114 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -87,50 +87,15 @@ 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; -} - -#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS) -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); -} -#endif - void OSystem_SDL::initBackend() { assert(!_inited); int joystick_num = ConfMan.getInt("joystick_num"); - uint32 sdlFlags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; + uint32 sdlFlags = 0; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; -#ifdef _WIN32_WCE - if (ConfMan.hasKey("use_GDI") && ConfMan.getBool("use_GDI")) { - SDL_VideoInit("windib", 0); - sdlFlags ^= SDL_INIT_VIDEO; - } -#endif - if (joystick_num > -1) sdlFlags |= SDL_INIT_JOYSTICK; @@ -138,51 +103,15 @@ void OSystem_SDL::initBackend() { error("Could not initialize SDL: %s", SDL_GetError()); } - _graphicsMutex = createMutex(); - - SDL_ShowCursor(SDL_DISABLE); - // Enable unicode support if possible SDL_EnableUNICODE(1); - memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); - memset(&_videoMode, 0, sizeof(_videoMode)); - memset(&_transactionDetails, 0, sizeof(_transactionDetails)); - -#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && defined(USE_SCALERS) - _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; - _videoMode.scaleFactor = 1; - _videoMode.aspectRatioCorrection = false; - _scalerProc = Normal1x; -#endif - _scalerType = 0; - -#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) - _videoMode.fullscreen = ConfMan.getBool("fullscreen"); -#else - _videoMode.fullscreen = true; -#endif - -#if !defined(MACOSX) && !defined(__SYMBIAN32__) - // Setup a custom program icon. - // Don't set icon on OS X, as we use a nicer external icon there. - // Don't for Symbian: it uses the EScummVM.aif file for the icon. - setupIcon(); -#endif - // enable joystick if (joystick_num > -1 && SDL_NumJoysticks() > 0) { printf("Using joystick: %s\n", SDL_JoystickName(0)); _joystick = SDL_JoystickOpen(joystick_num); } - // Create the savefile manager, if none exists yet (we check for this to // allow subclasses to provide their own). if (_savefile == 0) { @@ -196,23 +125,45 @@ void OSystem_SDL::initBackend() { // Create and hook up the mixer, if none exists yet (we check for this to // allow subclasses to provide their own). if (_mixer == 0) { + // TODO: Implement SdlAudioManager + if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) { + error("Could not initialize SDL: %s", SDL_GetError()); + } + setupMixer(); } // Create and hook up the timer manager, if none exists yet (we check for // this to allow subclasses to provide their own). if (_timer == 0) { - // Note: We could implement a custom SDLTimerManager by using - // SDL_AddTimer. That might yield better timer resolution, but it would - // also change the semantics of a timer: Right now, ScummVM timers - // *never* run in parallel, due to the way they are implemented. If we - // switched to SDL_AddTimer, each timer might run in a separate thread. - // However, not all our code is prepared for that, so we can't just - // switch. Still, it's a potential future change to keep in mind. + // TODO: Implement SdlTimerManager + if (SDL_InitSubSystem(SDL_INIT_TIMER) == -1) { + error("Could not initialize SDL: %s", SDL_GetError()); + } + _timer = new DefaultTimerManager(); _timerID = SDL_AddTimer(10, &timer_handler, _timer); } + // Create and hook up the mutex manager, if none exists yet (we check for + // this to allow subclasses to provide their own). + if (_mutexManager == 0) { + _mutexManager = new SdlMutexManager(); + } + + // Create and hook up the graphics manager, if none exists yet (we check for + // this to allow subclasses to provide their own). + if (_graphicsManager == 0) { + _graphicsManager = new SdlGraphicsManager(); + } + +#if !defined(MACOSX) && !defined(__SYMBIAN32__) + // Setup a custom program icon. + // Don't set icon on OS X, as we use a nicer external icon there. + // Don't for Symbian: it uses the EScummVM.aif file for the icon. + setupIcon(); +#endif + // Invoke parent implementation of this method OSystem::initBackend(); @@ -221,23 +172,9 @@ void OSystem_SDL::initBackend() { OSystem_SDL::OSystem_SDL() : -#ifdef USE_OSD - _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), -#endif - _hwscreen(0), _screen(0), _tmpscreen(0), -#ifdef USE_RGB_COLOR - _screenFormat(Graphics::PixelFormat::createFormatCLUT8()), - _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()), -#endif - _overlayVisible(false), - _overlayscreen(0), _tmpscreen2(0), - _cdrom(0), _scalerProc(0), _modeChanged(false), _screenChangeCount(0), + _cdrom(0), _scrollLock(false), - _mouseVisible(false), _mouseNeedsRedraw(false), _mouseData(0), _mouseSurface(0), - _mouseOrigSurface(0), _cursorTargetScale(1), _cursorPaletteDisabled(true), _joystick(0), - _currentShakePos(0), _newShakePos(0), - _paletteDirtyStart(0), _paletteDirtyEnd(0), #if MIXER_DOUBLE_BUFFERING _soundMutex(0), _soundCond(0), _soundThread(0), _soundThreadIsRunning(false), _soundThreadShouldQuit(false), @@ -246,22 +183,14 @@ OSystem_SDL::OSystem_SDL() _savefile(0), _mixer(0), _timer(0), - _screenIsLocked(false), - _graphicsMutex(0), _transactionMode(kTransactionNone) { - - // clear palette storage - memset(_currentPalette, 0, sizeof(_currentPalette)); - memset(_cursorPalette, 0, sizeof(_cursorPalette)); - - _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; + _mutexManager(0), + _graphicsManager(0) { // reset mouse state memset(&_km, 0, sizeof(_km)); - memset(&_mouseCurState, 0, sizeof(_mouseCurState)); _inited = false; - #if defined(__amigaos4__) _fsFactory = new AmigaOSFilesystemFactory(); #elif defined(UNIX) @@ -279,8 +208,6 @@ OSystem_SDL::~OSystem_SDL() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_mouseData); - delete _savefile; delete _timer; } @@ -445,41 +372,15 @@ void OSystem_SDL::setWindowCaption(const char *caption) { } bool OSystem_SDL::hasFeature(Feature f) { - return - (f == kFeatureFullscreenMode) || - (f == kFeatureAspectRatioCorrection) || - (f == kFeatureCursorHasPalette) || - (f == kFeatureIconifyWindow); + return _graphicsManager->hasFeature(f); } void OSystem_SDL::setFeatureState(Feature f, bool enable) { - switch (f) { - case kFeatureFullscreenMode: - setFullscreenMode(enable); - break; - case kFeatureAspectRatioCorrection: - setAspectRatioCorrection(enable); - break; - case kFeatureIconifyWindow: - if (enable) - SDL_WM_IconifyWindow(); - break; - default: - break; - } + _graphicsManager->setFeatureState(f, enable); } bool OSystem_SDL::getFeatureState(Feature f) { - assert (_transactionMode == kTransactionNone); - - switch (f) { - case kFeatureFullscreenMode: - return _videoMode.fullscreen; - case kFeatureAspectRatioCorrection: - return _videoMode.aspectRatioCorrection; - default: - return false; - } + return _graphicsManager->getFeatureState(f); } void OSystem_SDL::deinit() { @@ -487,8 +388,6 @@ void OSystem_SDL::deinit() { SDL_CDStop(_cdrom); SDL_CDClose(_cdrom); } - unloadGFXMode(); - deleteMutex(_graphicsMutex); if (_joystick) SDL_JoystickClose(_joystick); @@ -498,8 +397,6 @@ void OSystem_SDL::deinit() { SDL_RemoveTimer(_timerID); closeMixer(); - free(_mouseData); - delete _timer; SDL_Quit(); @@ -570,20 +467,24 @@ void OSystem_SDL::setupIcon() { free(icon); } +#pragma mark - +#pragma mark --- Mutex --- +#pragma mark - + OSystem::MutexRef OSystem_SDL::createMutex() { - return (MutexRef) SDL_CreateMutex(); + return _mutexManager->createMutex(); } void OSystem_SDL::lockMutex(MutexRef mutex) { - SDL_mutexP((SDL_mutex *) mutex); + _mutexManager->lockMutex(mutex); } void OSystem_SDL::unlockMutex(MutexRef mutex) { - SDL_mutexV((SDL_mutex *) mutex); + _mutexManager->unlockMutex(mutex); } void OSystem_SDL::deleteMutex(MutexRef mutex) { - SDL_DestroyMutex((SDL_mutex *) mutex); + _mutexManager->deleteMutex(mutex); } #pragma mark - @@ -856,3 +757,147 @@ void OSystem_SDL::updateCD() { _cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS; } } + +#pragma mark - +#pragma mark --- Graphics --- +#pragma mark - + +const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const { + return _graphicsManager->getSupportedGraphicsModes(); +} + +int OSystem_SDL::getDefaultGraphicsMode() const { + return _graphicsManager->getDefaultGraphicsMode(); +} + +bool OSystem_SDL::setGraphicsMode(int mode) { + return _graphicsManager->setGraphicsMode(mode); +} + +int OSystem_SDL::getGraphicsMode() const { + return _graphicsManager->getGraphicsMode(); +} + +#ifdef USE_RGB_COLOR +Graphics::PixelFormat OSystem_SDL::getScreenFormat() const { + return _graphicsManager->getScreenFormat(); +} + +Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() { + return _graphicsManager->getSupportedFormats(); +} +#endif + +void OSystem_SDL::beginGFXTransaction() { + _graphicsManager->beginGFXTransaction(); +} + +OSystem::TransactionError OSystem_SDL::endGFXTransaction() { + return _graphicsManager->endGFXTransaction(); +} + +void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format ) { + _graphicsManager->initSize(w, h, format); +} + +int16 OSystem_SDL::getHeight() { + return _graphicsManager->getHeight(); +} + +int16 OSystem_SDL::getWidth() { + return _graphicsManager->getWidth(); +} + +void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { + _graphicsManager->setPalette(colors, start, num); +} + +void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { + _graphicsManager->grabPalette(colors, start, num); +} + +void OSystem_SDL::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) { + _graphicsManager->copyRectToScreen(buf, pitch, x, y, w, h); +} + +Graphics::Surface *OSystem_SDL::lockScreen() { + return _graphicsManager->lockScreen(); +} + +void OSystem_SDL::unlockScreen() { + _graphicsManager->unlockScreen(); +} + +/*void OSystem_SDL::fillScreen(uint32 col) { + _graphicsManager->fillScreen(col); +}*/ + +void OSystem_SDL::updateScreen() { + _graphicsManager->updateScreen(); +} + +void OSystem_SDL::setShakePos(int shakeOffset) { + _graphicsManager->setShakePos(shakeOffset); +} + +void OSystem_SDL::showOverlay() { + _graphicsManager->showOverlay(); +} + +void OSystem_SDL::hideOverlay() { + _graphicsManager->hideOverlay(); +} + +Graphics::PixelFormat OSystem_SDL::getOverlayFormat() const { + return _graphicsManager->getOverlayFormat(); +} + +void OSystem_SDL::clearOverlay() { + _graphicsManager->clearOverlay(); +} + +void OSystem_SDL::grabOverlay(OverlayColor *buf, int pitch) { + _graphicsManager->grabOverlay(buf, pitch); +} + +void OSystem_SDL::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) { + _graphicsManager->copyRectToOverlay(buf, pitch, x, y, w, h); +} + +int16 OSystem_SDL::getOverlayHeight() { + return _graphicsManager->getOverlayHeight(); +} + +int16 OSystem_SDL::getOverlayWidth() { + return _graphicsManager->getOverlayWidth(); +} + +bool OSystem_SDL::showMouse(bool visible) { + return _graphicsManager->showMouse(visible); +} + +void OSystem_SDL::warpMouse(int x, int y) { + _graphicsManager->warpMouse(x, y); +} + +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { + _graphicsManager->setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, cursorTargetScale, format); +} + +void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { + _graphicsManager->setCursorPalette(colors, start, num); +} + +void OSystem_SDL::disableCursorPalette(bool disable) { + _graphicsManager->disableCursorPalette(disable); +} + +int OSystem_SDL::getScreenChangeID() const { + return _graphicsManager->getScreenChangeID(); +} + +#ifdef USE_OSD +void OSystem_SDL::displayMessageOnOSD(const char *msg) { + _graphicsManager->displayMessageOnOSD(msg); +} +#endif diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 341a59c8cf..214a8a988c 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -33,6 +33,10 @@ #endif #include "backends/base-backend.h" + +#include "backends/mutex/sdl/sdl-mutex.h" +#include "backends/graphics/sdl/sdl-graphics.h" + #include "graphics/scaler.h" @@ -54,35 +58,6 @@ namespace Audio { #define MIXER_DOUBLE_BUFFERING 1 #endif - -enum { - GFX_NORMAL = 0, - GFX_DOUBLESIZE = 1, - GFX_TRIPLESIZE = 2, - GFX_2XSAI = 3, - GFX_SUPER2XSAI = 4, - GFX_SUPEREAGLE = 5, - GFX_ADVMAME2X = 6, - GFX_ADVMAME3X = 7, - GFX_HQ2X = 8, - GFX_HQ3X = 9, - GFX_TV2X = 10, - 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(); @@ -90,12 +65,18 @@ public: virtual void initBackend(); + +protected: + SdlMutexManager *_mutexManager; + SdlGraphicsManager *_graphicsManager; + +public: void beginGFXTransaction(); TransactionError endGFXTransaction(); #ifdef USE_RGB_COLOR // Game screen - virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } + virtual Graphics::PixelFormat getScreenFormat() const; // Highest supported virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); @@ -105,7 +86,7 @@ public: // Typically, 320x200 CLUT8 virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend - virtual int getScreenChangeID() const { return _screenChangeCount; } + virtual int getScreenChangeID() const; // Set colors of the palette void setPalette(const byte *colors, uint start, uint num); @@ -138,10 +119,7 @@ public: void setCursorPalette(const byte *colors, uint start, uint num); // Disables or enables cursor palette - void disableCursorPalette(bool disable) { - _cursorPaletteDisabled = disable; - blitCursor(); - } + void disableCursorPalette(bool disable); // Shaking is used in SCUMM. Set current shake position. void setShakePos(int shake_pos); @@ -214,7 +192,7 @@ public: void deleteMutex(MutexRef mutex); // Overlay - virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } + virtual Graphics::PixelFormat getOverlayFormat() const; virtual void showOverlay(); virtual void hideOverlay(); @@ -223,8 +201,8 @@ public: virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); virtual int16 getHeight(); virtual int16 getWidth(); - virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; } - virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; } + virtual int16 getOverlayHeight(); + virtual int16 getOverlayWidth(); virtual const GraphicsMode *getSupportedGraphicsModes() const; virtual int getDefaultGraphicsMode() const; @@ -254,102 +232,11 @@ protected: bool _inited; SDL_AudioSpec _obtainedRate; -#ifdef USE_OSD - SDL_Surface *_osdSurface; - Uint8 _osdAlpha; // Transparency level of the OSD - uint32 _osdFadeStartTime; // When to start the fade out - enum { - kOSDFadeOutDelay = 2 * 1000, // Delay before the OSD is faded out (in milliseconds) - kOSDFadeOutDuration = 500, // Duration of the OSD fade out (in milliseconds) - kOSDColorKey = 1, - kOSDInitialAlpha = 80 // Initial alpha level, in percent - }; -#endif - - // hardware screen - SDL_Surface *_hwscreen; - - // unseen game screen - SDL_Surface *_screen; -#ifdef USE_RGB_COLOR - Graphics::PixelFormat _screenFormat; - Graphics::PixelFormat _cursorFormat; -#endif - - // temporary screen (for scalers) - SDL_Surface *_tmpscreen; - SDL_Surface *_tmpscreen2; - - // overlay - SDL_Surface *_overlayscreen; - bool _overlayVisible; - Graphics::PixelFormat _overlayFormat; - // CD Audio SDL_CD *_cdrom; int _cdTrack, _cdNumLoops, _cdStartFrame, _cdDuration; uint32 _cdEndTime, _cdStopTime; - enum { - kTransactionNone = 0, - kTransactionActive = 1, - kTransactionRollback = 2 - }; - - struct TransactionDetails { - bool sizeChanged; - bool needHotswap; - bool needUpdatescreen; - bool normal1xScaler; -#ifdef USE_RGB_COLOR - bool formatChanged; -#endif - }; - TransactionDetails _transactionDetails; - - struct VideoState { - bool setup; - - bool fullscreen; - bool aspectRatioCorrection; - AspectRatio desiredAspectRatio; - - int mode; - int scaleFactor; - - int screenWidth, screenHeight; - int overlayWidth, overlayHeight; - int hardwareWidth, hardwareHeight; -#ifdef USE_RGB_COLOR - Graphics::PixelFormat format; -#endif - }; - VideoState _videoMode, _oldVideoMode; - - virtual void setGraphicsModeIntern(); // overloaded by CE backend - - /** Force full redraw on next updateScreen */ - bool _forceFull; - ScalerProc *_scalerProc; - int _scalerType; - int _transactionMode; - - bool _screenIsLocked; - Graphics::Surface _framebuffer; - - /** Current video mode flags (see DF_* constants) */ - bool _modeChanged; - int _screenChangeCount; - - enum { - NUM_DIRTY_RECT = 100, - MAX_SCALING = 3 - }; - - // Dirty rect management - SDL_Rect _dirtyRectList[NUM_DIRTY_RECT]; - int _numDirtyRects; - // Keyboard mouse emulation. Disabled by fingolfin 2004-12-18. // I am keeping the rest of the code in for now, since the joystick // code (or rather, "hack") uses it, too. @@ -358,50 +245,7 @@ protected: uint32 last_time, delay_time, x_down_time, y_down_time; }; - struct MousePos { - // The mouse position, using either virtual (game) or real - // (overlay) coordinates. - int16 x, y; - - // The size and hotspot of the original cursor image. - int16 w, h; - int16 hotX, hotY; - - // The size and hotspot of the pre-scaled cursor image, in real - // coordinates. - int16 rW, rH; - int16 rHotX, rHotY; - - // The size and hotspot of the pre-scaled cursor image, in game - // coordinates. - int16 vW, vH; - int16 vHotX, vHotY; - - MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0), - rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0), - vHotX(0), vHotY(0) - { } - }; - - // mouse KbdMouse _km; - bool _mouseVisible; - bool _mouseNeedsRedraw; - byte *_mouseData; - SDL_Rect _mouseBackup; - MousePos _mouseCurState; -#ifdef USE_RGB_COLOR - uint32 _mouseKeyColor; -#else - byte _mouseKeyColor; -#endif - int _cursorTargetScale; - bool _cursorPaletteDisabled; - SDL_Surface *_mouseOrigSurface; - SDL_Surface *_mouseSurface; - enum { - kMouseColorKey = 1 - }; // Scroll lock state - since SDL doesn't track it bool _scrollLock; @@ -409,23 +253,6 @@ protected: // joystick SDL_Joystick *_joystick; - // Shake mode - int _currentShakePos; - int _newShakePos; - - // Palette data - SDL_Color _currentPalette[256]; - uint _paletteDirtyStart, _paletteDirtyEnd; - - // Cursor palette data - SDL_Color _cursorPalette[256]; - - /** - * Mutex which prevents multiple threads from interfering with each other - * when accessing the screen. - */ - MutexRef _graphicsMutex; - #ifdef MIXER_DOUBLE_BUFFERING SDL_mutex *_soundMutex; SDL_cond *_soundCond; @@ -451,37 +278,14 @@ protected: Common::TimerManager *_timer; protected: - virtual void addDirtyRect(int x, int y, int w, int h, bool realCoordinates = false); // overloaded by CE backend - - virtual void drawMouse(); // overloaded by CE backend - virtual void undrawMouse(); // overloaded by CE backend (FIXME) - virtual void blitCursor(); // overloaded by CE backend (FIXME) - - /** Set the position of the virtual mouse cursor. */ - void setMousePos(int x, int y); virtual void fillMouseEvent(Common::Event &event, int x, int y); // overloaded by CE backend void toggleMouseGrab(); - virtual void internUpdateScreen(); // overloaded by CE backend - - virtual bool loadGFXMode(); // overloaded by CE backend - virtual void unloadGFXMode(); // overloaded by CE backend - virtual bool hotswapGFXMode(); // overloaded by CE backend - - void setFullscreenMode(bool enable); - void setAspectRatioCorrection(bool enable); - - virtual bool saveScreenshot(const char *filename); // overloaded by CE backend - - int effectiveScreenHeight() const; + void handleKbdMouse(); void setupIcon(); - void handleKbdMouse(); virtual bool remapKey(SDL_Event &ev, Common::Event &event); - - bool handleScalerHotkeys(const SDL_KeyboardEvent &key); - bool isScalerHotkey(const Common::Event &event); }; #endif diff --git a/sound/mixer.h b/sound/mixer.h index 65d5d18cc6..5c7d902337 100644 --- a/sound/mixer.h +++ b/sound/mixer.h @@ -28,6 +28,7 @@ #include "common/types.h" #include "common/mutex.h" +#include "common/noncopyable.h" #include "sound/timestamp.h" @@ -61,7 +62,7 @@ public: * The main audio mixer handles mixing of an arbitrary number of * audio streams (in the form of AudioStream instances). */ -class Mixer { +class Mixer : Common::NonCopyable { public: enum SoundType { kPlainSoundType = 0, |