You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/DomAccess.mjs
+31Lines changed: 31 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,7 @@ class DomAccess extends Base {
84
84
'setStyle',
85
85
'startViewTransition',
86
86
'syncModalMask',
87
+
'transferCanvasToWorker',
87
88
'trapFocus',
88
89
'windowScrollTo'
89
90
]
@@ -1120,6 +1121,36 @@ class DomAccess extends Base {
1120
1121
}
1121
1122
}
1122
1123
1124
+
/**
1125
+
* @summary Extracts an OffscreenCanvas and transfers it directly to the Canvas Worker.
1126
+
*
1127
+
* This method implements a "Triangular Communication" pattern required to bypass a core limitation in Firefox Nightly (and potentially other browsers) regarding SharedWorkers.
1128
+
* Firefox fails silently when attempting to transfer an `OffscreenCanvas` from the Main Thread to the App Worker (SharedWorker), and then again from the App Worker to the Canvas Worker.
1129
+
* By calling this method, the Main Thread extracts the canvas and sends it directly to the Canvas Worker, bypassing the App Worker entirely for the buffer transfer.
1130
+
*
1131
+
* @param {Object} data
1132
+
* @param {String} data.id
1133
+
* @param {String} data.nodeId
1134
+
*/
1135
+
transferCanvasToWorker({nodeId}){
1136
+
letme=this,
1137
+
node=me.getElement(nodeId);
1138
+
1139
+
if(node){
1140
+
try{
1141
+
letoffscreen=node.transferControlToOffscreen();
1142
+
1143
+
Neo.worker.Manager.sendMessage('canvas',{
1144
+
action: 'registerCanvasDirect',
1145
+
node : offscreen,
1146
+
nodeId
1147
+
},[offscreen])
1148
+
}catch(e){
1149
+
// Ignore, means the canvas was already transferred or we do not support it
1150
+
}
1151
+
}
1152
+
}
1153
+
1123
1154
/**
1124
1155
* Traps (or stops trapping) focus within a Component
* @summary Receives an OffscreenCanvas directly from the Main Thread.
148
+
*
149
+
* This is the receiving end of the "Triangular Communication" pattern initiated by `Neo.main.DomAccess.transferCanvasToWorker`.
150
+
* By receiving the canvas directly from Main, we avoid the `OffscreenCanvas` transfer restrictions inherent in Firefox's SharedWorker implementation.
151
+
* Once the canvas is registered internally, this method pings the App Worker back over their direct `MessageChannel` to confirm receipt so the App Worker can proceed with rendering instructions.
152
+
*
153
+
* @param {Object} msg
154
+
* @protected
155
+
*/
156
+
registerCanvasDirect(msg){
157
+
this.registerCanvas(msg);
158
+
159
+
// Ping App worker that canvas was received from main.
0 commit comments