Skip to content

Commit e4794a6

Browse files
committed
Pre-render *one* additional page when spreadModes are enabled
Please note that we (obviously) don't want to unconditionally pre-render more than one page all the time, since that could very easily lead to overall worse performance in some documents.[1] However, when spreadModes are enabled it does make sense to attempt to pre-render both of the pages of the next/previous spread. --- [1] Since it may cause pre-rendering to unnecessarily compete for parsing resources, on the worker-thread, with "regular" rendering.
1 parent fb6c807 commit e4794a6

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

web/base_viewer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,10 +1250,16 @@ class BaseViewer {
12501250
const scrollAhead = this._isScrollModeHorizontal
12511251
? this.scroll.right
12521252
: this.scroll.down;
1253+
const preRenderExtra =
1254+
this._scrollMode === ScrollMode.VERTICAL &&
1255+
this._spreadMode !== SpreadMode.NONE &&
1256+
!this.isInPresentationMode;
1257+
12531258
const pageView = this.renderingQueue.getHighestPriority(
12541259
visiblePages,
12551260
this._pages,
1256-
scrollAhead
1261+
scrollAhead,
1262+
preRenderExtra
12571263
);
12581264
if (pageView) {
12591265
this._ensurePdfPageLoaded(pageView).then(() => {

web/pdf_rendering_queue.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ class PDFRenderingQueue {
102102
* @param {Object} visible
103103
* @param {Array} views
104104
* @param {boolean} scrolledDown
105+
* @param {boolean} [preRenderExtra]
105106
*/
106-
getHighestPriority(visible, views, scrolledDown) {
107+
getHighestPriority(visible, views, scrolledDown, preRenderExtra = false) {
107108
/**
108109
* The state has changed. Figure out which page has the highest priority to
109110
* render next (if any).
@@ -128,14 +129,20 @@ class PDFRenderingQueue {
128129

129130
// All the visible views have rendered; try to render next/previous page.
130131
// (IDs start at 1, so no need to add 1 when `scrolledDown === true`.)
131-
const preRenderIndex = scrolledDown
132-
? visible.last.id
133-
: visible.first.id - 2;
134-
const preRenderView = views[preRenderIndex];
132+
let preRenderIndex = scrolledDown ? visible.last.id : visible.first.id - 2;
133+
let preRenderView = views[preRenderIndex];
135134

136135
if (preRenderView && !this.isViewFinished(preRenderView)) {
137136
return preRenderView;
138137
}
138+
if (preRenderExtra) {
139+
preRenderIndex += scrolledDown ? 1 : -1;
140+
preRenderView = views[preRenderIndex];
141+
142+
if (preRenderView && !this.isViewFinished(preRenderView)) {
143+
return preRenderView;
144+
}
145+
}
139146
// Everything that needs to be rendered has been.
140147
return null;
141148
}

0 commit comments

Comments
 (0)