From ba7c66dd36fafff97b93aebd4907622c2c394fd1 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Wed, 20 May 2026 19:27:55 +0200 Subject: [PATCH] Fix issue #249 --- src/activities/reader/EpubReaderActivity.cpp | 30 ++++++++++++++++++++ src/activities/reader/EpubReaderActivity.h | 4 +++ 2 files changed, 34 insertions(+) diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index aac4dbc8..07b0bcff 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -334,6 +334,11 @@ void EpubReaderActivity::onExit() { Activity::onExit(); logReaderMemSnapshot("onExit_before_release"); + // If a pre-render left the next page in the frame buffer, redraw the current page so the + // next activity (notably SleepActivity's OVERLAY mode) sees what the user was looking at. + // Must run before section.reset() and the orientation reset below. + restoreCurrentPageToBufferIfPreRendered(); + // Save bookmarks before exit bookmarkStore.save(); if (epub) { @@ -2231,6 +2236,31 @@ void EpubReaderActivity::displayPreRenderedPage(const Page& page, const int orie } } +void EpubReaderActivity::restoreCurrentPageToBufferIfPreRendered() { + if (!preRenderedPage.ready || !section || !epub) { + return; + } + + int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft; + renderer.getOrientedViewableTRBL(&orientedMarginTop, &orientedMarginRight, &orientedMarginBottom, + &orientedMarginLeft); + const int statusBarTopHeight = UITheme::getStatusBarTopHeight(automaticPageTurnActive); + const int statusBarBottomHeight = UITheme::getStatusBarBottomHeight(automaticPageTurnActive); + orientedMarginTop += std::max(static_cast(SETTINGS.screenMargin), statusBarTopHeight); + orientedMarginLeft += SETTINGS.screenMargin; + orientedMarginRight += SETTINGS.screenMargin; + orientedMarginBottom += std::max(static_cast(SETTINGS.screenMargin), statusBarBottomHeight); + + auto p = section->loadPageFromSectionFile(); + if (!p) { + return; + } + renderPageContentOnly(*p, orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft); + preRenderedPage.ready = false; + pendingPreRender = false; + usePreRenderedBuffer = false; +} + void EpubReaderActivity::renderStatusBar() const { // Calculate progress in book const int currentPage = section->currentPage + 1; diff --git a/src/activities/reader/EpubReaderActivity.h b/src/activities/reader/EpubReaderActivity.h index 519f2de3..6bcafb1d 100644 --- a/src/activities/reader/EpubReaderActivity.h +++ b/src/activities/reader/EpubReaderActivity.h @@ -261,6 +261,10 @@ class EpubReaderActivity final : public Activity { // that was last rendered into the buffer (needed for image AA re-render). void displayPreRenderedPage(const Page& page, int orientedMarginTop, int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft); + // If the frame buffer currently holds a pre-rendered next page, redraw the current page + // into it (no status bar, no flush). Restores the invariant other activities — notably + // SleepActivity's OVERLAY mode — rely on when transitioning out of the reader. + void restoreCurrentPageToBufferIfPreRendered(); void renderStatusBar() const; // Snapshot of the three status-bar signals that can change while a page is otherwise idle. // Compared in shouldSkipPeriodicUpdate() to suppress no-op minute-tick re-renders that on