Files
electron/spec/fixtures/api/shared-texture/subtle/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

31 lines
1.0 KiB
JavaScript

const { sharedTexture } = require('electron');
const { ipcRenderer, contextBridge } = require('electron/renderer');
contextBridge.exposeInMainWorld('textures', {
onSharedTexture: (cb) => {
ipcRenderer.on('shared-texture', async (e, id, transfer) => {
// Step 5: Get the shared texture from the transfer
const importedSubtle = sharedTexture.subtle.finishTransferSharedTexture(transfer);
// Step 6: Let the renderer render using WebGPU
await cb(id, importedSubtle);
// Step 10: Release the shared texture with a callback
importedSubtle.release(() => {
// Step 11: When GPU command buffer is done, we can notify the main process to release
ipcRenderer.send('shared-texture-done', id);
});
});
},
webGpuUnavailable: () => {
ipcRenderer.send('webgpu-unavailable');
},
verifyCapturedImage: (verify) => {
ipcRenderer.on('verify-captured-image', (e, images) => {
verify(images, (result) => {
ipcRenderer.send('verify-captured-image-done', result);
});
});
}
});