2011-08-08 21:43:53 +02:00
|
|
|
/* 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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-08-08 21:43:53 +02:00
|
|
|
* 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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-08-08 21:43:53 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "backends/graphics/sdl/sdl-graphics.h"
|
2015-01-24 23:42:12 +01:00
|
|
|
#include "backends/platform/sdl/sdl-sys.h"
|
2011-08-08 21:43:53 +02:00
|
|
|
#include "backends/events/sdl/sdl-events.h"
|
2017-10-01 16:23:22 -05:00
|
|
|
#include "common/config-manager.h"
|
2015-01-24 23:42:12 +01:00
|
|
|
#include "common/textconsole.h"
|
2017-10-01 16:23:22 -05:00
|
|
|
#include "graphics/scaler/aspect.h"
|
2011-08-08 21:43:53 +02:00
|
|
|
|
2015-02-16 00:49:42 +01:00
|
|
|
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
|
2017-08-27 22:21:05 -05:00
|
|
|
: _eventSource(source), _window(window)
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2017-10-01 16:23:22 -05:00
|
|
|
, _allowWindowSizeReset(false), _hintedWidth(0), _hintedHeight(0), _lastFlags(0)
|
2017-08-27 22:21:05 -05:00
|
|
|
#endif
|
|
|
|
{
|
2011-08-08 21:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SdlGraphicsManager::~SdlGraphicsManager() {
|
|
|
|
}
|
|
|
|
|
2013-10-24 00:09:17 +02:00
|
|
|
void SdlGraphicsManager::activateManager() {
|
2013-10-20 22:27:50 +02:00
|
|
|
_eventSource->setGraphicsManager(this);
|
|
|
|
}
|
|
|
|
|
2013-10-24 00:09:17 +02:00
|
|
|
void SdlGraphicsManager::deactivateManager() {
|
2013-10-20 22:27:50 +02:00
|
|
|
_eventSource->setGraphicsManager(0);
|
|
|
|
}
|
2015-01-24 23:42:12 +01:00
|
|
|
|
2015-01-25 19:23:06 +01:00
|
|
|
SdlGraphicsManager::State SdlGraphicsManager::getState() {
|
|
|
|
State state;
|
|
|
|
|
|
|
|
state.screenWidth = getWidth();
|
|
|
|
state.screenHeight = getHeight();
|
|
|
|
state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection);
|
|
|
|
state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode);
|
|
|
|
state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette);
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
state.pixelFormat = getScreenFormat();
|
|
|
|
#endif
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SdlGraphicsManager::setState(const State &state) {
|
|
|
|
beginGFXTransaction();
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
|
|
|
|
#else
|
2017-10-01 16:23:22 -05:00
|
|
|
initSize(state.screenWidth, state.screenHeight, nullptr);
|
2015-01-25 19:23:06 +01:00
|
|
|
#endif
|
|
|
|
setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio);
|
|
|
|
setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen);
|
|
|
|
setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette);
|
|
|
|
|
|
|
|
if (endGFXTransaction() != OSystem::kTransactionSuccess) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 01:34:57 +01:00
|
|
|
|
2017-10-01 16:23:22 -05:00
|
|
|
bool SdlGraphicsManager::defaultGraphicsModeConfig() const {
|
|
|
|
const Common::ConfigManager::Domain *transientDomain = ConfMan.getDomain(Common::ConfigManager::kTransientDomain);
|
|
|
|
if (transientDomain && transientDomain->contains("gfx_mode")) {
|
|
|
|
const Common::String &mode = transientDomain->getVal("gfx_mode");
|
|
|
|
if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Common::ConfigManager::Domain *gameDomain = ConfMan.getActiveDomain();
|
|
|
|
if (gameDomain && gameDomain->contains("gfx_mode")) {
|
|
|
|
const Common::String &mode = gameDomain->getVal("gfx_mode");
|
|
|
|
if (!mode.equalsIgnoreCase("normal") && !mode.equalsIgnoreCase("default")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SdlGraphicsManager::getGraphicsModeIdByName(const Common::String &name) const {
|
|
|
|
const OSystem::GraphicsMode *mode = getSupportedGraphicsModes();
|
|
|
|
while (mode && mode->name != nullptr) {
|
|
|
|
if (name.equalsIgnoreCase(mode->name)) {
|
|
|
|
return mode->id;
|
|
|
|
}
|
|
|
|
++mode;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SdlGraphicsManager::initSizeHint(const Graphics::ModeList &modes) {
|
2017-08-27 22:21:05 -05:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
2017-10-01 16:23:22 -05:00
|
|
|
const bool useDefault = defaultGraphicsModeConfig();
|
|
|
|
|
|
|
|
int scale = getGraphicsModeScale(getGraphicsModeIdByName(ConfMan.get("gfx_mode")));
|
|
|
|
if (scale == -1) {
|
|
|
|
warning("Unknown scaler; defaulting to 1");
|
|
|
|
scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 bestWidth = 0, bestHeight = 0;
|
|
|
|
const Graphics::ModeList::const_iterator end = modes.end();
|
|
|
|
for (Graphics::ModeList::const_iterator it = modes.begin(); it != end; ++it) {
|
|
|
|
int16 width = it->width, height = it->height;
|
|
|
|
|
|
|
|
// TODO: Normalize AR correction by passing a PAR in the mode list
|
|
|
|
// instead of checking the dimensions here like this, since not all
|
|
|
|
// 320x200/640x400 uses are with non-square pixels (e.g. DreamWeb).
|
|
|
|
if (ConfMan.getBool("aspect_ratio")) {
|
|
|
|
if ((width == 320 && height == 200) || (width == 640 && height == 400)) {
|
|
|
|
height = real2Aspect(height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!useDefault || width <= 320) {
|
|
|
|
width *= scale;
|
|
|
|
height *= scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bestWidth < width) {
|
|
|
|
bestWidth = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bestHeight < height) {
|
|
|
|
bestHeight = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_hintedWidth = bestWidth;
|
|
|
|
_hintedHeight = bestHeight;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
bool SdlGraphicsManager::createOrUpdateWindow(int width, int height, const Uint32 flags) {
|
2017-08-27 22:21:05 -05:00
|
|
|
if (!_window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only update the actual window when flags change (which usually means
|
|
|
|
// fullscreen mode is entered/exited) or when updates are forced so that we
|
|
|
|
// do not reset the window size whenever a game makes a call to change the
|
|
|
|
// size or pixel format of the internal game surface (since a user may have
|
|
|
|
// resized the game window)
|
|
|
|
if (!_window->getSDLWindow() || _lastFlags != flags || _allowWindowSizeReset) {
|
2017-10-01 16:23:22 -05:00
|
|
|
if (_hintedWidth) {
|
|
|
|
width = _hintedWidth;
|
|
|
|
}
|
|
|
|
if (_hintedHeight) {
|
|
|
|
height = _hintedHeight;
|
|
|
|
}
|
|
|
|
|
2017-08-27 22:21:05 -05:00
|
|
|
if (!_window->createOrUpdateWindow(width, height, flags)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_lastFlags = flags;
|
|
|
|
_allowWindowSizeReset = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|