From 5977c8561a16aa4474f2ee0a9e46b08305ff710b Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Mon, 16 Dec 2019 09:38:16 +0100 Subject: [PATCH] Connect tia.filter. --- src/common/FBSurfaceSDL2.cxx | 9 +++++++++ src/common/FBSurfaceSDL2.hxx | 4 +++- src/emucore/FBSurface.hxx | 6 ++++++ src/emucore/FrameBuffer.cxx | 2 ++ src/emucore/TIASurface.cxx | 24 ++++++++++++++++++++++-- src/emucore/TIASurface.hxx | 5 +++++ src/libretro/FBSurfaceLIBRETRO.hxx | 1 + 7 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index 7bb78d344..3a3d92673 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -249,3 +249,12 @@ void FBSurfaceSDL2::applyAttributes() { reinitializeBlitter(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FBSurfaceSDL2::setScalingInterpolation(FrameBuffer::ScalingInterpolation interpolation) +{ + if (interpolation == myInterpolationMode) return; + + myInterpolationMode = interpolation; + reload(); +} diff --git a/src/common/FBSurfaceSDL2.hxx b/src/common/FBSurfaceSDL2.hxx index 523181a9d..cedbf9e98 100644 --- a/src/common/FBSurfaceSDL2.hxx +++ b/src/common/FBSurfaceSDL2.hxx @@ -62,6 +62,8 @@ class FBSurfaceSDL2 : public FBSurface void reload() override; void resize(uInt32 width, uInt32 height) override; + void setScalingInterpolation(FrameBuffer::ScalingInterpolation) override; + protected: void applyAttributes() override; @@ -81,7 +83,7 @@ class FBSurfaceSDL2 : public FBSurface FrameBufferSDL2& myFB; unique_ptr myBlitter; - const FrameBuffer::ScalingInterpolation myInterpolationMode; + FrameBuffer::ScalingInterpolation myInterpolationMode; SDL_Surface* mySurface; SDL_Rect mySrcR, myDstR; diff --git a/src/emucore/FBSurface.hxx b/src/emucore/FBSurface.hxx index 8b503f56d..27f78b954 100644 --- a/src/emucore/FBSurface.hxx +++ b/src/emucore/FBSurface.hxx @@ -29,6 +29,7 @@ namespace Common { } #include "FrameBufferConstants.hxx" +#include "FrameBuffer.hxx" #include "bspf.hxx" /** @@ -335,6 +336,11 @@ class FBSurface */ Attributes& attributes() { return myAttributes; } + /** + Configure scaling interpolation. + */ + virtual void setScalingInterpolation(FrameBuffer::ScalingInterpolation) = 0; + /** The child class chooses which (if any) of the actual attributes can be applied. diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 286cd2a6b..aa1aa1490 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -293,6 +293,8 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, Logger::info(post_about); } + if (myTIASurface) myTIASurface->updateSurfaceSettings(); + return FBInitStatus::Success; } diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index f6d8ddeed..aa9b6f19a 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -25,6 +25,19 @@ #include "PNGLibrary.hxx" #include "TIASurface.hxx" +namespace { + FrameBuffer::ScalingInterpolation interpolationModeFromSettings(const Settings& settings) + { + const string setting = settings.getString("tia.filter"); + + if (setting == "sharp") return FrameBuffer::ScalingInterpolation::sharp; + if (setting == "soft") return FrameBuffer::ScalingInterpolation::blur; + if (setting == "none") return FrameBuffer::ScalingInterpolation::none; + + return FrameBuffer::ScalingInterpolation::sharp; + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TIASurface::TIASurface(OSystem& system) : myOSystem(system), @@ -44,7 +57,7 @@ TIASurface::TIASurface(OSystem& system) myTiaSurface = myFB.allocateSurface( AtariNTSC::outWidth(TIAConstants::frameBufferWidth), TIAConstants::frameBufferHeight, - FrameBuffer::ScalingInterpolation::sharp + interpolationModeFromSettings(myOSystem.settings()) ); // Generate scanline data, and a pre-defined scanline surface @@ -55,7 +68,7 @@ TIASurface::TIASurface(OSystem& system) scanData[i] = 0x00000000; scanData[i+1] = 0xff000000; } - mySLineSurface = myFB.allocateSurface(1, scanHeight, FrameBuffer::ScalingInterpolation::sharp, scanData); + mySLineSurface = myFB.allocateSurface(1, scanHeight, interpolationModeFromSettings(myOSystem.settings()), scanData); // Base TIA surface for use in taking snapshots in 1x mode myBaseTiaSurface = myFB.allocateSurface(TIAConstants::frameBufferWidth*2, @@ -458,3 +471,10 @@ void TIASurface::renderForSnapshot() mySLineSurface->render(); } } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TIASurface::updateSurfaceSettings() +{ + myTiaSurface->setScalingInterpolation(interpolationModeFromSettings(myOSystem.settings())); + mySLineSurface->setScalingInterpolation(interpolationModeFromSettings(myOSystem.settings())); +} diff --git a/src/emucore/TIASurface.hxx b/src/emucore/TIASurface.hxx index e7d72dfe0..744e30f9e 100644 --- a/src/emucore/TIASurface.hxx +++ b/src/emucore/TIASurface.hxx @@ -156,6 +156,11 @@ class TIASurface */ void saveSnapShot() { mySaveSnapFlag = true; } + /** + Update surface settings. + */ + void updateSurfaceSettings(); + private: /** Average current calculated buffer's pixel with previous calculated buffer's pixel (50:50). diff --git a/src/libretro/FBSurfaceLIBRETRO.hxx b/src/libretro/FBSurfaceLIBRETRO.hxx index f7bbbf550..fde1925d6 100644 --- a/src/libretro/FBSurfaceLIBRETRO.hxx +++ b/src/libretro/FBSurfaceLIBRETRO.hxx @@ -56,6 +56,7 @@ class FBSurfaceLIBRETRO : public FBSurface void free() override { } void reload() override { } void resize(uInt32 width, uInt32 height) override { } + void setScalingInterpolation(FrameBuffer::ScalingInterpolation) override { } protected: void applyAttributes() override { }