浏览代码

no async for generated images

Laserlicht 2 月之前
父节点
当前提交
c9834c43d6
共有 4 个文件被更改,包括 21 次插入1 次删除
  1. 4 0
      client/render/IImage.h
  2. 3 0
      client/renderSDL/RenderHandler.cpp
  3. 11 1
      client/renderSDL/SDLImage.cpp
  4. 3 0
      client/renderSDL/SDLImage.h

+ 4 - 0
client/render/IImage.h

@@ -128,6 +128,10 @@ public:
 	/// Returns true if this image is still loading and can't be used
 	virtual bool isLoading() const = 0;
 
+	/// When disabled upscaling needs to be done in sync (e.g. because there is no 1x base image)
+	virtual void setAsyncUpscale(bool on) = 0;
+	virtual bool getAsyncUpscale() const = 0;
+
 	virtual ~ISharedImage() = default;
 
 	virtual const SDL_Palette * getPalette() const = 0;

+ 3 - 0
client/renderSDL/RenderHandler.cpp

@@ -333,6 +333,9 @@ std::shared_ptr<SDLImageShared> RenderHandler::loadScaledImage(const ImageLocato
 			img = img->drawShadow((*locator.generateShadow) == SharedImageLocator::ShadowMode::SHADOW_SHEAR);
 		if(isOverlay && generateOverlay && (*locator.generateOverlay) == SharedImageLocator::OverlayMode::OVERLAY_OUTLINE)
 			img = img->drawOutline(Colors::WHITE, 1);
+
+		if(locator.scalingFactor == 1)
+			img->setAsyncUpscale(false); // no base image, needs to be done in sync
 	}
 
 	return img;

+ 11 - 1
client/renderSDL/SDLImage.cpp

@@ -271,7 +271,7 @@ std::shared_ptr<SDLImageShared> SDLImageShared::createScaled(const SDLImageShare
 		self->upscalingInProgress = false;
 	};
 
-	if(settings["video"]["asyncUpscaling"].Bool())
+	if(settings["video"]["asyncUpscaling"].Bool() && from->getAsyncUpscale())
 		ENGINE->async().run(scalingTask);
 	else
 		scalingTask();
@@ -284,6 +284,16 @@ bool SDLImageShared::isLoading() const
 	return upscalingInProgress;
 }
 
+void SDLImageShared::setAsyncUpscale(bool on)
+{
+	asyncUpscale = on;
+}
+
+bool SDLImageShared::getAsyncUpscale() const
+{
+	return asyncUpscale;
+}
+
 std::shared_ptr<const ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Palette * palette) const
 {
 	if(upscalingInProgress)

+ 3 - 0
client/renderSDL/SDLImage.h

@@ -36,6 +36,7 @@ class SDLImageShared final : public ISharedImage, public std::enable_shared_from
 	Point fullSize;
 
 	std::atomic_bool upscalingInProgress = false;
+	bool asyncUpscale = true;
 
 	// Keep the original palette, in order to do color switching operation
 	void savePalette();
@@ -63,6 +64,8 @@ public:
 	Rect contentRect() const override;
 
 	bool isLoading() const override;
+	void setAsyncUpscale(bool on) override;
+	bool getAsyncUpscale() const override;
 
 	const SDL_Palette * getPalette() const override;