Revert optimisation

This commit is contained in:
jpirnay
2026-05-22 18:08:30 +02:00
parent 21aa367b65
commit c1b8c2af7f
+14 -68
View File
@@ -104,62 +104,6 @@ void logReaderMemSnapshot(const char* stage) {
inline void logReaderMemSnapshot(const char*) {} inline void logReaderMemSnapshot(const char*) {}
#endif #endif
bool computePageDynamicYBand(const Page& page, const GfxRenderer& renderer, const int fontId, const int viewportHeight,
int* outTop, int* outBottom) {
if (viewportHeight <= 0 || !outTop || !outBottom) {
return false;
}
bool hasRange = false;
int minY = viewportHeight;
int maxY = -1;
const int lineHeight = std::max(1, renderer.getLineHeight(fontId));
for (const auto& el : page.elements) {
if (!el) continue;
const int elementTop = el->yPos;
int elementBottom = elementTop;
switch (el->getTag()) {
case TAG_PageLine:
elementBottom = el->yPos + lineHeight;
break;
case TAG_PageImage: {
const auto& img = static_cast<const PageImage&>(*el);
elementBottom = el->yPos + img.getImageBlock().getHeight();
break;
}
case TAG_PageTable: {
const auto& table = static_cast<const PageTableFragment&>(*el);
elementBottom = el->yPos + table.getTotalHeight();
break;
}
default:
continue;
}
minY = std::min(minY, elementTop);
maxY = std::max(maxY, elementBottom);
hasRange = true;
}
if (!hasRange) {
return false;
}
constexpr int BAND_PAD_PX = 2;
minY = std::max(0, minY - BAND_PAD_PX);
maxY = std::min(viewportHeight, maxY + BAND_PAD_PX);
if (minY >= maxY) {
return false;
}
*outTop = minY;
*outBottom = maxY;
return true;
}
// Computes the [0..100] EPUB progress percent. Returns 0 when pageCount is unknown (sync/bookmark // Computes the [0..100] EPUB progress percent. Returns 0 when pageCount is unknown (sync/bookmark
// pre-render writes), in which case the next saveProgress() will overwrite progress.bin with the // pre-render writes), in which case the next saveProgress() will overwrite progress.bin with the
// real value before the user can leave the reader. // real value before the user can leave the reader.
@@ -2093,20 +2037,22 @@ void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int or
logReaderMemSnapshot("bw_store_begin"); logReaderMemSnapshot("bw_store_begin");
bool bwBufferStored = false; bool bwBufferStored = false;
if (shouldAttemptBwSnapshot) { if (shouldAttemptBwSnapshot) {
// Snapshot must cover every BW pixel drawn outside the grayscale text region —
// status bar (in top/bottom margins), truncated-section hint, edge progress bars.
// The AA pass clears the whole BW buffer to 0x00, renders text-only, and pushes
// grayscale; rows outside the restored band end up zero, causing a BW/grayscale
// mismatch in the status bar area on the next page turn — visible as ghosting
// at the bottom in Landscape CCW (issue #256).
//
// The X argument is only meaningful in portrait (where panel rows map to logical
// X); in landscape, panel rows map to logical Y and the X range doesn't affect
// the saved row band. So spanning the full logical Y always saves the full panel
// rows in landscape (≈ full framebuffer), while in portrait we keep the
// optimization by clipping to the content X band — the status bar still fits
// since it's anchored to the same content margins.
const int contentLeft = orientedMarginLeft; const int contentLeft = orientedMarginLeft;
const int contentRight = std::max(contentLeft, renderer.getScreenWidth() - orientedMarginRight); const int contentRight = std::max(contentLeft, renderer.getScreenWidth() - orientedMarginRight);
const int contentBottom = std::max(contentTop, renderer.getScreenHeight() - orientedMarginBottom); bwBufferStored = renderer.storeBwBufferRect(contentLeft, 0, contentRight - contentLeft, renderer.getScreenHeight());
int bandTop = 0;
int bandBottom = std::max(0, contentBottom - contentTop);
if (!computePageDynamicYBand(*page, renderer, getEffectiveReaderFontId(), bandBottom, &bandTop, &bandBottom)) {
bandTop = 0;
bandBottom = std::max(0, contentBottom - contentTop);
}
const int snapshotTop = contentTop + bandTop;
const int snapshotHeight = std::max(0, bandBottom - bandTop);
bwBufferStored = renderer.storeBwBufferRect(contentLeft, snapshotTop, contentRight - contentLeft, snapshotHeight);
} else { } else {
LOG_INF("ERS", "Skipping BW snapshot precheck (free=%lu contig=%lu, need free>=%lu contig>=%lu)", bwStoreFreeHeap, LOG_INF("ERS", "Skipping BW snapshot precheck (free=%lu contig=%lu, need free>=%lu contig>=%lu)", bwStoreFreeHeap,
bwStoreContigHeap, static_cast<uint32_t>(BW_SNAPSHOT_MIN_FREE_HEAP_BYTES), bwStoreContigHeap, static_cast<uint32_t>(BW_SNAPSHOT_MIN_FREE_HEAP_BYTES),