Skip to main content

sharedTexture

将共享纹理导入 Electron 并将平台特定的句柄转换为 VideoFrame。支持所有 Web 渲染系统,并且可以在 Electron 进程之间传输。更多信息请阅读 这里

进程:主进程渲染器

🌐 Process: Main, Renderer

方法

🌐 Methods

sharedTexture 模块具有以下方法:

🌐 The sharedTexture module has the following methods:

注意: 实验性 API 已标注为实验性,将来可能被移除。

sharedTexture.importSharedTexture(options) 实验性

🌐 sharedTexture.importSharedTexture(options) Experimental

  • options 对象 - 导入共享纹理的选项。
    • textureInfo SharedTextureImportTextureInfo - 要导入的共享纹理的信息。
    • allReferencesReleased 函数(可选)- 当所有进程中的所有引用都被释放时调用。在此回调被调用之前,你应保持导入的纹理有效。

从给定选项导入共享纹理。

🌐 Imports the shared texture from the given options.

note

此方法仅在主进程中可用。

返回 SharedTextureImported - 导入的共享纹理。

🌐 Returns SharedTextureImported - The imported shared texture.

sharedTexture.sendSharedTexture(options, ...args) 实验性

🌐 sharedTexture.sendSharedTexture(options, ...args) Experimental

  • options 对象 - 用于发送共享纹理的选项。
    • frame WebFrameMain - 要将共享纹理传输到的目标框架。对于 WebContents,你可以传入 webContents.mainFrame。如果你提供的 webFrameMain 不是主框架,则需要为此启用 webPreferences.nodeIntegrationInSubFrames,因为此功能需要主框架和该框架之间的 IPC
    • importedSharedTexture SharedTextureImported - 导入的共享纹理。
  • ...args any[] - 传递给渲染进程的额外参数。

将导入的共享纹理发送到渲染器进程。在调用此方法之前,必须在渲染器进程中注册接收器。此方法的超时时间为1000毫秒。请在调用此方法之前确保接收器已设置并且渲染器进程处于活动状态。

🌐 Send the imported shared texture to a renderer process. You must register a receiver at renderer process before calling this method. This method has a 1000ms timeout. Ensure the receiver is set and the renderer process is alive before calling this method.

note

此方法仅在主进程中可用。

返回 Promise<void> - 在传输完成时解析。

🌐 Returns Promise<void> - Resolves when the transfer is complete.

sharedTexture.setSharedTextureReceiver(callback) 实验性

🌐 sharedTexture.setSharedTextureReceiver(callback) Experimental

  • 'callback' 函数<Promise<void>> - 接收导入的共享纹理的函数。
    • receivedSharedTextureData 对象 - 来自主进程的数据。
    • ...args any[] - 从主进程传递的额外参数。

设置回调以接收来自主进程导入的共享纹理。

🌐 Set a callback to receive imported shared textures from the main process.

note

此方法仅在渲染进程中可用。

属性

🌐 Properties

sharedTexture 模块具有以下属性:

🌐 The sharedTexture module has the following properties:

sharedTexture.subtle 实验性

🌐 sharedTexture.subtle Experimental

一个 SharedTextureSubtle 属性,为高级用户提供与共享纹理交互的细微 API。

🌐 A SharedTextureSubtle property, provides subtle APIs for interacting with shared texture for advanced users.