From 4d99bca2cdfa64e6d6959a0060361f2aa119e6d1 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 31 Mar 2020 00:46:20 +0200 Subject: [PATCH] Fix snapshots on retina displays. --- src/common/FrameBufferSDL2.hxx | 4 ++-- src/common/PNGLibrary.cxx | 9 ++++++++- src/emucore/FrameBuffer.hxx | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index 64803e6bb..857891685 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -137,12 +137,12 @@ class FrameBufferSDL2 : public FrameBuffer /** Transform from window to renderer coordinates, x direction */ - int scaleX(int x) const { return (x * myRenderW) / myWindowW; } + int scaleX(int x) const override { return (x * myRenderW) / myWindowW; } /** Transform from window to renderer coordinates, y direction */ - int scaleY(int y) const { return (y * myRenderH) / myWindowH; } + int scaleY(int y) const override { return (y * myRenderH) / myWindowH; } protected: ////////////////////////////////////////////////////////////////////// diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index 779f6b0f6..e1980a975 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -29,6 +29,7 @@ #include "TIASurface.hxx" #include "Version.hxx" #include "PNGLibrary.hxx" +#include "Rect.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PNGLibrary::PNGLibrary(OSystem& osystem) @@ -129,7 +130,13 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments) throw runtime_error("ERROR: Couldn't create snapshot file"); const FrameBuffer& fb = myOSystem.frameBuffer(); - const Common::Rect& rect = fb.imageRect(); + + const Common::Rect& rectUnscaled = fb.imageRect(); + const Common::Rect rect( + Common::Point(fb.scaleX(rectUnscaled.x()), fb.scaleY(rectUnscaled.y())), + fb.scaleX(rectUnscaled.w()), fb.scaleY(rectUnscaled.h()) + ); + png_uint_32 width = rect.w(), height = rect.h(); // Get framebuffer pixel data (we get ABGR format) diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index ce215345a..67628ee84 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -381,6 +381,16 @@ class FrameBuffer */ virtual void clear() = 0; + /** + Transform from window to renderer coordinates, x direction + */ + virtual int scaleX(int x) const { return x; } + + /** + Transform from window to renderer coordinates, y direction + */ + virtual int scaleY(int y) const { return y; } + protected: /** This method is called to query and initialize the video hardware