canvas.present()
提交一帧完整软件渲染结果。v0.1 只接受 rgba8,不提供像素读回。
Syntax
await host.canvas.present(canvasId, pixels, frame);
Parameters
| 参数 | 类型 | 说明 |
|---|---|---|
canvasId |
string |
目标绘图面 |
pixels |
ByteSource |
完整帧字节 |
frame |
FrameInfo |
宽、高、步长、格式和单调 sequence |
FrameInfo { width, height, stride, format: "rgba8", sequence }
必须满足 stride >= width × 4,且字节数足以覆盖 stride × height。
Return value
无。完成表示宿主接收了帧,不保证显示设备已经输出。
Examples
const info = await host.canvas.getInfo('main');
if (!info) return;
const pixels = new Uint8Array(info.width * info.height * 4);
renderInto(pixels, info.width, info.height);
await host.canvas.present('main', pixels, {
width: info.width,
height: info.height,
stride: info.width * 4,
format: 'rgba8',
sequence: 42n,
});
Errors
not-found、invalid-frame、stale-frame、limit-exceeded。若期间发生 resize,旧尺寸帧可以以可重试的 stale-frame 失败。
Requirements
- 能力:
host:canvas.present - 用户激活:不需要
- 信任档位:green
- 背压:宿主只保留有限数量待呈现帧,新帧可以替换旧帧