Ticket #8926: sdl_transaction_rollback_v3.1.patch
File sdl_transaction_rollback_v3.1.patch, 40.4 KB (added by , 16 years ago) |
---|
-
common/system.h
391 391 */ 392 392 virtual void beginGFXTransaction() {} 393 393 394 /** 395 * This type is able to save the different errors which can happen while 396 * changing GFX config values inside GFX transactions. 397 * 398 * endGFXTransaction returns a ORed combination of the '*Failed' values 399 * if any problem occures, on success 0. 400 * 401 * @see endGFXTransaction 402 */ 403 enum kTransactionError { 404 kTransactionSuccess = 0, /**< Everything fine (use EQUAL check for this one!) */ 405 kTransactionAspectRatioFailed = (1 << 0), /**< Failed switchting aspect ratio correction mode */ 406 kTransactionFullscreenFailed = (1 << 1), /**< Failed switchting fullscreen mode */ 407 kTransactionModeSwitchFailed = (1 << 2), /**< Failed switchting the GFX graphics mode (setGraphicsMode) */ 408 kTransactionSizeChangeFailed = (1 << 3) /**< Failed switchting the screen dimensions (initSize) */ 409 }; 394 410 395 411 /** 396 412 * End (and thereby commit) the current GFX transaction. 397 413 * @see beginGFXTransaction 414 * @see kTransactionError 415 * @return returns a ORed combination of kTransactionError values or 0 on success 398 416 */ 399 virtual void endGFXTransaction() {}417 virtual kTransactionError endGFXTransaction() { return kTransactionSuccess; } 400 418 401 419 402 420 /** -
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::kTransactionError 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 (kTransactionError)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, … … 396 422 if (_overlayscreen == NULL) 397 423 error("allocating _overlayscreen failed"); 398 424 399 _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _ overlayWidth + 3, _overlayHeight + 3,425 _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3, 400 426 16, 401 427 _hwscreen->format->Rmask, 402 428 _hwscreen->format->Gmask, … … 421 447 #endif 422 448 423 449 // keyboard cursor control, some other better place for it? 424 _km.x_max = _ screenWidth * _scaleFactor - 1;450 _km.x_max = _videoMode.screenWidth * _videoMode.scaleFactor - 1; 425 451 _km.y_max = effectiveScreenHeight() - 1; 426 452 _km.delay_time = 25; 427 453 _km.last_time = 0; 454 455 return true; 428 456 } 429 457 430 458 void OSystem_SDL::unloadGFXMode() { … … 462 490 DestroyScalers(); 463 491 } 464 492 465 voidOSystem_SDL::hotswapGFXMode() {493 bool OSystem_SDL::hotswapGFXMode() { 466 494 if (!_screen) 467 return ;495 return false; 468 496 469 497 // Keep around the old _screen & _overlayscreen so we can restore the screen data 470 498 // after the mode switch. 471 499 SDL_Surface *old_screen = _screen; 472 500 SDL_Surface *old_overlayscreen = _overlayscreen; 501 _screen = NULL; 502 _overlayscreen = NULL; 473 503 474 504 // Release the HW screen surface 475 SDL_FreeSurface(_hwscreen); 505 SDL_FreeSurface(_hwscreen); _hwscreen = NULL; 476 506 477 SDL_FreeSurface(_tmpscreen); 478 SDL_FreeSurface(_tmpscreen2); 507 SDL_FreeSurface(_tmpscreen); _tmpscreen = NULL; 508 SDL_FreeSurface(_tmpscreen2); _tmpscreen2 = NULL; 479 509 480 510 #ifdef USE_OSD 481 511 // Release the OSD surface 482 SDL_FreeSurface(_osdSurface); 512 SDL_FreeSurface(_osdSurface); _osdSurface = NULL; 483 513 #endif 484 514 485 515 // Setup the new GFX mode 486 loadGFXMode(); 516 if (!loadGFXMode()) { 517 unloadGFXMode(); 487 518 519 _screen = old_screen; 520 _overlayscreen = old_overlayscreen; 521 522 return false; 523 } 524 488 525 // reset palette 489 526 SDL_SetColors(_screen, _currentPalette, 0, 256); 490 527 … … 502 539 // Blit everything to the screen 503 540 internUpdateScreen(); 504 541 505 // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later 506 _modeChanged = true; 542 return true; 507 543 } 508 544 509 545 void OSystem_SDL::updateScreen() { … … 527 563 528 564 // If the shake position changed, fill the dirty area with blackness 529 565 if (_currentShakePos != _newShakePos) { 530 SDL_Rect blackrect = {0, 0, _ screenWidth * _scaleFactor, _newShakePos * _scaleFactor};566 SDL_Rect blackrect = {0, 0, _videoMode.screenWidth * _videoMode.scaleFactor, _newShakePos * _videoMode.scaleFactor}; 531 567 532 if (_ adjustAspectRatio && !_overlayVisible)568 if (_videoMode.aspectRatio && !_overlayVisible) 533 569 blackrect.h = real2Aspect(blackrect.h - 1) + 1; 534 570 535 571 SDL_FillRect(_hwscreen, &blackrect, 0); … … 574 610 if (!_overlayVisible) { 575 611 origSurf = _screen; 576 612 srcSurf = _tmpscreen; 577 width = _ screenWidth;578 height = _ screenHeight;613 width = _videoMode.screenWidth; 614 height = _videoMode.screenHeight; 579 615 scalerProc = _scalerProc; 580 scale1 = _ scaleFactor;616 scale1 = _videoMode.scaleFactor; 581 617 } else { 582 618 origSurf = _overlayscreen; 583 619 srcSurf = _tmpscreen2; 584 width = _ overlayWidth;585 height = _ overlayHeight;620 width = _videoMode.overlayWidth; 621 height = _videoMode.overlayHeight; 586 622 scalerProc = Normal1x; 587 623 588 624 scale1 = 1; … … 635 671 orig_dst_y = dst_y; 636 672 dst_y = dst_y * scale1; 637 673 638 if (_ adjustAspectRatio && !_overlayVisible)674 if (_videoMode.aspectRatio && !_overlayVisible) 639 675 dst_y = real2Aspect(dst_y); 640 676 641 677 assert(scalerProc != NULL); … … 649 685 r->h = dst_h * scale1; 650 686 651 687 #ifndef DISABLE_SCALERS 652 if (_ adjustAspectRatio && orig_dst_y < height && !_overlayVisible)688 if (_videoMode.aspectRatio && orig_dst_y < height && !_overlayVisible) 653 689 r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1); 654 690 #endif 655 691 } … … 692 728 void OSystem_SDL::setFullscreenMode(bool enable) { 693 729 Common::StackLock lock(_graphicsMutex); 694 730 695 if (_ fullscreen == enable)731 if (_oldVideoMode.setup && _oldVideoMode.fullscreen == enable) 696 732 return; 697 733 698 if (_transactionMode == kTransactionCommit) { 699 assert(_hwscreen != 0); 700 _fullscreen = enable; 701 702 // Switch between fullscreen and windowed mode by invoking hotswapGFXMode(). 703 // We used to use SDL_WM_ToggleFullScreen() in the past, but this caused various 704 // problems. E.g. on OS X, it was implemented incorrectly for a long time; on 705 // the MAEMO platform, it seems to have caused problems, too. 706 // And on Linux, there were some troubles, too (see bug #1705410). 707 // So, we just do it "manually" now. There shouldn't be any drawbacks to that 708 // anyway. 709 hotswapGFXMode(); 710 } else if (_transactionMode == kTransactionActive) { 711 _transactionDetails.fs = enable; 712 _transactionDetails.fsChanged = true; 713 734 if (_transactionMode == kTransactionActive) { 735 _videoMode.fullscreen = enable; 714 736 _transactionDetails.needHotswap = true; 715 737 } 716 738 } 717 739 718 740 void OSystem_SDL::setAspectRatioCorrection(bool enable) { 719 if (((_screenHeight == 200 || _screenHeight == 400) && _adjustAspectRatio != enable) || 720 _transactionMode == kTransactionCommit) { 721 Common::StackLock lock(_graphicsMutex); 741 Common::StackLock lock(_graphicsMutex); 722 742 723 //assert(_hwscreen != 0);724 _adjustAspectRatio = enable;743 if (_oldVideoMode.setup && _oldVideoMode.aspectRatio == enable) 744 return; 725 745 726 if (_transactionMode == kTransactionActive) { 727 _transactionDetails.ar = enable; 728 _transactionDetails.arChanged = true; 729 730 _transactionDetails.needHotswap = true; 731 732 return; 733 } else { 734 if (_transactionMode != kTransactionCommit) 735 hotswapGFXMode(); 736 } 737 738 // Make sure that an Common::EVENT_SCREEN_CHANGED gets sent later 739 _modeChanged = true; 746 if (_transactionMode == kTransactionActive) { 747 _videoMode.aspectRatio = enable; 748 _transactionDetails.needHotswap = true; 740 749 } 741 750 } 742 751 … … 751 760 752 761 Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends 753 762 754 assert(x >= 0 && x < _ screenWidth);755 assert(y >= 0 && y < _ screenHeight);756 assert(h > 0 && y + h <= _ screenHeight);757 assert(w > 0 && x + w <= _ screenWidth);763 assert(x >= 0 && x < _videoMode.screenWidth); 764 assert(y >= 0 && y < _videoMode.screenHeight); 765 assert(h > 0 && y + h <= _videoMode.screenHeight); 766 assert(w > 0 && x + w <= _videoMode.screenWidth); 758 767 759 if (((long)src & 3) == 0 && pitch == _ screenWidth && x == 0 && y == 0 &&760 w == _ screenWidth && h == _screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) {768 if (((long)src & 3) == 0 && pitch == _videoMode.screenWidth && x == 0 && y == 0 && 769 w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { 761 770 /* Special, optimized case for full screen updates. 762 771 * It tries to determine what areas were actually changed, 763 772 * and just updates those, on the actual display. */ … … 776 785 y = 0; 777 786 } 778 787 779 if (w > _ screenWidth - x) {780 w = _ screenWidth - x;788 if (w > _videoMode.screenWidth - x) { 789 w = _videoMode.screenWidth - x; 781 790 } 782 791 783 if (h > _ screenHeight - y) {784 h = _ screenHeight - y;792 if (h > _videoMode.screenHeight - y) { 793 h = _videoMode.screenHeight - y; 785 794 } 786 795 787 796 if (w <= 0 || h <= 0) … … 795 804 if (SDL_LockSurface(_screen) == -1) 796 805 error("SDL_LockSurface failed: %s", SDL_GetError()); 797 806 798 byte *dst = (byte *)_screen->pixels + y * _ screenWidth + x;807 byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; 799 808 800 if (_ screenWidth == pitch && pitch == w) {809 if (_videoMode.screenWidth == pitch && pitch == w) { 801 810 memcpy(dst, src, h*w); 802 811 } else { 803 812 do { 804 813 memcpy(dst, src, w); 805 814 src += pitch; 806 dst += _ screenWidth;815 dst += _videoMode.screenWidth; 807 816 } while (--h); 808 817 } 809 818 … … 863 872 int height, width; 864 873 865 874 if (!_overlayVisible && !realCoordinates) { 866 width = _ screenWidth;867 height = _ screenHeight;875 width = _videoMode.screenWidth; 876 height = _videoMode.screenHeight; 868 877 } else { 869 width = _ overlayWidth;870 height = _ overlayHeight;878 width = _videoMode.overlayWidth; 879 height = _videoMode.overlayHeight; 871 880 } 872 881 873 882 // Extend the dirty region by 1 pixel for scalers … … 899 908 } 900 909 901 910 #ifndef DISABLE_SCALERS 902 if (_ adjustAspectRatio && !_overlayVisible && !realCoordinates) {911 if (_videoMode.aspectRatio && !_overlayVisible && !realCoordinates) { 903 912 makeRectStretchable(x, y, w, h); 904 913 } 905 914 #endif … … 924 933 assert(buf); 925 934 uint32 *sums = _dirtyChecksums; 926 935 uint x,y; 927 const uint last_x = (uint)_ screenWidth / 8;928 const uint last_y = (uint)_ screenHeight / 8;936 const uint last_x = (uint)_videoMode.screenWidth / 8; 937 const uint last_y = (uint)_videoMode.screenHeight / 8; 929 938 930 939 const uint BASE = 65521; /* largest prime smaller than 65536 */ 931 940 932 941 /* the 8x8 blocks in buf are enumerated starting in the top left corner and 933 942 * reading each line at a time from left to right */ 934 for (y = 0; y != last_y; y++, buf += _ screenWidth * (8 - 1))943 for (y = 0; y != last_y; y++, buf += _videoMode.screenWidth * (8 - 1)) 935 944 for (x = 0; x != last_x; x++, buf += 8) { 936 945 // Adler32 checksum algorithm (from RFC1950, used by gzip and zlib). 937 946 // This computes the Adler32 checksum of a 8x8 pixel block. Note … … 947 956 s1 += ptr[subX]; 948 957 s2 += s1; 949 958 } 950 ptr += _ screenWidth;959 ptr += _videoMode.screenWidth; 951 960 } 952 961 953 962 s1 %= BASE; … … 977 986 int x, y, w; 978 987 uint32 *ck = _dirtyChecksums; 979 988 980 for (y = 0; y != _ screenHeight / 8; y++) {981 for (x = 0; x != _ screenWidth / 8; x++, ck++) {989 for (y = 0; y != _videoMode.screenHeight / 8; y++) { 990 for (x = 0; x != _videoMode.screenWidth / 8; x++, ck++) { 982 991 if (ck[0] != ck[_cksumNum]) { 983 992 /* found a dirty 8x8 block, now go as far to the right as possible, 984 993 and at the same time, unmark the dirty status by setting old to new. */ … … 986 995 do { 987 996 ck[w + _cksumNum] = ck[w]; 988 997 w++; 989 } while (x + w != _ screenWidth / 8 && ck[w] != ck[w + _cksumNum]);998 } while (x + w != _videoMode.screenWidth / 8 && ck[w] != ck[w + _cksumNum]); 990 999 991 1000 addDirtyRect(x * 8, y * 8, w * 8, 8); 992 1001 … … 1003 1012 } 1004 1013 1005 1014 int16 OSystem_SDL::getHeight() { 1006 return _ screenHeight;1015 return _videoMode.screenHeight; 1007 1016 } 1008 1017 1009 1018 int16 OSystem_SDL::getWidth() { 1010 return _ screenWidth;1019 return _videoMode.screenWidth; 1011 1020 } 1012 1021 1013 1022 void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { … … 1093 1102 1094 1103 // Since resolution could change, put mouse to adjusted position 1095 1104 // Fixes bug #1349059 1096 x = _mouseCurState.x * _ scaleFactor;1097 if (_ adjustAspectRatio)1098 y = real2Aspect(_mouseCurState.y) * _ scaleFactor;1105 x = _mouseCurState.x * _videoMode.scaleFactor; 1106 if (_videoMode.aspectRatio) 1107 y = real2Aspect(_mouseCurState.y) * _videoMode.scaleFactor; 1099 1108 else 1100 y = _mouseCurState.y * _ scaleFactor;1109 y = _mouseCurState.y * _videoMode.scaleFactor; 1101 1110 1102 1111 warpMouse(x, y); 1103 1112 … … 1116 1125 1117 1126 // Since resolution could change, put mouse to adjusted position 1118 1127 // Fixes bug #1349059 1119 x = _mouseCurState.x / _ scaleFactor;1120 y = _mouseCurState.y / _ scaleFactor;1121 if (_ adjustAspectRatio)1128 x = _mouseCurState.x / _videoMode.scaleFactor; 1129 y = _mouseCurState.y / _videoMode.scaleFactor; 1130 if (_videoMode.aspectRatio) 1122 1131 y = aspect2Real(y); 1123 1132 1124 1133 warpMouse(x, y); … … 1140 1149 SDL_Rect src, dst; 1141 1150 src.x = src.y = 0; 1142 1151 dst.x = dst.y = 1; 1143 src.w = dst.w = _ screenWidth;1144 src.h = dst.h = _ screenHeight;1152 src.w = dst.w = _videoMode.screenWidth; 1153 src.h = dst.h = _videoMode.screenHeight; 1145 1154 if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) 1146 1155 error("SDL_BlitSurface failed: %s", SDL_GetError()); 1147 1156 1148 1157 SDL_LockSurface(_tmpscreen); 1149 1158 SDL_LockSurface(_overlayscreen); 1150 1159 _scalerProc((byte *)(_tmpscreen->pixels) + _tmpscreen->pitch + 2, _tmpscreen->pitch, 1151 (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _ screenWidth, _screenHeight);1160 (byte *)_overlayscreen->pixels, _overlayscreen->pitch, _videoMode.screenWidth, _videoMode.screenHeight); 1152 1161 1153 1162 #ifndef DISABLE_SCALERS 1154 if (_ adjustAspectRatio)1163 if (_videoMode.aspectRatio) 1155 1164 stretch200To240((uint8 *)_overlayscreen->pixels, _overlayscreen->pitch, 1156 _ overlayWidth, _screenHeight * _scaleFactor, 0, 0, 0);1165 _videoMode.overlayWidth, _videoMode.screenHeight * _videoMode.scaleFactor, 0, 0, 0); 1157 1166 #endif 1158 1167 SDL_UnlockSurface(_tmpscreen); 1159 1168 SDL_UnlockSurface(_overlayscreen); … … 1171 1180 error("SDL_LockSurface failed: %s", SDL_GetError()); 1172 1181 1173 1182 byte *src = (byte *)_overlayscreen->pixels; 1174 int h = _ overlayHeight;1183 int h = _videoMode.overlayHeight; 1175 1184 do { 1176 memcpy(buf, src, _ overlayWidth * 2);1185 memcpy(buf, src, _videoMode.overlayWidth * 2); 1177 1186 src += _overlayscreen->pitch; 1178 1187 buf += pitch; 1179 1188 } while (--h); … … 1199 1208 y = 0; 1200 1209 } 1201 1210 1202 if (w > _ overlayWidth - x) {1203 w = _ overlayWidth - x;1211 if (w > _videoMode.overlayWidth - x) { 1212 w = _videoMode.overlayWidth - x; 1204 1213 } 1205 1214 1206 if (h > _ overlayHeight - y) {1207 h = _ overlayHeight - y;1215 if (h > _videoMode.overlayHeight - y) { 1216 h = _videoMode.overlayHeight - y; 1208 1217 } 1209 1218 1210 1219 if (w <= 0 || h <= 0) … … 1260 1269 void OSystem_SDL::warpMouse(int x, int y) { 1261 1270 int y1 = y; 1262 1271 1263 if (_ adjustAspectRatio && !_overlayVisible)1272 if (_videoMode.aspectRatio && !_overlayVisible) 1264 1273 y1 = real2Aspect(y); 1265 1274 1266 1275 if (_mouseCurState.x != x || _mouseCurState.y != y) { 1267 1276 if (!_overlayVisible) 1268 SDL_WarpMouse(x * _ scaleFactor, y1 * _scaleFactor);1277 SDL_WarpMouse(x * _videoMode.scaleFactor, y1 * _videoMode.scaleFactor); 1269 1278 else 1270 1279 SDL_WarpMouse(x, y1); 1271 1280 … … 1368 1377 1369 1378 int rW, rH; 1370 1379 1371 if (_cursorTargetScale >= _ scaleFactor) {1380 if (_cursorTargetScale >= _videoMode.scaleFactor) { 1372 1381 // The cursor target scale is greater or equal to the scale at 1373 1382 // which the rest of the screen is drawn. We do not downscale 1374 1383 // the cursor image, we draw it at its original size. It will … … 1381 1390 1382 1391 // The virtual dimensions may be larger than the original. 1383 1392 1384 _mouseCurState.vW = w * _cursorTargetScale / _ scaleFactor;1385 _mouseCurState.vH = h * _cursorTargetScale / _ scaleFactor;1393 _mouseCurState.vW = w * _cursorTargetScale / _videoMode.scaleFactor; 1394 _mouseCurState.vH = h * _cursorTargetScale / _videoMode.scaleFactor; 1386 1395 _mouseCurState.vHotX = _mouseCurState.hotX * _cursorTargetScale / 1387 _ scaleFactor;1396 _videoMode.scaleFactor; 1388 1397 _mouseCurState.vHotY = _mouseCurState.hotY * _cursorTargetScale / 1389 _ scaleFactor;1398 _videoMode.scaleFactor; 1390 1399 } else { 1391 1400 // The cursor target scale is smaller than the scale at which 1392 1401 // the rest of the screen is drawn. We scale up the cursor 1393 1402 // image to make it appear correct. 1394 1403 1395 rW = w * _ scaleFactor / _cursorTargetScale;1396 rH = h * _ scaleFactor / _cursorTargetScale;1397 _mouseCurState.rHotX = _mouseCurState.hotX * _ scaleFactor /1404 rW = w * _videoMode.scaleFactor / _cursorTargetScale; 1405 rH = h * _videoMode.scaleFactor / _cursorTargetScale; 1406 _mouseCurState.rHotX = _mouseCurState.hotX * _videoMode.scaleFactor / 1398 1407 _cursorTargetScale; 1399 _mouseCurState.rHotY = _mouseCurState.hotY * _ scaleFactor /1408 _mouseCurState.rHotY = _mouseCurState.hotY * _videoMode.scaleFactor / 1400 1409 _cursorTargetScale; 1401 1410 1402 1411 // The virtual dimensions will be the same as the original. … … 1411 1420 int rH1 = rH; // store original to pass to aspect-correction function later 1412 1421 #endif 1413 1422 1414 if (_ adjustAspectRatio && _cursorTargetScale == 1) {1423 if (_videoMode.aspectRatio && _cursorTargetScale == 1) { 1415 1424 rH = real2Aspect(rH - 1) + 1; 1416 1425 _mouseCurState.rHotY = real2Aspect(_mouseCurState.rHotY); 1417 1426 } … … 1446 1455 // the game. This only works well with the non-blurring scalers so we 1447 1456 // actually only use the 1x, 1.5x, 2x and AdvMame scalers. 1448 1457 1449 if (_cursorTargetScale == 1 && (_ mode == GFX_DOUBLESIZE || _mode == GFX_TRIPLESIZE))1458 if (_cursorTargetScale == 1 && (_videoMode.mode == GFX_DOUBLESIZE || _videoMode.mode == GFX_TRIPLESIZE)) 1450 1459 scalerProc = _scalerProc; 1451 1460 else 1452 scalerProc = scalersMagn[_cursorTargetScale - 1][_ scaleFactor - 1];1461 scalerProc = scalersMagn[_cursorTargetScale - 1][_videoMode.scaleFactor - 1]; 1453 1462 1454 1463 scalerProc((byte *)_mouseOrigSurface->pixels + _mouseOrigSurface->pitch + 2, 1455 1464 _mouseOrigSurface->pitch, (byte *)_mouseSurface->pixels, _mouseSurface->pitch, 1456 1465 _mouseCurState.w, _mouseCurState.h); 1457 1466 1458 1467 #ifndef DISABLE_SCALERS 1459 if (_ adjustAspectRatio && _cursorTargetScale == 1)1468 if (_videoMode.aspectRatio && _cursorTargetScale == 1) 1460 1469 cursorStretch200To240((uint8 *)_mouseSurface->pixels, _mouseSurface->pitch, rW, rH1, 0, 0, 0); 1461 1470 #endif 1462 1471 … … 1499 1508 1500 1509 // When we switch bigger overlay off mouse jumps. Argh! 1501 1510 // This is intended to prevent undrawing offscreen mouse 1502 if (!_overlayVisible && (x >= _ screenWidth || y >= _screenHeight)) {1511 if (!_overlayVisible && (x >= _videoMode.screenWidth || y >= _videoMode.screenHeight)) { 1503 1512 return; 1504 1513 } 1505 1514 … … 1522 1531 dst.y = _mouseCurState.y; 1523 1532 1524 1533 if (!_overlayVisible) { 1525 scale = _ scaleFactor;1526 width = _ screenWidth;1527 height = _ screenHeight;1534 scale = _videoMode.scaleFactor; 1535 width = _videoMode.screenWidth; 1536 height = _videoMode.screenHeight; 1528 1537 dst.w = _mouseCurState.vW; 1529 1538 dst.h = _mouseCurState.vH; 1530 1539 hotX = _mouseCurState.vHotX; 1531 1540 hotY = _mouseCurState.vHotY; 1532 1541 } else { 1533 1542 scale = 1; 1534 width = _ overlayWidth;1535 height = _ overlayHeight;1543 width = _videoMode.overlayWidth; 1544 height = _videoMode.overlayHeight; 1536 1545 dst.w = _mouseCurState.rW; 1537 1546 dst.h = _mouseCurState.rH; 1538 1547 hotX = _mouseCurState.rHotX; … … 1554 1563 dst.y += _currentShakePos; 1555 1564 } 1556 1565 1557 if (_ adjustAspectRatio && !_overlayVisible)1566 if (_videoMode.aspectRatio && !_overlayVisible) 1558 1567 dst.y = real2Aspect(dst.y); 1559 1568 1560 1569 dst.x = scale * dst.x - _mouseCurState.rHotX; … … 1670 1679 void OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) { 1671 1680 // Ctrl-Alt-a toggles aspect ratio correction 1672 1681 if (key.keysym.sym == 'a') { 1673 setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio); 1682 beginGFXTransaction(); 1683 setFeatureState(kFeatureAspectRatioCorrection, !_videoMode.aspectRatio); 1684 endGFXTransaction(); 1674 1685 #ifdef USE_OSD 1675 1686 char buffer[128]; 1676 if (_ adjustAspectRatio)1687 if (_videoMode.aspectRatio) 1677 1688 sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d", 1678 _ screenWidth, _screenHeight,1689 _videoMode.screenWidth, _videoMode.screenHeight, 1679 1690 _hwscreen->w, _hwscreen->h 1680 1691 ); 1681 1692 else 1682 1693 sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d", 1683 _ screenWidth, _screenHeight,1694 _videoMode.screenWidth, _videoMode.screenHeight, 1684 1695 _hwscreen->w, _hwscreen->h 1685 1696 ); 1686 1697 displayMessageOnOSD(buffer); … … 1690 1701 } 1691 1702 1692 1703 int newMode = -1; 1693 int factor = _ scaleFactor - 1;1704 int factor = _videoMode.scaleFactor - 1; 1694 1705 1695 1706 // Increase/decrease the scale factor 1696 1707 if (key.keysym.sym == SDLK_EQUALS || key.keysym.sym == SDLK_PLUS || key.keysym.sym == SDLK_MINUS || … … 1716 1727 } 1717 1728 1718 1729 if (newMode >= 0) { 1719 setGraphicsMode(newMode); 1730 beginGFXTransaction(); 1731 setGraphicsMode(newMode); 1732 endGFXTransaction(); 1720 1733 #ifdef USE_OSD 1721 1734 if (_osdSurface) { 1722 1735 const char *newScalerName = 0; 1723 1736 const GraphicsMode *g = getSupportedGraphicsModes(); 1724 1737 while (g->name) { 1725 if (g->id == _ mode) {1738 if (g->id == _videoMode.mode) { 1726 1739 newScalerName = g->description; 1727 1740 break; 1728 1741 } … … 1732 1745 char buffer[128]; 1733 1746 sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d", 1734 1747 newScalerName, 1735 _ screenWidth, _screenHeight,1748 _videoMode.screenWidth, _videoMode.screenHeight, 1736 1749 _hwscreen->w, _hwscreen->h 1737 1750 ); 1738 1751 displayMessageOnOSD(buffer); -
backends/platform/sdl/sdl.cpp
112 112 // Enable unicode support if possible 113 113 SDL_EnableUNICODE(1); 114 114 115 _oldVideoMode.setup = false; 116 _videoMode.setup = false; 117 115 118 _cksumValid = false; 116 119 #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS) 117 _mode = GFX_DOUBLESIZE; 118 _scaleFactor = 2; 120 _videoMode.mode = GFX_DOUBLESIZE; 121 _videoMode.scaleFactor = 2; 122 _videoMode.aspectRatio = ConfMan.getBool("aspect_ratio"); 119 123 _scalerProc = Normal2x; 120 _adjustAspectRatio = ConfMan.getBool("aspect_ratio");121 124 #else // for small screen platforms 122 _mode = GFX_NORMAL; 123 _scaleFactor = 1; 125 _videoMode.mode = GFX_NORMAL; 126 _videoMode.scaleFactor = 1; 127 _videoMode.aspectRatio = false; 124 128 _scalerProc = Normal1x; 125 _adjustAspectRatio = false;126 129 #endif 127 130 _scalerType = 0; 128 131 _modeFlags = 0; 129 132 130 133 #if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) 131 _ fullscreen = ConfMan.getBool("fullscreen");134 _videoMode.fullscreen = ConfMan.getBool("fullscreen"); 132 135 #else 133 _ fullscreen = true;136 _videoMode.fullscreen = true; 134 137 #endif 135 138 136 139 #if !defined(MACOSX) && !defined(__SYMBIAN32__) … … 184 187 #ifdef USE_OSD 185 188 _osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0), 186 189 #endif 187 _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0), 188 _tmpscreen(0), _overlayWidth(0), _overlayHeight(0), 190 _hwscreen(0), _screen(0), _tmpscreen(0), 189 191 _overlayVisible(false), 190 192 _overlayscreen(0), _tmpscreen2(0), 191 193 _samplesPerSec(0), … … 421 423 422 424 switch (f) { 423 425 case kFeatureFullscreenMode: 424 return _ fullscreen;426 return _videoMode.fullscreen; 425 427 case kFeatureAspectRatioCorrection: 426 return _ adjustAspectRatio;428 return _videoMode.aspectRatio; 427 429 case kFeatureAutoComputeDirtyRects: 428 430 return _modeFlags & DF_WANT_RECT_OPTIM; 429 431 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
85 85 virtual void initBackend(); 86 86 87 87 void beginGFXTransaction(void); 88 voidendGFXTransaction(void);88 kTransactionError endGFXTransaction(void); 89 89 90 90 // Set the size of the video bitmap. 91 91 // Typically, 320x200 … … 183 183 virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); 184 184 virtual int16 getHeight(); 185 185 virtual int16 getWidth(); 186 virtual int16 getOverlayHeight() { return _ overlayHeight; }187 virtual int16 getOverlayWidth() { return _ overlayWidth; }186 virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; } 187 virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; } 188 188 189 189 // Methods that convert RGB to/from colors suitable for the overlay. 190 190 virtual OverlayColor RGBToColor(uint8 r, uint8 g, uint8 b); … … 235 235 // unseen game screen 236 236 SDL_Surface *_screen; 237 237 238 // TODO: We could get rid of the following two vars and just use _screen instead239 int _screenWidth, _screenHeight;240 241 238 // temporary screen (for scalers) 242 239 SDL_Surface *_tmpscreen; 243 240 SDL_Surface *_tmpscreen2; 244 241 245 242 // overlay 246 243 SDL_Surface *_overlayscreen; 247 int _overlayWidth, _overlayHeight;248 244 bool _overlayVisible; 249 245 250 246 // Audio … … 261 257 262 258 enum { 263 259 kTransactionNone = 0, 264 kTransaction Commit= 1,265 kTransaction Active= 2260 kTransactionActive = 1, 261 kTransactionRollback = 2 266 262 }; 267 263 268 264 struct TransactionDetails { 269 int mode;270 bool modeChanged;271 int w;272 int h;273 265 bool sizeChanged; 274 bool fs;275 bool fsChanged;276 bool ar;277 bool arChanged;278 266 bool needHotswap; 279 267 bool needUpdatescreen; 280 bool needUnload;281 bool needToggle;282 268 bool normal1xScaler; 283 269 }; 284 270 TransactionDetails _transactionDetails; 285 271 272 struct VideoState { 273 bool setup; 274 275 bool fullscreen; 276 bool aspectRatio; 277 278 int mode; 279 int scaleFactor; 280 281 int screenWidth, screenHeight; 282 int overlayWidth, overlayHeight; 283 }; 284 VideoState _videoMode, _oldVideoMode; 285 286 void setGraphicsModeIntern(); 287 286 288 /** Force full redraw on next updateScreen */ 287 289 bool _forceFull; 288 290 ScalerProc *_scalerProc; 289 291 int _scalerType; 290 int _scaleFactor;291 int _mode;292 292 int _transactionMode; 293 bool _fullscreen;294 293 295 294 bool _screenIsLocked; 296 295 Graphics::Surface _framebuffer; … … 300 299 bool _modeChanged; 301 300 int _screenChangeCount; 302 301 303 /** True if aspect ratio correction is enabled. */304 bool _adjustAspectRatio;305 306 302 enum { 307 303 NUM_DIRTY_RECT = 100, 308 304 MAX_SCALING = 3 … … 425 421 426 422 virtual void internUpdateScreen(); // overloaded by CE backend 427 423 428 virtual voidloadGFXMode(); // overloaded by CE backend424 virtual bool loadGFXMode(); // overloaded by CE backend 429 425 virtual void unloadGFXMode(); // overloaded by CE backend 430 virtual voidhotswapGFXMode(); // overloaded by CE backend426 virtual bool hotswapGFXMode(); // overloaded by CE backend 431 427 432 428 void setFullscreenMode(bool enable); 433 429 void setAspectRatioCorrection(bool enable); … … 435 431 virtual bool saveScreenshot(const char *filename); // overloaded by CE backend 436 432 437 433 int effectiveScreenHeight() const { 438 return (_ adjustAspectRatio ? real2Aspect(_screenHeight) : _screenHeight)439 * _ scaleFactor;434 return (_videoMode.aspectRatio ? real2Aspect(_videoMode.screenHeight) : _videoMode.screenHeight) 435 * _videoMode.scaleFactor; 440 436 } 441 437 442 438 void setupIcon();