BACKENDS: Split ModularBackend into two separate classes

This commit is contained in:
Cameron Cawley 2020-08-02 00:05:25 +01:00 committed by Eugene Sandulenko
parent 9a61a99590
commit 75852a786a
11 changed files with 130 additions and 108 deletions

View File

@ -426,7 +426,7 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
#endif
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
int screenID = g_system->getScreenChangeID();
if (screenID != _lastScreenID) {
_lastScreenID = screenID;
event.type = Common::EVENT_SCREEN_CHANGED;
@ -963,7 +963,7 @@ bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
_graphicsManager->notifyResize(w, h);
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
int screenID = g_system->getScreenChangeID();
if (screenID != _lastScreenID) {
_lastScreenID = screenID;
event.type = Common::EVENT_SCREEN_CHANGED;

View File

@ -71,7 +71,7 @@ SymbianFilesystemNode::SymbianFilesystemNode(const Common::String &path) {
TPtrC8 ptr((const unsigned char*)_path.c_str(),_path.size());
fname.Copy(ptr);
if (static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession().Entry(fname, fileAttribs) == KErrNone) {
if (dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession().Entry(fname, fileAttribs) == KErrNone) {
_isValid = true;
_isDirectory = fileAttribs.IsDir();
} else {
@ -88,7 +88,7 @@ bool SymbianFilesystemNode::exists() const {
TFileName fname;
TPtrC8 ptr((const unsigned char*) _path.c_str(), _path.size());
fname.Copy(ptr);
bool fileExists = BaflUtils::FileExists(static_cast<OSystem_SDL_Symbian *> (g_system)->FsSession(), fname);
bool fileExists = BaflUtils::FileExists(dynamic_cast<OSystem_SDL_Symbian *> (g_system)->FsSession(), fname);
if (!fileExists) {
TParsePtrC parser(fname);
if (parser.PathPresent() && parser.Path().Compare(_L("\\")) == KErrNone && !parser.NameOrExtPresent()) {

View File

@ -70,22 +70,22 @@ TSymbianFileEntry* CreateSymbianFileEntry(const char* name, const char* mode) {
switch (mode[0]) {
case 'a':
if (fileEntry->_fileHandle.Open(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
if (fileEntry->_fileHandle.Create(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
if (fileEntry->_fileHandle.Open(dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
if (fileEntry->_fileHandle.Create(dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
delete fileEntry;
fileEntry = NULL;
}
}
break;
case 'r':
if (fileEntry->_fileHandle.Open(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
if (fileEntry->_fileHandle.Open(dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
delete fileEntry;
fileEntry = NULL;
}
break;
case 'w':
if (fileEntry->_fileHandle.Replace(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
if (fileEntry->_fileHandle.Replace(dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) {
delete fileEntry;
fileEntry = NULL;
}

View File

@ -29,153 +29,147 @@
#include "common/timer.h"
#include "graphics/pixelformat.h"
ModularBackend::ModularBackend()
ModularGraphicsBackend::ModularGraphicsBackend()
:
_mutexManager(0),
_graphicsManager(0) {
}
ModularBackend::~ModularBackend() {
ModularGraphicsBackend::~ModularGraphicsBackend() {
delete _graphicsManager;
_graphicsManager = 0;
// _timerManager needs to be deleted before _mutexManager to avoid a crash.
delete _timerManager;
_timerManager = 0;
delete _mutexManager;
_mutexManager = 0;
}
bool ModularBackend::hasFeature(Feature f) {
bool ModularGraphicsBackend::hasFeature(Feature f) {
return _graphicsManager->hasFeature(f);
}
void ModularBackend::setFeatureState(Feature f, bool enable) {
void ModularGraphicsBackend::setFeatureState(Feature f, bool enable) {
_graphicsManager->setFeatureState(f, enable);
}
bool ModularBackend::getFeatureState(Feature f) {
bool ModularGraphicsBackend::getFeatureState(Feature f) {
return _graphicsManager->getFeatureState(f);
}
GraphicsManager *ModularBackend::getGraphicsManager() {
GraphicsManager *ModularGraphicsBackend::getGraphicsManager() {
assert(_graphicsManager);
return (GraphicsManager *)_graphicsManager;
}
const OSystem::GraphicsMode *ModularBackend::getSupportedGraphicsModes() const {
const OSystem::GraphicsMode *ModularGraphicsBackend::getSupportedGraphicsModes() const {
return _graphicsManager->getSupportedGraphicsModes();
}
int ModularBackend::getDefaultGraphicsMode() const {
int ModularGraphicsBackend::getDefaultGraphicsMode() const {
return _graphicsManager->getDefaultGraphicsMode();
}
bool ModularBackend::setGraphicsMode(int mode) {
bool ModularGraphicsBackend::setGraphicsMode(int mode) {
return _graphicsManager->setGraphicsMode(mode);
}
int ModularBackend::getGraphicsMode() const {
int ModularGraphicsBackend::getGraphicsMode() const {
return _graphicsManager->getGraphicsMode();
}
const OSystem::GraphicsMode *ModularBackend::getSupportedShaders() const {
const OSystem::GraphicsMode *ModularGraphicsBackend::getSupportedShaders() const {
return _graphicsManager->getSupportedShaders();
}
int ModularBackend::getDefaultShader() const {
int ModularGraphicsBackend::getDefaultShader() const {
return _graphicsManager->getDefaultShader();
}
bool ModularBackend::setShader(int id) {
bool ModularGraphicsBackend::setShader(int id) {
return _graphicsManager->setShader(id);
}
int ModularBackend::getShader() const {
int ModularGraphicsBackend::getShader() const {
return _graphicsManager->getShader();
}
const OSystem::GraphicsMode *ModularBackend::getSupportedStretchModes() const {
const OSystem::GraphicsMode *ModularGraphicsBackend::getSupportedStretchModes() const {
return _graphicsManager->getSupportedStretchModes();
}
int ModularBackend::getDefaultStretchMode() const {
int ModularGraphicsBackend::getDefaultStretchMode() const {
return _graphicsManager->getDefaultStretchMode();
}
bool ModularBackend::setStretchMode(int mode) {
bool ModularGraphicsBackend::setStretchMode(int mode) {
return _graphicsManager->setStretchMode(mode);
}
int ModularBackend::getStretchMode() const {
int ModularGraphicsBackend::getStretchMode() const {
return _graphicsManager->getStretchMode();
}
void ModularBackend::resetGraphicsScale() {
void ModularGraphicsBackend::resetGraphicsScale() {
_graphicsManager->resetGraphicsScale();
}
#ifdef USE_RGB_COLOR
Graphics::PixelFormat ModularBackend::getScreenFormat() const {
Graphics::PixelFormat ModularGraphicsBackend::getScreenFormat() const {
return _graphicsManager->getScreenFormat();
}
Common::List<Graphics::PixelFormat> ModularBackend::getSupportedFormats() const {
Common::List<Graphics::PixelFormat> ModularGraphicsBackend::getSupportedFormats() const {
return _graphicsManager->getSupportedFormats();
}
#endif
void ModularBackend::initSize(uint w, uint h, const Graphics::PixelFormat *format ) {
void ModularGraphicsBackend::initSize(uint w, uint h, const Graphics::PixelFormat *format ) {
_graphicsManager->initSize(w, h, format);
}
void ModularBackend::initSizeHint(const Graphics::ModeList &modes) {
void ModularGraphicsBackend::initSizeHint(const Graphics::ModeList &modes) {
_graphicsManager->initSizeHint(modes);
}
int ModularBackend::getScreenChangeID() const {
int ModularGraphicsBackend::getScreenChangeID() const {
return _graphicsManager->getScreenChangeID();
}
void ModularBackend::beginGFXTransaction() {
void ModularGraphicsBackend::beginGFXTransaction() {
_graphicsManager->beginGFXTransaction();
}
OSystem::TransactionError ModularBackend::endGFXTransaction() {
OSystem::TransactionError ModularGraphicsBackend::endGFXTransaction() {
return _graphicsManager->endGFXTransaction();
}
int16 ModularBackend::getHeight() {
int16 ModularGraphicsBackend::getHeight() {
return _graphicsManager->getHeight();
}
int16 ModularBackend::getWidth() {
int16 ModularGraphicsBackend::getWidth() {
return _graphicsManager->getWidth();
}
PaletteManager *ModularBackend::getPaletteManager() {
PaletteManager *ModularGraphicsBackend::getPaletteManager() {
return _graphicsManager;
}
void ModularBackend::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
void ModularGraphicsBackend::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
_graphicsManager->copyRectToScreen(buf, pitch, x, y, w, h);
}
Graphics::Surface *ModularBackend::lockScreen() {
Graphics::Surface *ModularGraphicsBackend::lockScreen() {
return _graphicsManager->lockScreen();
}
void ModularBackend::unlockScreen() {
void ModularGraphicsBackend::unlockScreen() {
_graphicsManager->unlockScreen();
}
void ModularBackend::fillScreen(uint32 col) {
void ModularGraphicsBackend::fillScreen(uint32 col) {
_graphicsManager->fillScreen(col);
}
void ModularBackend::updateScreen() {
void ModularGraphicsBackend::updateScreen() {
#ifdef ENABLE_EVENTRECORDER
g_eventRec.preDrawOverlayGui();
#endif
@ -187,90 +181,105 @@ void ModularBackend::updateScreen() {
#endif
}
void ModularBackend::setShakePos(int shakeXOffset, int shakeYOffset) {
void ModularGraphicsBackend::setShakePos(int shakeXOffset, int shakeYOffset) {
_graphicsManager->setShakePos(shakeXOffset, shakeYOffset);
}
void ModularBackend::setFocusRectangle(const Common::Rect& rect) {
void ModularGraphicsBackend::setFocusRectangle(const Common::Rect& rect) {
_graphicsManager->setFocusRectangle(rect);
}
void ModularBackend::clearFocusRectangle() {
void ModularGraphicsBackend::clearFocusRectangle() {
_graphicsManager->clearFocusRectangle();
}
void ModularBackend::showOverlay() {
void ModularGraphicsBackend::showOverlay() {
_graphicsManager->showOverlay();
}
void ModularBackend::hideOverlay() {
void ModularGraphicsBackend::hideOverlay() {
_graphicsManager->hideOverlay();
}
Graphics::PixelFormat ModularBackend::getOverlayFormat() const {
Graphics::PixelFormat ModularGraphicsBackend::getOverlayFormat() const {
return _graphicsManager->getOverlayFormat();
}
void ModularBackend::clearOverlay() {
void ModularGraphicsBackend::clearOverlay() {
_graphicsManager->clearOverlay();
}
void ModularBackend::grabOverlay(void *buf, int pitch) {
void ModularGraphicsBackend::grabOverlay(void *buf, int pitch) {
_graphicsManager->grabOverlay(buf, pitch);
}
void ModularBackend::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
void ModularGraphicsBackend::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
_graphicsManager->copyRectToOverlay(buf, pitch, x, y, w, h);
}
int16 ModularBackend::getOverlayHeight() {
int16 ModularGraphicsBackend::getOverlayHeight() {
return _graphicsManager->getOverlayHeight();
}
int16 ModularBackend::getOverlayWidth() {
int16 ModularGraphicsBackend::getOverlayWidth() {
return _graphicsManager->getOverlayWidth();
}
bool ModularBackend::showMouse(bool visible) {
bool ModularGraphicsBackend::showMouse(bool visible) {
return _graphicsManager->showMouse(visible);
}
void ModularBackend::warpMouse(int x, int y) {
void ModularGraphicsBackend::warpMouse(int x, int y) {
_eventManager->purgeMouseEvents();
_graphicsManager->warpMouse(x, y);
}
void ModularBackend::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
void ModularGraphicsBackend::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
_graphicsManager->setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format);
}
void ModularBackend::setCursorPalette(const byte *colors, uint start, uint num) {
void ModularGraphicsBackend::setCursorPalette(const byte *colors, uint start, uint num) {
_graphicsManager->setCursorPalette(colors, start, num);
}
OSystem::MutexRef ModularBackend::createMutex() {
void ModularGraphicsBackend::displayMessageOnOSD(const char *msg) {
_graphicsManager->displayMessageOnOSD(msg);
}
void ModularGraphicsBackend::displayActivityIconOnOSD(const Graphics::Surface *icon) {
_graphicsManager->displayActivityIconOnOSD(icon);
}
ModularMutexBackend::ModularMutexBackend()
:
_mutexManager(0) {
}
ModularMutexBackend::~ModularMutexBackend() {
// _timerManager needs to be deleted before _mutexManager to avoid a crash.
delete _timerManager;
_timerManager = 0;
delete _mutexManager;
_mutexManager = 0;
}
OSystem::MutexRef ModularMutexBackend::createMutex() {
assert(_mutexManager);
return _mutexManager->createMutex();
}
void ModularBackend::lockMutex(MutexRef mutex) {
void ModularMutexBackend::lockMutex(MutexRef mutex) {
assert(_mutexManager);
_mutexManager->lockMutex(mutex);
}
void ModularBackend::unlockMutex(MutexRef mutex) {
void ModularMutexBackend::unlockMutex(MutexRef mutex) {
assert(_mutexManager);
_mutexManager->unlockMutex(mutex);
}
void ModularBackend::deleteMutex(MutexRef mutex) {
void ModularMutexBackend::deleteMutex(MutexRef mutex) {
assert(_mutexManager);
_mutexManager->deleteMutex(mutex);
}
void ModularBackend::displayMessageOnOSD(const char *msg) {
_graphicsManager->displayMessageOnOSD(msg);
}
void ModularBackend::displayActivityIconOnOSD(const Graphics::Surface *icon) {
_graphicsManager->displayActivityIconOnOSD(icon);
}

View File

@ -29,12 +29,12 @@ class GraphicsManager;
class MutexManager;
/**
* Base class for modular backends.
* Base classes for modular backends.
*
* It wraps most functions to their manager equivalent, but not
* They wrap most functions to their manager equivalent, but not
* all OSystem functions are implemented here.
*
* A backend derivated from this class, will need to implement
* A backend derivated from these classes, will need to implement
* these functions on its own:
* OSystem::pollEvent()
* OSystem::getMillis()
@ -46,10 +46,10 @@ class MutexManager;
* And, it should also initialize all the managers variables
* declared in this class, or override their related functions.
*/
class ModularBackend : public BaseBackend {
class ModularGraphicsBackend : virtual public BaseBackend {
public:
ModularBackend();
virtual ~ModularBackend();
ModularGraphicsBackend();
virtual ~ModularGraphicsBackend();
/** @name Features */
//@{
@ -116,16 +116,6 @@ public:
//@}
/** @name Mutex handling */
//@{
virtual MutexRef createMutex() override final;
virtual void lockMutex(MutexRef mutex) override final;
virtual void unlockMutex(MutexRef mutex) override final;
virtual void deleteMutex(MutexRef mutex) override final;
//@}
/** @name Miscellaneous */
//@{
@ -138,10 +128,33 @@ protected:
/** @name Managers variables */
//@{
MutexManager *_mutexManager;
GraphicsManager *_graphicsManager;
//@}
};
class ModularMutexBackend : virtual public BaseBackend {
public:
ModularMutexBackend();
virtual ~ModularMutexBackend();
/** @name Mutex handling */
//@{
virtual MutexRef createMutex() override final;
virtual void lockMutex(MutexRef mutex) override final;
virtual void unlockMutex(MutexRef mutex) override final;
virtual void deleteMutex(MutexRef mutex) override final;
//@}
protected:
/** @name Managers variables */
//@{
MutexManager *_mutexManager;
//@}
};
#endif

View File

@ -368,7 +368,7 @@ void OSystem_Android::initBackend() {
JNI::setReadyForEvents(true);
ModularBackend::initBackend();
BaseBackend::initBackend();
}
bool OSystem_Android::hasFeature(Feature f) {
@ -379,7 +379,7 @@ bool OSystem_Android::hasFeature(Feature f) {
f == kFeatureClipboardSupport) {
return true;
}
return ModularBackend::hasFeature(f);
return ModularGraphicsBackend::hasFeature(f);
}
void OSystem_Android::setFeatureState(Feature f, bool enable) {
@ -399,7 +399,7 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) {
JNI::showKeyboardControl(enable);
break;
default:
ModularBackend::setFeatureState(f, enable);
ModularGraphicsBackend::setFeatureState(f, enable);
break;
}
}
@ -413,7 +413,7 @@ bool OSystem_Android::getFeatureState(Feature f) {
case kFeatureOnScreenControl:
return ConfMan.getBool("onscreen_control");
default:
return ModularBackend::getFeatureState(f);
return ModularGraphicsBackend::getFeatureState(f);
}
}

View File

@ -56,7 +56,7 @@ extern const char *android_log_tag;
#define ENTER(fmt, args...) do { } while (false)
#endif
class OSystem_Android : public ModularBackend, Common::EventSource {
class OSystem_Android : public ModularMutexBackend, public ModularGraphicsBackend, Common::EventSource {
private:
// passed from the dark side
int _audio_sample_rate;

View File

@ -65,7 +65,7 @@
#include "backends/fs/windows/windows-fs-factory.h"
#endif
class OSystem_NULL : public ModularBackend, Common::EventSource {
class OSystem_NULL : public ModularMutexBackend, public ModularGraphicsBackend, Common::EventSource {
public:
OSystem_NULL();
virtual ~OSystem_NULL();
@ -145,7 +145,7 @@ void OSystem_NULL::initBackend() {
// into the system somehow to be functional. Of course, can't do
// that in a NULL backend :).
ModularBackend::initBackend();
BaseBackend::initBackend();
}
bool OSystem_NULL::pollEvent(Common::Event &event) {

View File

@ -91,7 +91,7 @@ OSystem_SDL::~OSystem_SDL() {
SDL_ShowCursor(SDL_ENABLE);
// Delete the various managers here. Note that the ModularBackend
// destructor would also take care of this for us. However, various
// destructors would also take care of this for us. However, various
// of our managers must be deleted *before* we call SDL_Quit().
// Hence, we perform the destruction on our own.
delete _savefileManager;
@ -170,7 +170,7 @@ bool OSystem_SDL::hasFeature(Feature f) {
if (f == kFeatureJoystickDeadzone || f == kFeatureKbdMouseSpeed) {
return _eventSource->isJoystickConnected();
}
return ModularBackend::hasFeature(f);
return ModularGraphicsBackend::hasFeature(f);
}
void OSystem_SDL::initBackend() {
@ -266,7 +266,7 @@ void OSystem_SDL::initBackend() {
_inited = true;
ModularBackend::initBackend();
BaseBackend::initBackend();
// We have to initialize the graphics manager before the event manager
// so the virtual keyboard can be initialized, but we have to add the
@ -376,7 +376,7 @@ void OSystem_SDL::fatalError() {
}
Common::KeymapArray OSystem_SDL::getGlobalKeymaps() {
Common::KeymapArray globalMaps = ModularBackend::getGlobalKeymaps();
Common::KeymapArray globalMaps = BaseBackend::getGlobalKeymaps();
SdlGraphicsManager *graphicsManager = dynamic_cast<SdlGraphicsManager *>(_graphicsManager);
globalMaps.push_back(graphicsManager->getKeymap());
@ -447,7 +447,7 @@ Common::String OSystem_SDL::getSystemLanguage() const {
// Detect the language from the locale
if (locale.empty()) {
return ModularBackend::getSystemLanguage();
return BaseBackend::getSystemLanguage();
} else {
int length = 0;
@ -465,7 +465,7 @@ Common::String OSystem_SDL::getSystemLanguage() const {
return Common::String(locale.c_str(), length);
}
#else // USE_DETECTLANG
return ModularBackend::getSystemLanguage();
return BaseBackend::getSystemLanguage();
#endif // USE_DETECTLANG
}
@ -781,6 +781,6 @@ char *OSystem_SDL::convertEncoding(const char *to, const char *from, const char
SDL_free(result);
return finalResult;
#else
return ModularBackend::convertEncoding(to, from, string, length);
return BaseBackend::convertEncoding(to, from, string, length);
#endif // SDL_VERSION_ATLEAST(1, 2, 10)
}

View File

@ -36,7 +36,7 @@
/**
* Base OSystem class for all SDL ports.
*/
class OSystem_SDL : public ModularBackend {
class OSystem_SDL : public ModularMutexBackend, public ModularGraphicsBackend {
public:
OSystem_SDL();
virtual ~OSystem_SDL();

View File

@ -88,7 +88,7 @@ void OSystem_SDL_Symbian::initBackend() {
TFileName fname;
TPtrC8 ptr((const unsigned char*)currentPath.c_str(), currentPath.size());
fname.Copy(ptr);
BaflUtils::EnsurePathExistsL(static_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), fname);
BaflUtils::EnsurePathExistsL(dynamic_cast<OSystem_SDL_Symbian *>(g_system)->FsSession(), fname);
ConfMan.setBool("FM_high_quality", false);
#if !defined(S60) || defined(S60V3) // S60 has low quality as default