bool WINCESdlGraphicsManager::loadGFXMode() { int displayWidth; int displayHeight; unsigned int flags = SDL_FULLSCREEN | SDL_SWSURFACE; _videoMode.fullscreen = true; // forced _forceFull = true; _tmpscreen = NULL; // Recompute scalers if necessary update_scalers(); // Create the surface that contains the 8 bit game data _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) error("_screen failed (%s)", SDL_GetError()); // Create the surface that contains the scaled graphics in 16 bit mode // Always use full screen mode to have a "clean screen" if (!_videoMode.aspectRatioCorrection) { displayWidth = _videoMode.screenWidth * _scaleFactorXm / _scaleFactorXd; displayHeight = _videoMode.screenHeight * _scaleFactorYm / _scaleFactorYd; } else { displayWidth = _videoMode.screenWidth * _videoMode.scaleFactor; displayHeight = _videoMode.screenHeight * _videoMode.scaleFactor; } switch (_orientationLandscape) { case 1: flags |= SDL_LANDSCVIDEO; break; case 2: flags |= SDL_INVLNDVIDEO; break; default: flags |= SDL_PORTRTVIDEO; } _hwscreen = SDL_SetVideoMode(displayWidth, displayHeight, 16, flags); if (_hwscreen == NULL) { warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); g_system->quit(); } // see what orientation sdl finally accepted if (_hwscreen->flags & SDL_PORTRTVIDEO) _orientationLandscape = _newOrientation = 0; else if (_hwscreen->flags & SDL_LANDSCVIDEO) _orientationLandscape = _newOrientation = 1; else _orientationLandscape = _newOrientation = 2; // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // Distinguish 555 and 565 mode if (_hwscreen->format->Rmask == 0x7C00) InitScalers(555); else InitScalers(565); _overlayFormat.bytesPerPixel = _hwscreen->format->BytesPerPixel; _overlayFormat.rLoss = _hwscreen->format->Rloss; _overlayFormat.gLoss = _hwscreen->format->Gloss; _overlayFormat.bLoss = _hwscreen->format->Bloss; _overlayFormat.aLoss = _hwscreen->format->Aloss; _overlayFormat.rShift = _hwscreen->format->Rshift; _overlayFormat.gShift = _hwscreen->format->Gshift; _overlayFormat.bShift = _hwscreen->format->Bshift; _overlayFormat.aShift = _hwscreen->format->Ashift; // Need some extra bytes around when using 2xSaI _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_tmpscreen == NULL) error("_tmpscreen creation failed (%s)", SDL_GetError()); // Overlay if (CEDevice::hasDesktopResolution()) { _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth * _scaleFactorXm / _scaleFactorXd, _videoMode.overlayHeight * _scaleFactorYm / _scaleFactorYd, 16, 0, 0, 0, 0); if (_overlayscreen == NULL) error("_overlayscreen failed (%s)", SDL_GetError()); _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth * _scaleFactorXm / _scaleFactorXd + 3, _videoMode.overlayHeight * _scaleFactorYm / _scaleFactorYd + 3, 16, 0, 0, 0, 0); if (_tmpscreen2 == NULL) error("_tmpscreen2 failed (%s)", SDL_GetError()); } else { _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth, _videoMode.overlayHeight, 16, 0, 0, 0, 0); if (_overlayscreen == NULL) error("_overlayscreen failed (%s)", SDL_GetError()); _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3, 16, 0, 0, 0, 0); if (_tmpscreen2 == NULL) error("_tmpscreen2 failed (%s)", SDL_GetError()); } // Toolbar _toolbarHighDrawn = false; uint16 *toolbar_screen = (uint16 *)calloc(320 * 40, sizeof(uint16)); // *not* leaking memory here _toolbarLow = SDL_CreateRGBSurfaceFrom(toolbar_screen, 320, 40, 16, 320 * 2, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_toolbarLow == NULL) error("_toolbarLow failed (%s)", SDL_GetError()); if (_videoMode.screenHeight > 240) { uint16 *toolbar_screen_high = (uint16 *)calloc(640 * 80, sizeof(uint16)); _toolbarHigh = SDL_CreateRGBSurfaceFrom(toolbar_screen_high, 640, 80, 16, 640 * 2, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_toolbarHigh == NULL) error("_toolbarHigh failed (%s)", SDL_GetError()); } else _toolbarHigh = NULL; // keyboard cursor control, some other better place for it? _eventSource->resetKeyboardEmulation(_videoMode.screenWidth * _scaleFactorXm / _scaleFactorXd - 1, _videoMode.screenHeight * _scaleFactorXm / _scaleFactorXd - 1); return true; }
void OSystem_SDL::loadGFXMode() { assert(_inited); _forceFull = true; _modeFlags |= DF_UPDATE_EXPAND_1_PIXEL; int hwW, hwH; #ifndef __MAEMO__ _overlayWidth = _screenWidth * _scaleFactor; _overlayHeight = _screenHeight * _scaleFactor; if (_screenHeight != 200) _adjustAspectRatio = false; if (_adjustAspectRatio) _overlayHeight = real2Aspect(_overlayHeight); hwW = _screenWidth * _scaleFactor; hwH = effectiveScreenHeight(); #else hwW = _overlayWidth; hwH = _overlayHeight; #endif // // Create the surface that contains the 8 bit game data // _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth, _screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) error("allocating _screen failed"); // // Create the surface that contains the scaled graphics in 16 bit mode // _hwscreen = SDL_SetVideoMode(hwW, hwH, 16, _fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE ); if (_hwscreen == NULL) { // DON'T use error(), as this tries to bring up the debug // console, which WON'T WORK now that _hwscreen is hosed. // FIXME: We should be able to continue the game without // shutting down or bringing up the debug console, but at // this point we've already screwed up all our member vars. // We need to find a way to call SDL_SetVideoMode *before* // that happens and revert to all the old settings if we // can't pull off the switch to the new settings. // // Fingolfin says: the "easy" way to do that is not to modify // the member vars before we are sure everything is fine. Think // of "transactions, commit, rollback" style... we use local vars // in place of the member vars, do everything etc. etc.. In case // of a failure, rollback is trivial. Only if everything worked fine // do we "commit" the changed values to the member vars. warning("SDL_SetVideoMode says we can't switch to that mode (%s)", SDL_GetError()); quit(); } // // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // // Distinguish 555 and 565 mode if (_hwscreen->format->Rmask == 0x7C00) InitScalers(555); else InitScalers(565); // Need some extra bytes around when using 2xSaI _tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _screenWidth + 3, _screenHeight + 3, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_tmpscreen == NULL) error("allocating _tmpscreen failed"); _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_overlayscreen == NULL) error("allocating _overlayscreen failed"); _tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth + 3, _overlayHeight + 3, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_tmpscreen2 == NULL) error("allocating _tmpscreen2 failed"); #ifdef USE_OSD _osdSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _hwscreen->w, _hwscreen->h, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask); if (_osdSurface == NULL) error("allocating _osdSurface failed"); SDL_SetColorKey(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kOSDColorKey); #endif // keyboard cursor control, some other better place for it? _km.x_max = _screenWidth * _scaleFactor - 1; _km.y_max = effectiveScreenHeight() - 1; _km.delay_time = 25; _km.last_time = 0; }