diff --git a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp deleted file mode 100644 index 946b653389..0000000000 --- a/src/openrct2-ui/drawing/engines/SoftwareDrawingEngine.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2025 OpenRCT2 developers - * - * For a complete list of all authors, please refer to contributors.md - * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 - * - * OpenRCT2 is licensed under the GNU General Public License version 3. - *****************************************************************************/ - -#include "DrawingEngineFactory.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace OpenRCT2; -using namespace OpenRCT2::Drawing; -using namespace OpenRCT2::Ui; - -class SoftwareDrawingEngine final : public X8DrawingEngine -{ -private: - std::shared_ptr const _uiContext; - SDL_Window* _window = nullptr; - SDL_Surface* _surface = nullptr; - SDL_Surface* _RGBASurface = nullptr; - SDL_Palette* _palette = nullptr; - -public: - explicit SoftwareDrawingEngine(const std::shared_ptr& uiContext) - : X8DrawingEngine(uiContext) - , _uiContext(uiContext) - { - _window = static_cast(_uiContext->GetWindow()); - } - - ~SoftwareDrawingEngine() override - { - SDL_FreeSurface(_surface); - SDL_FreeSurface(_RGBASurface); - SDL_FreePalette(_palette); - } - - void Initialise() override - { - } - - void Resize(uint32_t width, uint32_t height) override - { - SDL_FreeSurface(_surface); - SDL_FreeSurface(_RGBASurface); - SDL_FreePalette(_palette); - - _surface = SDL_CreateRGBSurface(0, width, height, 8, 0, 0, 0, 0); - _RGBASurface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0); - SDL_SetSurfaceBlendMode(_RGBASurface, SDL_BLENDMODE_NONE); - _palette = SDL_AllocPalette(256); - - if (_surface == nullptr || _palette == nullptr || _RGBASurface == nullptr) - { - LOG_FATAL("%p || %p || %p == nullptr %s", _surface, _palette, _RGBASurface, SDL_GetError()); - exit(-1); - } - - if (SDL_SetSurfacePalette(_surface, _palette)) - { - LOG_FATAL("SDL_SetSurfacePalette failed %s", SDL_GetError()); - exit(-1); - } - - ConfigureBits(width, height, _surface->pitch); - } - - void SetPalette(const GamePalette& palette) override - { - SDL_Surface* windowSurface = SDL_GetWindowSurface(_window); - if (windowSurface != nullptr && _palette != nullptr) - { - SDL_Colour colours[256]; - for (int32_t i = 0; i < 256; i++) - { - colours[i].r = palette[i].Red; - colours[i].g = palette[i].Green; - colours[i].b = palette[i].Blue; - colours[i].a = palette[i].Alpha; - } - SDL_SetPaletteColors(_palette, colours, 0, 256); - } - } - - void EndDraw() override - { - X8DrawingEngine::EndDraw(); - - Display(); - } - -private: - void Display() - { - // Lock the surface before setting its pixels - if (SDL_MUSTLOCK(_surface)) - { - if (SDL_LockSurface(_surface) < 0) - { - LOG_ERROR("locking failed %s", SDL_GetError()); - return; - } - } - - // Copy pixels from the virtual screen buffer to the surface - std::copy_n(_bits, _surface->pitch * _surface->h, static_cast(_surface->pixels)); - - // Unlock the surface - if (SDL_MUSTLOCK(_surface)) - { - SDL_UnlockSurface(_surface); - } - -// On macOS with high DPI ("retina") screens this renders only to a quarter of the screen. -// A workaround is to always scale the surface, but that incurs an additonal copy. -// https://github.com/OpenRCT2/OpenRCT2/issues/21772 -#if !defined(__APPLE__) - // Copy the surface to the window - if (Config::Get().general.WindowScale == 1 || Config::Get().general.WindowScale <= 0) - { - SDL_Surface* windowSurface = SDL_GetWindowSurface(_window); - if (SDL_BlitSurface(_surface, nullptr, windowSurface, nullptr)) - { - LOG_FATAL("SDL_BlitSurface %s", SDL_GetError()); - exit(1); - } - } - else -#endif - { - // first blit to rgba surface to change the pixel format - if (SDL_BlitSurface(_surface, nullptr, _RGBASurface, nullptr)) - { - LOG_FATAL("SDL_BlitSurface %s", SDL_GetError()); - exit(1); - } - - // then scale to window size. Without changing to RGBA first, SDL complains - // about blit configurations being incompatible. - if (SDL_BlitScaled(_RGBASurface, nullptr, SDL_GetWindowSurface(_window), nullptr)) - { - LOG_FATAL("SDL_BlitScaled %s", SDL_GetError()); - exit(1); - } - } - if (SDL_UpdateWindowSurface(_window)) - { - LOG_FATAL("SDL_UpdateWindowSurface %s", SDL_GetError()); - exit(1); - } - } -}; - -std::unique_ptr OpenRCT2::Ui::CreateSoftwareDrawingEngine(const std::shared_ptr& uiContext) -{ - return std::make_unique(uiContext); -} diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj index 82e299cf25..2f1e8233cc 100644 --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -128,7 +128,6 @@ -