@@ -56,6 +56,81 @@ import { XfaLayerBuilder } from "./xfa_layer_builder.js";
56
56
// enable the feature?
57
57
const ENABLE_ZOOM_DETAIL = true ;
58
58
59
+ class Recorder {
60
+ constructor ( kind ) {
61
+ this . kind = kind ;
62
+ this . accumulatedTime = 0 ;
63
+ this . startTime = 0 ;
64
+ this . currentStartTime = 0 ;
65
+ this . running = false ;
66
+ }
67
+
68
+ start ( ) {
69
+ if ( this . running ) {
70
+ console . warn ( `Start ${ this . kind } recorder while running` ) ;
71
+ return ;
72
+ }
73
+
74
+ console . log ( `Start rendering ${ this . kind } ` ) ;
75
+ this . currentStartTime = this . startTime = performance . now ( ) ;
76
+ this . accumulatedTime = 0 ;
77
+ this . running = true ;
78
+ }
79
+
80
+ pause ( ) {
81
+ if ( ! this . running ) {
82
+ console . warn ( `Pause ${ this . kind } recorder while not running` ) ;
83
+ return ;
84
+ }
85
+
86
+ console . log ( `Pause rendering ${ this . kind } ` ) ;
87
+ this . accumulatedTime += performance . now ( ) - this . currentStartTime ;
88
+ this . running = false ;
89
+ }
90
+
91
+ resume ( ) {
92
+ if ( this . running ) {
93
+ console . warn ( `Resume ${ this . kind } recorder while running` ) ;
94
+ return ;
95
+ }
96
+
97
+ console . log ( `Resume rendering ${ this . kind } ` ) ;
98
+ this . currentStartTime = performance . now ( ) ;
99
+ this . running = true ;
100
+ }
101
+
102
+ finish ( ) {
103
+ if ( ! this . running ) {
104
+ console . warn ( `Finish ${ this . kind } recorder while not running` ) ;
105
+ return ;
106
+ }
107
+
108
+ this . accumulatedTime += performance . now ( ) - this . currentStartTime ;
109
+ const totalTime = performance . now ( ) - this . startTime ;
110
+ this . running = false ;
111
+
112
+ console . log (
113
+ `Finish renderig ${ this . kind } (self: ${ this . accumulatedTime } ms, total: ${ totalTime } ms)`
114
+ ) ;
115
+ }
116
+
117
+ cancel ( ) {
118
+ if ( this . running ) {
119
+ this . accumulatedTime += performance . now ( ) - this . currentStartTime ;
120
+ this . running = false ;
121
+ }
122
+
123
+ const totalTime = performance . now ( ) - this . startTime ;
124
+
125
+ console . log (
126
+ `Cancel renderig ${ this . kind } (self: ${ this . accumulatedTime } ms, total: ${ totalTime } ms)`
127
+ ) ;
128
+ }
129
+ }
130
+
131
+ const detailRecorder = new Recorder ( "foreground" ) ;
132
+ const backgroundRecorder = new Recorder ( "background" ) ;
133
+
59
134
/**
60
135
* @typedef {Object } PDFPageViewOptions
61
136
* @property {HTMLDivElement } [container] - The viewer element.
@@ -253,8 +328,10 @@ class PDFPageViewBase {
253
328
#renderContinueCallback = cont => {
254
329
this . #showCanvas?. ( false ) ;
255
330
if ( this . renderingQueue && ! this . renderingQueue . isHighestPriority ( this ) ) {
331
+ this . recorder . pause ( ) ;
256
332
this . renderingState = RenderingStates . PAUSED ;
257
333
this . resume = ( ) => {
334
+ this . recorder . resume ( ) ;
258
335
this . renderingState = RenderingStates . RUNNING ;
259
336
cont ( ) ;
260
337
} ;
@@ -327,6 +404,12 @@ class PDFPageViewBase {
327
404
}
328
405
329
406
cancelRendering ( { cancelExtraDelay = 0 } = { } ) {
407
+ if (
408
+ this . renderingState !== RenderingStates . INITIAL &&
409
+ this . renderingState !== RenderingStates . FINISHED
410
+ ) {
411
+ this . recorder . cancel ( ) ;
412
+ }
330
413
if ( this . renderTask ) {
331
414
this . renderTask . cancel ( cancelExtraDelay ) ;
332
415
this . renderTask = null ;
@@ -349,6 +432,8 @@ class PDFPageViewBase {
349
432
* @implements {IRenderableView}
350
433
*/
351
434
class PDFPageView extends PDFPageViewBase {
435
+ recorder = backgroundRecorder ;
436
+
352
437
#annotationMode = AnnotationMode . ENABLE_FORMS ;
353
438
354
439
#hasRestrictedScaling = false ;
@@ -1038,6 +1123,8 @@ class PDFPageView extends PDFPageViewBase {
1038
1123
}
1039
1124
1040
1125
async draw ( ) {
1126
+ this . recorder . start ( ) ;
1127
+
1041
1128
if ( this . renderingState !== RenderingStates . INITIAL ) {
1042
1129
console . error ( "Must be in new state before drawing" ) ;
1043
1130
this . reset ( ) ; // Ensure that we reset all state to prevent issues.
@@ -1138,6 +1225,15 @@ class PDFPageView extends PDFPageViewBase {
1138
1225
} else {
1139
1226
this . #hasRestrictedScaling = false ;
1140
1227
}
1228
+ console . log ( {
1229
+ hasRestrictedScaling : this . #hasRestrictedScaling,
1230
+ maxCanvasPixels : this . maxCanvasPixels . toLocaleString ( ) ,
1231
+ pixelsInViewport : Math . round ( pixelsInViewport ) . toLocaleString ( ) ,
1232
+ outputScaleSx : outputScale . sx ,
1233
+ outputScaleSy : outputScale . sy ,
1234
+ maxScale : maxScale ,
1235
+ ratio : window . devicePixelRatio
1236
+ } ) ;
1141
1237
}
1142
1238
const sfx = approximateFraction ( outputScale . sx ) ;
1143
1239
const sfy = approximateFraction ( outputScale . sy ) ;
@@ -1182,6 +1278,8 @@ class PDFPageView extends PDFPageViewBase {
1182
1278
renderContext ,
1183
1279
prevCanvas ,
1184
1280
renderTask => {
1281
+ this . recorder . finish ( ) ;
1282
+
1185
1283
// Ensure that the thumbnails won't become partially (or fully) blank,
1186
1284
// for documents that contain interactive form elements.
1187
1285
this . #useThumbnailCanvas. regularAnnotations =
@@ -1289,6 +1387,8 @@ class PDFPageView extends PDFPageViewBase {
1289
1387
* @implements {IRenderableView}
1290
1388
*/
1291
1389
class PDFPageDetailView extends PDFPageViewBase {
1390
+ recorder = detailRecorder ;
1391
+
1292
1392
constructor ( { pageView } ) {
1293
1393
super ( pageView ) ;
1294
1394
@@ -1390,6 +1490,8 @@ class PDFPageDetailView extends PDFPageViewBase {
1390
1490
}
1391
1491
1392
1492
async draw ( ) {
1493
+ this . recorder . start ( ) ;
1494
+
1393
1495
const initialRenderingState = this . renderingState ;
1394
1496
if ( initialRenderingState !== RenderingStates . INITIAL ) {
1395
1497
console . error ( "Must be in new state before drawing" ) ;
@@ -1448,7 +1550,10 @@ class PDFPageDetailView extends PDFPageViewBase {
1448
1550
viewport,
1449
1551
pageColors : this . pageColors ,
1450
1552
} ,
1451
- prevCanvas
1553
+ prevCanvas ,
1554
+ ( ) => {
1555
+ this . recorder . finish ( ) ;
1556
+ }
1452
1557
) ;
1453
1558
1454
1559
div . setAttribute ( "data-loaded" , true ) ;
0 commit comments