scummvm/backends/modular-backend.cpp

318 lines
8.8 KiB
C++
Raw Normal View History

/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/modular-backend.h"
#include "backends/audiocd/audiocd.h"
#include "backends/graphics/graphics.h"
#include "backends/mixer/mixer.h"
2013-05-16 21:18:09 +00:00
#include "gui/EventRecorder.h"
#include "common/timer.h"
#include "graphics/pixelformat.h"
ModularGraphicsBackend::ModularGraphicsBackend()
:
_graphicsManager(nullptr) {
}
ModularGraphicsBackend::~ModularGraphicsBackend() {
2010-10-13 17:58:48 +00:00
delete _graphicsManager;
_graphicsManager = nullptr;
}
bool ModularGraphicsBackend::hasFeature(Feature f) {
return _graphicsManager->hasFeature(f);
}
void ModularGraphicsBackend::setFeatureState(Feature f, bool enable) {
2013-06-25 11:08:55 +00:00
_graphicsManager->setFeatureState(f, enable);
}
bool ModularGraphicsBackend::getFeatureState(Feature f) {
return _graphicsManager->getFeatureState(f);
}
GraphicsManager *ModularGraphicsBackend::getGraphicsManager() {
assert(_graphicsManager);
return (GraphicsManager *)_graphicsManager;
}
const OSystem::GraphicsMode *ModularGraphicsBackend::getSupportedGraphicsModes() const {
return _graphicsManager->getSupportedGraphicsModes();
}
int ModularGraphicsBackend::getDefaultGraphicsMode() const {
return _graphicsManager->getDefaultGraphicsMode();
}
2020-10-09 17:04:07 +00:00
bool ModularGraphicsBackend::setGraphicsMode(int mode, uint flags) {
return _graphicsManager->setGraphicsMode(mode, flags);
}
int ModularGraphicsBackend::getGraphicsMode() const {
return _graphicsManager->getGraphicsMode();
}
#if defined(USE_IMGUI)
void ModularGraphicsBackend::setImGuiCallbacks(const ImGuiCallbacks &callbacks) {
_graphicsManager->setImGuiCallbacks(callbacks);
}
#endif
bool ModularGraphicsBackend::setShader(const Common::Path &fileName) {
return _graphicsManager->setShader(fileName);
}
const OSystem::GraphicsMode *ModularGraphicsBackend::getSupportedStretchModes() const {
2018-07-01 18:24:25 +00:00
return _graphicsManager->getSupportedStretchModes();
}
int ModularGraphicsBackend::getDefaultStretchMode() const {
2018-07-01 18:24:25 +00:00
return _graphicsManager->getDefaultStretchMode();
}
bool ModularGraphicsBackend::setStretchMode(int mode) {
2018-07-01 18:24:25 +00:00
return _graphicsManager->setStretchMode(mode);
}
int ModularGraphicsBackend::getStretchMode() const {
2018-07-01 18:24:25 +00:00
return _graphicsManager->getStretchMode();
}
uint ModularGraphicsBackend::getDefaultScaler() const {
return _graphicsManager->getDefaultScaler();
}
uint ModularGraphicsBackend::getDefaultScaleFactor() const {
return _graphicsManager->getDefaultScaleFactor();
}
bool ModularGraphicsBackend::setScaler(uint mode, int factor) {
return _graphicsManager->setScaler(mode, factor);
}
uint ModularGraphicsBackend::getScaler() const {
return _graphicsManager->getScaler();
}
uint ModularGraphicsBackend::getScaleFactor() const {
return _graphicsManager->getScaleFactor();
}
#ifdef USE_RGB_COLOR
Graphics::PixelFormat ModularGraphicsBackend::getScreenFormat() const {
return _graphicsManager->getScreenFormat();
}
Common::List<Graphics::PixelFormat> ModularGraphicsBackend::getSupportedFormats() const {
return _graphicsManager->getSupportedFormats();
}
#endif
void ModularGraphicsBackend::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
_graphicsManager->initSize(w, h, format);
}
void ModularGraphicsBackend::initSizeHint(const Graphics::ModeList &modes) {
_graphicsManager->initSizeHint(modes);
}
int ModularGraphicsBackend::getScreenChangeID() const {
return _graphicsManager->getScreenChangeID();
}
void ModularGraphicsBackend::beginGFXTransaction() {
_graphicsManager->beginGFXTransaction();
}
OSystem::TransactionError ModularGraphicsBackend::endGFXTransaction() {
return _graphicsManager->endGFXTransaction();
}
int16 ModularGraphicsBackend::getHeight() {
return _graphicsManager->getHeight();
}
int16 ModularGraphicsBackend::getWidth() {
return _graphicsManager->getWidth();
}
PaletteManager *ModularGraphicsBackend::getPaletteManager() {
return _graphicsManager;
}
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 *ModularGraphicsBackend::lockScreen() {
return _graphicsManager->lockScreen();
}
void ModularGraphicsBackend::unlockScreen() {
_graphicsManager->unlockScreen();
}
void ModularGraphicsBackend::fillScreen(uint32 col) {
_graphicsManager->fillScreen(col);
}
void ModularGraphicsBackend::fillScreen(const Common::Rect &r, uint32 col) {
_graphicsManager->fillScreen(r, col);
}
void ModularGraphicsBackend::updateScreen() {
#ifdef ENABLE_EVENTRECORDER
g_system->getMillis(); // force event recorder to update the tick count
g_eventRec.processScreenUpdate();
2013-05-16 21:18:09 +00:00
g_eventRec.preDrawOverlayGui();
#endif
_graphicsManager->updateScreen();
#ifdef ENABLE_EVENTRECORDER
2013-05-16 21:18:09 +00:00
g_eventRec.postDrawOverlayGui();
#endif
}
void ModularGraphicsBackend::setShakePos(int shakeXOffset, int shakeYOffset) {
_graphicsManager->setShakePos(shakeXOffset, shakeYOffset);
}
void ModularGraphicsBackend::setFocusRectangle(const Common::Rect& rect) {
_graphicsManager->setFocusRectangle(rect);
}
void ModularGraphicsBackend::clearFocusRectangle() {
_graphicsManager->clearFocusRectangle();
}
void ModularGraphicsBackend::showOverlay(bool inGUI) {
_graphicsManager->showOverlay(inGUI);
}
void ModularGraphicsBackend::hideOverlay() {
_graphicsManager->hideOverlay();
}
bool ModularGraphicsBackend::isOverlayVisible() const {
return _graphicsManager->isOverlayVisible();
}
Graphics::PixelFormat ModularGraphicsBackend::getOverlayFormat() const {
return _graphicsManager->getOverlayFormat();
}
void ModularGraphicsBackend::clearOverlay() {
_graphicsManager->clearOverlay();
}
BACKENDS: fixed segfault in EventRecorder with buffer out of bounds writes ==3124361== Invalid write of size 8 ==3124361== at 0x483F803: memmove (vg_replace_strmem.c:1270) ==3124361== by 0x4DBF61: SurfaceSdlGraphicsManager::grabOverlay(void*, int) const (surfacesdl-graphics.cpp:1753) ==3124361== by 0x482051: ModularGraphicsBackend::grabOverlay(void*, int) (modular-backend.cpp:215) ==3124361== by 0x434EE1: GUI::ThemeEngine::clearAll() (ThemeEngine.cpp:376) ==3124361== by 0x40128E: GUI::EventRecorder::preDrawOverlayGui() (EventRecorder.cpp:558) ==3124361== by 0x481DB2: ModularGraphicsBackend::updateScreen() (modular-backend.cpp:173) ==3124361== by 0x559967: Graphics::Screen::updateScreen() (screen.cpp:62) ==3124361== by 0x55991C: Graphics::Screen::update() (screen.cpp:56) ==3124361== by 0x38AFC7: TwinE::TwineScreen::update() (twine.cpp:126) ==3124361== by 0x3B8759: TwinE::Screens::adjustPalette(unsigned char, unsigned char, unsigned char, unsigned int const*, int) (screens.cpp:150) ==3124361== by 0x3B8A89: TwinE::Screens::fadeToPal(unsigned int const*) (screens.cpp:207) ==3124361== by 0x3B8403: TwinE::Screens::loadImage(int, int, bool) (screens.cpp:80) ==3124361== Address 0x31453050 is 16 bytes after a block of size 512,000 alloc'd ==3124361== at 0x483AB65: calloc (vg_replace_malloc.c:760) ==3124361== by 0x55B38C: Graphics::Surface::create(unsigned short, unsigned short, Graphics::PixelFormat const&) (surface.cpp:75) ==3124361== by 0x551111: Graphics::ManagedSurface::create(unsigned short, unsigned short, Graphics::PixelFormat const&) (managed_surface.cpp:153) ==3124361== by 0x4352D5: GUI::ThemeEngine::setGraphicsMode(GUI::ThemeEngine::GraphicsMode) (ThemeEngine.cpp:453) ==3124361== by 0x434A52: GUI::ThemeEngine::init() (ThemeEngine.cpp:324) ==3124361== by 0x43501B: GUI::ThemeEngine::refresh() (ThemeEngine.cpp:394) ==3124361== by 0x405780: GUI::GuiManager::screenChange() (gui-manager.cpp:603) ==3124361== by 0x405C6B: GUI::GuiManager::processEvent(Common::Event const&, GUI::Dialog*) (gui-manager.cpp:677) ==3124361== by 0x404EBA: GUI::GuiManager::runLoop() (gui-manager.cpp:429) ==3124361== by 0x3FD847: GUI::Dialog::runModal() (dialog.cpp:77) ==3124361== by 0x36D747: launcherDialog() (main.cpp:106) ==3124361== by 0x36FF92: scummvm_main (main.cpp:552) It looks like the _videoMode.overlayHeight in SurfaceSdlGraphicsManager::grabOverlay and ThemeEngine::_backBuffer::h are somehow out of sync after starting the game in a different resolution as the gui was started with. So the overlayHeight is updated - but the backbuffer (Surface) is not resized. This is with event recorder being active - right after starting the game and switching the resolution.
2021-06-16 18:05:03 +00:00
void ModularGraphicsBackend::grabOverlay(Graphics::Surface &surface) {
_graphicsManager->grabOverlay(surface);
}
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 ModularGraphicsBackend::getOverlayHeight() {
return _graphicsManager->getOverlayHeight();
}
int16 ModularGraphicsBackend::getOverlayWidth() {
return _graphicsManager->getOverlayWidth();
}
float ModularGraphicsBackend::getHiDPIScreenFactor() const {
return _graphicsManager->getHiDPIScreenFactor();
}
bool ModularGraphicsBackend::showMouse(bool visible) {
return _graphicsManager->showMouse(visible);
}
bool ModularGraphicsBackend::lockMouse(bool visible) {
return _graphicsManager->lockMouse(visible);
}
void ModularGraphicsBackend::warpMouse(int x, int y) {
#ifdef ENABLE_EVENTRECORDER
// short circuit for EventRecorder calling warpMouse inside an event poll
if ((g_eventRec.getRecordMode() == GUI::EventRecorder::kRecorderPlayback) ||
(g_eventRec.getRecordMode() == GUI::EventRecorder::kRecorderUpdate)) {
_graphicsManager->warpMouse(x, y);
return;
}
#endif
_eventManager->purgeMouseEvents();
_graphicsManager->warpMouse(x, y);
}
void ModularGraphicsBackend::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
_graphicsManager->setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format, mask);
}
void ModularGraphicsBackend::setCursorPalette(const byte *colors, uint start, uint num) {
_graphicsManager->setCursorPalette(colors, start, num);
}
void ModularGraphicsBackend::displayMessageOnOSD(const Common::U32String &msg) {
_graphicsManager->displayMessageOnOSD(msg);
}
void ModularGraphicsBackend::displayActivityIconOnOSD(const Graphics::Surface *icon) {
_graphicsManager->displayActivityIconOnOSD(icon);
}
void ModularGraphicsBackend::saveScreenshot() {
_graphicsManager->saveScreenshot();
}
ModularMixerBackend::ModularMixerBackend()
:
_mixerManager(nullptr) {
}
ModularMixerBackend::~ModularMixerBackend() {
// _audiocdManager needs to be deleted before _mixerManager to avoid a crash.
delete _audiocdManager;
_audiocdManager = nullptr;
delete _mixerManager;
_mixerManager = nullptr;
}
MixerManager *ModularMixerBackend::getMixerManager() {
assert(_mixerManager);
return _mixerManager;
}
Audio::Mixer *ModularMixerBackend::getMixer() {
assert(_mixerManager);
return getMixerManager()->getMixer();
}