v0.1首个版本化设计基线查看版本范围
Developer

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-foundinvalid-framestale-framelimit-exceeded。若期间发生 resize,旧尺寸帧可以以可重试的 stale-frame 失败。

Requirements

  • 能力:host:canvas.present
  • 用户激活:不需要
  • 信任档位:green
  • 背压:宿主只保留有限数量待呈现帧,新帧可以替换旧帧

See also

canvas.getInfo()canvas.frame

Host API 版本与分层概览Host API v0.1版本非正式提议提议canvas API呈现canvas.getInfo()方法canvas.draw()方法canvas.present()方法canvas.measureText()方法canvas.frame event事件canvas.resize event事件asset API呈现asset.read()方法asset.loadFont()方法playback API呈现playback.open()方法playback.write()方法playback.stop()方法playback.ready event事件playback.ended event事件input API输入input.focus()方法input.pointer event事件input.key event事件input.wheel event事件ime API输入ime.openSession()方法ime.updateState()方法ime.updateGeometry()方法ime.closeSession()方法ime.textUpdate event事件ime.composition event事件ime.formatUpdate event事件ime.characterBoundsRequest event事件capture API输入capture.requestCamera()方法capture.requestMic()方法capture.frame()方法capture.readAudio()方法capture.stop()方法capture.ended event事件store API数据store.get()方法store.put()方法store.delete()方法store.list()方法store.deletePrefix()方法clipboard API数据clipboard.readText()方法clipboard.writeText()方法clipboard.readImage()方法clipboard.writeImage()方法net API网络net.fetch()方法identity API身份identity.status()方法identity.login()方法identity.logout()方法env API平台集成env.snapshot()方法env.change event事件print API平台集成print.open()方法开始调用 Host API指南构建交互式绘图应用指南构建自绘文本编辑器指南管理媒体采集与播放指南组织本地数据与同步指南