[Scummvm-git-logs] scummvm master -> 9d6562189da269df580bd0708dad21db23507f18

elasota noreply at scummvm.org
Thu Sep 29 02:42:07 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
9d6562189d MTROPOLIS: Convert most Surface usages to ManagedSurface to fix tons of memory leaks from Surface not freeing memory whe


Commit: 9d6562189da269df580bd0708dad21db23507f18
    https://github.com/scummvm/scummvm/commit/9d6562189da269df580bd0708dad21db23507f18
Author: elasota (ejlasota at gmail.com)
Date: 2022-09-28T22:41:11-04:00

Commit Message:
MTROPOLIS: Convert most Surface usages to ManagedSurface to fix tons of memory leaks from Surface not freeing memory when destroyed

Changed paths:
    engines/mtropolis/assets.cpp
    engines/mtropolis/assets.h
    engines/mtropolis/elements.cpp
    engines/mtropolis/elements.h
    engines/mtropolis/hacks.cpp
    engines/mtropolis/metaengine.cpp
    engines/mtropolis/modifiers.cpp
    engines/mtropolis/render.cpp
    engines/mtropolis/render.h
    engines/mtropolis/runtime.cpp
    engines/mtropolis/runtime.h
    engines/mtropolis/saveload.cpp


diff --git a/engines/mtropolis/assets.cpp b/engines/mtropolis/assets.cpp
index 2ae84cc8417..3e3221cfc25 100644
--- a/engines/mtropolis/assets.cpp
+++ b/engines/mtropolis/assets.cpp
@@ -204,7 +204,7 @@ void CachedMToon::decompressFrames(const Common::Array<uint8> &data) {
 }
 
 template<class TNumber, uint32 TLiteralMask, uint32 TTransparentRowSkipMask>
-bool CachedMToon::decompressMToonRLE(const RleFrame &frame, const Common::Array<TNumber> &coefsArray, Graphics::Surface &surface, bool isBottomUp) {
+bool CachedMToon::decompressMToonRLE(const RleFrame &frame, const Common::Array<TNumber> &coefsArray, Graphics::ManagedSurface &surface, bool isBottomUp) {
 	assert(sizeof(TNumber) == surface.format.bytesPerPixel);
 
 	size_t size = coefsArray.size();
@@ -293,7 +293,7 @@ bool CachedMToon::decompressMToonRLE(const RleFrame &frame, const Common::Array<
 	return true;
 }
 
-void CachedMToon::decompressRLEFrameToImage(size_t frameIndex, Graphics::Surface &surface) {
+void CachedMToon::decompressRLEFrameToImage(size_t frameIndex, Graphics::ManagedSurface &surface) {
 	assert(surface.format == _rleOptimizedFormat);
 
 	bool isBottomUp = (_metadata->imageFormat == MToonMetadata::kImageFormatWindows);
@@ -384,7 +384,7 @@ void CachedMToon::loadRLEFrames(const Common::Array<uint8> &data) {
 }
 
 void CachedMToon::decompressRLEFrame(size_t frameIndex) {
-	Common::SharedPtr<Graphics::Surface> surface(new Graphics::Surface());
+	Common::SharedPtr<Graphics::ManagedSurface> surface(new Graphics::ManagedSurface());
 
 	RleFrame &frame = _rleData[frameIndex];
 
@@ -401,7 +401,7 @@ void CachedMToon::loadUncompressedFrame(const Common::Array<uint8> &data, size_t
 
 	uint16 bpp = _metadata->bitsPerPixel;
 
-	Common::SharedPtr<Graphics::Surface> surface(new Graphics::Surface());
+	Common::SharedPtr<Graphics::ManagedSurface> surface(new Graphics::ManagedSurface());
 	Graphics::PixelFormat pixFmt;
 
 	if (bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8)
@@ -495,7 +495,7 @@ void CachedMToon::decompressQuickTimeFrame(const Common::Array<uint8> &data, siz
 	}
 
 	// Clone the decompressed frame
-	_decompressedFrames[frameIndex] = Common::SharedPtr<Graphics::Surface>(new Graphics::Surface(*surface));
+	_decompressedFrames[frameIndex].reset(new Graphics::ManagedSurface(surface));
 }
 
 template<class TSrcNumber, uint32 TSrcLiteralMask, uint32 TSrcTransparentSkipMask, class TDestNumber, uint32 TDestLiteralMask, uint32 TDestTransparentSkipMask>
@@ -558,8 +558,8 @@ void CachedMToon::optimizeNonTemporal(const Graphics::PixelFormat &targetFormatR
 	_optimizedFrames.resize(_decompressedFrames.size());
 
 	for (size_t i = 0; i < _decompressedFrames.size(); i++) {
-		Common::SharedPtr<Graphics::Surface> srcSurface = _decompressedFrames[i];
-		Common::SharedPtr<Graphics::Surface> &optimizedSurfRef = _optimizedFrames[i];
+		Common::SharedPtr<Graphics::ManagedSurface> srcSurface = _decompressedFrames[i];
+		Common::SharedPtr<Graphics::ManagedSurface> &optimizedSurfRef = _optimizedFrames[i];
 
 		// FIXME: Aggregate these checks and merge into a single format field
 		if (optimizedSurfRef == nullptr || optimizedSurfRef->format != targetFormat) {
@@ -569,7 +569,7 @@ void CachedMToon::optimizeNonTemporal(const Graphics::PixelFormat &targetFormatR
 					optimizedSurfRef = srcSurface;
 				} else {
 					optimizedSurfRef.reset();
-					optimizedSurfRef.reset(srcSurface->convertTo(targetFormat));
+					optimizedSurfRef.reset(new Graphics::ManagedSurface(srcSurface->surfacePtr()->convertTo(targetFormat)));
 				}
 			} else {
 				optimizedSurfRef = srcSurface;
@@ -608,7 +608,7 @@ void CachedMToon::optimizeRLE(const Graphics::PixelFormat &targetFormatRef) {
 	_rleOptimizedFormat = targetFormat;
 }
 
-void CachedMToon::getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr<Graphics::Surface>& surface) const {
+void CachedMToon::getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr<Graphics::ManagedSurface> &surface) const {
 	if (!_isRLETemporalCompressed) {
 		surface = _optimizedFrames[targetFrame];
 	} else if (_metadata->codecID == kMToonRLECodecID) {
@@ -633,7 +633,7 @@ void CachedMToon::getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common:
 		}
 
 		if (!surface || surface->format != _rleOptimizedFormat) {
-			surface.reset(new Graphics::Surface());
+			surface.reset(new Graphics::ManagedSurface());
 			surface->create(_metadata->rect.width(), _metadata->rect.height(), _rleOptimizedFormat);
 		}
 
@@ -787,7 +787,7 @@ const Common::Array<int> &MovieAsset::getDamagedFrames() const {
 CachedImage::CachedImage() : _colorDepth(kColorDepthModeInvalid), _isOptimized(false) {
 }
 
-void CachedImage::resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::Surface> &surface) {
+void CachedImage::resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::ManagedSurface> &surface) {
 	_optimizedSurface.reset();
 	_isOptimized = false;
 
@@ -795,7 +795,7 @@ void CachedImage::resetSurface(ColorDepthMode colorDepth, const Common::SharedPt
 	_surface = surface;
 }
 
-const Common::SharedPtr<Graphics::Surface> &CachedImage::optimize(Runtime *runtime) {
+const Common::SharedPtr<Graphics::ManagedSurface> &CachedImage::optimize(Runtime *runtime) {
 	ColorDepthMode renderDepth = runtime->getRealColorDepth();
 	const Graphics::PixelFormat &renderFmt = runtime->getRenderPixelFormat();
 
@@ -804,11 +804,11 @@ const Common::SharedPtr<Graphics::Surface> &CachedImage::optimize(Runtime *runti
 		size_t h = _surface->h;
 
 		if (renderDepth == kColorDepthMode16Bit && _colorDepth == kColorDepthMode32Bit) {
-			_optimizedSurface.reset(new Graphics::Surface());
+			_optimizedSurface.reset(new Graphics::ManagedSurface());
 			_optimizedSurface->create(w, h, renderFmt);
 			Render::convert32To16(*_optimizedSurface, *_surface);
 		} else if (renderDepth == kColorDepthMode32Bit && _colorDepth == kColorDepthMode16Bit) {
-			_optimizedSurface.reset(new Graphics::Surface());
+			_optimizedSurface.reset(new Graphics::ManagedSurface());
 			_optimizedSurface->create(w, h, renderFmt);
 			Render::convert16To32(*_optimizedSurface, *_surface);
 		} else {
@@ -969,8 +969,8 @@ const Common::SharedPtr<CachedImage> &ImageAsset::loadAndCacheImage(Runtime *run
 	bool bottomUp = (imageFormat == ImageAsset::kImageFormatWindows);
 	bool isBigEndian = (imageFormat == ImageAsset::kImageFormatMac);
 
-	Common::SharedPtr<Graphics::Surface> imageSurface;
-	imageSurface.reset(new Graphics::Surface());
+	Common::SharedPtr<Graphics::ManagedSurface> imageSurface;
+	imageSurface.reset(new Graphics::ManagedSurface());
 	imageSurface->create(width, height, pixelFmt);
 
 	for (int inRow = 0; inRow < height; inRow++) {
diff --git a/engines/mtropolis/assets.h b/engines/mtropolis/assets.h
index eb7788a4a46..c41f674393d 100644
--- a/engines/mtropolis/assets.h
+++ b/engines/mtropolis/assets.h
@@ -107,7 +107,7 @@ public:
 
 	void optimize(Runtime *runtime);
 
-	void getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr<Graphics::Surface> &surface) const;
+	void getOrRenderFrame(uint32 prevFrame, uint32 targetFrame, Common::SharedPtr<Graphics::ManagedSurface> &surface) const;
 	const Common::SharedPtr<MToonMetadata> &getMetadata() const;
 
 private:
@@ -131,7 +131,7 @@ private:
 	static const uint32 kMToonRLETemporalFramePrefix = 1;
 
 	void decompressFrames(const Common::Array<uint8> &data);
-	void decompressRLEFrameToImage(size_t frameIndex, Graphics::Surface &surface);
+	void decompressRLEFrameToImage(size_t frameIndex, Graphics::ManagedSurface &surface);
 	void loadRLEFrames(const Common::Array<uint8> &data);
 	void decompressRLEFrame(size_t frameIndex);
 	void loadUncompressedFrame(const Common::Array<uint8> &data, size_t frameIndex);
@@ -141,13 +141,13 @@ private:
 	void rleReformat(RleFrame &frame, const Common::Array<TSrcNumber> &srcData, const Graphics::PixelFormat &srcFormatRef, Common::Array<TDestNumber> &destData, const Graphics::PixelFormat &destFormatRef);
 
 	template<class TNumber, uint32 TLiteralMask, uint32 TTransparentRowSkipMask>
-	static bool decompressMToonRLE(const RleFrame &frame, const Common::Array<TNumber> &coefsArray, Graphics::Surface &surface, bool isBottomUp);
+	static bool decompressMToonRLE(const RleFrame &frame, const Common::Array<TNumber> &coefsArray, Graphics::ManagedSurface &surface, bool isBottomUp);
 
 	Common::Array<RleFrame> _rleData;
 	bool _isRLETemporalCompressed;
 
-	Common::Array<Common::SharedPtr<Graphics::Surface> > _decompressedFrames;
-	Common::Array<Common::SharedPtr<Graphics::Surface> > _optimizedFrames;
+	Common::Array<Common::SharedPtr<Graphics::ManagedSurface> > _decompressedFrames;
+	Common::Array<Common::SharedPtr<Graphics::ManagedSurface> > _optimizedFrames;
 
 	Graphics::PixelFormat _rleInternalFormat;
 	Graphics::PixelFormat _rleOptimizedFormat;
@@ -229,13 +229,13 @@ class CachedImage {
 public:
 	CachedImage();
 
-	const Common::SharedPtr<Graphics::Surface> &optimize(Runtime *runtime);
+	const Common::SharedPtr<Graphics::ManagedSurface> &optimize(Runtime *runtime);
 
-	void resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::Surface> &surface);
+	void resetSurface(ColorDepthMode colorDepth, const Common::SharedPtr<Graphics::ManagedSurface> &surface);
 
 private:
-	Common::SharedPtr<Graphics::Surface> _surface;
-	Common::SharedPtr<Graphics::Surface> _optimizedSurface;
+	Common::SharedPtr<Graphics::ManagedSurface> _surface;
+	Common::SharedPtr<Graphics::ManagedSurface> _optimizedSurface;
 
 	ColorDepthMode _colorDepth;
 	bool _isOptimized;
diff --git a/engines/mtropolis/elements.cpp b/engines/mtropolis/elements.cpp
index 51e73904b44..f9ce55505a7 100644
--- a/engines/mtropolis/elements.cpp
+++ b/engines/mtropolis/elements.cpp
@@ -652,7 +652,7 @@ void MovieElement::render(Window *window) {
 		if (_resizeFilter) {
 			if (!_scaledFrame)
 				_scaledFrame = _resizeFilter->scaleFrame(*_displayFrame, _currentTimestamp);
-			displaySurface = _scaledFrame.get();
+			displaySurface = _scaledFrame->surfacePtr();
 		}
 
 		Graphics::ManagedSurface *target = window->getSurface().get();
@@ -1077,7 +1077,7 @@ void ImageElement::render(Window *window) {
 		if (inkMode == VisualElementRenderProperties::kInkModeInvisible)
 			return;
 
-		Common::SharedPtr<Graphics::Surface> optimized = _cachedImage->optimize(_runtime);
+		Common::SharedPtr<Graphics::ManagedSurface> optimized = _cachedImage->optimize(_runtime);
 		Common::Rect srcRect(optimized->w, optimized->h);
 		Common::Rect destRect(_cachedAbsoluteOrigin.x, _cachedAbsoluteOrigin.y, _cachedAbsoluteOrigin.x + _rect.width(), _cachedAbsoluteOrigin.y + _rect.height());
 
diff --git a/engines/mtropolis/elements.h b/engines/mtropolis/elements.h
index e184c24494f..c91ccf851de 100644
--- a/engines/mtropolis/elements.h
+++ b/engines/mtropolis/elements.h
@@ -78,7 +78,7 @@ class MovieResizeFilter {
 public:
 	virtual ~MovieResizeFilter();
 
-	virtual Common::SharedPtr<Graphics::Surface> scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const = 0;
+	virtual Common::SharedPtr<Graphics::ManagedSurface> scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const = 0;
 };
 
 class MovieElement : public VisualElement, public ISegmentUnloadSignalReceiver, public IPlayMediaSignalReceiver {
@@ -162,7 +162,7 @@ private:
 	IntRange _playRange;
 
 	const Graphics::Surface *_displayFrame;
-	Common::SharedPtr<Graphics::Surface> _scaledFrame;
+	Common::SharedPtr<Graphics::ManagedSurface> _scaledFrame;
 	Common::SharedPtr<MovieResizeFilter> _resizeFilter;
 
 	Common::SharedPtr<SegmentUnloadSignaller> _unloadSignaller;
@@ -283,7 +283,7 @@ private:
 	bool _isPlaying;	// Is actually rolling media, this is only set by playMedia because it needs to start after scene transition
 
 	Runtime *_runtime;
-	Common::SharedPtr<Graphics::Surface> _renderSurface;
+	Common::SharedPtr<Graphics::ManagedSurface> _renderSurface;
 	uint32 _renderedFrame;
 
 	Common::SharedPtr<MToonMetadata> _metadata;
diff --git a/engines/mtropolis/hacks.cpp b/engines/mtropolis/hacks.cpp
index f04d87fcdb5..9755010e10a 100644
--- a/engines/mtropolis/hacks.cpp
+++ b/engines/mtropolis/hacks.cpp
@@ -156,20 +156,20 @@ class ObsidianRSGLogoAnamorphicFilter : public MovieResizeFilter {
 public:
 	ObsidianRSGLogoAnamorphicFilter();
 
-	Common::SharedPtr<Graphics::Surface> scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const override;
+	Common::SharedPtr<Graphics::ManagedSurface> scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const override;
 
 private:
 	template<class TPixel>
-	void anamorphicScaleFrameTyped(const Graphics::Surface &src, Graphics::Surface &dest) const;
+	void anamorphicScaleFrameTyped(const Graphics::Surface &src, Graphics::ManagedSurface &dest) const;
 
 	static double anamorphicCurve(double d);
 	static double inverseAnamorphicCurve(double d);
 
 	template<class TPixel>
-	void halveWidthTyped(const Graphics::Surface &src, Graphics::Surface &dest) const;
+	void halveWidthTyped(const Graphics::ManagedSurface &src, Graphics::ManagedSurface &dest) const;
 
 	template<class TPixel>
-	void halveHeightTyped(const Graphics::Surface &src, Graphics::Surface &dest) const;
+	void halveHeightTyped(const Graphics::ManagedSurface &src, Graphics::ManagedSurface &dest) const;
 
 	Common::Array<uint> _xCoordinates;
 	Common::Array<uint> _yCoordinates;
@@ -244,7 +244,7 @@ ObsidianRSGLogoAnamorphicFilter::ObsidianRSGLogoAnamorphicFilter() {
 }
 
 template<class TPixel>
-void ObsidianRSGLogoAnamorphicFilter::anamorphicScaleFrameTyped(const Graphics::Surface &src, Graphics::Surface &dest) const {
+void ObsidianRSGLogoAnamorphicFilter::anamorphicScaleFrameTyped(const Graphics::Surface &src, Graphics::ManagedSurface &dest) const {
 	const uint width = _xCoordinates.size();
 	const uint height = _yCoordinates.size();
 
@@ -272,7 +272,7 @@ double ObsidianRSGLogoAnamorphicFilter::inverseAnamorphicCurve(double d) {
 }
 
 template<class TPixel>
-void ObsidianRSGLogoAnamorphicFilter::halveWidthTyped(const Graphics::Surface &src, Graphics::Surface &dest) const {
+void ObsidianRSGLogoAnamorphicFilter::halveWidthTyped(const Graphics::ManagedSurface &src, Graphics::ManagedSurface &dest) const {
 	const uint widthHigh = src.w;
 	const uint widthLow = dest.w;
 	const uint height = src.h;
@@ -302,7 +302,7 @@ void ObsidianRSGLogoAnamorphicFilter::halveWidthTyped(const Graphics::Surface &s
 }
 
 template<class TPixel>
-void ObsidianRSGLogoAnamorphicFilter::halveHeightTyped(const Graphics::Surface &src, Graphics::Surface &dest) const {
+void ObsidianRSGLogoAnamorphicFilter::halveHeightTyped(const Graphics::ManagedSurface &src, Graphics::ManagedSurface &dest) const {
 	const uint heightHigh = src.h;
 	const uint heightLow = dest.h;
 	const uint width = src.w;
@@ -332,12 +332,12 @@ void ObsidianRSGLogoAnamorphicFilter::halveHeightTyped(const Graphics::Surface &
 	}
 }
 
-Common::SharedPtr<Graphics::Surface> ObsidianRSGLogoAnamorphicFilter::scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const {
-	Common::SharedPtr<Graphics::Surface> result(new Graphics::Surface());
+Common::SharedPtr<Graphics::ManagedSurface> ObsidianRSGLogoAnamorphicFilter::scaleFrame(const Graphics::Surface &surface, uint32 timestamp) const {
+	Common::SharedPtr<Graphics::ManagedSurface> result(new Graphics::ManagedSurface());
 	result->create(_xCoordinates.size() / 2, _yCoordinates.size() / 2, surface.format);
 
-	Common::SharedPtr<Graphics::Surface> temp1(new Graphics::Surface());
-	Common::SharedPtr<Graphics::Surface> temp2(new Graphics::Surface());
+	Common::SharedPtr<Graphics::ManagedSurface> temp1(new Graphics::ManagedSurface());
+	Common::SharedPtr<Graphics::ManagedSurface> temp2(new Graphics::ManagedSurface());
 
 	temp1->create(_xCoordinates.size(), _yCoordinates.size(), surface.format);
 	temp2->create(_xCoordinates.size() / 2, _yCoordinates.size(), surface.format);
@@ -385,13 +385,13 @@ void ObsidianSaveScreenshotHooks::onSceneTransitionSetup(Runtime *runtime, const
 		Window *mainWindow = runtime->getMainWindow().lock().get();
 		if (mainWindow) {
 			Common::SharedPtr<Graphics::ManagedSurface> mainWindowSurface = mainWindow->getSurface();
-			Common::SharedPtr<Graphics::Surface> screenshot(new Graphics::Surface());
+			Common::SharedPtr<Graphics::ManagedSurface> screenshot(new Graphics::ManagedSurface());
 			screenshot->copyFrom(*mainWindowSurface);
 
 			runtime->setSaveScreenshotOverride(screenshot);
 		}
 	} else {
-		runtime->setSaveScreenshotOverride(Common::SharedPtr<Graphics::Surface>());
+		runtime->setSaveScreenshotOverride(Common::SharedPtr<Graphics::ManagedSurface>());
 	}
 }
 
diff --git a/engines/mtropolis/metaengine.cpp b/engines/mtropolis/metaengine.cpp
index ac2d898cfc9..19829627670 100644
--- a/engines/mtropolis/metaengine.cpp
+++ b/engines/mtropolis/metaengine.cpp
@@ -26,6 +26,7 @@
 #include "backends/keymapper/action.h"
 #include "backends/keymapper/keymap.h"
 
+#include "graphics/managed_surface.h"
 #include "graphics/scaler.h"
 #include "graphics/surface.h"
 
@@ -113,7 +114,7 @@ void MTropolisMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 			thumbnailWidth = thumbnailHeight * savegameScreenshot->w / savegameScreenshot->h;
 		}
 
-		Common::SharedPtr<Graphics::Surface> outSurface(new Graphics::Surface());
+		Common::SharedPtr<Graphics::ManagedSurface> outSurface(new Graphics::ManagedSurface());
 		outSurface->create(savegameScreenshot->w, savegameScreenshot->h, Graphics::createPixelFormat<888>());
 
 		for (int y = 0; y < savegameScreenshot->h; y++) {
@@ -125,7 +126,7 @@ void MTropolisMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 		}
 
 		while (outSurface->w >= thumbnailWidth * 2) {
-			Common::SharedPtr<Graphics::Surface> temp(new Graphics::Surface());
+			Common::SharedPtr<Graphics::ManagedSurface> temp(new Graphics::ManagedSurface());
 			temp->create(outSurface->w / 2, outSurface->h, Graphics::createPixelFormat<888>());
 
 			for (int y = 0; y < temp->h; y++) {
@@ -147,7 +148,7 @@ void MTropolisMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 		}
 
 		while (outSurface->h >= thumbnailHeight * 2) {
-			Common::SharedPtr<Graphics::Surface> temp(new Graphics::Surface());
+			Common::SharedPtr<Graphics::ManagedSurface> temp(new Graphics::ManagedSurface());
 			temp->create(outSurface->w, outSurface->h / 2, Graphics::createPixelFormat<888>());
 
 			for (int y = 0; y < temp->h; y++) {
@@ -169,8 +170,8 @@ void MTropolisMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
 		}
 
 		// TODO: Fix this for weird sizes
-		Common::SharedPtr<Graphics::Surface> changeTo16Temp = outSurface;
-		outSurface.reset(new Graphics::Surface());
+		Common::SharedPtr<Graphics::ManagedSurface> changeTo16Temp = outSurface;
+		outSurface.reset(new Graphics::ManagedSurface());
 		outSurface->create(changeTo16Temp->w, changeTo16Temp->h, Graphics::createPixelFormat<565>());
 
 		for (int y = 0; y < outSurface->h; y++) {
diff --git a/engines/mtropolis/modifiers.cpp b/engines/mtropolis/modifiers.cpp
index f808077fc18..3af088eb7a3 100644
--- a/engines/mtropolis/modifiers.cpp
+++ b/engines/mtropolis/modifiers.cpp
@@ -21,6 +21,8 @@
 
 #include "common/memstream.h"
 
+#include "graphics/managed_surface.h"
+
 #include "mtropolis/assets.h"
 #include "mtropolis/audio_player.h"
 #include "mtropolis/miniscript.h"
@@ -371,11 +373,17 @@ VThreadState SaveAndRestoreModifier::consumeMessage(Runtime *runtime, const Comm
 	if (_saveWhen.respondsTo(msg->getEvent())) {
 		CompoundVarSaver saver(obj);
 
+		const Graphics::ManagedSurface *screenshotOverrideManaged = runtime->getSaveScreenshotOverride().get();
+		const Graphics::Surface *screenshotOverride = nullptr;
+
+		if (screenshotOverrideManaged)
+			screenshotOverride = &screenshotOverrideManaged->rawSurface();
+
 		bool succeeded = false;
 		if (isPrompt)
-			succeeded = runtime->getSaveProvider()->promptSave(&saver, runtime->getSaveScreenshotOverride().get());
+			succeeded = runtime->getSaveProvider()->promptSave(&saver, screenshotOverride);
 		else
-			succeeded = runtime->getSaveProvider()->namedSave(&saver, runtime->getSaveScreenshotOverride().get(), _fileName);
+			succeeded = runtime->getSaveProvider()->namedSave(&saver, screenshotOverride, _fileName);
 
 		if (succeeded) {
 			for (const Common::SharedPtr<SaveLoadHooks> &hooks : runtime->getHacks().saveLoadHooks)
diff --git a/engines/mtropolis/render.cpp b/engines/mtropolis/render.cpp
index 86c2d49fb57..78190929c68 100644
--- a/engines/mtropolis/render.cpp
+++ b/engines/mtropolis/render.cpp
@@ -419,7 +419,7 @@ static void runDissolveTransition(Graphics::ManagedSurface &surface, const Graph
 	}
 }
 
-static void safeCopyRectToSurface(Graphics::ManagedSurface &surface, const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {
+static void safeCopyRectToSurface(Graphics::ManagedSurface &surface, const Graphics::ManagedSurface &srcSurface, int destX, int destY, const Common::Rect subRect) {
 	if (subRect.width() == 0 || subRect.height() == 0)
 		return;
 
@@ -524,7 +524,7 @@ void renderSceneTransition(Runtime *runtime, Window *mainWindow, const SceneTran
 	}
 }
 
-void convert32To16(Graphics::Surface &destSurface, const Graphics::Surface &srcSurface) {
+void convert32To16(Graphics::ManagedSurface &destSurface, const Graphics::ManagedSurface &srcSurface) {
 	const Graphics::PixelFormat srcFmt = srcSurface.format;
 	const Graphics::PixelFormat destFmt = destSurface.format;
 
@@ -564,7 +564,7 @@ void convert32To16(Graphics::Surface &destSurface, const Graphics::Surface &srcS
 	}
 }
 
-void convert16To32(Graphics::Surface &destSurface, const Graphics::Surface &srcSurface) {
+void convert16To32(Graphics::ManagedSurface &destSurface, const Graphics::ManagedSurface &srcSurface) {
 	const Graphics::PixelFormat srcFmt = srcSurface.format;
 	const Graphics::PixelFormat destFmt = destSurface.format;
 
diff --git a/engines/mtropolis/render.h b/engines/mtropolis/render.h
index 9b0305f837e..761ef688fab 100644
--- a/engines/mtropolis/render.h
+++ b/engines/mtropolis/render.h
@@ -138,8 +138,8 @@ uint32 resolveRGB(uint8 r, uint8 g, uint8 b, const Graphics::PixelFormat &fmt);
 void renderProject(Runtime *runtime, Window *mainWindow, bool *outSkipped);
 void renderSceneTransition(Runtime *runtime, Window *mainWindow, const SceneTransitionEffect &effect, uint32 startTime, uint32 endTime, uint32 currentTime, const Graphics::ManagedSurface &oldFrame, const Graphics::ManagedSurface &newFrame);
 
-void convert32To16(Graphics::Surface &destSurface, const Graphics::Surface &srcSurface);
-void convert16To32(Graphics::Surface &destSurface, const Graphics::Surface &srcSurface);
+void convert32To16(Graphics::ManagedSurface &destSurface, const Graphics::ManagedSurface &srcSurface);
+void convert16To32(Graphics::ManagedSurface &destSurface, const Graphics::ManagedSurface &srcSurface);
 
 } // End of namespace Render
 
diff --git a/engines/mtropolis/runtime.cpp b/engines/mtropolis/runtime.cpp
index 026aab84955..c34a5dd4586 100644
--- a/engines/mtropolis/runtime.cpp
+++ b/engines/mtropolis/runtime.cpp
@@ -5820,11 +5820,11 @@ const Common::WeakPtr<Window> &Runtime::getMainWindow() const {
 	return _mainWindow;
 }
 
-const Common::SharedPtr<Graphics::Surface> &Runtime::getSaveScreenshotOverride() const {
+const Common::SharedPtr<Graphics::ManagedSurface> &Runtime::getSaveScreenshotOverride() const {
 	return _saveScreenshotOverride;
 }
 
-void Runtime::setSaveScreenshotOverride(const Common::SharedPtr<Graphics::Surface> &screenshot) {
+void Runtime::setSaveScreenshotOverride(const Common::SharedPtr<Graphics::ManagedSurface> &screenshot) {
 	_saveScreenshotOverride = screenshot;
 }
 
diff --git a/engines/mtropolis/runtime.h b/engines/mtropolis/runtime.h
index bde7be1ef61..1a1df0e52a3 100644
--- a/engines/mtropolis/runtime.h
+++ b/engines/mtropolis/runtime.h
@@ -1608,8 +1608,8 @@ public:
 
 	const Common::WeakPtr<Window> &getMainWindow() const;
 
-	const Common::SharedPtr<Graphics::Surface> &getSaveScreenshotOverride() const;
-	void setSaveScreenshotOverride(const Common::SharedPtr<Graphics::Surface> &screenshot);
+	const Common::SharedPtr<Graphics::ManagedSurface> &getSaveScreenshotOverride() const;
+	void setSaveScreenshotOverride(const Common::SharedPtr<Graphics::ManagedSurface> &screenshot);
 
 	bool isIdle() const;
 
@@ -1799,7 +1799,7 @@ private:
 
 	ISaveUIProvider *_saveProvider;
 	ILoadUIProvider *_loadProvider;
-	Common::SharedPtr<Graphics::Surface> _saveScreenshotOverride;
+	Common::SharedPtr<Graphics::ManagedSurface> _saveScreenshotOverride;
 
 	Common::SharedPtr<CursorGraphic> _lastFrameCursor;
 	Common::SharedPtr<CursorGraphic> _defaultCursor;
diff --git a/engines/mtropolis/saveload.cpp b/engines/mtropolis/saveload.cpp
index 1f865aa49da..525b28a0acc 100644
--- a/engines/mtropolis/saveload.cpp
+++ b/engines/mtropolis/saveload.cpp
@@ -197,9 +197,9 @@ bool MTropolisEngine::autoSave(ISaveWriter *writer) {
 }
 
 const Graphics::Surface *MTropolisEngine::getSavegameScreenshot() const {
-	const Graphics::Surface *screenshotOverride = _runtime->getSaveScreenshotOverride().get();
+	const Graphics::ManagedSurface *screenshotOverride = _runtime->getSaveScreenshotOverride().get();
 	if (screenshotOverride)
-		return screenshotOverride;
+		return &screenshotOverride->rawSurface();
 	else {
 		Window *mainWindow = _runtime->getMainWindow().lock().get();
 		if (!mainWindow)




More information about the Scummvm-git-logs mailing list