* Resets the screen surfaces based on the current display options, * as they don't automatically take effect. * @param resetVideo Reset display surface. */
| 303 | * @param resetVideo Reset display surface. |
| 304 | */ |
| 305 | void Screen::resetDisplay(bool resetVideo) |
| 306 | { |
| 307 | int width = Options::displayWidth; |
| 308 | int height = Options::displayHeight; |
| 309 | #ifdef __linux__ |
| 310 | Uint32 oldFlags = _flags; |
| 311 | #endif |
| 312 | makeVideoFlags(); |
| 313 | |
| 314 | if (!_surface || (_surface && |
| 315 | (_surface->getSurface()->format->BitsPerPixel != _bpp || |
| 316 | _surface->getSurface()->w != _baseWidth || |
| 317 | _surface->getSurface()->h != _baseHeight))) // don't reallocate _surface if not necessary, it's a waste of CPU cycles |
| 318 | { |
| 319 | if (_surface) delete _surface; |
| 320 | _surface = new Surface(_baseWidth, _baseHeight, 0, 0, Screen::isHQXEnabled() ? 32 : 8); // only HQX needs 32bpp for this surface; the OpenGL class has its own 32bpp buffer |
| 321 | if (_surface->getSurface()->format->BitsPerPixel == 8) _surface->setPalette(deferredPalette); |
| 322 | } |
| 323 | SDL_SetColorKey(_surface->getSurface(), 0, 0); // turn off color key! |
| 324 | |
| 325 | if (resetVideo || _screen->format->BitsPerPixel != _bpp) |
| 326 | { |
| 327 | #ifdef __linux__ |
| 328 | // Workaround for segfault when switching to opengl |
| 329 | if (!(oldFlags & SDL_OPENGL) && (_flags & SDL_OPENGL)) |
| 330 | { |
| 331 | Uint8 cursor = 0; |
| 332 | char *_oldtitle = 0; |
| 333 | SDL_WM_GetCaption(&_oldtitle, NULL); |
| 334 | std::string title(_oldtitle); |
| 335 | SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 336 | SDL_InitSubSystem(SDL_INIT_VIDEO); |
| 337 | SDL_ShowCursor(SDL_ENABLE); |
| 338 | SDL_EnableUNICODE(1); |
| 339 | SDL_WM_SetCaption(title.c_str(), 0); |
| 340 | SDL_SetCursor(SDL_CreateCursor(&cursor, &cursor, 1,1,0,0)); |
| 341 | } |
| 342 | #endif |
| 343 | Log(LOG_INFO) << "Attempting to set display to " << width << "x" << height << "x" << _bpp << "..."; |
| 344 | _screen = SDL_SetVideoMode(width, height, _bpp, _flags); |
| 345 | if (_screen == 0) |
| 346 | { |
| 347 | Log(LOG_ERROR) << SDL_GetError(); |
| 348 | Log(LOG_INFO) << "Attempting to set display to default resolution..."; |
| 349 | _screen = SDL_SetVideoMode(640, 400, _bpp, _flags); |
| 350 | if (_screen == 0) |
| 351 | { |
| 352 | throw Exception(SDL_GetError()); |
| 353 | } |
| 354 | } |
| 355 | Log(LOG_INFO) << "Display set to " << getWidth() << "x" << getHeight() << "x" << (int)_screen->format->BitsPerPixel << "."; |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | clear(); |
| 360 | } |
| 361 | |
| 362 | Options::displayWidth = getWidth(); |
no test coverage detected