Files
electron/spec/fixtures/api/shared-texture/managed/preload.js
trop[bot] c229e274a0 feat: add sharedTexture module to import shared texture (#48831)
feat: add `sharedTexture` module.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: reito <reito@chromium.org>
2025-11-11 11:55:54 -05:00

29 lines
984 B
JavaScript

const { sharedTexture } = require('electron');
const { ipcRenderer, contextBridge } = require('electron/renderer');
contextBridge.exposeInMainWorld('textures', {
onSharedTexture: (cb) => {
// Step 0: Register the receiver for transferred shared texture
sharedTexture.setSharedTextureReceiver(async (data) => {
// Step 5: Receive the imported shared texture
const { importedSharedTexture: imported } = data;
await cb(imported);
// Release the imported shared texture since we're done.
// No need to use the callback here, as the util function automatically
// managed the lifetime via sync token.
imported.release();
});
},
webGpuUnavailable: () => {
ipcRenderer.send('webgpu-unavailable');
},
verifyCapturedImage: (verify) => {
ipcRenderer.on('verify-captured-image', (e, images) => {
verify(images, (result) => {
ipcRenderer.send('verify-captured-image-done', result);
});
});
}
});