| 70 | } |
| 71 | |
| 72 | void SoftwareDrawingEngine::resize(const int32_t width, const int32_t height) |
| 73 | { |
| 74 | // Scale the width and height by configured scale factor |
| 75 | const auto scaleFactor = Config::get().scaleFactor; |
| 76 | const auto scaledWidth = (int32_t)(width / scaleFactor); |
| 77 | const auto scaledHeight = (int32_t)(height / scaleFactor); |
| 78 | |
| 79 | // Release old resources. |
| 80 | if (_screenSurface != nullptr) |
| 81 | { |
| 82 | SDL_DestroySurface(_screenSurface); |
| 83 | } |
| 84 | if (_screenRGBASurface != nullptr) |
| 85 | { |
| 86 | SDL_DestroySurface(_screenRGBASurface); |
| 87 | } |
| 88 | |
| 89 | if (_screenTexture != nullptr) |
| 90 | { |
| 91 | SDL_DestroyTexture(_screenTexture); |
| 92 | _screenTexture = nullptr; |
| 93 | } |
| 94 | |
| 95 | if (_scaledScreenTexture != nullptr) |
| 96 | { |
| 97 | SDL_DestroyTexture(_scaledScreenTexture); |
| 98 | _scaledScreenTexture = nullptr; |
| 99 | } |
| 100 | |
| 101 | SDL_PixelFormat outputFormat = SDL_GetWindowPixelFormat(_window); |
| 102 | if (outputFormat == SDL_PIXELFORMAT_UNKNOWN) |
| 103 | { |
| 104 | Logging::error("SDL_GetWindowPixelFormat failed: {}", SDL_GetError()); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | // Surfaces. |
| 109 | _screenSurface = SDL_CreateSurface(scaledWidth, scaledHeight, SDL_PIXELFORMAT_INDEX8); |
| 110 | if (_screenSurface == nullptr) |
| 111 | { |
| 112 | Logging::error("SDL_CreateRGBSurface (_screenSurface) failed: {}", SDL_GetError()); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | _screenRGBASurface = SDL_CreateSurface(scaledWidth, scaledHeight, outputFormat); |
| 117 | if (_screenRGBASurface == nullptr) |
| 118 | { |
| 119 | Logging::error("SDL_CreateRGBSurface (_screenRGBASurface) failed: {}", SDL_GetError()); |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | if (!SDL_SetSurfaceBlendMode(_screenRGBASurface, SDL_BLENDMODE_NONE)) |
| 124 | { |
| 125 | Logging::error("SDL_SetSurfaceBlendMode (_screenRGBASurface) failed: {}", SDL_GetError()); |
| 126 | } |
| 127 | if (!SDL_SetSurfacePalette(_screenSurface, _palette)) |
| 128 | { |
| 129 | Logging::error("SDL_SetSurfacePalette (_screenSurface) failed: {}", SDL_GetError()); |
no test coverage detected