diff options
Diffstat (limited to 'backends/graphics/surfacesdl')
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 85 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.h | 7 |
2 files changed, 50 insertions, 42 deletions
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 02e58ab319..c946b8e747 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -40,6 +40,7 @@ #include "graphics/scaler.h" #include "graphics/scaler/aspect.h" #include "graphics/surface.h" +#include "gui/EventRecorder.h" static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { {"1x", _s("Normal (no scaling)"), GFX_NORMAL}, @@ -135,19 +136,12 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou _paletteDirtyStart(0), _paletteDirtyEnd(0), _screenIsLocked(false), _graphicsMutex(0), + _displayDisabled(false), #ifdef USE_SDL_DEBUG_FOCUSRECT _enableFocusRectDebugCode(false), _enableFocusRect(false), _focusRect(), #endif _transactionMode(kTransactionNone) { - if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { - error("Could not initialize SDL: %s", SDL_GetError()); - } - - // This is also called in initSDL(), but initializing graphics - // may reset it. - SDL_EnableUNICODE(1); - // allocate palette storage _currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); _cursorPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256); @@ -163,8 +157,6 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou _enableFocusRectDebugCode = ConfMan.getBool("use_sdl_debug_focusrect"); #endif - SDL_ShowCursor(SDL_DISABLE); - memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); memset(&_videoMode, 0, sizeof(_videoMode)); memset(&_transactionDetails, 0, sizeof(_transactionDetails)); @@ -191,10 +183,6 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou } SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { - // Unregister the event observer - if (g_system->getEventManager()->getEventDispatcher() != NULL) - g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); - unloadGFXMode(); if (_mouseSurface) SDL_FreeSurface(_mouseSurface); @@ -209,11 +197,24 @@ SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() { free(_mouseData); } -void SurfaceSdlGraphicsManager::initEventObserver() { +void SurfaceSdlGraphicsManager::activateManager() { + GraphicsManager::activateManager(); + initEventSource(); + // Register the graphics manager as a event observer g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false); } +void SurfaceSdlGraphicsManager::deactivateManager() { + // Unregister the event observer + if (g_system->getEventManager()->getEventDispatcher()) { + g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); + } + + deinitEventSource(); + GraphicsManager::deactivateManager(); +} + bool SurfaceSdlGraphicsManager::hasFeature(OSystem::Feature f) { return (f == OSystem::kFeatureFullscreenMode) || @@ -261,10 +262,6 @@ bool SurfaceSdlGraphicsManager::getFeatureState(OSystem::Feature f) { } } -const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::supportedGraphicsModes() { - return s_supportedGraphicsModes; -} - const OSystem::GraphicsMode *SurfaceSdlGraphicsManager::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } @@ -765,9 +762,20 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() { fixupResolutionForAspectRatio(_videoMode.desiredAspectRatio, _videoMode.hardwareWidth, _videoMode.hardwareHeight); } - _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16, - _videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE - ); + +#ifdef ENABLE_EVENTRECORDER + _displayDisabled = ConfMan.getBool("disable_display"); + + if (_displayDisabled) { + _hwscreen = g_eventRec.getSurface(_videoMode.hardwareWidth, _videoMode.hardwareHeight); + } else +#endif + { + _hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16, + _videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE + ); + } + #ifdef USE_RGB_COLOR detectSupportedFormats(); #endif @@ -1188,7 +1196,9 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() { #endif // Finally, blit all our changes to the screen - SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList); + if (!_displayDisabled) { + SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList); + } } _numDirtyRects = 0; @@ -1293,15 +1303,13 @@ Graphics::Surface *SurfaceSdlGraphicsManager::lockScreen() { if (SDL_LockSurface(_screen) == -1) error("SDL_LockSurface failed: %s", SDL_GetError()); - _framebuffer.pixels = _screen->pixels; - _framebuffer.w = _screen->w; - _framebuffer.h = _screen->h; - _framebuffer.pitch = _screen->pitch; + _framebuffer.init(_screen->w, _screen->h, _screen->pitch, _screen->pixels, #ifdef USE_RGB_COLOR - _framebuffer.format = _screenFormat; + _screenFormat #else - _framebuffer.format = Graphics::PixelFormat::createFormatCLUT8(); + Graphics::PixelFormat::createFormatCLUT8() #endif + ); return &_framebuffer; } @@ -1325,8 +1333,8 @@ void SurfaceSdlGraphicsManager::unlockScreen() { void SurfaceSdlGraphicsManager::fillScreen(uint32 col) { Graphics::Surface *screen = lockScreen(); - if (screen && screen->pixels) - memset(screen->pixels, col, screen->h * screen->pitch); + if (screen && screen->getPixels()) + memset(screen->getPixels(), col, screen->h * screen->pitch); unlockScreen(); } @@ -2047,15 +2055,12 @@ void SurfaceSdlGraphicsManager::displayMessageOnOSD(const char *msg) { error("displayMessageOnOSD: SDL_LockSurface failed: %s", SDL_GetError()); Graphics::Surface dst; - dst.pixels = _osdSurface->pixels; - dst.w = _osdSurface->w; - dst.h = _osdSurface->h; - dst.pitch = _osdSurface->pitch; - dst.format = Graphics::PixelFormat(_osdSurface->format->BytesPerPixel, - 8 - _osdSurface->format->Rloss, 8 - _osdSurface->format->Gloss, - 8 - _osdSurface->format->Bloss, 8 - _osdSurface->format->Aloss, - _osdSurface->format->Rshift, _osdSurface->format->Gshift, - _osdSurface->format->Bshift, _osdSurface->format->Ashift); + dst.init(_osdSurface->w, _osdSurface->h, _osdSurface->pitch, _osdSurface->pixels, + Graphics::PixelFormat(_osdSurface->format->BytesPerPixel, + 8 - _osdSurface->format->Rloss, 8 - _osdSurface->format->Gloss, + 8 - _osdSurface->format->Bloss, 8 - _osdSurface->format->Aloss, + _osdSurface->format->Rshift, _osdSurface->format->Gshift, + _osdSurface->format->Bshift, _osdSurface->format->Ashift)); // The font we are going to use: const Graphics::Font *font = FontMan.getFontByUsage(Graphics::FontManager::kLocalizedFont); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index 21444cc25d..00c05ff2bf 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -80,13 +80,13 @@ public: SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSource); virtual ~SurfaceSdlGraphicsManager(); - virtual void initEventObserver(); + virtual void activateManager(); + virtual void deactivateManager(); virtual bool hasFeature(OSystem::Feature f); virtual void setFeatureState(OSystem::Feature f, bool enable); virtual bool getFeatureState(OSystem::Feature f); - static const OSystem::GraphicsMode *supportedGraphicsModes(); virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; virtual int getDefaultGraphicsMode() const; virtual bool setGraphicsMode(int mode); @@ -232,6 +232,9 @@ protected: int _scalerType; int _transactionMode; + // Indicates whether it is needed to free _hwsurface in destructor + bool _displayDisabled; + bool _screenIsLocked; Graphics::Surface _framebuffer; |