From 68bac7363293c336bb9d7e7038c101a04e4e2a35 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 17 Jan 2025 17:05:34 +0000 Subject: [PATCH] Initial part of background scaling --- client/renderSDL/ScalableImage.h | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/client/renderSDL/ScalableImage.h b/client/renderSDL/ScalableImage.h index 01bbe97a8..5bb68f855 100644 --- a/client/renderSDL/ScalableImage.h +++ b/client/renderSDL/ScalableImage.h @@ -15,6 +15,9 @@ #include "../../lib/Color.h" +#include +#include + struct SDL_Palette; class ScalableImageInstance; @@ -44,9 +47,27 @@ struct ScalableImageParameters : boost::noncopyable void adjustPalette(const SDL_Palette * originalPalette, EImageBlitMode blitMode, const ColorFilter & shifter, uint32_t colorsToSkipMask); }; +class ImageScaler +{ + ImageScaler(); + + tbb::task_arena arena; +public: + static ImageScaler & getInstance() + { + static ImageScaler scaler; + return scaler; + } + + void enqueueTask(const std::function & task) + { + arena.enqueue(task); + } +}; + class ScalableImageShared final : public std::enable_shared_from_this, boost::noncopyable { - static constexpr int maxScaling = 4; + static constexpr int scalingSize = 5; // 0-4 range. TODO: switch to either 2-4 or 1-4 static constexpr int maxFlips = 4; using FlippedImages = std::array, maxFlips>; @@ -63,18 +84,25 @@ class ScalableImageShared final : public std::enable_shared_from_this scaled; + /// 1x-4x images. 1x are currently unused, but can be used for providing non-palette version of these images + std::array scaled; + /// Locator of this image, for loading additional (e.g. upscaled) images const SharedImageLocator locator; + /// Contains all upscaling tasks related to this image that finished processing and can be applied + tbb::concurrent_queue> upscalingQueue; + + /// Number of images that are currently being upscaled + int scheduledUpscalingEvents = 0; + std::shared_ptr loadOrGenerateImage(EImageBlitMode mode, int8_t scalingFactor, PlayerColor color) const; void loadScaledImages(int8_t scalingFactor, PlayerColor color);