From e1358b966a1a2f48d5ef6af2cd1b5ffc302ef6f2 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 14 Feb 2020 06:21:46 +0100 Subject: [PATCH] 3DS: Defer texture updates when the palette changes Fixes a performance issue with the Gob engine where the palette is updated a large number of times during a single frame. --- backends/platform/3ds/osystem-graphics.cpp | 14 ++++++++------ backends/platform/3ds/osystem.cpp | 1 + backends/platform/3ds/osystem.h | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backends/platform/3ds/osystem-graphics.cpp b/backends/platform/3ds/osystem-graphics.cpp index a94557b3c16..b4ff84cbcaa 100644 --- a/backends/platform/3ds/osystem-graphics.cpp +++ b/backends/platform/3ds/osystem-graphics.cpp @@ -329,12 +329,9 @@ float OSystem_3DS::getScaleRatio() const { void OSystem_3DS::setPalette(const byte *colors, uint start, uint num) { assert(start + num <= 256); memcpy(_palette + 3 * start, colors, 3 * num); - - // Manually update all color that were changed - if (_gameScreen.format.bytesPerPixel == 1) { - flushGameScreen(); - } + _gameTextureDirty = true; } + void OSystem_3DS::grabPalette(byte *colors, uint start, uint num) const { assert(start + num <= 256); memcpy(colors, _palette + 3 * start, 3 * num); @@ -391,7 +388,7 @@ Graphics::Surface *OSystem_3DS::lockScreen() { return &_gameScreen; } void OSystem_3DS::unlockScreen() { - flushGameScreen(); + _gameTextureDirty = true; } void OSystem_3DS::updateScreen() { @@ -399,6 +396,11 @@ void OSystem_3DS::updateScreen() { return; } + if (_gameTextureDirty) { + flushGameScreen(); + _gameTextureDirty = false; + } + // updateFocus(); updateMagnify(); diff --git a/backends/platform/3ds/osystem.cpp b/backends/platform/3ds/osystem.cpp index 11022b6ec93..ce68f97815a 100644 --- a/backends/platform/3ds/osystem.cpp +++ b/backends/platform/3ds/osystem.cpp @@ -78,6 +78,7 @@ OSystem_3DS::OSystem_3DS(): _magY(0), _magWidth(400), _magHeight(240), + _gameTextureDirty(false), _overlayVisible(false), _screenChangeId(0), _magnifyMode(MODE_MAGOFF), diff --git a/backends/platform/3ds/osystem.h b/backends/platform/3ds/osystem.h index 93439d50611..d4fa6e4ed3e 100644 --- a/backends/platform/3ds/osystem.h +++ b/backends/platform/3ds/osystem.h @@ -222,6 +222,7 @@ private: byte _cursorPalette[3 * 256]; Graphics::Surface _gameScreen; + bool _gameTextureDirty; Sprite _gameTopTexture; Sprite _gameBottomTexture; Sprite _overlay;