Skip to content

Commit 5de14aa

Browse files
Only record bboxes when needed
Before this patch, when `enableOptimizedPartialRendering` is enabled we would record the bounding boxes of the various operations on the first render. This patches change it to happen on the first render that we know will also need a detail view, so that the performance cost is not paid for the case when the detail view is not used.
1 parent beb5f5c commit 5de14aa

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

web/pdf_page_detail_view.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ class PDFPageDetailView extends BasePDFPageView {
187187
}
188188

189189
_getRenderingContext(canvas, transform) {
190-
const baseContext = this.pageView._getRenderingContext(canvas, transform);
190+
const baseContext = this.pageView._getRenderingContext(
191+
canvas,
192+
transform,
193+
false
194+
);
191195
const recordedBBoxes = this.pdfPage.recordedBBoxes;
192196

193197
if (!recordedBBoxes || !this.enableOptimizedPartialRendering) {
194-
return { ...baseContext, recordOperations: false };
198+
return baseContext;
195199
}
196200

197201
const {
@@ -211,7 +215,6 @@ class PDFPageDetailView extends BasePDFPageView {
211215

212216
return {
213217
...baseContext,
214-
recordOperations: false,
215218
operationsFilter(index) {
216219
if (recordedBBoxes.isEmpty(index)) {
217220
return false;

web/pdf_page_view.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ class PDFPageView extends BasePDFPageView {
929929
return canvasWrapper;
930930
}
931931

932-
_getRenderingContext(canvas, transform) {
932+
_getRenderingContext(canvas, transform, recordOperations) {
933933
return {
934934
canvas,
935935
transform,
@@ -939,8 +939,7 @@ class PDFPageView extends BasePDFPageView {
939939
annotationCanvasMap: this._annotationCanvasMap,
940940
pageColors: this.pageColors,
941941
isEditing: this.#isEditing,
942-
recordOperations:
943-
this.enableOptimizedPartialRendering && !this.recordedBBoxes,
942+
recordOperations,
944943
};
945944
}
946945

@@ -1058,12 +1057,17 @@ class PDFPageView extends BasePDFPageView {
10581057
this.#scaleRoundY = sfy[1];
10591058
}
10601059

1060+
const recordBBoxes =
1061+
this.enableOptimizedPartialRendering &&
1062+
this.#hasRestrictedScaling &&
1063+
!this.recordedBBoxes;
1064+
10611065
// Rendering area
10621066
const transform = outputScale.scaled
10631067
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
10641068
: null;
10651069
const resultPromise = this._drawCanvas(
1066-
this._getRenderingContext(canvas, transform),
1070+
this._getRenderingContext(canvas, transform, recordBBoxes),
10671071
() => {
10681072
prevCanvas?.remove();
10691073
this._resetCanvas();

0 commit comments

Comments
 (0)