diff --git a/src/common/sdl_blitter/BlitterFactory.cxx b/src/common/sdl_blitter/BlitterFactory.cxx index 2eabbd6e3..0a35ba62f 100644 --- a/src/common/sdl_blitter/BlitterFactory.cxx +++ b/src/common/sdl_blitter/BlitterFactory.cxx @@ -27,10 +27,6 @@ unique_ptr BlitterFactory::createBlitter(FrameBufferSDL2& fb) throw runtime_error("BlitterFactory requires an initialized framebuffer!"); } - SDL_RendererInfo info; - - SDL_GetRendererInfo(fb.renderer(), &info); - - return (info.flags & SDL_RENDERER_TARGETTEXTURE) ? + return HqBlitter::isSupported(fb) ? unique_ptr(new HqBlitter(fb)) : unique_ptr(new BilinearBlitter(fb)); } diff --git a/src/common/sdl_blitter/HqBlitter.cxx b/src/common/sdl_blitter/HqBlitter.cxx index ae1baea06..2ec1f16dc 100644 --- a/src/common/sdl_blitter/HqBlitter.cxx +++ b/src/common/sdl_blitter/HqBlitter.cxx @@ -36,6 +36,31 @@ HqBlitter::~HqBlitter() free(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool HqBlitter::isSupported(FrameBufferSDL2 &fb) +{ + ASSERT_MAIN_THREAD; + + if (!fb.isInitialized()) throw runtime_error("frambuffer not initialized"); + + SDL_RendererInfo info; + + SDL_GetRendererInfo(fb.renderer(), &info); + + if (!(info.flags & SDL_RENDERER_TARGETTEXTURE)) return false; + + SDL_Texture* tex = SDL_CreateTexture(fb.renderer(), fb.pixelFormat().format, SDL_TEXTUREACCESS_TARGET, 16, 16); + + if (!tex) return false; + + int sdlError = SDL_SetRenderTarget(fb.renderer(), tex); + SDL_SetRenderTarget(fb.renderer(), nullptr); + + SDL_DestroyTexture(tex); + + return sdlError == 0; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void HqBlitter::reinitialize( SDL_Rect srcRect, @@ -103,15 +128,17 @@ void HqBlitter::blit(SDL_Surface& surface) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void HqBlitter::blitToIntermediate() { - SDL_Rect r = mySrcRect; - r.x = r.y = 0; + ASSERT_MAIN_THREAD; - SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w); + SDL_Rect r = mySrcRect; + r.x = r.y = 0; - SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture); - SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect); + SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w); - SDL_SetRenderTarget(myFB.renderer(), nullptr); + SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture); + SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect); + + SDL_SetRenderTarget(myFB.renderer(), nullptr); } diff --git a/src/common/sdl_blitter/HqBlitter.hxx b/src/common/sdl_blitter/HqBlitter.hxx index 8c60de00e..285019db7 100644 --- a/src/common/sdl_blitter/HqBlitter.hxx +++ b/src/common/sdl_blitter/HqBlitter.hxx @@ -28,6 +28,8 @@ class HqBlitter : public Blitter { HqBlitter(FrameBufferSDL2& fb); + static bool isSupported(FrameBufferSDL2 &fb); + virtual ~HqBlitter(); virtual void reinitialize(