From fd36f180611a84b0753c1005eef7d570ca146060 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 10 Dec 2019 21:13:13 +0100 Subject: [PATCH] Fall back to bilinear filtering if rendertargets are not supported. --- .vscode/settings.json | 3 +- src/common/FBSurfaceSDL2.cxx | 14 +++++---- src/common/FrameBufferSDL2.cxx | 6 ++++ src/common/FrameBufferSDL2.hxx | 2 ++ src/common/module.mk | 3 +- src/common/sdl_blitter/BlitterFactory.cxx | 36 +++++++++++++++++++++++ src/common/sdl_blitter/BlitterFactory.hxx | 31 +++++++++++++++++++ 7 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/common/sdl_blitter/BlitterFactory.cxx create mode 100644 src/common/sdl_blitter/BlitterFactory.hxx diff --git a/.vscode/settings.json b/.vscode/settings.json index fb31d406b..b6490aaa3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,6 +24,7 @@ "utility": "cpp", "*.tcc": "cpp", "functional": "cpp", - "iomanip": "cpp" + "iomanip": "cpp", + "__cxx_version": "cpp" } } diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index ae6e23bd7..ab1dab6c1 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -18,8 +18,7 @@ #include "FBSurfaceSDL2.hxx" #include "ThreadDebugging.hxx" -#include "sdl_blitter/BilinearBlitter.hxx" -#include "sdl_blitter/HqBlitter.hxx" +#include "sdl_blitter/BlitterFactory.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer, @@ -29,7 +28,6 @@ FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer, myIsVisible(true), myIsStatic(false) { - myBlitter = make_unique(buffer); createSurface(width, height, data); } @@ -137,7 +135,9 @@ void FBSurfaceSDL2::translateCoords(Int32& x, Int32& y) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool FBSurfaceSDL2::render() { - if(myIsVisible) + if (!myBlitter) reinitializeBlitter(); + + if(myIsVisible && myBlitter) { myBlitter->blit(*mySurface); @@ -157,7 +157,7 @@ void FBSurfaceSDL2::invalidate() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FBSurfaceSDL2::free() { - myBlitter->free(); + myBlitter.release(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -215,7 +215,9 @@ void FBSurfaceSDL2::createSurface(uInt32 width, uInt32 height, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FBSurfaceSDL2::reinitializeBlitter() { - myBlitter->reinitialize(mySrcR, myDstR, myAttributes, myIsStatic ? mySurface : nullptr); + if (!myBlitter && myFB.isInitialized()) myBlitter = BlitterFactory::createBlitter(myFB); + + if (myBlitter) myBlitter->reinitialize(mySrcR, myDstR, myAttributes, myIsStatic ? mySurface : nullptr); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index 13bba00e5..71fb75d2d 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -434,6 +434,12 @@ SDL_Renderer* FrameBufferSDL2::renderer() return myRenderer; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool FrameBufferSDL2::isInitialized() const +{ + return myRenderer != nullptr; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const SDL_PixelFormat& FrameBufferSDL2::pixelFormat() { diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index 216738529..11d162e35 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -118,6 +118,8 @@ class FrameBufferSDL2 : public FrameBuffer SDL_Renderer* renderer(); + bool isInitialized() const; + const SDL_PixelFormat& pixelFormat(); protected: diff --git a/src/common/module.mk b/src/common/module.mk index caff547df..3140fe831 100644 --- a/src/common/module.mk +++ b/src/common/module.mk @@ -27,7 +27,8 @@ MODULE_OBJS := \ src/common/StaggeredLogger.o \ src/common/repository/KeyValueRepositoryConfigfile.o \ src/common/sdl_blitter/BilinearBlitter.o \ - src/common/sdl_blitter/HqBlitter.o + src/common/sdl_blitter/HqBlitter.o \ + src/common/sdl_blitter/BlitterFactory.o \ MODULE_DIRS += \ src/common diff --git a/src/common/sdl_blitter/BlitterFactory.cxx b/src/common/sdl_blitter/BlitterFactory.cxx new file mode 100644 index 000000000..2eabbd6e3 --- /dev/null +++ b/src/common/sdl_blitter/BlitterFactory.cxx @@ -0,0 +1,36 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "BlitterFactory.hxx" + +#include "SDL_lib.hxx" +#include "BilinearBlitter.hxx" +#include "HqBlitter.hxx" + +unique_ptr BlitterFactory::createBlitter(FrameBufferSDL2& fb) +{ + if (!fb.isInitialized()) { + throw runtime_error("BlitterFactory requires an initialized framebuffer!"); + } + + SDL_RendererInfo info; + + SDL_GetRendererInfo(fb.renderer(), &info); + + return (info.flags & SDL_RENDERER_TARGETTEXTURE) ? + unique_ptr(new HqBlitter(fb)) : unique_ptr(new BilinearBlitter(fb)); +} diff --git a/src/common/sdl_blitter/BlitterFactory.hxx b/src/common/sdl_blitter/BlitterFactory.hxx new file mode 100644 index 000000000..c653292c7 --- /dev/null +++ b/src/common/sdl_blitter/BlitterFactory.hxx @@ -0,0 +1,31 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef BLITTER_FACTORY_HXX +#define BLITTER_FACTORY_HXX + +#include "Blitter.hxx" +#include "bspf.hxx" +#include "FrameBufferSDL2.hxx" + +class BlitterFactory { + public: + + static unique_ptr createBlitter(FrameBufferSDL2& fb); +}; + +#endif // BLITTER_FACTORY_HXX