diff --git a/src/activities/boot_sleep/BootActivity.cpp b/src/activities/boot_sleep/BootActivity.cpp index 9e59ed59..174ffb7d 100644 --- a/src/activities/boot_sleep/BootActivity.cpp +++ b/src/activities/boot_sleep/BootActivity.cpp @@ -8,6 +8,7 @@ void BootActivity::onEnter() { Activity::onEnter(); + RenderLock lock(*this); const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); diff --git a/src/activities/home/BookInfoActivity.cpp b/src/activities/home/BookInfoActivity.cpp index 1c82ec8b..7c883cc6 100644 --- a/src/activities/home/BookInfoActivity.cpp +++ b/src/activities/home/BookInfoActivity.cpp @@ -98,7 +98,10 @@ void BookInfoActivity::loadData() { void BookInfoActivity::onEnter() { Activity::onEnter(); - renderLoading(); + { + RenderLock lock(*this); + renderLoading(); + } loadData(); requestUpdate(true); } diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 21ef9566..8bf48f9d 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -58,7 +58,10 @@ void EpubReaderActivity::onEnter() { // Configure screen orientation based on settings // NOTE: This affects layout math and must be applied before any render calls. - ReaderUtils::applyOrientation(renderer, SETTINGS.orientation); + { + RenderLock lock(*this); + ReaderUtils::applyOrientation(renderer, SETTINGS.orientation); + } epub->setupCacheDir(); @@ -107,7 +110,10 @@ void EpubReaderActivity::onExit() { Activity::onExit(); // Reset orientation back to portrait for the rest of the UI - renderer.setOrientation(GfxRenderer::Orientation::Portrait); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::Portrait); + } APP_STATE.readerActivityLoadCount = 0; APP_STATE.saveToFile(); diff --git a/src/activities/reader/ReaderActivity.cpp b/src/activities/reader/ReaderActivity.cpp index 3a19ea39..3f702ab8 100644 --- a/src/activities/reader/ReaderActivity.cpp +++ b/src/activities/reader/ReaderActivity.cpp @@ -125,9 +125,12 @@ void ReaderActivity::onEnter() { if (isImageFile(initialBookPath)) { onGoToBmpViewer(initialBookPath); } else if (isXtcFile(initialBookPath)) { - renderer.clearScreen(); - renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_LOADING), true, EpdFontFamily::BOLD); - renderer.displayBuffer(); + { + RenderLock lock(*this); + renderer.clearScreen(); + renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_LOADING), true, EpdFontFamily::BOLD); + renderer.displayBuffer(); + } auto xtc = loadXtc(initialBookPath); if (!xtc) { diff --git a/src/activities/reader/TxtReaderActivity.cpp b/src/activities/reader/TxtReaderActivity.cpp index bef5ffaf..b328a7dc 100644 --- a/src/activities/reader/TxtReaderActivity.cpp +++ b/src/activities/reader/TxtReaderActivity.cpp @@ -92,7 +92,10 @@ void TxtReaderActivity::onEnter() { return; } - ReaderUtils::applyOrientation(renderer, SETTINGS.orientation); + { + RenderLock lock(*this); + ReaderUtils::applyOrientation(renderer, SETTINGS.orientation); + } txt->setupCacheDir(); @@ -111,7 +114,10 @@ void TxtReaderActivity::onExit() { Activity::onExit(); // Reset orientation back to portrait for the rest of the UI - renderer.setOrientation(GfxRenderer::Orientation::Portrait); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::Portrait); + } pageOffsets.clear(); currentPageLines.clear(); diff --git a/src/activities/util/BmpViewerActivity.cpp b/src/activities/util/BmpViewerActivity.cpp index 38ea7f9c..54c4d60d 100644 --- a/src/activities/util/BmpViewerActivity.cpp +++ b/src/activities/util/BmpViewerActivity.cpp @@ -127,6 +127,7 @@ void BmpViewerActivity::onExit() { } bool BmpViewerActivity::renderBmpImage(const bool showControls) { + RenderLock lock(*this); FsFile file; const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); @@ -192,6 +193,7 @@ bool BmpViewerActivity::renderBmpImage(const bool showControls) { } bool BmpViewerActivity::renderDecodedImage(const bool showControls) { + RenderLock lock(*this); const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); Rect popupRect = GUI.drawPopup(renderer, tr(STR_LOADING_POPUP)); @@ -291,8 +293,11 @@ void BmpViewerActivity::toggleDisplayMode() { grayscaleDisplay = !grayscaleDisplay; // Switching between 1-bit BW and 4-level grayscale requires a full refresh to clear // ghosting from the previous mode — a half refresh leaves visible residue. - renderer.clearScreen(); - renderer.displayBuffer(HalDisplay::FULL_REFRESH); + { + RenderLock lock(*this); + renderer.clearScreen(); + renderer.displayBuffer(HalDisplay::FULL_REFRESH); + } if (!renderCurrentImage()) { renderError(tr(STR_COULD_NOT_RENDER_IMAGE)); } @@ -335,6 +340,7 @@ void BmpViewerActivity::saveDitherSettingsIfNeeded() { #endif void BmpViewerActivity::renderError(const char* message) { + RenderLock lock(*this); const auto pageHeight = renderer.getScreenHeight(); renderer.clearScreen(); renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, message); @@ -365,8 +371,11 @@ void BmpViewerActivity::setAsSleepScreen() { if (!success) { LOG_ERR("BMP", "Failed to set %s as sleep screen", filePath.c_str()); - GUI.drawPopup(renderer, tr(STR_FAILED_TO_SET_SLEEP_SCREEN)); - renderer.displayBuffer(HalDisplay::HALF_REFRESH); + { + RenderLock lock(*this); + GUI.drawPopup(renderer, tr(STR_FAILED_TO_SET_SLEEP_SCREEN)); + renderer.displayBuffer(HalDisplay::HALF_REFRESH); + } return; } @@ -374,8 +383,11 @@ void BmpViewerActivity::setAsSleepScreen() { SETTINGS.saveToFile(); LOG_INF("BMP", "Set %s as sleep screen", filePath.c_str()); - GUI.drawPopup(renderer, tr(STR_SLEEP_SCREEN_SET)); - renderer.displayBuffer(HalDisplay::HALF_REFRESH); + { + RenderLock lock(*this); + GUI.drawPopup(renderer, tr(STR_SLEEP_SCREEN_SET)); + renderer.displayBuffer(HalDisplay::HALF_REFRESH); + } } void BmpViewerActivity::loop() { diff --git a/src/activities/util/FullScreenMessageActivity.cpp b/src/activities/util/FullScreenMessageActivity.cpp index 3b7428ab..144cd746 100644 --- a/src/activities/util/FullScreenMessageActivity.cpp +++ b/src/activities/util/FullScreenMessageActivity.cpp @@ -6,6 +6,7 @@ void FullScreenMessageActivity::onEnter() { Activity::onEnter(); + RenderLock lock(*this); const auto height = renderer.getLineHeight(UI_10_FONT_ID); const auto top = (renderer.getScreenHeight() - height) / 2; diff --git a/src/activities/weather/WeatherActivity.cpp b/src/activities/weather/WeatherActivity.cpp index dc382a83..51e2ec96 100644 --- a/src/activities/weather/WeatherActivity.cpp +++ b/src/activities/weather/WeatherActivity.cpp @@ -202,7 +202,10 @@ void WeatherActivity::onEnter() { Activity::onEnter(); // Force landscape orientation for weather display - renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + } state = State::LOADING_CACHE; errorMessage.clear(); @@ -217,7 +220,10 @@ void WeatherActivity::onExit() { Activity::onExit(); // Weather screen is always landscape; restore app UI to portrait on exit. - renderer.setOrientation(GfxRenderer::Orientation::Portrait); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::Portrait); + } WiFi.mode(WIFI_OFF); } @@ -283,7 +289,10 @@ void WeatherActivity::launchWifiSelection() { void WeatherActivity::onWifiSelectionComplete(bool connected) { // Re-apply landscape after returning from WiFi selection (which uses portrait) - renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + } LOG_DBG("WEA", "onWifiSelectionComplete connected=%d wifiStatus=%d", connected ? 1 : 0, (int)WiFi.status()); if (connected) { @@ -325,10 +334,16 @@ void WeatherActivity::fetchWeather() { } void WeatherActivity::openSettingsActivity() { - renderer.setOrientation(GfxRenderer::Orientation::Portrait); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::Portrait); + } startActivityForResult(std::make_unique(renderer, mappedInput), [this](const ActivityResult&) { - renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + { + RenderLock lock(*this); + renderer.setOrientation(GfxRenderer::Orientation::LandscapeClockwise); + } forceRefresh = true; loadAndDisplay(); });