From 1298f49be69b9cf0ba0936b4a353258ae7875ac0 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 5 Oct 2020 21:03:47 +0100 Subject: [PATCH] SDL2: Update whole window surface if >= 80% needs updating --- src/video/sdl2_v.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 8b92b02546..9e412c7b47 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -373,7 +373,18 @@ static void DrawSurfaceToScreen() _num_dirty_rects = 0; - if (n > MAX_DIRTY_RECTS) { + bool update_whole_screen = n > MAX_DIRTY_RECTS; + + if (!update_whole_screen) { + int area = 0; + for (int i = 0; i < n; i++) { + area += _dirty_rects[i].w * _dirty_rects[i].h; + } + // Rectangles cover more than 80% of screen area, just do the whole screen + if ((area * 5) / 4 >= _sdl_surface->w * _sdl_surface->h) update_whole_screen = true; + } + + if (update_whole_screen) { if (_sdl_surface != _sdl_realscreen) { SDL_BlitSurface(_sdl_surface, nullptr, _sdl_realscreen, nullptr); }