@deepseek-ai/libreoffice-kit 0.2.0-alpha7 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +7 -7
  3. package/README.zh.md +7 -7
  4. package/frame-forwarding/CMakeLists.txt +3 -4
  5. package/frame-forwarding/README.md +18 -18
  6. package/frame-forwarding/README.zh.md +19 -19
  7. package/frame-forwarding/include/dsh_frame_forwarding.h +33 -9
  8. package/frame-forwarding/index.d.ts +58 -54
  9. package/frame-forwarding/index.mjs +14 -17
  10. package/frame-forwarding/prebuilds/darwin-arm64/frame-forwarding.node +0 -0
  11. package/frame-forwarding/prebuilds/darwin-arm64/libdsh_frame_forwarding_sdk.a +0 -0
  12. package/frame-forwarding/prebuilds/darwin-arm64/manifest.json +22 -21
  13. package/frame-forwarding/prebuilds/darwin-x64/frame-forwarding.node +0 -0
  14. package/frame-forwarding/prebuilds/darwin-x64/libdsh_frame_forwarding_sdk.a +0 -0
  15. package/frame-forwarding/prebuilds/darwin-x64/manifest.json +22 -21
  16. package/frame-forwarding/prebuilds/win32-arm64/dsh_frame_forwarding_sdk.lib +0 -0
  17. package/frame-forwarding/prebuilds/win32-arm64/frame-forwarding.node +0 -0
  18. package/frame-forwarding/prebuilds/win32-arm64/manifest.json +22 -21
  19. package/frame-forwarding/prebuilds/win32-x64/dsh_frame_forwarding_sdk.lib +0 -0
  20. package/frame-forwarding/prebuilds/win32-x64/frame-forwarding.node +0 -0
  21. package/frame-forwarding/prebuilds/win32-x64/manifest.json +22 -21
  22. package/frame-forwarding/receipt.json +15 -14
  23. package/frame-forwarding/scripts/build-webgpu.mjs +1 -0
  24. package/frame-forwarding/scripts/build.mjs +5 -4
  25. package/frame-forwarding/scripts/metadata.mjs +11 -8
  26. package/frame-forwarding/scripts/source-identity.mjs +3 -3
  27. package/frame-forwarding/sdk.json +6 -5
  28. package/frame-forwarding/{include/dsh_webgpu.h → src/graphite-interop-internal.hxx} +22 -22
  29. package/frame-forwarding/src/{webgpu.cc → graphite-interop.cc} +34 -24
  30. package/frame-forwarding/src/node-producer.cc +24 -154
  31. package/frame-forwarding/src/producer.cc +93 -26
  32. package/frame-forwarding/src/receiver.cc +416 -212
  33. package/frame-forwarding/src/relay-transport.inc +38 -10
  34. package/frame-forwarding/src/transport.cc +307 -141
  35. package/frame-forwarding/src/transport.h +60 -9
  36. package/frame-forwarding/verify.d.mts +1 -1
  37. package/frame-forwarding/verify.mjs +19 -17
  38. package/lib/cli.js +79 -8
  39. package/lib/editor.js +16 -11
  40. package/lib/index.js +79 -8
  41. package/lib/types/editor.d.ts +17 -4
  42. package/lib/types/engine.d.ts +1 -1
  43. package/lib/types/fonts.d.ts +1 -1
  44. package/lib/types/index.d.ts +4 -2
  45. package/lib/types/pdf.d.ts +10 -0
  46. package/lib/worker.js +4 -3
  47. package/package.json +8 -10
  48. package/frame-forwarding/include/dsh_frame_forwarding_engine.h +0 -66
  49. package/frame-forwarding/include/dsh_frame_forwarding_node.h +0 -27
package/NOTICE CHANGED
@@ -1,6 +1,6 @@
1
1
  Browser presentation, Electron texture transfer and adapter detection, and GPU diagnostic examples originate from MIT-licensed DeepSeek Harness commit 21261bee8b9a820c62c9e42cade3ff644b747a29. They retain the frame-forwarding/LICENSE notice.
2
2
 
3
- The frame-forwarding subpaths contain MIT-licensed SDK sources from DeepSeek Harness at commit 4438b67c13d529c9882d89893ed5cd610ace11cc, integrated with the LibreOffice Kit WebGPU adapter from commit 2ae2de8c7e88df00e74ee538ebd5662f47c7a1df. The SDK retains its MIT license in frame-forwarding/LICENSE. The Windows Node delay-load implementation retains its separate notice in frame-forwarding/src/win-delay-load.LICENSE. Native-render does not require the LibreOffice engine.
3
+ The frame-forwarding subpaths contain MIT-licensed SDK sources from DeepSeek Harness at commit 4438b67c13d529c9882d89893ed5cd610ace11cc, integrated with the LibreOffice Kit WebGPU adapter from commit 2ae2de8c7e88df00e74ee538ebd5662f47c7a1df. The SDK retains its MIT license in frame-forwarding/LICENSE. The Windows Node delay-load implementation retains its separate notice in frame-forwarding/src/win-delay-load.LICENSE. Frame forwarding does not require the LibreOffice engine.
4
4
 
5
5
  LibreOffice Kit incorporates font handling and conversion integration derived from DeepSeek Harness. These portions retain the following notice. LibreOffice engine sources and their separate third-party notices are distributed in the engine packages.
6
6
 
package/README.md CHANGED
@@ -8,14 +8,14 @@ The conversion and native preview entry points can run together in one process,
8
8
 
9
9
  Binary `.doc`, `.xls`, and `.ppt` inputs must be OLE compound documents, such as Office 97–2003 files. Renamed RTF/HTML and `.wps` inputs are unsupported. `missingFonts` is empty for binary inputs because their font tables are interpreted by LibreOffice rather than the OOXML inspector.
10
10
 
11
- The Node API version is independent of its platform engine versions. The 0.2.0-alpha7 adapter uses alpha7 macOS and Windows x64 engines, retains the Windows ARM64 0.1.5 engine, and uses a portable alpha5 WASM package containing the 0.1.5 engine files. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible engine versions. `discoverRuntime().nativePreview` distinguishes native preview support from PDF conversion. Missing native packages select WASM; malformed installed packages reject.
11
+ The Node API version is independent of its platform engine versions. The 0.2.2 candidate selects 0.2.2 macOS and Windows ARM64/x64 engines and a rebuilt portable 0.2.2 WASM engine. `ENGINE_VERSION` and `discoverRuntime().version` identify the Node API; `ENGINE_VERSIONS` lists the exact compatible engine versions. `discoverRuntime().nativePreview` distinguishes native preview support from PDF conversion. Missing native packages select WASM; malformed installed packages reject.
12
12
 
13
13
  ## Installation and usage
14
14
 
15
- Use Node.js 22.19.0 or newer. This command applies after alpha7 is published; unpublished candidates must be built and qualified from source first:
15
+ Use Node.js 22.19.0 or newer. This command applies after 0.2.2 is published; unpublished candidates must be built and qualified from source first:
16
16
 
17
17
  ```sh
18
- npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha7
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.2
19
19
  ```
20
20
 
21
21
  npm installs the shared WASM engine and any matching native engine. The adapter prefers a compatible installed native engine, then selects WASM when no native package supports the host or the optional native package is absent. A corrupt installed package rejects with `unavailable`. Conversion failures never switch engines.
@@ -29,7 +29,7 @@ try {
29
29
  inputPath: '/private/work/document.docx',
30
30
  outputPath: '/private/work/document.pdf',
31
31
  });
32
- console.log(result.backend, result.missingFonts);
32
+ console.log(result.backend, result.missingFonts, result.pageCount);
33
33
  } finally {
34
34
  await converter.dispose();
35
35
  }
@@ -43,7 +43,7 @@ Converters created through the compatibility `createConverter(options)` API tran
43
43
 
44
44
  For a long-lived service that wants one explicit lifecycle owner for concurrent conversion slots, create one `createConverterFactory(options)` and obtain converters through `factory.create()`. Those converters use a factory-private cache while retaining separate Workers, native helpers, profiles, and output ownership. Dispose the factory to stop and join every converter it created.
45
45
 
46
- `convert()` exports the format named by the output suffix, `recalculate()` refreshes spreadsheet formula results before saving, and `renderImages()` writes a fresh directory containing PNG tiles plus `manifest.json`. Office images are painted directly from one loaded model; PDF images use PDFium. The CLI exposes the same operations through `dsoffice capabilities|convert|recalculate|render`. Worksheet names are exact: a missing image-render selection rejects with `invalid-document`, and a missing CSV selection rejects with `failed`; neither leaves output behind. Recalculation applies to the entire workbook and rejects `--sheet`. A rejected selection leaves the converter available for subsequent operations.
46
+ `convert()` exports the format named by the output suffix. PDF results from `render()` and `convert()` include `pageCount`, read from the written PDF's page tree; an output whose trailer, catalog, or page tree is unreadable rejects with `invalid-output` and is removed. `recalculate()` refreshes spreadsheet formula results before saving, and `renderImages()` writes a fresh directory containing PNG tiles plus `manifest.json`. Office images are painted directly from one loaded model; PDF images use PDFium. The CLI exposes the same operations through `dsoffice capabilities|convert|recalculate|render`. Worksheet names are exact: a missing image-render selection rejects with `invalid-document`, and a missing CSV selection rejects with `failed`; neither leaves output behind. Recalculation applies to the entire workbook and rejects `--sheet`. A rejected selection leaves the converter available for subsequent operations.
47
47
 
48
48
  ```sh
49
49
  npm exec -- dsoffice render --input report.docx --output-dir report-pages --pages 1
@@ -96,7 +96,7 @@ Opening requires editor protocol 4 and frame-forwarding protocol 1 from the inst
96
96
 
97
97
  `input()` and `dispatch()` submit ordered input and whitelisted editing commands. `exportSnapshot()` returns original-format bytes with their format and revision; the caller saves them. Opening copies the input bytes, and editing or exporting never overwrites the caller's source. Read-only documents reject mutations and snapshot export. An abort signal ends the document lifetime; call `close()` to await cleanup even after an operation fails.
98
98
 
99
- Desktop applications that need shared images can bind a trusted native receiver to `processId`, then use `attachSurfaceTransport()`, `renderSurface()`, or `presentationSurface()`. Replies carry correlation fields while the separate SDK transports the image; the receiver releases each frame after its display consumer finishes. `waitForInput()` orders commands or exports after the requested input sequence. `detachSurfaceTransport()` retains the document. A healthy device can still serve RGBA requests, but detaching does not change the backend and Graphite pixel requests require readback. Raster reads tiles into a CPU buffer and uploads them into the SDK texture. Ganesh reuses LibreOffice's existing GPU context and copies its final image into the SDK texture with Metal blits or Vulkan external-memory copies; Windows allocates that texture on the Vulkan device's matching D3D11 adapter. Ganesh and Graphite shared output skip final-target CPU readback; document features may still need internal bitmap reads or asset uploads.
99
+ Desktop applications that need shared images pass a frame-forwarding channel's TX credential to `attachSurfaceTransport(tx, { timeoutMs })`, then use `renderSurface()` or `presentationSurface()`. `timeoutMs` bounds the connection, including a wait while a previous producer of the channel drains, and must be shorter than the document's operation timeout; a busy channel rejects with a message starting `channel-busy`. After `detachSurfaceTransport()` or process exit, another document process can connect to the same channel with the same credential. Replies carry correlation fields while the separate SDK transports the image; the receiver releases each frame after its display consumer finishes. `waitForInput()` orders commands or exports after the requested input sequence. `detachSurfaceTransport()` retains the document. A healthy device can still serve RGBA requests, but detaching does not change the backend and Graphite pixel requests require readback. Raster reads tiles into a CPU buffer and uploads them into the SDK texture. Ganesh reuses LibreOffice's existing GPU context and copies its final image into the SDK texture with Metal blits or Vulkan external-memory copies; Windows allocates that texture on the Vulkan device's matching D3D11 adapter. Ganesh and Graphite shared output skip final-target CPU readback; document features may still need internal bitmap reads or asset uploads.
100
100
 
101
101
  Continuous presentation streams acquire and publish only when the slideshow requests a canvas update. Static or paused slides retain their last image without consuming additional frame credits. A pending change survives unavailable credits; the next successful frame includes the latest state, including an animation's final frame. Starting a stream or changing its viewport forces a frame. Explicit `presentationFrame()` and `presentationSurface()` calls still return a frame on every request; document views paint only on explicit requests.
102
102
 
@@ -148,6 +148,6 @@ This package is licensed under [MPL-2.0](LICENSE). The engine packages include `
148
148
  - Windows requires the Microsoft Visual C++ v14 Redistributable matching the Node.js architecture (x64 or ARM64); it is not bundled. Use ARM64 Node.js for the Windows ARM64 engine.
149
149
  - The preview declares macOS and Windows native engines for ARM64 and x64 and a shared Node WASM engine for Linux. Other native platforms are development recipes.
150
150
 
151
- ## Native rendering SDK
151
+ ## Frame forwarding SDK
152
152
 
153
153
  `@deepseek-ai/libreoffice-kit/frame-forwarding` provides the standalone Node producer/receiver and C/C++ SDK for macOS and Windows x64/ARM64. Install with `--omit=optional` when LibreOffice engines are not needed. All four addons and static libraries ship in the main Kit package. `./frame-forwarding/sdk` describes source and library paths, and `./frame-forwarding/verify` checks complete SDK payloads. Installation and normal runtime do not compile or download native code. See the [SDK documentation](../frame-forwarding/README.md) for ownership and explicit diagnostic builds.
package/README.zh.md CHANGED
@@ -8,14 +8,14 @@
8
8
 
9
9
  二进制 `.doc`、`.xls`、`.ppt` 输入必须是 OLE 复合文档,例如 Office 97–2003 文件。不支持改后缀的 RTF/HTML 和 `.wps`。二进制输入的 `missingFonts` 为空,因为其字体表由 LibreOffice 读取,而不是由 OOXML 检查器读取。
10
10
 
11
- Node API 与各平台引擎独立指定版本。0.2.0-alpha7 转换器使用 alpha7 的 macOS 与 Windows x64 引擎,保留 Windows ARM64 的 0.1.5 引擎,并使用包含 0.1.5 引擎文件的通用 alpha5 WASM 包。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。`discoverRuntime().nativePreview` 区分原生预览与 PDF 转换能力。缺少原生包时选择 WASM;已安装的包损坏时拒绝。
11
+ Node API 与各平台引擎独立指定版本。0.2.2 candidate 指定 0.2.2 的 macOS 与 Windows ARM64/x64 引擎,并使用重新编译的通用 0.2.2 WASM 引擎。`ENGINE_VERSION` 和 `discoverRuntime().version` 表示 Node API 版本;`ENGINE_VERSIONS` 列出各平台兼容的精确引擎版本。`discoverRuntime().nativePreview` 区分原生预览与 PDF 转换能力。缺少原生包时选择 WASM;已安装的包损坏时拒绝。
12
12
 
13
13
  ## 安装与使用
14
14
 
15
- 使用 Node.js 22.19.0 或更新版本。alpha7 发布后可使用以下命令安装;未发布的候选包需先从源码构建并验证:
15
+ 使用 Node.js 22.19.0 或更新版本。0.2.2 发布后可使用以下命令安装;未发布的候选包需先从源码构建并验证:
16
16
 
17
17
  ```sh
18
- npm install @deepseek-ai/libreoffice-kit@0.2.0-alpha7
18
+ npm install @deepseek-ai/libreoffice-kit@0.2.2
19
19
  ```
20
20
 
21
21
  npm 安装共享 WASM 引擎和匹配平台的原生引擎。转换器优先使用已安装且兼容的原生引擎;平台没有原生包或可选原生包未安装时选择 WASM。已安装的包损坏时以 `unavailable` 拒绝。转换失败不会切换引擎。
@@ -29,7 +29,7 @@ try {
29
29
  inputPath: '/private/work/document.docx',
30
30
  outputPath: '/private/work/document.pdf',
31
31
  });
32
- console.log(result.backend, result.missingFonts);
32
+ console.log(result.backend, result.missingFonts, result.pageCount);
33
33
  } finally {
34
34
  await converter.dispose();
35
35
  }
@@ -43,7 +43,7 @@ try {
43
43
 
44
44
  长驻服务如果需要为多个并发转换槽提供一个显式生命周期所有者,可创建 `createConverterFactory(options)`,再通过 `factory.create()` 建立转换器。这些转换器使用 factory 私有缓存,同时仍分别拥有 Worker、原生 helper、配置目录和输出。释放 factory 会停止并等待它创建的全部转换器。
45
45
 
46
- `convert()` 按输出后缀导出格式,`recalculate()` 在保存前刷新电子表格公式结果,`renderImages()` 在全新目录中写入 PNG tile 和 `manifest.json`。Office 图像直接从一次加载的模型绘制,PDF 使用 PDFium。CLI 通过 `dsoffice capabilities|convert|recalculate|render` 提供相同行为。工作表名称按精确名称匹配:图像渲染指定不存在的工作表时返回 `invalid-document`,CSV 导出返回 `failed`,两者均不保留输出。重算作用于整个工作簿并拒绝 `--sheet`。选择失败后仍可复用转换器。
46
+ `convert()` 按输出后缀导出格式。`render()` 和 `convert()` 的 PDF 结果包含从输出 PDF 页面树读取的 `pageCount`;尾部、目录或页面树无法读取的输出返回 `invalid-output` 并被删除。`recalculate()` 在保存前刷新电子表格公式结果,`renderImages()` 在全新目录中写入 PNG tile 和 `manifest.json`。Office 图像直接从一次加载的模型绘制,PDF 使用 PDFium。CLI 通过 `dsoffice capabilities|convert|recalculate|render` 提供相同行为。工作表名称按精确名称匹配:图像渲染指定不存在的工作表时返回 `invalid-document`,CSV 导出返回 `failed`,两者均不保留输出。重算作用于整个工作簿并拒绝 `--sheet`。选择失败后仍可复用转换器。
47
47
 
48
48
  ```sh
49
49
  npm exec -- dsoffice render --input report.docx --output-dir report-pages --pages 1
@@ -96,7 +96,7 @@ Graphite 后端不可用的设备会拒绝初始化;Linux 原生开发引擎
96
96
 
97
97
  `input()` 和 `dispatch()` 按顺序提交输入与允许的编辑命令;`exportSnapshot()` 返回包含格式和修订号的原格式字节,调用方负责保存。打开时会复制输入字节,编辑和导出不会覆盖调用方源文件。只读文档拒绝修改和快照导出。取消信号结束文档生命周期;即使操作失败,也应调用 `close()` 等待清理。
98
98
 
99
- 需要共享图像的桌面应用可通过 `processId` 绑定可信原生接收端,再调用 `attachSurfaceTransport()`、`renderSurface()` 或 `presentationSurface()`。回复只包含关联信息,图像由独立 SDK 传输;接收端在显示消费者完成使用后释放帧。`waitForInput()` 可让命令或导出等待对应输入序号;`detachSurfaceTransport()` 保留文档;设备健康时可继续请求 RGBA 输出,但它不会更换后端,Graphite 的像素请求仍需要回读。Raster 将 tile 回读到 CPU 缓冲区,再上传到 SDK 纹理。Ganesh 复用 LibreOffice 的 GPU 上下文,通过 Metal blit 或 Vulkan 外部内存复制将最终图像送入 SDK 纹理;Windows 在与 Vulkan 设备匹配的 D3D11 适配器上分配纹理。Ganesh 和 Graphite 的共享输出均跳过最终目标的 CPU 回读。文档功能仍可能要求内部位图回读或素材上传。
99
+ 需要共享图像的桌面应用将帧转发通道的 TX 凭据传给 `attachSurfaceTransport(tx, { timeoutMs })`,再调用 `renderSurface()` 或 `presentationSurface()`。`timeoutMs` 限制连接时长(包括等待该通道前一个生产者排空),且必须短于文档操作超时;通道忙时以 `channel-busy` 开头的消息拒绝。`detachSurfaceTransport()` 或进程退出后,另一个文档进程可使用同一凭据连接同一通道。回复只包含关联信息,图像由独立 SDK 传输;接收端在显示消费者完成使用后释放帧。`waitForInput()` 可让命令或导出等待对应输入序号;`detachSurfaceTransport()` 保留文档;设备健康时可继续请求 RGBA 输出,但它不会更换后端,Graphite 的像素请求仍需要回读。Raster 将 tile 回读到 CPU 缓冲区,再上传到 SDK 纹理。Ganesh 复用 LibreOffice 的 GPU 上下文,通过 Metal blit 或 Vulkan 外部内存复制将最终图像送入 SDK 纹理;Windows 在与 Vulkan 设备匹配的 D3D11 适配器上分配纹理。Ganesh 和 Graphite 的共享输出均跳过最终目标的 CPU 回读。文档功能仍可能要求内部位图回读或素材上传。
100
100
 
101
101
  连续放映流仅在幻灯片请求 canvas 更新时申请并提交帧。静止或暂停时保留最后一张图像,不消耗额外帧额度。等待可用额度期间会保留变化,下一次成功提交包含最新状态及动画末帧。启动流或更改视口会强制输出一帧。显式调用 `presentationFrame()` 和 `presentationSurface()` 仍每次返回一帧;文档视图仅在显式请求时绘制。
102
102
 
@@ -148,6 +148,6 @@ Node WASM 的图像降采样使用 LibreOffice 的 CPU 图像过滤器。文本
148
148
  - Windows 需要系统安装与 Node.js 架构一致的 Microsoft Visual C++ v14 Redistributable(x64 或 ARM64);包中不捆绑该运行库。Windows ARM64 引擎需要使用 ARM64 Node.js。
149
149
  - 预览版声明 macOS 和 Windows 的 ARM64、x64 原生引擎,以及供 Linux 使用的共享 Node WASM 引擎;其他原生平台仅保留开发构建配方。
150
150
 
151
- ## 原生渲染 SDK
151
+ ## 帧转发 SDK
152
152
 
153
153
  `@deepseek-ai/libreoffice-kit/frame-forwarding` 提供独立的 Node 生产者、接收者和 C/C++ SDK,支持 macOS、Windows 的 x64/ARM64。不需要 LibreOffice 引擎时可使用 `--omit=optional` 安装。四套插件及静态库均随 Kit 主包分发。`./frame-forwarding/sdk` 描述源码与库路径,`./frame-forwarding/verify` 校验完整 SDK。正常安装和运行不编译或下载原生二进制。资源所有权与显式诊断构建见 [SDK 文档](../frame-forwarding/README.zh.md)。
@@ -14,10 +14,10 @@ elseif(WIN32)
14
14
  target_compile_definitions(dsh_frame_forwarding_sdk PUBLIC _WIN32_WINNT=0x0602)
15
15
  target_link_libraries(dsh_frame_forwarding_sdk PUBLIC d3d11 dxgi advapi32)
16
16
  else()
17
- message(FATAL_ERROR "DSH native render requires macOS or Windows")
17
+ message(FATAL_ERROR "DSH frame forwarding requires macOS or Windows")
18
18
  endif()
19
19
  install(TARGETS dsh_frame_forwarding_sdk ARCHIVE DESTINATION lib)
20
- install(FILES include/dsh_frame_forwarding.h include/dsh_frame_forwarding_engine.h include/dsh_frame_forwarding_node.h DESTINATION include)
20
+ install(FILES include/dsh_frame_forwarding.h DESTINATION include)
21
21
 
22
22
  option(DSH_FRAME_FORWARDING_WEBGPU "Build the native WebGPU producer adapter" OFF)
23
23
  if(DSH_FRAME_FORWARDING_WEBGPU)
@@ -29,12 +29,11 @@ if(DSH_FRAME_FORWARDING_WEBGPU)
29
29
  set(DAWN_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
30
30
  add_subdirectory("${DSH_DAWN_SOURCE_DIR}" dawn)
31
31
  set_target_properties(webgpu_dawn PROPERTIES OUTPUT_NAME dawn)
32
- add_library(dsh_webgpu STATIC src/webgpu.cc)
32
+ add_library(dsh_webgpu STATIC src/graphite-interop.cc)
33
33
  target_compile_features(dsh_webgpu PUBLIC cxx_std_20)
34
34
  target_include_directories(dsh_webgpu PUBLIC include)
35
35
  target_link_libraries(dsh_webgpu PUBLIC dsh_frame_forwarding_sdk dawn::webgpu_dawn)
36
36
  set_target_properties(dsh_webgpu PROPERTIES POSITION_INDEPENDENT_CODE ON)
37
37
  target_compile_options(dsh_webgpu PRIVATE $<$<PLATFORM_ID:Windows>:/EHsc>)
38
38
  install(TARGETS dsh_webgpu ARCHIVE DESTINATION lib)
39
- install(FILES include/dsh_webgpu.h DESTINATION include)
40
39
  endif()
@@ -8,7 +8,7 @@ Installing Kit with `--omit=optional` provides the SDK without Office engines or
8
8
 
9
9
  ## Receiver
10
10
 
11
- Create one `createBudget(maxBytes)` per window and pass it to every `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`. Start the owned producer through its normal application lifecycle, bind its PID once with `bindProducer(pid)`, and pass the private `endpoint` directly to that producer. The endpoint contains authentication credentials and must never reach the Renderer or logs.
11
+ Create one `createBudget(maxBytes)` per window and pass it to every `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`. Each receiver is one channel, and its `tx` is an opaque, serializable credential. Pass `tx` to the producer process, for example from the parent that starts it; any process holding a copy may connect, and copying it revokes nothing. The credential must never reach the Renderer, logs or diagnostics.
12
12
 
13
13
  Frame events carry `transport: "shared-texture"`, an eight-byte native handle, the producer's `frameId`, and a receiver-owned `deliveryId`. Call `release(deliveryId)` only after Electron reports `allReferencesReleased`; queue submission and frame timeout do not release consumer ownership. Delivery IDs remain distinct when a producer reuses a released frame ID. Duplicate releases return false. `close()` asynchronously drains submitted GPU work and joins the owned workers; delivered resources remain retained until release or receiver destruction. A stalled GPU can keep close pending; cancellation never frees resources still used by that GPU.
14
14
 
@@ -18,49 +18,49 @@ The receiver’s Windows target uses a keyed mutex recognized by Chromium to ord
18
18
 
19
19
  [Chromium 152 acquires key 0 with `INFINITE`](https://github.com/chromium/chromium/blob/24072c1aa400ec4a89dc738b6b6acd12a8589b6f/gpu/command_buffer/service/dxgi_shared_handle_manager.cc#L129). Before direct handoff, the receiver worker performs a bounded acquire/release readiness check. This moves a possible CPU wait to that worker without copying pixels; it does not impose a timeout on Chromium. A producer must release before submitting and must not access the surface until credit returns. A producer that violates this after the check can still stall Chromium or trigger its GPU watchdog.
20
20
 
21
- Shared-texture `framePolicy` defaults to `ordered`, preserving independent request/reply frames such as Office tiles. Continuous streams may select `latest`: a completed relay readback replaces the frame whose upload has not begun, with at most one pending frame and one upload in progress. Two staging slots allow source copying while a prepared frame waits for a target. Held targets stop further uploads; ordered delivery also stops readback when both staging slots are occupied.
21
+ Shared-texture `framePolicy` defaults to `ordered`, preserving independent request/reply frames such as Office tiles. Continuous streams may select `latest`: a completed relay readback replaces the frame whose upload has not begun, with at most one pending frame and one upload in progress. Two staging slots allow source copying while a prepared frame waits for a target. Held targets stop further uploads; ordered delivery also stops readback when both staging slots are occupied. Under `ordered`, a frame the producer marked replaceable replaces the replaceable frames whose upload has not begun and leaves other frames queued, so one receiver serves request/reply frames and a stream.
22
22
 
23
23
  The byte budget reserves one surface per macOS allocation or declared Windows same-adapter keyed allocation. A legacy same-adapter allocation reserves a source plus target. The optional hello capability permits the smaller reservation; a declared keyed producer that supplies a non-keyed texture is rejected. An undeclared keyed source can still be imported directly, with the conservative legacy reservation. Relay reserves up to `N = maxFrames` source textures, `N` independent targets, and two staging textures. Target and staging capacity tracks the connection's largest requested frame; source and pool growth receive one atomic budget grant. Relay limits each frame to `maxBytes / (2N + 2)` bytes and advertises `N` times that allowance to the producer. With three frames and 256 MiB, three 4K BGRA sources plus the five receiver textures reserve 253.125 MiB. Idle storage retains its reservation; closing frees independent pool slots while each held target retains its own budget until release. Renderer queues and canvas storage have separate limits; this budget is not a process-memory ceiling.
24
24
 
25
- `send(json)` queues a bounded control message without blocking Main on native I/O. Producer messages arrive as `message` events. OS peer identity is checked in addition to the endpoint credential. A receiver accepts one producer connection and cannot be rebound. Errors require the consumer to terminate or replace that connection. Frames discarded before delivery release their native resources; delivered frames still require explicit release after closure.
25
+ A channel serves one producer connection at a time. Each `connected` event carries an increasing `connectionId` that the channel never reuses; every connection event names it. `send(connectionId, json)` queues a bounded control message for that connection without blocking Main on native I/O, and throws once that connection is no longer connected. Producer messages arrive as `message` events. While a producer is connected, other candidates are refused with `channel-busy`; a connected producer is never preempted, even when it stops responding. After it closes, fails or its process exits, the channel emits `disconnected` and drains: the connection keeps its frames, allocations, budget and GPU relay state until every delivered frame is released and its GPU work completes, then emits `drained`. During the drain one authenticated successor waits for its ready and further candidates are refused with `channel-busy`; the successor's own deadline and cancellation still apply, and a successor that gives up frees its place. Frame and allocation IDs belong to their connection, so late releases of an old connection do not affect a successor reusing the same IDs, and credit returns only to the connection that sent the frame. `drain-blocked` reports GPU work whose completion is unknown: its resources and budget stay retained and the drain waits without a timeout. `rejected` reports a refused candidate, and `failed` means the channel stopped accepting producers. `close()` withdraws the credential, refuses a waiting successor and ends the current connection. Frames discarded before delivery release their native resources; delivered frames still require explicit release after closure. The OS-reported peer process is checked per physical connection for packet origin and handle duplication only; it grants no access.
26
26
 
27
- ## Node/TypeScript producer
28
-
29
- Import `createProducer` from `@deepseek-ai/libreoffice-kit/frame-forwarding` inside the owning Node process. Bind the receiver to that Node process's PID; an in-process plugin uses `process.pid`. Pass the private endpoint, `maxPendingOperations`, `operationTimeoutMs`, and an optional native engine descriptor. Await `ready`, and register explicit `close()` with the owning plugin's disposal. The [TypeScript API](index.d.ts) defines operations and resource ownership.
27
+ Producers and receivers of protocol version 1 declare transferable channels in their handshake. A receiver refuses a producer without that declaration with `transferable-tx-required`, and a producer refuses a receiver whose ready carries no connection ID, so builds that bind producers by PID cannot interoperate with these sources. A producer of another protocol version is refused with `protocol-mismatch`, naming both versions.
30
28
 
31
- A dedicated native worker serializes connection, uploads, engine callbacks, mutex waits and submission. A separate polling thread wakes it on credit and control events; acquisition does not poll on a timer. Accepted operations may queue before readiness; excess ordinary operations reject, including control messages. Discard has one reserved queue slot per owned lease so a full queue cannot prevent release. Pending acquisitions wait for credits without blocking worker execution. Acquisition timeout rejects that request without closing the producer. Transport or uncertain GPU completion failures close the connection. `closed` resolves after queued operations settle and the worker, client and engine are destroyed. Event-listener exceptions are contained; listeners remain responsible for their own diagnostics. Worker termination uses asynchronous native cleanup. Set `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` to report contained producer callback exceptions to stderr.
29
+ On Windows, CPU relay retains one imported texture per allocation across staging slots. Reuse requires the NT handle to name the same object and dimensions to match; every frame still acquires key 0 before copying. Allocation retirement drops cached imports before returning credit, while pending copies retain their active source until completion. Systems without `CompareObjectHandles` continue opening and validating each frame.
32
30
 
33
- `acquire(width, height)` returns an explicit surface lease. Await `writeBgra(buffer, stride)` or `render()`, then `submit(frameId, metadata)` or `discard()`; surface `close()` is a discard alias. Busy or consumed surfaces reject reuse. Garbage collection never grants frame credit. Submission consumes the lease, but the underlying texture remains unavailable until the receiver releases its frame.
34
-
35
- CPU uploads borrow a non-shared Node Buffer until the returned promise settles. During that time callers must not modify it, detach it or transfer its backing ArrayBuffer. Row stride may exceed the packed row width. The binding retains the Buffer and avoids an intermediate binding copy; the C SDK still copies or uploads those bytes. CPU upload is not GPU zero-copy.
31
+ ## Node/TypeScript producer
36
32
 
37
- For continuous GPU rendering, supply an engine exported by another Node addon using [dsh_frame_forwarding_node.h](include/dsh_frame_forwarding_node.h). Its [engine callbacks](include/dsh_frame_forwarding_engine.h) run serially on the producer worker. The descriptor stays alive through engine destruction. `render` borrows the acquired native texture and releases imports before returning. Windows callbacks queue work on the supplied device's immediate context while the SDK owns key 0; they must not acquire that lock themselves. macOS callbacks complete GPU work before returning. Both observe cancellation. Third-party callbacks must return promptly; the SDK cannot preempt arbitrary engine code. Engine creation, update and destruction must not call JavaScript.
33
+ Import `createProducer` from `@deepseek-ai/libreoffice-kit/frame-forwarding` inside the owning Node process. Pass the channel's `tx`, `maxPendingOperations`, and `operationTimeoutMs`. `ready` resolves once the channel's ready arrives, which waits while a previous producer drains, and rejects with a message starting `channel-busy` while another producer is connected; `operationTimeoutMs` bounds that wait. Register explicit `close()` with the owning plugin's disposal: it stops new operations, discards unsubmitted surfaces and disconnects, and its completion means the local sender is closed. A successor's `ready` marks the completed handoff. The [TypeScript API](index.d.ts) defines operations and resource ownership.
38
34
 
39
- `start({ width, height, generation, frameIntervalMs })` renders continuously in native code; `update(json, inputSequence)` applies batched engine state, and `stop()` stops new frames. The interval includes rendering time and accepts fractions such as `1000 / 60`; elapsed deadlines are skipped without catch-up bursts. Manual leases must be released before starting. Frame metadata contains request ID, viewport generation, revision and the latest applied input sequence.
35
+ A dedicated native worker serializes connection, uploads, mutex waits and submission. A separate polling thread wakes it on credit and control events; acquisition does not poll on a timer. Accepted operations may queue before readiness; excess ordinary operations reject, including control messages. Discard has one reserved queue slot per owned lease so a full queue cannot prevent release. Pending acquisitions wait for credits without blocking worker execution. Acquisition timeout rejects that request without closing the producer. Transport or uncertain GPU completion failures close the connection. `closed` resolves after queued operations settle and the worker and client are destroyed. Event-listener exceptions are contained; listeners remain responsible for their own diagnostics. Worker termination uses asynchronous native cleanup. Set `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` to report contained producer callback exceptions to stderr.
40
36
 
41
- Engine ABI v2 adds `prepare` before surface acquisition: return 1 for a changed frame, 0 for no change, or -1 for failure. An unchanged frame makes no acquisition or submission and consumes no credit. A declared change remains pending through credit waits; preparation continues at the stream cadence, and newer updates may replace the state rendered when credit arrives. Start and resize force one frame, and updates make the next change check immediately eligible. ABI v1 keeps continuous rendering; manual Node callers skip a frame by not acquiring or submitting it. Manual `surface.render()` does not call `prepare`.
37
+ `acquire(width, height)` returns an explicit surface lease. Await `writeBgra(buffer, stride)`, then `submit(frameId, metadata)` or `discard()`; surface `close()` is a discard alias. Busy or consumed surfaces reject reuse. Garbage collection never grants frame credit. Submission consumes the lease, but the underlying texture remains unavailable until the receiver releases its frame.
42
38
 
43
- The display path can match the C producer's native path without per-frame JavaScript or pixel readback on the same adapter. End-to-end performance still depends on engine work, callbacks, pacing, GPU choice and CPU copying. Displayed-frame intervals, skipped revisions, input-to-observed-frame latency and memory require separate measurement; arrival throughput alone is not displayed FPS. Both languages use the same automatic receiver transport.
39
+ CPU uploads borrow a non-shared Node Buffer until the returned promise settles. During that time callers must not modify it, detach it or transfer its backing ArrayBuffer. Row stride may exceed the packed row width. The binding retains the Buffer and avoids an intermediate binding copy; the C SDK still copies or uploads those bytes. CPU upload is not GPU zero-copy.
44
40
 
45
41
  ## C/C++ producer
46
42
 
47
43
  Include `include/dsh_frame_forwarding.h` and link the matching `libdsh_frame_forwarding_sdk.a` or `dsh_frame_forwarding_sdk.lib`, or build the sources listed in `sdk.json`. The API has no Node or Electron dependency. Poll on one thread; acquisition, writing, submission and discard may run on another. Callers must serialize use of the same graphics context. Interrupt polling, join that thread, and close the client after all its API calls return.
48
44
 
49
- On Windows, `dsh_frame_forwarding_connect_with_device` accepts the application’s `ID3D11Device` and retains it until close. Passing null, or using `dsh_frame_forwarding_connect`, creates a default device. `dsh_frame_forwarding_connect_with_options` additionally bounds connection/handshake time and accepts a cancellation callback on the connecting thread. Applications choose their own GPU; DSH selects the transport. Serialize the adopted device’s immediate context with SDK writes. macOS requires a null device.
45
+ The only public C header is `include/dsh_frame_forwarding.h`. The Graphite WebGPU adapter in `src/graphite-interop-internal.hxx` and `src/graphite-interop.cc` (`dsh::graphite::detail`) is an internal engine implementation and is not an SDK API. It waits for submitted GPU work to complete before publishing a frame; failed completion retains the allocation until the client closes.
46
+
47
+ On Windows, `dsh_frame_forwarding_connect_with_device` accepts the application’s `ID3D11Device` and retains it until close. Passing null, or using `dsh_frame_forwarding_connect`, creates a default device. Every connect function takes the channel's TX credential. `dsh_frame_forwarding_connect_with_options` additionally bounds connection/handshake time, including a wait while a previous producer drains, and accepts a cancellation callback on the connecting thread; a busy channel fails with text starting `channel-busy`. Applications choose their own GPU; DSH selects the transport. Serialize the adopted device’s immediate context with SDK writes. macOS requires a null device.
50
48
 
51
49
  Acquisition initially returns null while the receiver grants allocation credit. Poll and retry when the owning application is ready; do not spin. Allocation requests enter a shared FIFO budget queue. Grants cover idle pool allocations as well as displayed frames. A null acquisition otherwise indicates exhausted credits; terminal allocation errors are reported by polling with `kind = -1` and explanatory text. Stop processing on a negative poll result and preserve its diagnostic before closing. A consumer must bound its overall operation lifetime and disconnect on timeout.
52
50
 
53
- Textures use top-left BGRA8 premultiplied pixels in sRGB. Windows surfaces have a keyed mutex using key 0. Acquisition grants a lease without locking: SDK CPU uploads and engine callbacks own the write lock; external GPU writers own it themselves through `dsh_frame_forwarding_surface_keyed_mutex` or their import API. Writers release key 0 after queueing commands and release imported objects/views before submit or discard. CPU uploads copy the input before returning and do not wait for GPU completion; `dsh_frame_forwarding_write_bgra_with_timeout` bounds mutex acquisition. `AcquireSync` can block the CPU. macOS writers must complete GPU work before submit or discard. Reusing a surface requires both a new acquisition and the write lock on Windows. If GPU access release fails, close the connection without reusing the surface.
51
+ Textures use top-left BGRA8 premultiplied pixels in sRGB. Windows surfaces have a keyed mutex using key 0. Acquisition grants a lease without locking: SDK CPU uploads own the write lock; external GPU writers own it themselves through `dsh_frame_forwarding_surface_keyed_mutex` or their import API. Writers release key 0 after queueing commands and release imported objects/views before submit or discard. CPU uploads copy the input before returning and do not wait for GPU completion; `dsh_frame_forwarding_write_bgra_with_timeout` bounds mutex acquisition. `AcquireSync` can block the CPU. macOS writers must complete GPU work before submit or discard. Reusing a surface requires both a new acquisition and the write lock on Windows. If GPU access release fails, close the connection without reusing the surface.
54
52
 
55
53
  Frame IDs must be integers from 1 through 9007199254740991 and unique among outstanding submissions. `dsh_frame_forwarding_submit` returns 1 when submitted and 0 on failure. A failed submission leaves a valid acquisition with the caller for retry or discard under the same GPU completion requirements.
56
54
 
55
+ Continuous streams submit with `dsh_frame_forwarding_submit_latest`, which never waits for receiver credit. With `N` the receiver's frame limit, a frame is sent at once while fewer than `max(1, N - 1)` submissions await release; otherwise it becomes the client's single queued frame, and the older queued frame returns to the pool unsent. When polling observes a release, the SDK sends the queued frame, so the receiver gets the newest complete frame without another render or external input. Acquisition reuses the queued surface when no other surface of that size is free, so with `N` of at least 2 an allocated stream always has a target and its application state can advance at its own cadence. Memory stays within the `N` allocations. `dsh_frame_forwarding_submit_latest` marks its frames replaceable, so a relay receiver presents the newest staged stream frame. Request/reply frames keep `dsh_frame_forwarding_submit`, which never drops a frame. Node producers call `submitLatest(frameId, metadata)`.
56
+
57
57
  Windows Vulkan and D3D12 consumers borrow the NT handle through `dsh_frame_forwarding_surface_shared_handle` while the surface is acquired. They must use the SDK's GPU adapter and enable keyed-mutex synchronization in their import API, following the ownership rules above. The SDK owns the handle; callers must not close it. The function returns null on macOS. Receiver copies acquire the source mutex with a bounded timeout when the actual texture descriptor declares one; legacy textures retain the completed-write requirement.
58
58
 
59
59
  Application JSON, frame correlation, input semantics, viewport generations and input acknowledgements are defined by the consuming application protocol. Control messages are limited to 16383 UTF-8 bytes. The SDK does not expose arbitrary process launching or native handles to webpages. The SDK has no LibreOffice runtime dependency; applications may install Kit with `--omit=optional` when only native rendering is needed.
60
60
 
61
61
  ## Build and validation
62
62
 
63
- Run `node scripts/build.mjs` on the target platform with complete matching Node headers available. The SDK version comes from the public Kit package metadata. Set `DSH_NODE_INCLUDE` explicitly when necessary; Windows additionally requires a developer toolchain environment and `DSH_NODE_LIB`. Builds produce precompiled Node-API and static SDK artifacts with SHA-256 receipts. Installation never invokes a compiler. Public Kit packing requires all four supported targets from one source commit. Partial payloads cannot be packed. The verifier checks addon and static-library architectures, artifact hashes, source hashes, versions and protocol before signing. Desktop runtime packaging retains only the selected target’s frame-forwarding prebuilds, along with the package license.
63
+ Run `node scripts/build.mjs` on the target platform with complete matching Node headers available. The SDK version comes from the public Kit package metadata. Set `DSH_NODE_INCLUDE` explicitly when necessary; Windows additionally requires a developer toolchain environment and `DSH_NODE_LIB`. Builds produce precompiled Node-API and static SDK artifacts with SHA-256 receipts. Installation never invokes a compiler. Public Kit packing requires all four supported targets from one source commit. Partial payloads cannot be packed. The verifier checks addon and static-library architectures, artifact hashes, source hashes, versions, protocol and the `transferable-tx` capability before signing. Desktop runtime packaging retains only the selected target’s frame-forwarding prebuilds, along with the package license.
64
64
 
65
65
  Run `pnpm test` in this directory after building. `DSH_FRAME_FORWARDING_PACKAGE_ROOT` selects an installed SDK payload for transport and lifecycle tests; diagnostics may be retained outside the package with `DSH_FRAME_FORWARDING_DIAGNOSTICS`. Fixture setup gives each complete compile/link group 120 seconds within a 180-second setup hook; protocol and runner deadlines are separate. Compiler receipts preserve the resolved executable, arguments, working directory, elapsed time, direct-child outcome and stdout/stderr. Compiler descendant exit is not observed. Parent fixtures prepare GPU inspectors and pass their paths only to owned runners, retaining the temporary files until those runners exit. The native CI lane runs C transport and Node producer integration tests serially before packing, including asynchronous shutdown and Worker termination. Performance and Electron shared-texture import require separate actual GPU validation; a successful native transport test alone does not establish those results.
66
66
 
@@ -80,4 +80,4 @@ The public Kit package exports the Node SDK, SDK metadata, verifier, browser and
80
80
 
81
81
  The browser painters/display, Electron adapter probe and generic texture ownership tests originate from DeepSeek Harness commit `21261bee8b9a820c62c9e42cade3ff644b747a29`, under `packages/client/frame-forwarding` and `apps/desktop`. Their unit tests are maintained with these implementations; DSH retains application integration tests.
82
82
 
83
- The MIT SDK originated in DeepSeek Harness commit `4438b67c13d529c9882d89893ed5cd610ace11cc`. Its WebGPU adapter retains the Office fixes from LibreOffice Kit commit `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df`. The Node binding and standalone C SDK share the source tree used by the Kit engine build. Protocol version 1 and engine ABI versions 1 and 2 are unchanged.
83
+ The MIT SDK originated in DeepSeek Harness commit `4438b67c13d529c9882d89893ed5cd610ace11cc`. Its WebGPU adapter retains the Office fixes from LibreOffice Kit commit `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df`. The Node binding and standalone C SDK share the source tree used by the Kit engine build. Protocol version 1 is unchanged; the `capabilities` field of `sdk.json`, `receipt.json` and each prebuild manifest records `transferable-tx`, which distinguishes current builds from earlier protocol 1 builds.
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## 接收端
10
10
 
11
- 每个窗口创建一个 `createBudget(maxBytes)`,传给窗口内所有 `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`。通过应用已有生命周期启动生产者,仅调用一次 `bindProducer(pid)` 绑定其 PID,并直接向生产者提供私有 `endpoint`。端点包含认证凭据,不得进入 Renderer 或日志。
11
+ 每个窗口创建一个 `createBudget(maxBytes)`,传给窗口内所有 `createReceiver({ maxFrames, maxBytes, budget, displayAdapter, readbackTimeoutMs, framePolicy }, onEvent)`。每个接收端是一个通道,其 `tx` 是不透明、可序列化的凭据。将 `tx` 交给生产者进程,例如由启动它的父进程传入;任何持有副本的进程都可连接,复制凭据不会吊销任何持有者。凭据不得进入 Renderer、日志或诊断信息。
12
12
 
13
13
  帧事件通过 `transport: "shared-texture"` 携带八字节原生句柄、生产者的 `frameId` 和接收端持有的 `deliveryId`。仅在 Electron 发出 `allReferencesReleased` 后调用 `release(deliveryId)`;提交队列和帧超时不解除消费者的所有权。生产者复用已释放的帧 ID 时,交付 ID 仍然不同。重复释放返回 false。`close()` 异步等待已提交 GPU 工作完成并回收所属线程;已交付资源保留至显式释放或接收端销毁。GPU 停滞可能使关闭持续等待;取消操作不会释放该 GPU 仍在使用的资源。
14
14
 
@@ -18,49 +18,49 @@ Windows shared-texture 接收端要求 `displayAdapter` 提供合成器实际使
18
18
 
19
19
  [Chromium 152 使用 `INFINITE` 获取 key 0](https://github.com/chromium/chromium/blob/24072c1aa400ec4a89dc738b6b6acd12a8589b6f/gpu/command_buffer/service/dxgi_shared_handle_manager.cc#L129)。直接交付前,接收端工作线程有界获取并释放锁,检查源纹理是否就绪。这将可能的 CPU 等待移至该线程,不复制像素,也无法限制 Chromium 自身的等待。生产者必须在提交前释放锁,且在信用归还前不得访问表面。在检查后违反规则的生产者仍可能阻塞 Chromium 或触发 GPU 看门狗。
20
20
 
21
- shared-texture 的 `framePolicy` 默认为 `ordered`,保留 Office 瓦片等独立请求与响应帧。连续流可以选择 `latest`:完成的中转读回替换尚未开始上传的帧,最多保留一帧等待和一帧上传。两个暂存槽允许源复制与等待目标的准备帧并存。目标被持有时停止后续上传;有序交付在两个暂存槽均占用时也停止读回。
21
+ shared-texture 的 `framePolicy` 默认为 `ordered`,保留 Office 瓦片等独立请求与响应帧。连续流可以选择 `latest`:完成的中转读回替换尚未开始上传的帧,最多保留一帧等待和一帧上传。两个暂存槽允许源复制与等待目标的准备帧并存。目标被持有时停止后续上传;有序交付在两个暂存槽均占用时也停止读回。在 `ordered` 下,producer 标记为可替换的帧会替换尚未开始上传的可替换帧,其他帧保持排队,因此一个接收端可同时服务请求/应答帧和流。
22
22
 
23
23
  字节预算为每个 macOS 分配或声明 keyed mutex 的 Windows 同卡分配预留一份表面。旧同卡分配预留源和目标各一份。可选 hello 能力声明允许较小的预留;声明 keyed mutex 却提供无锁纹理的生产者会被拒绝。未声明但带锁的源纹理也可直接导入,预算仍按旧路径保守预留。中转最多预留 `N = maxFrames` 张源纹理、`N` 张独立目标及两张暂存纹理。目标和暂存容量按当前连接申请过的最大帧计算;源及池扩容通过一次原子预算授予。中转将每帧限制为 `maxBytes / (2N + 2)` 字节,向生产者声明其 `N` 倍的额度。三帧、256 MiB 配置下,三张 4K BGRA 源与五张接收端纹理合计预留 253.125 MiB。闲置存储保留预算;关闭释放独立池槽,仍被持有的各目标仅保留自己的预算直到释放。渲染进程队列和画布存储有独立限制;该预算不是进程内存上限。
24
24
 
25
- `send(json)` 将控制消息加入有界队列,不让 Main 阻塞于原生 I/O。生产者消息以 `message` 事件到达。除端点凭据外还验证操作系统提供的对端身份。接收端只接受一个生产者连接且不能重新绑定。发生错误时消费者应终止或替换该连接。交付前丢弃的帧释放其原生资源;已交付帧在连接关闭后仍需显式释放。
25
+ 通道同一时间只服务一个生产者连接。每个 `connected` 事件携带递增且永不复用的 `connectionId`,所有连接事件都标明该值。`send(connectionId, json)` 将控制消息加入该连接的有界队列,不让 Main 阻塞于原生 I/O;该连接不再处于连接状态时抛出异常。生产者消息以 `message` 事件到达。生产者在线时,其他候选连接以 `channel-busy` 被拒绝;在线生产者即使停止响应也不会被抢占。它关闭、失败或进程退出后,通道发出 `disconnected` 并进入排空:该连接保留其帧、分配、预算及 GPU 中继状态,直至所有已交付帧释放、GPU 工作完成,再发出 `drained`。排空期间仅一个通过认证的后继连接等待 ready,其余候选连接以 `channel-busy` 被拒绝;后继连接自身的截止时间和取消仍然生效,放弃等待的后继会让出位置。帧 ID 与分配 ID 归属各自连接,因此旧连接迟到的释放不影响复用相同 ID 的后继,信用只返还给发送该帧的连接。`drain-blocked` 表示 GPU 工作完成情况未知:其资源和预算继续保留,排空无超时地等待。`rejected` 表示候选连接被拒绝,`failed` 表示通道停止接受生产者。`close()` 撤回凭据、拒绝等待中的后继并结束当前连接。交付前丢弃的帧释放其原生资源;已交付帧在关闭后仍需显式释放。操作系统报告的对端进程仅按物理连接用于检查数据包来源和句柄复制,不授予任何访问权。
26
26
 
27
- ## Node/TypeScript 生产者
28
-
29
- 在所属 Node 进程中,从 `@deepseek-ai/libreoffice-kit/frame-forwarding` 导入 `createProducer`。将接收端绑定至该 Node 进程的 PID;进程内插件使用 `process.pid`。传入私有端点、`maxPendingOperations`、`operationTimeoutMs` 及可选原生引擎描述符。等待 `ready`,并在所属插件的销毁流程中注册显式 `close()`。[TypeScript API](index.d.ts) 定义操作和资源所有权。
27
+ 协议版本 1 的生产者与接收端在握手中声明可转交通道。接收端以 `transferable-tx-required` 拒绝未声明该能力的生产者,生产者拒绝 ready 中不含连接 ID 的接收端,因此按 PID 绑定生产者的旧构建无法与这些源码互通。其他协议版本的生产者以 `protocol-mismatch` 被拒绝,拒绝原因写明双方版本。
30
28
 
31
- 专用原生工作线程串行执行连接、上传、引擎回调、锁等待及提交。独立轮询线程收到信用和控制事件后唤醒它;表面获取不使用定时器轮询。就绪前可以将操作入队;超出额度的普通操作被拒绝,包括控制消息。每个持有的租约均预留一个 discard 队列位置,因此队列满时仍可归还表面。等待额度的获取操作不会阻塞工作线程执行。获取超时仅拒绝该请求,不关闭生产者。传输故障或无法确认 GPU 完成的错误会关闭连接。`closed` 在排队操作全部完成,且工作线程、客户端和引擎销毁后解决。事件监听器异常被隔离;监听器自行负责诊断。Worker 终止通过异步原生清理处理。 设置 `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` 可将已隔离的生产者回调异常报告到 stderr。
29
+ Windows CPU 中继按分配保留已导入纹理,供不同 staging 槽使用。仅在 NT 句柄指向同一对象且尺寸一致时复用;每帧复制前仍获取 key 0。分配退役时,先清除缓存导入再返还额度,未完成的复制仍持有其活动源纹理直至完成。不提供 `CompareObjectHandles` 的系统仍逐帧打开并验证纹理。
32
30
 
33
- `acquire(width, height)` 返回显式表面租约。等待 `writeBgra(buffer, stride)` 或 `render()`,再调用 `submit(frameId, metadata)` 或 `discard()`;表面的 `close()` 等同于 discard。忙碌或已消费的表面拒绝复用。垃圾回收不会归还帧额度。提交消耗租约,但底层纹理仍须等待接收端释放该帧后才可复用。
34
-
35
- CPU 上传借用非共享的 Node Buffer,直到返回的 promise 完成。在此期间,调用者不得修改 Buffer、分离其底层 ArrayBuffer 或转移所有权。行跨度可以大于紧密排列的行宽。绑定层持有 Buffer,省去绑定层的中间复制;C SDK 仍需复制或上传像素。CPU 上传不属于 GPU 零拷贝。
31
+ ## Node/TypeScript 生产者
36
32
 
37
- 持续 GPU 渲染需要提供由另一 Node addon 通过 [dsh_frame_forwarding_node.h](include/dsh_frame_forwarding_node.h) 导出的引擎。[引擎回调](include/dsh_frame_forwarding_engine.h) 在生产者工作线程上串行运行,描述符保留至引擎销毁。`render` 借用已获取的原生纹理,并在返回前释放导入对象。Windows 回调在所提供设备的即时上下文上排队命令,由 SDK 持有 key 0;回调不得重复获取该锁。macOS 回调在返回前完成 GPU 工作。两者都须遵守取消回调。第三方回调必须及时返回;SDK 无法抢占任意引擎代码。引擎创建、更新和销毁不得调用 JavaScript。
33
+ 在所属 Node 进程中,从 `@deepseek-ai/libreoffice-kit/frame-forwarding` 导入 `createProducer`。传入通道的 `tx`、`maxPendingOperations` 和 `operationTimeoutMs`。`ready` 在通道的 ready 到达后完成,前一个生产者排空期间会等待;另一生产者在线时以 `channel-busy` 开头的消息拒绝,等待受 `operationTimeoutMs` 限制。在所属插件的销毁流程中注册显式 `close()`:它停止新操作、丢弃未提交的表面并断开连接,完成即表示本地发送端已关闭。后继的 `ready` 标志交接完成。[TypeScript API](index.d.ts) 定义操作和资源所有权。
38
34
 
39
- `start({ width, height, generation, frameIntervalMs })` 在原生代码中持续渲染;`update(json, inputSequence)` 批量更新引擎状态,`stop()` 停止新帧。帧间隔包含渲染耗时,支持 `1000 / 60` 等小数;已过的截止时刻会被跳过,不会突发补帧。启动前必须释放手动租约。帧元数据包含请求 ID、视口代次、修订号和最新应用的输入序列。
35
+ 专用原生工作线程串行执行连接、上传、锁等待及提交。独立轮询线程收到信用和控制事件后唤醒它;表面获取不使用定时器轮询。就绪前可以将操作入队;超出额度的普通操作被拒绝,包括控制消息。每个持有的租约均预留一个 discard 队列位置,因此队列满时仍可归还表面。等待额度的获取操作不会阻塞工作线程执行。获取超时仅拒绝该请求,不关闭生产者。传输故障或无法确认 GPU 完成的错误会关闭连接。`closed` 在排队操作全部完成,且工作线程和客户端销毁后解决。事件监听器异常被隔离;监听器自行负责诊断。Worker 终止通过异步原生清理处理。 设置 `DSH_FRAME_FORWARDING_DIAGNOSTICS=1` 可将已隔离的生产者回调异常报告到 stderr。
40
36
 
41
- 引擎 ABI v2 在获取表面前增加 `prepare`:有变化返回 1,无变化返回 0,失败返回 -1。无变化的帧不获取、不提交,也不消耗信用。已声明的变化在等待信用期间保持待处理;准备工作继续按流的节奏执行,新更新也可以替换信用到达后要绘制的状态。启动和调整尺寸强制生成一帧,更新会让下一次变化检查立即具备执行条件。ABI v1 保持持续渲染;Node 手动调用方通过不获取、不提交来跳过一帧。手动 `surface.render()` 不调用 `prepare`。
37
+ `acquire(width, height)` 返回显式表面租约。等待 `writeBgra(buffer, stride)`,再调用 `submit(frameId, metadata)` 或 `discard()`;表面的 `close()` 等同于 discard。忙碌或已消费的表面拒绝复用。垃圾回收不会归还帧额度。提交消耗租约,但底层纹理仍须等待接收端释放该帧后才可复用。
42
38
 
43
- 同卡时,显示可以沿用 C 生产者的原生路径,不逐帧执行 JavaScript 或像素读回。端到端性能仍取决于引擎工作量、回调、节奏、GPU 选择及 CPU 复制。实际显示帧间隔、跳过的修订、输入到观测帧延迟和内存需分别测量;到达吞吐不等于显示 FPS。两种语言使用相同的接收端自动传输策略。
39
+ CPU 上传借用非共享的 Node Buffer,直到返回的 promise 完成。在此期间,调用者不得修改 Buffer、分离其底层 ArrayBuffer 或转移所有权。行跨度可以大于紧密排列的行宽。绑定层持有 Buffer,省去绑定层的中间复制;C SDK 仍需复制或上传像素。CPU 上传不属于 GPU 零拷贝。
44
40
 
45
41
  ## C/C++ 生产者
46
42
 
47
43
  包含 `include/dsh_frame_forwarding.h` 并链接对应的 `libdsh_frame_forwarding_sdk.a` 或 `dsh_frame_forwarding_sdk.lib`,也可以构建 `sdk.json` 列出的源码。API 不依赖 Node 或 Electron。仅一个线程执行轮询;获取、写入、提交和归还表面可以在另一线程执行。调用者必须串行使用同一图形上下文。先中断轮询并等待该线程退出,所有 API 调用返回后再关闭客户端。
48
44
 
49
- 在 Windows 上,`dsh_frame_forwarding_connect_with_device` 接受应用的 `ID3D11Device`,并保留引用至关闭。传入空值或使用 `dsh_frame_forwarding_connect` 会创建默认设备。`dsh_frame_forwarding_connect_with_options` 还限制连接及握手时长,并接受在连接线程执行的取消回调。应用自行选择 GPU,DSH 选择传输方式。使用被接管设备的即时上下文时须与 SDK 写入串行执行。macOS 要求传入空设备。
45
+ 唯一公开的 C 头文件是 `include/dsh_frame_forwarding.h`。`src/graphite-interop-internal.hxx` 和 `src/graphite-interop.cc` 中的 Graphite WebGPU 适配器(`dsh::graphite::detail` 命名空间)是引擎内部实现,不属于 SDK API。适配器在发布帧之前等待已提交的 GPU 工作完成;完成失败时,分配的纹理保留到客户端关闭。
46
+
47
+ 在 Windows 上,`dsh_frame_forwarding_connect_with_device` 接受应用的 `ID3D11Device`,并保留引用至关闭。传入空值或使用 `dsh_frame_forwarding_connect` 会创建默认设备。所有连接函数都接受通道的 TX 凭据。`dsh_frame_forwarding_connect_with_options` 还限制连接及握手时长(包括等待前一个生产者排空),并接受在连接线程执行的取消回调;通道忙时以 `channel-busy` 开头的文本失败。应用自行选择 GPU,DSH 选择传输方式。使用被接管设备的即时上下文时须与 SDK 写入串行执行。macOS 要求传入空设备。
50
48
 
51
49
  首次获取表面时返回空值,等待接收端授予分配额度。轮询后在所属应用适合的时机重试,不得忙等。分配请求进入共享 FIFO 预算队列。额度同时覆盖闲置池和显示中的帧。其他获取空值表示额度不足;终止性分配错误由轮询返回 `kind = -1` 和说明文本。轮询返回负数时停止处理,并在关闭前保留诊断信息。消费者必须限制操作总时长,超时后断开连接。
52
50
 
53
- 纹理采用左上原点、sRGB、BGRA8 预乘像素。Windows 表面带有使用 key 0 的 keyed mutex。获取租约不加锁:SDK CPU 上传和引擎回调持有写锁;外部 GPU 写入方通过 `dsh_frame_forwarding_surface_keyed_mutex` 或导入 API 自行持锁。写入方将命令排队后释放 key 0,并在提交或归还前释放导入对象和视图。CPU 上传在返回前复制输入,不等待 GPU 完成;`dsh_frame_forwarding_write_bgra_with_timeout` 限制锁获取时间。`AcquireSync` 可能阻塞 CPU。macOS 写入方必须在提交或归还前完成 GPU 工作。复用表面需要重新获取租约,Windows 上还必须取得写锁。GPU 访问释放失败时,应关闭连接,不得复用表面。
51
+ 纹理采用左上原点、sRGB、BGRA8 预乘像素。Windows 表面带有使用 key 0 的 keyed mutex。获取租约不加锁:SDK CPU 上传持有写锁;外部 GPU 写入方通过 `dsh_frame_forwarding_surface_keyed_mutex` 或导入 API 自行持锁。写入方将命令排队后释放 key 0,并在提交或归还前释放导入对象和视图。CPU 上传在返回前复制输入,不等待 GPU 完成;`dsh_frame_forwarding_write_bgra_with_timeout` 限制锁获取时间。`AcquireSync` 可能阻塞 CPU。macOS 写入方必须在提交或归还前完成 GPU 工作。复用表面需要重新获取租约,Windows 上还必须取得写锁。GPU 访问释放失败时,应关闭连接,不得复用表面。
54
52
 
55
53
  帧 ID 必须是 1 到 9007199254740991 之间的整数,且在尚未释放的提交中唯一。`dsh_frame_forwarding_submit` 提交成功返回 1,失败返回 0。提交失败后,有效的获取仍归调用方所有,可在满足相同 GPU 完成要求后重试或归还。
56
54
 
55
+ 连续流使用 `dsh_frame_forwarding_submit_latest` 提交,它从不等待接收端信用。设接收端帧上限为 `N`:尚未释放的提交少于 `max(1, N - 1)` 时立即发送该帧;否则它成为客户端唯一的排队帧,原先的排队帧未经发送即回到池中。轮询观察到释放时,SDK 发送排队帧,因此接收端无需再次渲染或外部输入即可得到最新的完整帧。没有其他同尺寸空闲表面时,获取会复用排队帧的表面,因此 `N` 至少为 2 时,已分配的流总能得到目标表面,应用状态可按自身节奏推进。内存不超出这 `N` 个分配。`dsh_frame_forwarding_submit_latest` 把它的帧标记为可替换,因此中转接收端呈现最新暂存的流帧。请求/应答帧仍使用 `dsh_frame_forwarding_submit`,它从不丢帧。Node producer 调用 `submitLatest(frameId, metadata)`。
56
+
57
57
  Windows Vulkan 和 D3D12 消费者在表面获取期间,通过 `dsh_frame_forwarding_surface_shared_handle` 借用 NT 句柄。消费者必须使用 SDK 所在的 GPU 适配器,并在导入 API 中启用 keyed mutex 同步,遵守上述所有权规则。句柄归 SDK 所有,调用方不得关闭。macOS 上该函数返回空值。接收端复制会在实际纹理描述符声明 keyed mutex 时有界获取源锁;旧纹理仍要求写入已经完成。
58
58
 
59
59
  应用 JSON、帧关联、输入语义、视口代次及输入确认由消费者协议定义。控制消息上限为 16383 个 UTF-8 字节。SDK 不向网页暴露任意进程启动或原生句柄。
60
60
 
61
61
  ## 构建与验证
62
62
 
63
- 在目标平台运行 `node scripts/build.mjs`,并提供完整且匹配的 Node 头文件。SDK 版本读取公开 Kit 包元数据。需要时显式设置 `DSH_NODE_INCLUDE`;Windows 还需要开发者工具链环境和 `DSH_NODE_LIB`。构建产出预编译 Node-API 插件、静态 SDK 及 SHA-256 回执。正常安装不调用编译器。公开 Kit 打包必须包含同一源码提交的四个平台,不能打包局部产物。校验同时检查插件和静态库架构、二进制和源码哈希、版本及协议。Desktop 运行时仅保留目标平台插件和必要元数据、许可证。
63
+ 在目标平台运行 `node scripts/build.mjs`,并提供完整且匹配的 Node 头文件。SDK 版本读取公开 Kit 包元数据。需要时显式设置 `DSH_NODE_INCLUDE`;Windows 还需要开发者工具链环境和 `DSH_NODE_LIB`。构建产出预编译 Node-API 插件、静态 SDK 及 SHA-256 回执。正常安装不调用编译器。公开 Kit 打包必须包含同一源码提交的四个平台,不能打包局部产物。校验同时检查插件和静态库架构、二进制和源码哈希、版本、协议及 `transferable-tx` 能力。Desktop 运行时仅保留目标平台插件和必要元数据、许可证。
64
64
 
65
65
  构建后在本目录运行 `pnpm test`。测试沿用串行范围,覆盖 C 传输、Node 生产者、异步关闭及 Worker 终止。`DSH_FRAME_FORWARDING_PACKAGE_ROOT` 可选择已安装 SDK,`DSH_FRAME_FORWARDING_DIAGNOSTICS` 可将失败诊断保留到包外目录。性能及 Electron 共享纹理导入仍需实际 GPU 验证。
66
66
 
@@ -76,8 +76,8 @@ Windows Vulkan 和 D3D12 消费者在表面获取期间,通过 `dsh_frame_forw
76
76
 
77
77
  ## 分发
78
78
 
79
- 公开 Kit 包独立提供 Node SDK、SDK 元数据、校验器、browser 和 Electron 入口。以 SDK JSON 所在目录为根解析 `header`、`sources` 和 `staticLibraries[target]`。原生渲染无需 LibreOffice 引擎,只使用此功能时可用 `--omit=optional` 安装 Kit。正常安装和运行使用包内插件,不编译或下载额外原生二进制。
79
+ 公开 Kit 包独立提供 Node SDK、SDK 元数据、校验器、browser 和 Electron 入口。以 SDK JSON 所在目录为根解析 `header`、`sources` 和 `staticLibraries[target]`。正常安装和运行使用包内插件,不编译或下载额外原生二进制。
80
80
 
81
81
  浏览器绘制器、display、Electron 适配器探测及通用纹理所有权测试源自 DeepSeek Harness 提交 `21261bee8b9a820c62c9e42cade3ff644b747a29` 的 `packages/client/frame-forwarding` 与 `apps/desktop`。单元测试随实现维护;DSH 保留产品集成测试。
82
82
 
83
- MIT SDK 来自 DeepSeek Harness 提交 `4438b67c13d529c9882d89893ed5cd610ace11cc`,WebGPU 适配器保留 LibreOffice Kit 提交 `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df` 的 Office 修复。Node 绑定、独立 C SDK 与 Kit 引擎使用同一源码目录。协议版本 1 及引擎 ABI 版本 1、2 保持不变。
83
+ MIT SDK 来自 DeepSeek Harness 提交 `4438b67c13d529c9882d89893ed5cd610ace11cc`,WebGPU 适配器保留 LibreOffice Kit 提交 `2ae2de8c7e88df00e74ee538ebd5662f47c7a1df` 的 Office 修复。Node 绑定、独立 C SDK 与 Kit 引擎使用同一源码目录。协议版本 1 保持不变;`sdk.json`、`receipt.json` 与各预构建清单的 `capabilities` 字段记录 `transferable-tx`,用以区分当前构建与早期协议 1 构建。
@@ -19,13 +19,19 @@ typedef struct dsh_frame_forwarding_surface dsh_frame_forwarding_surface;
19
19
  * Terminal events carry diagnostic text when available.
20
20
  */
21
21
  typedef struct dsh_frame_forwarding_event { int kind; char text[DSH_FRAME_FORWARDING_TEXT_CAPACITY]; } dsh_frame_forwarding_event;
22
- /** Connect to a private receiver. Blocks until the receiver binds this process. */
23
- dsh_frame_forwarding_client* dsh_frame_forwarding_connect(const char* endpoint, char* error, size_t error_size);
22
+ /** Connect to a frame-forwarding channel with its TX credential, the opaque text the receiver issued. The credential
23
+ * names no producer process: any process holding a copy may connect, and a parent may hand it to the process it
24
+ * starts. The channel serves one connection at a time. While another producer is connected, connect fails with an
25
+ * error starting "channel-busy". After that producer disconnects, the first authenticated successor waits until the
26
+ * receiver has released every frame and resource of the previous connection; further candidates fail as busy.
27
+ * Without options the wait is unbounded. Receivers that predate transferable credentials are refused.
28
+ */
29
+ dsh_frame_forwarding_client* dsh_frame_forwarding_connect(const char* tx, char* error, size_t error_size);
24
30
  /** Connect using the application's ID3D11Device on Windows; NULL selects the default
25
31
  * device. The client retains a device reference until close. macOS requires NULL.
26
32
  * Serialize the device's immediate context with all SDK writes.
27
33
  */
28
- dsh_frame_forwarding_client* dsh_frame_forwarding_connect_with_device(const char* endpoint, void* device, char* error, size_t error_size);
34
+ dsh_frame_forwarding_client* dsh_frame_forwarding_connect_with_device(const char* tx, void* device, char* error, size_t error_size);
29
35
  /** Bounded connection options. cancelled is optional and runs on the connecting
30
36
  * thread; its context must remain alive until connect_with_options returns.
31
37
  */
@@ -35,12 +41,14 @@ typedef struct dsh_frame_forwarding_connect_options {
35
41
  void* cancellation_context;
36
42
  int (*cancelled)(void*);
37
43
  } dsh_frame_forwarding_connect_options;
38
- /** Connect with a positive timeout and optional cancellation, including PID bind
39
- * waiting. Device ownership and platform rules match connect_with_device.
44
+ /** Connect with a positive timeout and optional cancellation, which also bound waiting
45
+ * for the previous connection to drain. Device ownership and platform rules match connect_with_device.
40
46
  */
41
- dsh_frame_forwarding_client* dsh_frame_forwarding_connect_with_options(const char* endpoint,
47
+ dsh_frame_forwarding_client* dsh_frame_forwarding_connect_with_options(const char* tx,
42
48
  const dsh_frame_forwarding_connect_options* options, char* error, size_t error_size);
43
- /** Acquire BGRA8 premultiplied top-left pixels; NULL means allocation pending or no credit; poll reports terminal allocation errors. */
49
+ /** Acquire BGRA8 premultiplied top-left pixels; NULL means allocation pending or no credit; poll reports terminal allocation errors.
50
+ * When no other surface of the size is free, the surface of an unsent submit_latest frame is reused and that frame is dropped.
51
+ */
44
52
  dsh_frame_forwarding_surface* dsh_frame_forwarding_acquire(dsh_frame_forwarding_client* client, uint32_t width, uint32_t height);
45
53
  /** Borrow an IOSurfaceRef (macOS) or ID3D11Texture2D* (Windows) while acquired.
46
54
  * Windows external writers acquire/release key 0 around GPU commands (see
@@ -60,7 +68,7 @@ void* dsh_frame_forwarding_device(dsh_frame_forwarding_client* client);
60
68
  /** Borrow the acquired Windows surface's IDXGIKeyedMutex, or NULL on macOS.
61
69
  * acquire itself never locks. External writers acquire key 0 before issuing GPU
62
70
  * commands and release key 0 before submit/discard, without waiting for completion.
63
- * SDK write_bgra and engine render own this lock; do not lock around those calls.
71
+ * SDK write_bgra owns this lock; do not lock around that call.
64
72
  * Do not release the borrowed COM reference. AcquireSync may block the CPU.
65
73
  */
66
74
  void* dsh_frame_forwarding_surface_keyed_mutex(dsh_frame_forwarding_surface* surface);
@@ -80,6 +88,19 @@ int dsh_frame_forwarding_write_bgra_with_timeout(dsh_frame_forwarding_surface* s
80
88
  * Return 0 on failure; a valid acquisition stays with the caller for retry or discard.
81
89
  */
82
90
  int dsh_frame_forwarding_submit(dsh_frame_forwarding_client* client, dsh_frame_forwarding_surface* surface, uint64_t frame_id, const char* metadata_json);
91
+ /** Submit a continuous-stream frame without waiting for receiver credit, under the GPU
92
+ * ownership rules of submit. With N the receiver's frame limit, the frame is sent at once
93
+ * while fewer than max(1, N - 1) submissions await release; otherwise it becomes the client's
94
+ * single queued frame, and an older queued frame returns to the pool unsent. Polling that
95
+ * observes a release sends the queued frame, so the newest complete frame reaches the receiver
96
+ * without another render. Acquisition reuses the queued surface when no other surface of that
97
+ * size is free; with N of at least 2 an allocated stream always obtains a surface. The frame is
98
+ * marked replaceable, so a receiver that stages frames before presentation may drop it once a
99
+ * newer latest frame is ready; submit frames are never dropped.
100
+ * frame_id must be unique among outstanding submissions. Return 1 when sent or queued.
101
+ * Return 0 on failure; a valid acquisition stays with the caller for retry or discard.
102
+ */
103
+ int dsh_frame_forwarding_submit_latest(dsh_frame_forwarding_client* client, dsh_frame_forwarding_surface* surface, uint64_t frame_id, const char* metadata_json);
83
104
  /** Return an acquired, unsubmitted surface under the same GPU ownership rules as
84
105
  * submit. If releasing GPU access failed, terminate the connection instead of
85
106
  * discarding. The next writer must acquire key 0 even after a discard.
@@ -93,7 +114,10 @@ int dsh_frame_forwarding_poll(dsh_frame_forwarding_client* client, uint32_t time
93
114
  int dsh_frame_forwarding_send(dsh_frame_forwarding_client* client, const char* json);
94
115
  /** Interrupt polling without freeing client. Join polling thread before close. */
95
116
  void dsh_frame_forwarding_interrupt(dsh_frame_forwarding_client* client);
96
- /** Destroy producer after all its API calls have returned. Receiver references stay valid. */
117
+ /** Close this producer's connection after all its API calls have returned: no further operation is sent, unsubmitted
118
+ * and queued frames are dropped, and the receiver drains the frames it still holds before a successor holding the same
119
+ * TX credential becomes ready. Closing does not revoke other copies of the credential; only the receiver closes the
120
+ * channel. Receiver references stay valid. */
97
121
  void dsh_frame_forwarding_close(dsh_frame_forwarding_client* client);
98
122
  #ifdef __cplusplus
99
123
  }