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.
This commit is contained in:
Nicolò Ribaudo 2025-09-09 14:54:59 +02:00
parent beb5f5ca85
commit 5de14aa429
No known key found for this signature in database
GPG Key ID: AAFDA9101C58F338
2 changed files with 14 additions and 7 deletions

View File

@ -187,11 +187,15 @@ class PDFPageDetailView extends BasePDFPageView {
} }
_getRenderingContext(canvas, transform) { _getRenderingContext(canvas, transform) {
const baseContext = this.pageView._getRenderingContext(canvas, transform); const baseContext = this.pageView._getRenderingContext(
canvas,
transform,
false
);
const recordedBBoxes = this.pdfPage.recordedBBoxes; const recordedBBoxes = this.pdfPage.recordedBBoxes;
if (!recordedBBoxes || !this.enableOptimizedPartialRendering) { if (!recordedBBoxes || !this.enableOptimizedPartialRendering) {
return { ...baseContext, recordOperations: false }; return baseContext;
} }
const { const {
@ -211,7 +215,6 @@ class PDFPageDetailView extends BasePDFPageView {
return { return {
...baseContext, ...baseContext,
recordOperations: false,
operationsFilter(index) { operationsFilter(index) {
if (recordedBBoxes.isEmpty(index)) { if (recordedBBoxes.isEmpty(index)) {
return false; return false;

View File

@ -929,7 +929,7 @@ class PDFPageView extends BasePDFPageView {
return canvasWrapper; return canvasWrapper;
} }
_getRenderingContext(canvas, transform) { _getRenderingContext(canvas, transform, recordOperations) {
return { return {
canvas, canvas,
transform, transform,
@ -939,8 +939,7 @@ class PDFPageView extends BasePDFPageView {
annotationCanvasMap: this._annotationCanvasMap, annotationCanvasMap: this._annotationCanvasMap,
pageColors: this.pageColors, pageColors: this.pageColors,
isEditing: this.#isEditing, isEditing: this.#isEditing,
recordOperations: recordOperations,
this.enableOptimizedPartialRendering && !this.recordedBBoxes,
}; };
} }
@ -1058,12 +1057,17 @@ class PDFPageView extends BasePDFPageView {
this.#scaleRoundY = sfy[1]; this.#scaleRoundY = sfy[1];
} }
const recordBBoxes =
this.enableOptimizedPartialRendering &&
this.#hasRestrictedScaling &&
!this.recordedBBoxes;
// Rendering area // Rendering area
const transform = outputScale.scaled const transform = outputScale.scaled
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
: null; : null;
const resultPromise = this._drawCanvas( const resultPromise = this._drawCanvas(
this._getRenderingContext(canvas, transform), this._getRenderingContext(canvas, transform, recordBBoxes),
() => { () => {
prevCanvas?.remove(); prevCanvas?.remove();
this._resetCanvas(); this._resetCanvas();