Ticket #8926: sdl_transaction_rollback_v3.2.patch
File sdl_transaction_rollback_v3.2.patch, 57.0 KB (added by , 15 years ago) |
---|
-
engines/sword1/sword1.cpp
78 78 79 79 Common::Error SwordEngine::init() { 80 80 81 _system->beginGFXTransaction(); 82 initCommonGFX(true); 83 _system->initSize(640, 480); 84 _system->endGFXTransaction(); 81 initGraphics(640, 480, true); 85 82 86 83 if ( 0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword1mac") || 87 84 0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword1macdemo") ) -
engines/m4/m4.cpp
143 143 144 144 Common::Error M4Engine::init() { 145 145 // Initialize backend 146 _system->beginGFXTransaction();147 initCommonGFX(isM4());148 146 if (isM4()) 149 _system->initSize(640, 480);147 initGraphics(640, 480, true); 150 148 else 151 _system->initSize(320, 200); 152 _system->endGFXTransaction(); 149 initGraphics(320, 200, false); 153 150 154 151 _screen = new M4Surface(true); // Special form for creating screen reference 155 152 -
engines/sword2/sword2.cpp
371 371 _resman = NULL; 372 372 _memory = NULL; 373 373 374 _system->beginGFXTransaction(); 375 initCommonGFX(true); 376 _screen = new Screen(this, 640, 480); 377 _system->endGFXTransaction(); 374 initGraphics(640, 480, true); 375 _screen = new Screen(this, 640, 480); 378 376 379 377 // Create the debugger as early as possible (but not before the 380 378 // screen object!) so that errors can be displayed in it. In -
engines/sword2/screen.cpp
52 52 53 53 _dirtyGrid = _buffer = NULL; 54 54 55 _vm->_system->initSize(width, height);56 57 55 _screenWide = width; 58 56 _screenDeep = height; 59 57 -
engines/scumm/scumm.cpp
822 822 } 823 823 824 824 Common::Error ScummEngine_vCUPhe::init() { 825 _system->beginGFXTransaction(); 826 _system->initSize(CUP_Player::kDefaultVideoWidth, CUP_Player::kDefaultVideoHeight); 827 initCommonGFX(true); 828 _system->endGFXTransaction(); 825 initGraphics(CUP_Player::kDefaultVideoWidth, CUP_Player::kDefaultVideoHeight, true); 829 826 830 827 return Common::kNoError; 831 828 } … … 1069 1066 loadCJKFont(); 1070 1067 1071 1068 // Initialize backend 1072 _system->beginGFXTransaction(); 1073 bool defaultTo1XScaler = false; 1074 if (_renderMode == Common::kRenderHercA || _renderMode == Common::kRenderHercG) { 1075 _system->initSize(Common::kHercW, Common::kHercH); 1076 defaultTo1XScaler = true; 1077 } else if (_useCJKMode) { 1078 _system->initSize(_screenWidth * _textSurfaceMultiplier, _screenHeight * _textSurfaceMultiplier); 1069 if (_renderMode == Common::kRenderHercA || _renderMode == Common::kRenderHercG) { 1070 initGraphics(Common::kHercW, Common::kHercH, true); 1071 } else if (_useCJKMode) { 1072 initGraphics(_screenWidth * _textSurfaceMultiplier, _screenHeight * _textSurfaceMultiplier, 1073 // CJK FT and DIG use usual NUT fonts, not FM-TOWNS ROM, so 1074 // there is no text surface for them. This takes that into account 1075 (_screenWidth * _textSurfaceMultiplier > 320)); 1076 } else { 1077 initGraphics(_screenWidth, _screenHeight, _screenWidth > 320); 1078 } 1079 1079 1080 // CJK FT and DIG use usual NUT fonts, not FM-TOWNS ROM, so1081 // there is no text surface for them. This takes that into account1082 defaultTo1XScaler = (_screenWidth * _textSurfaceMultiplier > 320);1083 } else {1084 _system->initSize(_screenWidth, _screenHeight);1085 defaultTo1XScaler = (_screenWidth > 320);1086 }1087 initCommonGFX(defaultTo1XScaler);1088 _system->endGFXTransaction();1089 1090 1080 setupScumm(); 1091 1081 1092 1082 readIndexFile(); -
engines/engine.cpp
125 125 g_system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen")); 126 126 } 127 127 128 void initGraphics(int width, int height, bool defaultTo1xScaler) { 129 g_system->beginGFXTransaction(); 130 131 initCommonGFX(defaultTo1xScaler); 132 g_system->initSize(width, height); 133 134 OSystem::TransactionError gfxError = g_system->endGFXTransaction(); 135 136 if (gfxError == OSystem::kTransactionSuccess) 137 return; 138 139 // Error out on size switch failure 140 if (gfxError & OSystem::kTransactionSizeChangeFailed) { 141 char buffer[16]; 142 snprintf(buffer, 16, "%dx%d", width, height); 143 144 Common::String message = "Could not switch to resolution: '"; 145 message += buffer; 146 message += "'."; 147 148 GUIErrorMessage(message); 149 error(message.c_str()); 150 } 151 152 // Just show warnings then these occur: 153 if (gfxError & OSystem::kTransactionModeSwitchFailed) { 154 Common::String message = "Could not switch to video mode: '"; 155 message += ConfMan.get("gfx_mode"); 156 message += "'."; 157 158 GUI::MessageDialog dialog(message); 159 dialog.runModal(); 160 } 161 162 if (gfxError & OSystem::kTransactionAspectRatioFailed) { 163 GUI::MessageDialog dialog("Could not apply aspect ratio setting."); 164 dialog.runModal(); 165 } 166 167 if (gfxError & OSystem::kTransactionFullscreenFailed) { 168 GUI::MessageDialog dialog("Could not apply fullscreen setting."); 169 dialog.runModal(); 170 } 171 } 172 128 173 void GUIErrorMessage(const Common::String msg) { 129 174 g_system->setWindowCaption("Error"); 130 175 g_system->beginGFXTransaction(); 131 176 initCommonGFX(false); 132 177 g_system->initSize(320, 200); 133 g_system->endGFXTransaction(); 134 135 GUI::MessageDialog dialog(msg); 136 dialog.runModal(); 178 if (g_system->endGFXTransaction() == OSystem::kTransactionSuccess) { 179 GUI::MessageDialog dialog(msg); 180 dialog.runModal(); 181 } else { 182 error(msg.c_str()); 183 } 137 184 } 138 185 139 186 void Engine::checkCD() { -
engines/touche/touche.cpp
82 82 } 83 83 84 84 Common::Error ToucheEngine::init() { 85 _system->beginGFXTransaction(); 86 initCommonGFX(true); 87 _system->initSize(kScreenWidth, kScreenHeight); 88 _system->endGFXTransaction(); 85 initGraphics(kScreenWidth, kScreenHeight, true); 89 86 90 87 Graphics::setupFont(_language); 91 88 -
engines/agos/agos.cpp
540 540 _screenHeight = 200; 541 541 } 542 542 543 _system->beginGFXTransaction(); 544 initCommonGFX(getGameType() == GType_FF || getGameType() == GType_PP); 545 _system->initSize(_screenWidth, _screenHeight); 546 _system->endGFXTransaction(); 543 initGraphics(_screenWidth, _screenHeight, getGameType() == GType_FF || getGameType() == GType_PP); 547 544 548 545 // Setup mixer 549 546 _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); -
engines/cruise/cruise.cpp
72 72 73 73 Common::Error CruiseEngine::init() { 74 74 // Initialize backend 75 _system->beginGFXTransaction(); 76 initCommonGFX(false); 77 _system->initSize(320, 200); 78 _system->endGFXTransaction(); 75 initGraphics(320, 200, false); 79 76 80 77 initialize(); 81 78 -
engines/engine.h
51 51 void initCommonGFX(bool defaultTo1XScaler); 52 52 53 53 /** 54 * Initialized graphics and shows error message. 54 * Setup the backend's screen size and graphics mode. 55 * 56 * Shows an various warnings on certain backend graphics 57 * transaction failures (aspect switch, fullscreen switch, etc.). 58 * 59 * Errors out when backend is not able to switch to the specified 60 * mode. 55 61 */ 62 void initGraphics(int width, int height, bool defaultTo1xScaler); 63 64 /** 65 * Initializes graphics and shows error message. 66 */ 56 67 void GUIErrorMessage(const Common::String msg); 57 68 58 69 -
engines/tucker/tucker.cpp
42 42 } 43 43 44 44 Common::Error TuckerEngine::init() { 45 _system->beginGFXTransaction(); 46 initCommonGFX(false); 47 _system->initSize(320, 200); 48 _system->endGFXTransaction(); 45 initGraphics(320, 200, false); 49 46 50 47 _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); 51 48 _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); -
engines/drascula/drascula.cpp
106 106 107 107 Common::Error DrasculaEngine::init() { 108 108 // Initialize backend 109 _system->beginGFXTransaction(); 110 initCommonGFX(false); 111 _system->initSize(320, 200); 112 _system->endGFXTransaction(); 109 initGraphics(320, 200, false); 113 110 114 111 switch (getLanguage()) { 115 112 case Common::EN_ANY: -
engines/tinsel/tinsel.cpp
660 660 661 661 Common::Error TinselEngine::init() { 662 662 // Initialize backend 663 _system->beginGFXTransaction(); 664 initCommonGFX(false); 665 _system->initSize(SCREEN_WIDTH, SCREEN_HEIGHT); 666 _system->endGFXTransaction(); 663 initGraphics(SCREEN_WIDTH, SCREEN_HEIGHT, false); 667 664 668 665 _screenSurface.create(SCREEN_WIDTH, SCREEN_HEIGHT, 1); 669 666 -
engines/agi/agi.cpp
782 782 Common::Error AgiBase::init() { 783 783 784 784 // Initialize backend 785 _system->beginGFXTransaction(); 786 initCommonGFX(false); 787 _system->initSize(320, 200); 788 _system->endGFXTransaction(); 785 initGraphics(320, 200, false); 789 786 790 787 initialize(); 791 788 -
engines/igor/igor.cpp
89 89 } 90 90 91 91 Common::Error IgorEngine::init() { 92 _system->beginGFXTransaction(); 93 initCommonGFX(false); 94 _system->initSize(320, 200); 95 _system->endGFXTransaction(); 92 initGraphics(320, 200, false); 96 93 97 94 _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); 98 95 return Common::kNoError; -
engines/sky/sky.cpp
238 238 } 239 239 240 240 Common::Error SkyEngine::init() { 241 _system->beginGFXTransaction(); 242 initCommonGFX(false); 243 _system->initSize(320, 200); 244 _system->endGFXTransaction(); 241 initGraphics(320, 200, false); 245 242 246 243 if (ConfMan.getBool("sfx_mute")) { 247 244 SkyEngine::_systemVars.systemFlags |= SF_FX_OFF; -
engines/made/made.cpp
130 130 131 131 Common::Error MadeEngine::init() { 132 132 // Initialize backend 133 _system->beginGFXTransaction(); 134 initCommonGFX(false); 135 _system->initSize(320, 200); 136 _system->endGFXTransaction(); 133 initGraphics(320, 200, false); 137 134 138 135 return Common::kNoError; 139 136 } -
engines/kyra/screen.cpp
186 186 byte palette[4*256]; 187 187 _system->grabPalette(palette, 0, 256); 188 188 189 int width = 320, height = 200; 190 bool defaultTo1xScaler = false; 191 189 192 if (_vm->gameFlags().useHiResOverlay) { 190 _system->beginGFXTransaction();191 if (_debugEnabled)192 _system->initSize(960, 400); 193 else194 _system->initSize(640, 400);195 initCommonGFX(true);196 _system->endGFXTransaction();193 defaultTo1xScaler = true; 194 height = 400; 195 196 if (_debugEnabled) 197 width = 960; 198 else 199 width = 640; 197 200 } else { 198 _system->beginGFXTransaction(); 199 if (_debugEnabled) 200 _system->initSize(640, 200); 201 else 202 _system->initSize(320, 200); 203 initCommonGFX(false); 204 _system->endGFXTransaction(); 201 if (_debugEnabled) 202 width = 640; 203 else 204 width = 320; 205 205 } 206 206 207 initGraphics(width, height, defaultTo1xScaler); 208 207 209 _system->setPalette(palette, 0, 256); 208 210 } 209 211 -
engines/lure/lure.cpp
52 52 int_engine = this; 53 53 _initialised = false; 54 54 55 _system->beginGFXTransaction(); 56 initCommonGFX(false); 57 _system->initSize(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT); 58 _system->endGFXTransaction(); 55 initGraphics(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT, false); 59 56 60 57 // Check the version of the lure.dat file 61 58 Common::File f; -
engines/gob/video.cpp
169 169 } 170 170 171 171 void Video::setSize(bool defaultTo1XScaler) { 172 _vm->_system->beginGFXTransaction(); 173 _vm->_system->initSize(_vm->_width, _vm->_height); 174 initCommonGFX(defaultTo1XScaler); 175 _vm->_system->endGFXTransaction(); 172 initGraphics(_vm->_width, _vm->_height, defaultTo1XScaler); 176 173 } 177 174 178 175 void Video::retrace(bool mouse) { -
engines/parallaction/graphics.cpp
749 749 Gfx::Gfx(Parallaction* vm) : 750 750 _vm(vm), _disk(vm->_disk) { 751 751 752 _vm->_system->beginGFXTransaction(); 753 _vm->_system->initSize(_vm->_screenWidth, _vm->_screenHeight); 754 initCommonGFX(_vm->getGameType() == GType_BRA); 755 _vm->_system->endGFXTransaction(); 752 initGraphics(_vm->_screenWidth, _vm->_screenHeight, _vm->getGameType() == GType_BRA); 756 753 757 754 setPalette(_palette); 758 755 -
engines/saga/gfx.cpp
40 40 #define RID_IHNM_HOURGLASS_CURSOR 11 // not in demo 41 41 42 42 Gfx::Gfx(SagaEngine *vm, OSystem *system, int width, int height) : _vm(vm), _system(system) { 43 _system->beginGFXTransaction(); 44 initCommonGFX(width > 320); 45 _system->initSize(width, height); 46 _system->endGFXTransaction(); 43 initGraphics(width, height, width > 320); 47 44 48 45 debug(5, "Init screen %dx%d", width, height); 49 46 // Convert surface data to R surface data -
engines/queen/queen.cpp
473 473 } 474 474 475 475 Common::Error QueenEngine::init() { 476 _system->beginGFXTransaction(); 477 initCommonGFX(false); 478 _system->initSize(GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT); 479 _system->endGFXTransaction(); 476 initGraphics(GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, false); 480 477 481 478 _resource = new Resource(); 482 479 -
engines/cine/cine.cpp
76 76 77 77 Common::Error CineEngine::init() { 78 78 // Initialize backend 79 _system->beginGFXTransaction(); 80 initCommonGFX(false); 81 _system->initSize(320, 200); 82 _system->endGFXTransaction(); 79 initGraphics(320, 200, false); 83 80 84 81 if (g_cine->getPlatform() == Common::kPlatformPC) { 85 82 g_sound = new PCSound(_mixer, this); -
common/system.h
393 393 */ 394 394 virtual void beginGFXTransaction() {} 395 395 396 /** 397 * This type is able to save the different errors which can happen while 398 * changing GFX config values inside GFX transactions. 399 * 400 * endGFXTransaction returns a ORed combination of the '*Failed' values 401 * if any problem occures, on success 0. 402 * 403 * @see endGFXTransaction 404 */ 405 enum TransactionError { 406 kTransactionSuccess = 0, /**< Everything fine (use EQUAL check for this one!) */ 407 kTransactionAspectRatioFailed = (1 << 0), /**< Failed switchting aspect ratio correction mode */ 408 kTransactionFullscreenFailed = (1 << 1), /**< Failed switchting fullscreen mode */ 409 kTransactionModeSwitchFailed = (1 << 2), /**< Failed switchting the GFX graphics mode (setGraphicsMode) */ 410 kTransactionSizeChangeFailed = (1 << 3) /**< Failed switchting the screen dimensions (initSize) */ 411 }; 396 412 397 413 /** 398 414 * End (and thereby commit) the current GFX transaction. 399 415 * @see beginGFXTransaction 416 * @see kTransactionError 417 * @return returns a ORed combination of TransactionError values or 0 on success 400 418 */ 401 virtual void endGFXTransaction() {}419 virtual TransactionError endGFXTransaction() { return kTransactionSuccess; } 402 420 403 421 404 422 /** -
backends/platform/sdl/graphics.cpp
49 49 }; 50 50 51 51 // Table of relative scalers magnitudes 52 // [definedScale - 1][ _scaleFactor - 1]52 // [definedScale - 1][scaleFactor - 1] 53 53 static ScalerProc *scalersMagn[3][3] = { 54 54 #ifndef DISABLE_SCALERS 55 55 { Normal1x, AdvMame2x, AdvMame3x }, … … 86 86 } 87 87 88 88 void OSystem_SDL::beginGFXTransaction(void) { 89 assert 89 assert(_transactionMode == kTransactionNone); 90 90 91 91 _transactionMode = kTransactionActive; 92 92 93 _transactionDetails.modeChanged = false;94 93 _transactionDetails.sizeChanged = false; 95 _transactionDetails.arChanged = false;96 _transactionDetails.fsChanged = false;97 94 98 95 _transactionDetails.needHotswap = false; 99 96 _transactionDetails.needUpdatescreen = false; 100 _transactionDetails.needUnload = false;101 97 102 98 _transactionDetails.normal1xScaler = false; 99 100 _oldVideoMode = _videoMode; 103 101 } 104 102 105 void OSystem_SDL::endGFXTransaction(void) { 106 // for each engine we run initCommonGFX() as first thing in the transaction 107 // and initSize() is called later. If user runs launcher at 320x200 with 108 // 2x overlay, setting to Nomral1x sclaler in that case will be suppressed 109 // and backend is forced to 2x 110 // 111 // This leads to bad results such as 1280x960 window for 640x480 engines. 112 // To prevent that we rerun setGraphicsMode() if there was 1x scaler request 113 if (_transactionDetails.normal1xScaler) 114 setGraphicsMode(GFX_NORMAL); 103 OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { 104 int errors = kTransactionSuccess; 115 105 116 assert (_transactionMode == kTransactionActive);106 assert(_transactionMode != kTransactionNone); 117 107 118 _transactionMode = kTransactionCommit;119 if (_transactionDetails.modeChanged)120 setGraphicsMode(_transactionDetails.mode);108 if (_transactionMode == kTransactionRollback) { 109 if (_videoMode.fullscreen != _oldVideoMode.fullscreen) { 110 errors |= kTransactionFullscreenFailed; 121 111 122 if (_transactionDetails.sizeChanged) 123 initSize(_transactionDetails.w, _transactionDetails.h); 112 _videoMode.fullscreen = _oldVideoMode.fullscreen; 113 } else if (_videoMode.aspectRatio != _oldVideoMode.aspectRatio) { 114 errors |= kTransactionAspectRatioFailed; 124 115 125 if (_transactionDetails.arChanged) 126 setAspectRatioCorrection(_transactionDetails.ar); 116 _videoMode.aspectRatio = _oldVideoMode.aspectRatio; 117 } else if (_videoMode.mode != _oldVideoMode.mode) { 118 errors |= kTransactionModeSwitchFailed; 127 119 128 if (_transactionDetails.needUnload) { 120 _videoMode.mode = _oldVideoMode.mode; 121 _videoMode.scaleFactor = _oldVideoMode.scaleFactor; 122 } else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) { 123 errors |= kTransactionSizeChangeFailed; 124 125 _videoMode.screenWidth = _oldVideoMode.screenWidth; 126 _videoMode.screenHeight = _oldVideoMode.screenHeight; 127 _videoMode.overlayWidth = _oldVideoMode.overlayWidth; 128 _videoMode.overlayHeight = _oldVideoMode.overlayHeight; 129 } 130 131 if (_videoMode.fullscreen == _oldVideoMode.fullscreen && 132 _videoMode.aspectRatio == _oldVideoMode.aspectRatio && 133 _videoMode.mode == _oldVideoMode.mode && 134 _videoMode.screenWidth == _oldVideoMode.screenWidth && 135 _videoMode.screenHeight == _oldVideoMode.screenHeight) { 136 137 // Our new video mode would now be exactly the same as the 138 // old one. Since we still can not assume SDL_SetVideoMode 139 // to be working fine, we need to invalidate the old video 140 // mode, so loadGFXMode would error out properly. 141 _oldVideoMode.setup = false; 142 } 143 } 144 145 if (_transactionDetails.sizeChanged) { 129 146 unloadGFXMode(); 130 loadGFXMode(); 131 clearOverlay(); 132 } else { 133 if (!_transactionDetails.fsChanged) { 134 if (_transactionDetails.needHotswap) 135 hotswapGFXMode(); 136 else if (_transactionDetails.needUpdatescreen) 147 if (!loadGFXMode()) { 148 if (_oldVideoMode.setup) { 149 _transactionMode = kTransactionRollback; 150 errors |= endGFXTransaction(); 151 } 152 } else { 153 setGraphicsModeIntern(); 154 clearOverlay(); 155 156 _videoMode.setup = true; 157 _modeChanged = true; 158 } 159 } else if (_transactionDetails.needHotswap) { 160 setGraphicsModeIntern(); 161 if (!hotswapGFXMode()) { 162 if (_oldVideoMode.setup) { 163 _transactionMode = kTransactionRollback; 164 errors |= endGFXTransaction(); 165 } 166 } else { 167 _videoMode.setup = true; 168 _modeChanged = true; 169 170 if (_transactionDetails.needUpdatescreen) 137 171 internUpdateScreen(); 138 172 } 139 173 } 140 174 141 if (_transactionDetails.fsChanged)142 setFullscreenMode(_transactionDetails.fs);143 144 175 _transactionMode = kTransactionNone; 176 return (TransactionError)errors; 145 177 } 146 178 147 179 bool OSystem_SDL::setGraphicsMode(int mode) { 148 180 Common::StackLock lock(_graphicsMutex); 149 181 182 assert(_transactionMode == kTransactionActive); 183 184 if (_oldVideoMode.setup && _oldVideoMode.mode == mode) 185 return true; 186 150 187 int newScaleFactor = 1; 151 ScalerProc *newScalerProc;152 188 153 189 switch(mode) { 154 190 case GFX_NORMAL: 155 191 newScaleFactor = 1; 156 newScalerProc = Normal1x;157 192 break; 158 193 #ifndef DISABLE_SCALERS 159 194 case GFX_DOUBLESIZE: 160 195 newScaleFactor = 2; 161 newScalerProc = Normal2x;162 196 break; 163 197 case GFX_TRIPLESIZE: 164 198 newScaleFactor = 3; 165 newScalerProc = Normal3x;166 199 break; 167 200 168 201 case GFX_2XSAI: 169 202 newScaleFactor = 2; 170 newScalerProc = _2xSaI;171 203 break; 172 204 case GFX_SUPER2XSAI: 173 205 newScaleFactor = 2; 174 newScalerProc = Super2xSaI;175 206 break; 176 207 case GFX_SUPEREAGLE: 177 208 newScaleFactor = 2; 178 newScalerProc = SuperEagle;179 209 break; 180 210 case GFX_ADVMAME2X: 181 211 newScaleFactor = 2; 182 newScalerProc = AdvMame2x;183 212 break; 184 213 case GFX_ADVMAME3X: 185 214 newScaleFactor = 3; 186 newScalerProc = AdvMame3x;187 215 break; 188 216 #ifndef DISABLE_HQ_SCALERS 189 217 case GFX_HQ2X: 190 218 newScaleFactor = 2; 191 newScalerProc = HQ2x;192 219 break; 193 220 case GFX_HQ3X: 194 221 newScaleFactor = 3; 195 newScalerProc = HQ3x;196 222 break; 197 223 #endif 198 224 case GFX_TV2X: 199 225 newScaleFactor = 2; 200 newScalerProc = TV2x;201 226 break; 202 227 case GFX_DOTMATRIX: 203 228 newScaleFactor = 2; 204 newScalerProc = DotMatrix;205 229 break; 206 230 #endif // DISABLE_SCALERS 207 231 … … 211 235 } 212 236 213 237 _transactionDetails.normal1xScaler = (mode == GFX_NORMAL); 238 if (_oldVideoMode.setup && _oldVideoMode.scaleFactor != newScaleFactor) 239 _transactionDetails.needHotswap = true; 214 240 215 _mode = mode; 216 _scalerProc = newScalerProc; 241 _transactionDetails.needUpdatescreen = true; 217 242 218 if (_transactionMode == kTransactionActive) { 219 _transactionDetails.mode = mode; 220 _transactionDetails.modeChanged = true; 243 _videoMode.mode = mode; 244 _videoMode.scaleFactor = newScaleFactor; 221 245 222 if (newScaleFactor != _scaleFactor) { 223 _transactionDetails.needHotswap = true; 224 _scaleFactor = newScaleFactor; 225 } 246 return true; 247 } 226 248 227 _transactionDetails.needUpdatescreen = true; 249 void OSystem_SDL::setGraphicsModeIntern() { 250 Common::StackLock lock(_graphicsMutex); 251 ScalerProc *newScalerProc = 0; 228 252 229 return true; 230 } 253 switch (_videoMode.mode) { 254 case GFX_NORMAL: 255 newScalerProc = Normal1x; 256 break; 257 #ifndef DISABLE_SCALERS 258 case GFX_DOUBLESIZE: 259 newScalerProc = Normal2x; 260 break; 261 case GFX_TRIPLESIZE: 262 newScalerProc = Normal3x; 263 break; 231 264 232 // NOTE: This should not be executed at transaction commit 233 // Otherwise there is some unsolicited setGraphicsMode() call 234 // which should be properly removed 235 if (newScaleFactor != _scaleFactor) { 236 assert(_transactionMode != kTransactionCommit); 265 case GFX_2XSAI: 266 newScalerProc = _2xSaI; 267 break; 268 case GFX_SUPER2XSAI: 269 newScalerProc = Super2xSaI; 270 break; 271 case GFX_SUPEREAGLE: 272 newScalerProc = SuperEagle; 273 break; 274 case GFX_ADVMAME2X: 275 newScalerProc = AdvMame2x; 276 break; 277 case GFX_ADVMAME3X: 278 newScalerProc = AdvMame3x; 279 break; 280 #ifndef DISABLE_HQ_SCALERS 281 case GFX_HQ2X: 282 newScalerProc = HQ2x; 283 break; 284 case GFX_HQ3X: 285 newScalerProc = HQ3x; 286 break; 287 #endif 288 case GFX_TV2X: 289 newScalerProc = TV2x; 290 break; 291 case GFX_DOTMATRIX: 292 newScalerProc = DotMatrix; 293 break; 294 #endif // DISABLE_SCALERS 237 295 238 _scaleFactor = newScaleFactor;239 hotswapGFXMode();296 default: 297 error("Unknown gfx mode %d", _videoMode.mode); 240 298 } 241 299 242 // Determine the "scaler type", i.e. essentially an index into the243 // s_gfxModeSwitchTable array defined in events.cpp.244 if (_ mode != GFX_NORMAL) {300 _scalerProc = newScalerProc; 301 302 if (_videoMode.mode != GFX_NORMAL) { 245 303 for (int i = 0; i < ARRAYSIZE(s_gfxModeSwitchTable); i++) { 246 if (s_gfxModeSwitchTable[i][1] == _ mode || s_gfxModeSwitchTable[i][2] == _mode) {304 if (s_gfxModeSwitchTable[i][1] == _videoMode.mode || s_gfxModeSwitchTable[i][2] == _videoMode.mode) { 247 305 _scalerType = i; 248 306 break; 249 307 } 250 308 } 251 309 } 252 310 253 if (!_screen )254 return true;311 if (!_screen || !_hwscreen) 312 return; 255 313 256 314 // Blit everything to the screen 257 315 _forceFull = true; … … 259 317 // Even if the old and new scale factors are the same, we may have a 260 318 // different scaler for the cursor now. 261 319 blitCursor(); 262 263 if (_transactionMode != kTransactionCommit)264 internUpdateScreen();265 266 // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later267 _modeChanged = true;268 269 return true;270 320 } 271 321 272 322 int OSystem_SDL::getGraphicsMode() const { 273 323 assert (_transactionMode == kTransactionNone); 274 return _ mode;324 return _videoMode.mode; 275 325 } 276 326 277 327 void OSystem_SDL::initSize(uint w, uint h) { 328 assert(_transactionMode == kTransactionActive); 329 278 330 // Avoid redundant res changes 279 if ((int)w == _screenWidth && (int)h == _screenHeight && 280 _transactionMode != kTransactionCommit) 331 if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) 281 332 return; 282 333 283 _ screenWidth = w;284 _ screenHeight = h;334 _videoMode.screenWidth = w; 335 _videoMode.screenHeight = h; 285 336 286 _cksumNum = ( _screenWidth * _screenHeight/ (8 * 8));337 _cksumNum = (w * h / (8 * 8)); 287 338 288 if (_transactionMode == kTransactionActive) { 289 _transactionDetails.w = w; 290 _transactionDetails.h = h; 291 _transactionDetails.sizeChanged = true; 339 _transactionDetails.sizeChanged = true; 292 340 293 _transactionDetails.needUnload = true;294 295 return;296 }297 298 341 free(_dirtyChecksums); 299 342 _dirtyChecksums = (uint32 *)calloc(_cksumNum * 2, sizeof(uint32)); 300 301 if (_transactionMode != kTransactionCommit) {302 unloadGFXMode();303 loadGFXMode();304 305 // if initSize() gets called in the middle, overlay is not transparent306 clearOverlay();307 }308 343 } 309 344 310 voidOSystem_SDL::loadGFXMode() {345 bool OSystem_SDL::loadGFXMode() { 311 346 assert(_inited); 312 347 _forceFull = true; 313 348 314 349 int hwW, hwH; 315 350 316 351 #ifndef __MAEMO__ 317 _ overlayWidth = _screenWidth * _scaleFactor;318 _ overlayHeight = _screenHeight * _scaleFactor;352 _videoMode.overlayWidth = _videoMode.screenWidth * _videoMode.scaleFactor; 353 _videoMode.overlayHeight = _videoMode.screenHeight * _videoMode.scaleFactor; 319 354 320 if (_ screenHeight != 200 && _screenHeight != 400)321 _ adjustAspectRatio = false;355 if (_videoMode.screenHeight != 200 && _videoMode.screenHeight != 400) 356 _videoMode.aspectRatio = false; 322 357 323 if (_ adjustAspectRatio)324 _ overlayHeight = real2Aspect(_overlayHeight);358 if (_videoMode.aspectRatio) 359 _videoMode.overlayHeight = real2Aspect(_videoMode.overlayHeight); 325 360 326 hwW = _ screenWidth * _scaleFactor;361 hwW = _videoMode.screenWidth * _videoMode.scaleFactor; 327 362 hwH = effectiveScreenHeight(); 328 363 #else 329 hwW = _ overlayWidth;330 hwH = _ overlayHeight;364 hwW = _videoMode.overlayWidth; 365 hwH = _videoMode.overlayHeight; 331 366 #endif 332 367 333 368 // 334 369 // Create the surface that contains the 8 bit game data 335 370 // 336 _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _ screenWidth, _screenHeight, 8, 0, 0, 0, 0);371 _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); 337 372 if (_screen == NULL) 338 373 error("allocating _screen failed"); 339 374 … … 342 377 // 343 378 344 379 _hwscreen = SDL_SetVideoMode(hwW, hwH, 16, 345 _ fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE380 _videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE 346 381 ); 347 382 if (_hwscreen == NULL) { 348 383 // DON'T use error(), as this tries to bring up the debug 349 384 // console, which WON'T WORK now that _hwscreen is hosed. 350 385 351 // FIXME: We should be able to continue the game without 352 // shutting down or bringing up the debug console, but at 353 // this point we've already screwed up all our member vars. 354 // We need to find a way to call SDL_SetVideoMode *before* 355 // that happens and revert to all the old settings if we 356 // can't pull off the switch to the new settings. 357 // 358 // Fingolfin says: the "easy" way to do that is not to modify 359 // the member vars before we are sure everything is fine. Think 360 // of "transactions, commit, rollback" style... we use local vars 361 // in place of the member vars, do everything etc. etc.. In case 362 // of a failure, rollback is trivial. Only if everything worked fine 363 // do we "commit" the changed values to the member vars. 364 warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); 365 quit(); 386 if (!_oldVideoMode.setup) { 387 warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); 388 quit(); 389 } else { 390 return false; 391 } 366 392 } 367 393 368 394 // … … 376 402 InitScalers(565); 377 403 378 404 // Need some extra bytes around when using 2xSaI 379 _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _ screenWidth + 3, _screenHeight + 3,405 _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3, 380 406 16, 381 407 _hwscreen->format->Rmask, 382 408 _hwscreen->format->Gmask, … … 386 412 if (_tmpscreen == NULL) 387 413 error("allocating _tmpscreen failed"); 388 414 389 _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _ overlayWidth, _overlayHeight,415 _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth, _videoMode.overlayHeight, 390 416 16, 391 417 _hwscreen->format->Rmask, 392 418 _hwscreen->format->Gmask, … … 408 434 _overlayFormat.bShift = _overlayscreen->format->Bshift; 409 435 _overlayFormat.aShift = _overlayscreen->format->Ashift; 410 436 411 _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _ overlayWidth + 3, _overlayHeight + 3,437 _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3, 412 438 16, 413 439 _hwscreen->format->Rmask, 414 440 _hwscreen->format->Gmask, … … 433 459 #endif 434 460 435 461 // keyboard cursor control, some other better place for it? 436 _km.x_max = _ screenWidth * _scaleFactor - 1;462 _km.x_max = _videoMode.screenWidth * _videoMode.scaleFactor - 1; 437 463 _km.y_max = effectiveScreenHeight() - 1; 438 464 _km.delay_time = 25; 439 465 _km.last_time = 0; 466 467 return true; 440 468 } 441 469 442 470 void OSystem_SDL::unloadGFXMode() { … … 474 502 DestroyScalers(); 475 503 } 476 504 477 voidOSystem_SDL::hotswapGFXMode() {505 bool OSystem_SDL::hotswapGFXMode() { 478 506 if (!_screen) 479 return ;507 return false; 480 508 481 509 // Keep around the old _screen & _overlayscreen so we can restore the screen data 482 510 // after the mode switch. 483 511 SDL_Surface *old_screen = _screen; 484 512 SDL_Surface *old_overlayscreen = _overlayscreen; 513 _screen = NULL; 514 _overlayscreen = NULL; 485 515 486 516 // Release the HW screen surface 487 SDL_FreeSurface(_hwscreen); 517 SDL_FreeSurface(_hwscreen); _hwscreen = NULL; 488 518 489 SDL_FreeSurface(_tmpscreen); 490 SDL_FreeSurface(_tmpscreen2); 519 SDL_FreeSurface(_tmpscreen); _tmpscreen = NULL; 520 SDL_FreeSurface(_tmpscreen2); _tmpscreen2 = NULL; 491 521 492 522 #ifdef USE_OSD 493 523 // Release the OSD surface 494 SDL_FreeSurface(_osdSurface); 524 SDL_FreeSurface(_osdSurface); _osdSurface = NULL; 495 525 #endif 496 526 497 527 // Setup the new GFX mode 498 loadGFXMode(); 528 if (!loadGFXMode()) { 529 unloadGFXMode(); 499 530 531 _screen = old_screen; 532 _overlayscreen = old_overlayscreen; 533 534 return false; 535 } 536 500 537 // reset palette 501 538 SDL_SetColors(_screen, _currentPalette, 0, 256); 502 539 … … 514 551 // Blit everything to the screen 515 552 internUpdateScreen(); 516 553 517 // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later 518 _modeChanged = true; 554 return true; 519 555 } 520 556 521 557 void OSystem_SDL::updateScreen() { … … 539 575 540 576 // If the shake position changed, fill the dirty area with blackness 541 577 if (_currentShakePos != _newShakePos) { 542 SDL_Rect blackrect = {0, 0, _ screenWidth * _scaleFactor, _newShakePos * _scaleFactor};578 SDL_Rect blackrect = {0, 0, _videoMode.screenWidth * _videoMode.scaleFactor, _newShakePos * _videoMode.scaleFactor}; 543 579 544 if (_ adjustAspectRatio && !_overlayVisible)580 if (_videoMode.aspectRatio && !_overlayVisible) 545 581 blackrect.h = real2Aspect(blackrect.h - 1) + 1; 546 582 547 583 SDL_FillRect(_hwscreen, &blackrect, 0); … … 586 622 if (!_overlayVisible) { 587 623 origSurf = _screen; 588 624 srcSurf = _tmpscreen; 589 width = _ screenWidth;590 height = _ screenHeight;625 width = _videoMode.screenWidth; 626 height = _videoMode.screenHeight; 591 627 scalerProc = _scalerProc; 592 scale1 = _ scaleFactor;628 scale1 = _videoMode.scaleFactor; 593 629 } else { 594 630 origSurf = _overlayscreen; 595 631 srcSurf = _tmpscreen2; 596 width = _ overlayWidth;597 height = _ overlayHeight;632 width = _videoMode.overlayWidth; 633 height = _videoMode.overlayHeight; 598 634 scalerProc = Normal1x; 599 635 600 636 scale1 = 1; … … 647 683 orig_dst_y = dst_y; 648 684 dst_y = dst_y * scale1; 649 685 650 if (_ adjustAspectRatio && !_overlayVisible)686 if (_videoMode.aspectRatio && !_overlayVisible) 651 687 dst_y = real2Aspect(dst_y); 652 688 653 689 assert(scalerProc != NULL); … … 661 697 r->h = dst_h * scale1; 662 698 663 699 #ifndef DISABLE_SCALERS 664 if (_ adjustAspectRatio && orig_dst_y < height && !_overlayVisible)700 if (_videoMode.aspectRatio && orig_dst_y < height && !_overlayVisible) 665 701 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1); 666 702 #endif 667 703 } … … 704 740 void OSystem_SDL::setFullscreenMode(bool enable) { 705 741 Common::StackLock lock(_graphicsMutex); 706 742 707 if (_ fullscreen == enable)743 if (_oldVideoMode.setup && _oldVideoMode.fullscreen == enable) 708 744 return; 709 745 710 if (_transactionMode == kTransactionCommit) { 711 assert(_hwscreen != 0); 712 _fullscreen = enable; 713 714 // Switch between fullscreen and windowed mode by invoking hotswapGFXMode(). 715 // We used to use SDL_WM_ToggleFullScreen() in the past, but this caused various 716 // problems. E.g. on OS X, it was implemented incorrectly for a long time; on 717 // the MAEMO platform, it seems to have caused problems, too. 718 // And on Linux, there were some troubles, too (see bug #1705410). 719 // So, we just do it "manually" now. There shouldn't be any drawbacks to that 720 // anyway. 721 hotswapGFXMode(); 722 } else if (_transactionMode == kTransactionActive) { 723 _transactionDetails.fs = enable; 724 _transactionDetails.fsChanged = true; 725 746 if (_transactionMode == kTransactionActive) { 747 _videoMode.fullscreen = enable; 726 748 _transactionDetails.needHotswap = true; 727 749 } 728 750 } 729 751 730 752 void OSystem_SDL::setAspectRatioCorrection(bool enable) { 731 if (((_screenHeight == 200 || _screenHeight == 400) && _adjustAspectRatio != enable) || 732 _transactionMode == kTransactionCommit) { 733 Common::StackLock lock(_graphicsMutex); 753 Common::StackLock lock(_graphicsMutex); 734 754 735 //assert(_hwscreen != 0);736 _adjustAspectRatio = enable;755 if (_oldVideoMode.setup && _oldVideoMode.aspectRatio == enable) 756 return; 737 757 738 if (_transactionMode == kTransactionActive) { 739 _transactionDetails.ar = enable; 740 _transactionDetails.arChanged = true; 741 742 _transactionDetails.needHotswap = true; 743 744 return; 745 } else { 746 if (_transactionMode != kTransactionCommit) 747 hotswapGFXMode(); 748 } 749 750 // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later 751 _modeChanged = true; 758 if (_transactionMode == kTransactionActive) { 759 _videoMode.aspectRatio = enable; 760 _transactionDetails.needHotswap = true; 752 761 } 753 762 } 754 763 … … 763 772 764 773 Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends 765 774 766 assert(x >= 0 && x < _ screenWidth);767 assert(y >= 0 && y < _ screenHeight);768 assert(h > 0 && y + h <= _ screenHeight);769 assert(w > 0 && x + w <= _ screenWidth);775 assert(x >= 0 && x < _videoMode.screenWidth); 776 assert(y >= 0 && y < _videoMode.screenHeight); 777 assert(h > 0 && y + h <= _videoMode.screenHeight); 778 assert(w > 0 && x + w <= _videoMode.screenWidth); 770 779 771 if (((long)src & 3) == 0 && pitch == _ screenWidth && x == 0 && y == 0 &&772 w == _ screenWidth && h == _screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) {780 if (((long)src & 3) == 0 && pitch == _videoMode.screenWidth && x == 0 && y == 0 && 781 w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { 773 782 /* Special, optimized case for full screen updates. 774 783 * It tries to determine what areas were actually changed, 775 784 * and just updates those, on the actual display. */ … … 788 797 y = 0; 789 798 } 790 799 791 if (w > _ screenWidth - x) {792 w = _ screenWidth - x;800 if (w > _videoMode.screenWidth - x) { 801 w = _videoMode.screenWidth - x; 793 802 } 794 803 795 if (h > _ screenHeight - y) {796 h = _ screenHeight - y;804 if (h > _videoMode.screenHeight - y) { 805 h = _videoMode.screenHeight - y; 797 806 } 798 807 799 808 if (w <= 0 || h <= 0) … … 807 816 if (SDL_LockSurface(_screen) == -1) 808 817 error("SDL_LockSurface failed: %s", SDL_GetError()); 809 818 810 byte *dst = (byte *)_screen->pixels + y * _ screenWidth + x;819 byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; 811 820 812 if (_ screenWidth == pitch && pitch == w) {821 if (_videoMode.screenWidth == pitch && pitch == w) { 813 822 memcpy(dst, src, h*w); 814 823 } else { 815 824 do { 816 825 memcpy(dst, src, w); 817 826 src += pitch; 818 dst += _ screenWidth;827 dst += _videoMode.screenWidth; 819 828 } while (--h); 820 829 } 821 830 … … 875 884 int height, width; 876 885 877 886 if (!_overlayVisible && !realCoordinates) { 878 width = _ screenWidth;879 height = _ screenHeight;887 width = _videoMode.screenWidth; 888 height = _videoMode.screenHeight; 880 889 } else { 881 width = _ overlayWidth;882 height = _ overlayHeight;890 width = _videoMode.overlayWidth; 891 height = _videoMode.overlayHeight; 883 892 } 884 893 885 894 // Extend the dirty region by 1 pixel for scalers … … 911 920 } 912 921 913 922 #ifndef DISABLE_SCALERS 914 if (_ adjustAspectRatio && !_overlayVisible && !realCoordinates) {923 if (_videoMode.aspectRatio && !_overlayVisible && !realCoordinates) { 915 924 makeRectStretchable(x, y, w, h); 916 925 } 917 926 #endif … … 936 945 assert(buf); 937 946 uint32 *sums = _dirtyChecksums; 938 947 uint x,y; 939 const uint last_x = (uint)_ screenWidth / 8;940 const uint last_y = (uint)_ screenHeight / 8;948 const uint last_x = (uint)_videoMode.screenWidth / 8; 949 const uint last_y = (uint)_videoMode.screenHeight / 8; 941 950 942 951 const uint BASE = 65521; /* largest prime smaller than 65536 */ 943 952 944 953 /* the 8x8 blocks in buf are enumerated starting in the top left corner and 945 954 * reading each line at a time from left to right */ 946 for (y = 0; y != last_y; y++, buf += _ screenWidth * (8 - 1))955 for (y = 0; y != last_y; y++, buf += _videoMode.screenWidth * (8 - 1)) 947 956 for (x = 0; x != last_x; x++, buf += 8) { 948 957 // Adler32 checksum algorithm (from RFC1950, used by gzip and zlib). 949 958 // This computes the Adler32 checksum of a 8x8 pixel block. Note … … 959 968 s1 += ptr[subX]; 960 969 s2 += s1; 961 970 } 962 ptr += _ screenWidth;971 ptr += _videoMode.screenWidth; 963 972 } 964 973 965 974 s1 %= BASE; … … 989 998 int x, y, w; 990 999 uint32 *ck = _dirtyChecksums; 991 1000 992 for (y = 0; y != _ screenHeight / 8; y++) {993 for (x = 0; x != _ screenWidth / 8; x++, ck++) {1001 for (y = 0; y != _videoMode.screenHeight / 8; y++) { 1002 for (x = 0; x != _videoMode.screenWidth / 8; x++, ck++) { 994 1003 if (ck[0] != ck[_cksumNum]) { 995 1004 /* found a dirty 8x8 block, now go as far to the right as possible, 996 1005 and at the same time, unmark the dirty status by setting old to new. */ … … 998 1007 do { 999 1008 ck[w + _cksumNum] = ck[w]; 1000 1009 w++; 1001 } while (x + w != _ screenWidth / 8 && ck[w] != ck[w + _cksumNum]);1010 } while (x + w != _videoMode.screenWidth / 8 && ck[w] != ck[w + _cksumNum]); 1002 1011 1003 1012 addDirtyRect(x * 8, y * 8, w * 8, 8); 1004 1013 … … 1015 1024 } 1016 1025 1017 1026 int16 OSystem_SDL::getHeight() { 1018 return _ screenHeight;1027 return _videoMode.screenHeight; 1019 1028 } 1020 1029 1021 1030 int16 OSystem_SDL::getWidth() { 1022 return _ screenWidth;1031 return _videoMode.screenWidth; 1023 1032 } 1024 1033 1025 1034 void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { … … 1105 1114 1106 1115 // Since resolution could change, put mouse to adjusted position 1107 1116 // Fixes bug #1349059 1108 x = _mouseCurState.x * _ scaleFactor;1109 if (_ adjustAspectRatio)1110 y = real2Aspect(_mouseCurState.y) * _ scaleFactor;1117 x = _mouseCurState.x * _videoMode.scaleFactor; 1118 if (_videoMode.aspectRatio) 1119 y = real2Aspect(_mouseCurState.y) * _videoMode.scaleFactor; 1111 1120 else 1112 y = _mouseCurState.y * _ scaleFactor;1121 y = _mouseCurState.y * _videoMode.scaleFactor; 1113 1122 1114 1123 warpMouse(x, y); 1115 1124 … … 1128 1137 1129 1138 // Since resolution could change, put mouse to adjusted position 1130 1139 // Fixes bug #1349059 1131 x = _mouseCurState.x / _ scaleFactor;1132 y = _mouseCurState.y / _ scaleFactor;1133 if (_ adjustAspectRatio)1140 x = _mouseCurState.x / _videoMode.scaleFactor; 1141 y = _mouseCurState.y / _videoMode.scaleFactor; 1142 if (_videoMode.aspectRatio) 1134 1143 y = aspect2Real(y); 1135 1144 1136 1145 warpMouse(x, y); … … 1152 1161 SDL_Rect src, dst; 1153 1162 src.x = src.y = 0; 1154 1163 dst.x = dst.y = 1; 1155 src.w = dst.w = _ screenWidth;1156 src.h = dst.h = _ screenHeight;1164 src.w = dst.w = _videoMode.screenWidth; 1165 src.h = dst.h = _videoMode.screenHeight; 1157 1166 if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) 1158 1167 error("SDL_BlitSurface failed: %s", SDL_GetError()); 1159 1168 1160 1169 SDL_LockSurface(_tmpscreen); 1161 1170 SDL_LockSurface(_overlayscreen); 1162 1171 _scalerProc((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch, 1163 (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _ screenWidth, _screenHeight);1172 (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _videoMode.screenWidth, _videoMode.screenHeight); 1164 1173 1165 1174 #ifndef DISABLE_SCALERS 1166 if (_ adjustAspectRatio)1175 if (_videoMode.aspectRatio) 1167 1176 stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch, 1168 _ overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0);1177 _videoMode.overlayWidth, _videoMode.screenHeight * _videoMode.scaleFactor, 0, 0, 0); 1169 1178 #endif 1170 1179 SDL_UnlockSurface(_tmpscreen); 1171 1180 SDL_UnlockSurface(_overlayscreen); … … 1183 1192 error("SDL_LockSurface failed: %s", SDL_GetError()); 1184 1193 1185 1194 byte *src = (byte *)_overlayscreen->pixels; 1186 int h = _ overlayHeight;1195 int h = _videoMode.overlayHeight; 1187 1196 do { 1188 memcpy(buf, src, _ overlayWidth * 2);1197 memcpy(buf, src, _videoMode.overlayWidth * 2); 1189 1198 src += _overlayscreen->pitch; 1190 1199 buf += pitch; 1191 1200 } while (--h); … … 1211 1220 y = 0; 1212 1221 } 1213 1222 1214 if (w > _ overlayWidth - x) {1215 w = _ overlayWidth - x;1223 if (w > _videoMode.overlayWidth - x) { 1224 w = _videoMode.overlayWidth - x; 1216 1225 } 1217 1226 1218 if (h > _ overlayHeight - y) {1219 h = _ overlayHeight - y;1227 if (h > _videoMode.overlayHeight - y) { 1228 h = _videoMode.overlayHeight - y; 1220 1229 } 1221 1230 1222 1231 if (w <= 0 || h <= 0) … … 1264 1273 void OSystem_SDL::warpMouse(int x, int y) { 1265 1274 int y1 = y; 1266 1275 1267 if (_ adjustAspectRatio && !_overlayVisible)1276 if (_videoMode.aspectRatio && !_overlayVisible) 1268 1277 y1 = real2Aspect(y); 1269 1278 1270 1279 if (_mouseCurState.x != x || _mouseCurState.y != y) { 1271 1280 if (!_overlayVisible) 1272 SDL_WarpMouse(x * _ scaleFactor, y1 * _scaleFactor);1281 SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); 1273 1282 else 1274 1283 SDL_WarpMouse(x, y1); 1275 1284 … … 1372 1381 1373 1382 int rW, rH; 1374 1383 1375 if (_cursorTargetScale >= _ scaleFactor) {1384 if (_cursorTargetScale >= _videoMode.scaleFactor) { 1376 1385 // The cursor target scale is greater or equal to the scale at 1377 1386 // which the rest of the screen is drawn. We do not downscale 1378 1387 // the cursor image, we draw it at its original size. It will … … 1385 1394 1386 1395 // The virtual dimensions may be larger than the original. 1387 1396 1388 _mouseCurState.vW = w * _cursorTargetScale / _ scaleFactor;1389 _mouseCurState.vH = h * _cursorTargetScale / _ scaleFactor;1397 _mouseCurState.vW = w * _cursorTargetScale / _videoMode.scaleFactor; 1398 _mouseCurState.vH = h * _cursorTargetScale / _videoMode.scaleFactor; 1390 1399 _mouseCurState.vHotX = _mouseCurState.hotX * _cursorTargetScale / 1391 _ scaleFactor;1400 _videoMode.scaleFactor; 1392 1401 _mouseCurState.vHotY = _mouseCurState.hotY * _cursorTargetScale / 1393 _ scaleFactor;1402 _videoMode.scaleFactor; 1394 1403 } else { 1395 1404 // The cursor target scale is smaller than the scale at which 1396 1405 // the rest of the screen is drawn. We scale up the cursor 1397 1406 // image to make it appear correct. 1398 1407 1399 rW = w * _ scaleFactor / _cursorTargetScale;1400 rH = h * _ scaleFactor / _cursorTargetScale;1401 _mouseCurState.rHotX = _mouseCurState.hotX * _ scaleFactor /1408 rW = w * _videoMode.scaleFactor / _cursorTargetScale; 1409 rH = h * _videoMode.scaleFactor / _cursorTargetScale; 1410 _mouseCurState.rHotX = _mouseCurState.hotX * _videoMode.scaleFactor / 1402 1411 _cursorTargetScale; 1403 _mouseCurState.rHotY = _mouseCurState.hotY * _ scaleFactor /1412 _mouseCurState.rHotY = _mouseCurState.hotY * _videoMode.scaleFactor / 1404 1413 _cursorTargetScale; 1405 1414 1406 1415 // The virtual dimensions will be the same as the original. … … 1415 1424 int rH1 = rH; // store original to pass to aspect-correction function later 1416 1425 #endif 1417 1426 1418 if (_ adjustAspectRatio && _cursorTargetScale == 1) {1427 if (_videoMode.aspectRatio && _cursorTargetScale == 1) { 1419 1428 rH = real2Aspect(rH - 1) + 1; 1420 1429 _mouseCurState.rHotY = real2Aspect(_mouseCurState.rHotY); 1421 1430 } … … 1450 1459 // the game. This only works well with the non-blurring scalers so we 1451 1460 // actually only use the 1x, 1.5x, 2x and AdvMame scalers. 1452 1461 1453 if (_cursorTargetScale == 1 && (_ mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE))1462 if (_cursorTargetScale == 1 && (_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE)) 1454 1463 scalerProc = _scalerProc; 1455 1464 else 1456 scalerProc = scalersMagn[_cursorTargetScale - 1][_ scaleFactor - 1];1465 scalerProc = scalersMagn[_cursorTargetScale - 1][_videoMode.scaleFactor - 1]; 1457 1466 1458 1467 scalerProc((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2, 1459 1468 _mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch, 1460 1469 _mouseCurState.w, _mouseCurState.h); 1461 1470 1462 1471 #ifndef DISABLE_SCALERS 1463 if (_ adjustAspectRatio && _cursorTargetScale == 1)1472 if (_videoMode.aspectRatio && _cursorTargetScale == 1) 1464 1473 cursorStretch200To240((uint8 *)_mouseSurface->pixels, _mouseSurface->pitch, rW, rH1, 0, 0, 0); 1465 1474 #endif 1466 1475 … … 1503 1512 1504 1513 // When we switch bigger overlay off mouse jumps. Argh! 1505 1514 // This is intended to prevent undrawing offscreen mouse 1506 if (!_overlayVisible && (x >= _ screenWidth || y >= _screenHeight)) {1515 if (!_overlayVisible && (x >= _videoMode.screenWidth || y >= _videoMode.screenHeight)) { 1507 1516 return; 1508 1517 } 1509 1518 … … 1526 1535 dst.y = _mouseCurState.y; 1527 1536 1528 1537 if (!_overlayVisible) { 1529 scale = _ scaleFactor;1530 width = _ screenWidth;1531 height = _ screenHeight;1538 scale = _videoMode.scaleFactor; 1539 width = _videoMode.screenWidth; 1540 height = _videoMode.screenHeight; 1532 1541 dst.w = _mouseCurState.vW; 1533 1542 dst.h = _mouseCurState.vH; 1534 1543 hotX = _mouseCurState.vHotX; 1535 1544 hotY = _mouseCurState.vHotY; 1536 1545 } else { 1537 1546 scale = 1; 1538 width = _ overlayWidth;1539 height = _ overlayHeight;1547 width = _videoMode.overlayWidth; 1548 height = _videoMode.overlayHeight; 1540 1549 dst.w = _mouseCurState.rW; 1541 1550 dst.h = _mouseCurState.rH; 1542 1551 hotX = _mouseCurState.rHotX; … … 1558 1567 dst.y += _currentShakePos; 1559 1568 } 1560 1569 1561 if (_ adjustAspectRatio && !_overlayVisible)1570 if (_videoMode.aspectRatio && !_overlayVisible) 1562 1571 dst.y = real2Aspect(dst.y); 1563 1572 1564 1573 dst.x = scale * dst.x - _mouseCurState.rHotX; … … 1674 1683 void OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) { 1675 1684 // Ctrl-Alt-a toggles aspect ratio correction 1676 1685 if (key.keysym.sym == 'a') { 1677 setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio); 1686 beginGFXTransaction(); 1687 setFeatureState(kFeatureAspectRatioCorrection, !_videoMode.aspectRatio); 1688 endGFXTransaction(); 1678 1689 #ifdef USE_OSD 1679 1690 char buffer[128]; 1680 if (_ adjustAspectRatio)1691 if (_videoMode.aspectRatio) 1681 1692 sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d", 1682 _ screenWidth, _screenHeight,1693 _videoMode.screenWidth, _videoMode.screenHeight, 1683 1694 _hwscreen->w, _hwscreen->h 1684 1695 ); 1685 1696 else 1686 1697 sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d", 1687 _ screenWidth, _screenHeight,1698 _videoMode.screenWidth, _videoMode.screenHeight, 1688 1699 _hwscreen->w, _hwscreen->h 1689 1700 ); 1690 1701 displayMessageOnOSD(buffer); … … 1694 1705 } 1695 1706 1696 1707 int newMode = -1; 1697 int factor = _ scaleFactor - 1;1708 int factor = _videoMode.scaleFactor - 1; 1698 1709 1699 1710 // Increase/decrease the scale factor 1700 1711 if (key.keysym.sym == SDLK_EQUALS || key.keysym.sym == SDLK_PLUS || key.keysym.sym == SDLK_MINUS || … … 1720 1731 } 1721 1732 1722 1733 if (newMode >= 0) { 1723 setGraphicsMode(newMode); 1734 beginGFXTransaction(); 1735 setGraphicsMode(newMode); 1736 endGFXTransaction(); 1724 1737 #ifdef USE_OSD 1725 1738 if (_osdSurface) { 1726 1739 const char *newScalerName = 0; 1727 1740 const GraphicsMode *g = getSupportedGraphicsModes(); 1728 1741 while (g->name) { 1729 if (g->id == _ mode) {1742 if (g->id == _videoMode.mode) { 1730 1743 newScalerName = g->description; 1731 1744 break; 1732 1745 } … … 1736 1749 char buffer[128]; 1737 1750 sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d", 1738 1751 newScalerName, 1739 _ screenWidth, _screenHeight,1752 _videoMode.screenWidth, _videoMode.screenHeight, 1740 1753 _hwscreen->w, _hwscreen->h 1741 1754 ); 1742 1755 displayMessageOnOSD(buffer); -
backends/platform/sdl/sdl.cpp
116 116 // Enable unicode support if possible 117 117 SDL_EnableUNICODE(1); 118 118 119 _oldVideoMode.setup = false; 120 _videoMode.setup = false; 121 119 122 _cksumValid = false; 120 123 #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS) 121 _mode = GFX_DOUBLESIZE; 122 _scaleFactor = 2; 124 _videoMode.mode = GFX_DOUBLESIZE; 125 _videoMode.scaleFactor = 2; 126 _videoMode.aspectRatio = ConfMan.getBool("aspect_ratio"); 123 127 _scalerProc = Normal2x; 124 _adjustAspectRatio = ConfMan.getBool("aspect_ratio");125 128 #else // for small screen platforms 126 _mode = GFX_NORMAL; 127 _scaleFactor = 1; 129 _videoMode.mode = GFX_NORMAL; 130 _videoMode.scaleFactor = 1; 131 _videoMode.aspectRatio = false; 128 132 _scalerProc = Normal1x; 129 _adjustAspectRatio = false;130 133 #endif 131 134 _scalerType = 0; 132 135 _modeFlags = 0; 133 136 134 137 #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) 135 _ fullscreen = ConfMan.getBool("fullscreen");138 _videoMode.fullscreen = ConfMan.getBool("fullscreen"); 136 139 #else 137 _ fullscreen = true;140 _videoMode.fullscreen = true; 138 141 #endif 139 142 140 143 #if !defined(MACOSX) && !defined(__SYMBIAN32__) … … 192 195 #ifdef USE_OSD 193 196 _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), 194 197 #endif 195 _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0), 196 _tmpscreen(0), _overlayWidth(0), _overlayHeight(0), 198 _hwscreen(0), _screen(0), _tmpscreen(0), 197 199 _overlayVisible(false), 198 200 _overlayscreen(0), _tmpscreen2(0), 199 201 _samplesPerSec(0), … … 429 431 430 432 switch (f) { 431 433 case kFeatureFullscreenMode: 432 return _ fullscreen;434 return _videoMode.fullscreen; 433 435 case kFeatureAspectRatioCorrection: 434 return _ adjustAspectRatio;436 return _videoMode.aspectRatio; 435 437 case kFeatureAutoComputeDirtyRects: 436 438 return _modeFlags & DF_WANT_RECT_OPTIM; 437 439 default: -
backends/platform/sdl/events.cpp
77 77 78 78 // Adjust for the screen scaling 79 79 if (!_overlayVisible) { 80 event.mouse.x /= _ scaleFactor;81 event.mouse.y /= _ scaleFactor;82 if (_ adjustAspectRatio)80 event.mouse.x /= _videoMode.scaleFactor; 81 event.mouse.y /= _videoMode.scaleFactor; 82 if (_videoMode.aspectRatio) 83 83 event.mouse.y = aspect2Real(event.mouse.y); 84 84 } 85 85 } … … 196 196 if (b == Common::KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN 197 197 || ev.key.keysym.sym == SDLK_KP_ENTER)) { 198 198 beginGFXTransaction(); 199 setFullscreenMode(!_fullscreen);199 setFullscreenMode(!_videoMode.fullscreen); 200 200 endGFXTransaction(); 201 201 #ifdef USE_OSD 202 if (_ fullscreen)202 if (_videoMode.fullscreen) 203 203 displayMessageOnOSD("Fullscreen mode"); 204 204 else 205 205 displayMessageOnOSD("Windowed mode"); -
backends/platform/sdl/sdl.h
80 80 virtual void initBackend(); 81 81 82 82 void beginGFXTransaction(void); 83 voidendGFXTransaction(void);83 TransactionError endGFXTransaction(void); 84 84 85 85 // Set the size of the video bitmap. 86 86 // Typically, 320x200 … … 179 179 virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); 180 180 virtual int16 getHeight(); 181 181 virtual int16 getWidth(); 182 virtual int16 getOverlayHeight() { return _ overlayHeight; }183 virtual int16 getOverlayWidth() { return _ overlayWidth; }182 virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; } 183 virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; } 184 184 185 185 virtual const GraphicsMode *getSupportedGraphicsModes() const; 186 186 virtual int getDefaultGraphicsMode() const; … … 226 226 // unseen game screen 227 227 SDL_Surface *_screen; 228 228 229 // TODO: We could get rid of the following two vars and just use _screen instead230 int _screenWidth, _screenHeight;231 232 229 // temporary screen (for scalers) 233 230 SDL_Surface *_tmpscreen; 234 231 SDL_Surface *_tmpscreen2; 235 232 236 233 // overlay 237 234 SDL_Surface *_overlayscreen; 238 int _overlayWidth, _overlayHeight;239 235 bool _overlayVisible; 240 236 Graphics::PixelFormat _overlayFormat; 241 237 … … 253 249 254 250 enum { 255 251 kTransactionNone = 0, 256 kTransaction Commit= 1,257 kTransaction Active= 2252 kTransactionActive = 1, 253 kTransactionRollback = 2 258 254 }; 259 255 260 256 struct TransactionDetails { 261 int mode;262 bool modeChanged;263 int w;264 int h;265 257 bool sizeChanged; 266 bool fs;267 bool fsChanged;268 bool ar;269 bool arChanged;270 258 bool needHotswap; 271 259 bool needUpdatescreen; 272 bool needUnload;273 bool needToggle;274 260 bool normal1xScaler; 275 261 }; 276 262 TransactionDetails _transactionDetails; 277 263 264 struct VideoState { 265 bool setup; 266 267 bool fullscreen; 268 bool aspectRatio; 269 270 int mode; 271 int scaleFactor; 272 273 int screenWidth, screenHeight; 274 int overlayWidth, overlayHeight; 275 }; 276 VideoState _videoMode, _oldVideoMode; 277 278 void setGraphicsModeIntern(); 279 278 280 /** Force full redraw on next updateScreen */ 279 281 bool _forceFull; 280 282 ScalerProc *_scalerProc; 281 283 int _scalerType; 282 int _scaleFactor;283 int _mode;284 284 int _transactionMode; 285 bool _fullscreen;286 285 287 286 bool _screenIsLocked; 288 287 Graphics::Surface _framebuffer; … … 292 291 bool _modeChanged; 293 292 int _screenChangeCount; 294 293 295 /** True if aspect ratio correction is enabled. */296 bool _adjustAspectRatio;297 298 294 enum { 299 295 NUM_DIRTY_RECT = 100, 300 296 MAX_SCALING = 3 … … 417 413 418 414 virtual void internUpdateScreen(); // overloaded by CE backend 419 415 420 virtual voidloadGFXMode(); // overloaded by CE backend416 virtual bool loadGFXMode(); // overloaded by CE backend 421 417 virtual void unloadGFXMode(); // overloaded by CE backend 422 virtual voidhotswapGFXMode(); // overloaded by CE backend418 virtual bool hotswapGFXMode(); // overloaded by CE backend 423 419 424 420 void setFullscreenMode(bool enable); 425 421 void setAspectRatioCorrection(bool enable); … … 427 423 virtual bool saveScreenshot(const char *filename); // overloaded by CE backend 428 424 429 425 int effectiveScreenHeight() const { 430 return (_ adjustAspectRatio ? real2Aspect(_screenHeight) : _screenHeight)431 * _ scaleFactor;426 return (_videoMode.aspectRatio ? real2Aspect(_videoMode.screenHeight) : _videoMode.screenHeight) 427 * _videoMode.scaleFactor; 432 428 } 433 429 434 430 void setupIcon(); -
base/main.cpp
67 67 system.setFeatureState(OSystem::kFeatureAspectRatioCorrection, ConfMan.getBool("aspect_ratio")); 68 68 if (ConfMan.hasKey("fullscreen")) 69 69 system.setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen")); 70 system.endGFXTransaction(); 70 if (system.endGFXTransaction() != OSystem::kTransactionSuccess) 71 error("Could not switch to graphics mode: 320x200 ('%s')", ConfMan.get("gfx_mode").c_str()); 71 72 72 73 // When starting up launcher for the first time, the user might have specified 73 74 // a --gui-theme option, to allow that option to be working, we need to initialize