@@ -1912,6 +1912,16 @@ class PDFPageProxy {
19121912 this . _intentStates . clear ( ) ;
19131913 this . objs . clear ( ) ;
19141914 this . #pendingCleanup = false ;
1915+
1916+ if ( this . _transport . rendererHandler ) {
1917+ try {
1918+ this . _transport . rendererHandler . send ( "cleanupPage" , {
1919+ pageIndex : this . _pageIndex ,
1920+ } ) ;
1921+ } catch {
1922+ // Ignore errors if the renderer worker has been destroyed.
1923+ }
1924+ }
19151925 return true ;
19161926 }
19171927
@@ -3442,25 +3452,43 @@ class InternalRenderTask {
34423452 } ,
34433453 configurable : true ,
34443454 } ) ;
3445- this . rendererHandler . send (
3446- "init" ,
3447- {
3448- pageIndex : this . _pageIndex ,
3449- canvas : offscreen ,
3450- map : this . annotationCanvasMap ,
3451- colors : this . pageColors ,
3452- taskID : this . taskID ,
3453- transform,
3454- viewport,
3455- transparency,
3456- background,
3457- renderingIntent,
3458- optionalContentConfig : optionalContentConfigData ,
3459- optionalContentConfigState,
3460- dependencyTracker,
3461- } ,
3462- [ offscreen ]
3463- ) ;
3455+ const initTransfers = [ offscreen ] ;
3456+ const initParams = {
3457+ pageIndex : this . _pageIndex ,
3458+ canvas : offscreen ,
3459+ colors : this . pageColors ,
3460+ taskID : this . taskID ,
3461+ transform,
3462+ viewport,
3463+ transparency,
3464+ background,
3465+ renderingIntent,
3466+ optionalContentConfig : optionalContentConfigData ,
3467+ optionalContentConfigState,
3468+ dependencyTracker,
3469+ } ;
3470+
3471+ if ( this . annotationCanvasMap ) {
3472+ const annotationCanvases = [ ] ;
3473+ for ( const [ id , canvas ] of this . annotationCanvasMap ) {
3474+ try {
3475+ const annotationCanvas = canvas . transferControlToOffscreen ( ) ;
3476+ annotationCanvases . push ( [ id , annotationCanvas ] ) ;
3477+ initTransfers . push ( annotationCanvas ) ;
3478+ } catch ( ex ) {
3479+ warn (
3480+ `Failed to transfer annotation canvas to worker: ${ ex . message } . `
3481+ ) ;
3482+ }
3483+ }
3484+ if ( annotationCanvases . length > 0 ) {
3485+ initParams . annotationCanvases = annotationCanvases ;
3486+ } else {
3487+ initParams . map = new Map ( ) ;
3488+ }
3489+ }
3490+
3491+ this . rendererHandler . send ( "init" , initParams , initTransfers ) ;
34643492 } catch ( ex ) {
34653493 // If transferControlToOffscreen fails (e.g., canvas already
34663494 // has a context), fall back to main thread rendering
0 commit comments