Review changes
This commit is contained in:
@@ -358,8 +358,8 @@ void EpubReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingProgressSave.pending) {
|
if (pendingProgressSave.pending.load(std::memory_order_acquire)) {
|
||||||
pendingProgressSave.pending = false;
|
pendingProgressSave.pending.store(false, std::memory_order_relaxed);
|
||||||
saveProgress(pendingProgressSave.spineIndex, pendingProgressSave.page, pendingProgressSave.pageCount);
|
saveProgress(pendingProgressSave.spineIndex, pendingProgressSave.page, pendingProgressSave.pageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1135,8 +1135,15 @@ void EpubReaderActivity::applyPendingSyncSession() {
|
|||||||
// Build the navigation target from the sync result.
|
// Build the navigation target from the sync result.
|
||||||
NavigationTarget restoreTarget;
|
NavigationTarget restoreTarget;
|
||||||
if (sync.outcome == KOReaderSyncOutcomeState::APPLIED_REMOTE) {
|
if (sync.outcome == KOReaderSyncOutcomeState::APPLIED_REMOTE) {
|
||||||
restoreSpineIndex = sync.resultSpineIndex;
|
const int spineCount = epub->getSpineItemsCount();
|
||||||
restorePage = sync.resultPage;
|
if (sync.resultSpineIndex < 0 || sync.resultSpineIndex >= spineCount) {
|
||||||
|
LOG_ERR("ERS", "Sync resultSpineIndex %d out of range [0,%d), clamping to previous %d", sync.resultSpineIndex,
|
||||||
|
spineCount, restoreSpineIndex);
|
||||||
|
// Keep restoreSpineIndex / restorePage from the pre-validation block above.
|
||||||
|
} else {
|
||||||
|
restoreSpineIndex = sync.resultSpineIndex;
|
||||||
|
restorePage = sync.resultPage;
|
||||||
|
}
|
||||||
if (sync.resultHasListItemIndex) {
|
if (sync.resultHasListItemIndex) {
|
||||||
restoreTarget = NavigationTarget::makeListItem(sync.resultListItemIndex);
|
restoreTarget = NavigationTarget::makeListItem(sync.resultListItemIndex);
|
||||||
LOG_DBG("ERS", "Applied synced remote position: spine=%d page=%d li[%u]", restoreSpineIndex, restorePage,
|
LOG_DBG("ERS", "Applied synced remote position: spine=%d page=%d li[%u]", restoreSpineIndex, restorePage,
|
||||||
@@ -1459,6 +1466,11 @@ void EpubReaderActivity::NavigationTarget::resolveInto(Section& sec, int spineIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Safety clamp.
|
// Safety clamp.
|
||||||
|
if (sec.currentPage < 0) {
|
||||||
|
LOG_DBG("ERS", "Clamping negative page %d to 0 (spine=%d cachedPageCount=%d)", sec.currentPage, spineIndex,
|
||||||
|
cachedPageCount);
|
||||||
|
sec.currentPage = 0;
|
||||||
|
}
|
||||||
if (sec.pageCount > 0 && sec.currentPage >= sec.pageCount) {
|
if (sec.pageCount > 0 && sec.currentPage >= sec.pageCount) {
|
||||||
LOG_DBG("ERS", "Clamping page %d to last page %d", sec.currentPage, sec.pageCount - 1);
|
LOG_DBG("ERS", "Clamping page %d to last page %d", sec.currentPage, sec.pageCount - 1);
|
||||||
sec.currentPage = sec.pageCount - 1;
|
sec.currentPage = sec.pageCount - 1;
|
||||||
@@ -1750,7 +1762,10 @@ void EpubReaderActivity::render(RenderLock&& lock) {
|
|||||||
LOG_DBG("ERS", "Rendered page in %dms", lastRenderStats.requestRenderMs);
|
LOG_DBG("ERS", "Rendered page in %dms", lastRenderStats.requestRenderMs);
|
||||||
}
|
}
|
||||||
silentIndexNextChapterIfNeeded(viewportWidth, viewportHeight);
|
silentIndexNextChapterIfNeeded(viewportWidth, viewportHeight);
|
||||||
pendingProgressSave = {true, currentSpineIndex, section->currentPage, section->pageCount};
|
pendingProgressSave.spineIndex = currentSpineIndex;
|
||||||
|
pendingProgressSave.page = section->currentPage;
|
||||||
|
pendingProgressSave.pageCount = section->pageCount;
|
||||||
|
pendingProgressSave.pending.store(true, std::memory_order_release);
|
||||||
lastRenderStats.freeHeapAfter = esp_get_free_heap_size();
|
lastRenderStats.freeHeapAfter = esp_get_free_heap_size();
|
||||||
lastRenderStats.largestFreeBlockAfter = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT);
|
lastRenderStats.largestFreeBlockAfter = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT);
|
||||||
lastRenderStats.valid = true;
|
lastRenderStats.valid = true;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <Epub/FootnoteEntry.h>
|
#include <Epub/FootnoteEntry.h>
|
||||||
#include <Epub/Section.h>
|
#include <Epub/Section.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "BookmarkStore.h"
|
#include "BookmarkStore.h"
|
||||||
#include "EpubReaderMenuActivity.h"
|
#include "EpubReaderMenuActivity.h"
|
||||||
#include "ReaderUtils.h"
|
#include "ReaderUtils.h"
|
||||||
@@ -188,8 +190,10 @@ class EpubReaderActivity final : public Activity {
|
|||||||
};
|
};
|
||||||
LastRenderStats lastRenderStats;
|
LastRenderStats lastRenderStats;
|
||||||
// Progress save is posted by render() and consumed by loop() to keep SD I/O off the render task.
|
// Progress save is posted by render() and consumed by loop() to keep SD I/O off the render task.
|
||||||
|
// render() writes spineIndex/page/pageCount then sets pending with release semantics so loop()
|
||||||
|
// sees a coherent snapshot when it observes pending==true via acquire.
|
||||||
struct PendingProgressSave {
|
struct PendingProgressSave {
|
||||||
bool pending = false;
|
std::atomic<bool> pending{false};
|
||||||
int spineIndex = 0;
|
int spineIndex = 0;
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int pageCount = 0;
|
int pageCount = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user