Skip to content

Commit

Permalink
Integrate canvas and OffscreenCanvas with WebGPU
Browse files Browse the repository at this point in the history
See gpuweb/gpuweb#131 for the discussion on the exact naming of the string used in getContext("webgpu").
  • Loading branch information
toji committed Jul 14, 2021
1 parent 3d45584 commit 74a7491
Showing 1 changed file with 103 additions and 13 deletions.
116 changes: 103 additions & 13 deletions source
Expand Up @@ -3825,6 +3825,18 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute



<dt>WebGPU</dt>

<dd>
<p>The following interfaces are defined in <cite>WebGPU</cite>: <ref spec=WEBGPU></p>

<ul class="brief">
<li><dfn data-x-href="https://gpuweb.github.io/gpuweb/#canvas-context"><code>GPUCanvasContext</code></dfn> interface</li>
</ul>
</dd>



<dt>WebVTT</dt>

<dd>
Expand Down Expand Up @@ -60270,7 +60282,7 @@ dictionary <dfn dictionary>AssignedNodesOptions</dfn> {
<dd><a href="https://w3c.github.io/html-aam/#el-canvas">For implementers</a>.</dd>
<dt><span data-x="concept-element-dom">DOM interface</span>:</dt>
<dd w-nodev>
<pre><code class="idl">typedef (<span>CanvasRenderingContext2D</span> or <span>ImageBitmapRenderingContext</span> or <span>WebGLRenderingContext</span> or <span>WebGL2RenderingContext</span>) <dfn typedef>RenderingContext</dfn>;
<pre><code class="idl">typedef (<span>CanvasRenderingContext2D</span> or <span>ImageBitmapRenderingContext</span> or <span>WebGLRenderingContext</span> or <span>WebGL2RenderingContext</span> or <span>GPUCanvasContext</span>) <dfn typedef>RenderingContext</dfn>;

[Exposed=Window]
interface <dfn interface>HTMLCanvasElement</dfn> : <span>HTMLElement</span> {
Expand Down Expand Up @@ -60389,8 +60401,9 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
data-x="concept-canvas-placeholder">placeholder</dfn>, <dfn
data-x="concept-canvas-2d">2d</dfn>, <dfn
data-x="concept-canvas-bitmaprenderer">bitmaprenderer</dfn>, <dfn
data-x="concept-canvas-webgl">webgl</dfn>, or <dfn
data-x="concept-canvas-webgl2">webgl2</dfn> by algorithms defined in this specification.</p>
data-x="concept-canvas-webgl">webgl</dfn>, <dfn
data-x="concept-canvas-webgl2">webgl2</dfn>, or <dfn
data-x="concept-canvas-webgpu">webgpu</dfn> by algorithms defined in this specification.</p>

<p>When its <span data-x="concept-canvas-context-mode">canvas context mode</span> is <span
data-x="concept-canvas-none">none</span>, a <code>canvas</code> element has no rendering context,
Expand Down Expand Up @@ -60444,6 +60457,12 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
<td>
<p>Follow the behavior defined in the WebGL specifications. <ref spec=WEBGL></p>

<tr>
<th>
<p><span data-x="concept-canvas-webgpu">webgpu</span></p>
<td>
<p>Follow the behavior defined in <cite>WebGPU</cite>. <ref spec=WEBGPU></p>

<tr>
<th>
<p><span data-x="concept-canvas-bitmaprenderer">bitmaprenderer</span></p>
Expand Down Expand Up @@ -60481,13 +60500,15 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
<p>Returns an object that exposes an API for drawing on the canvas. <var>contextId</var>
specifies the desired API: "<code data-x="canvas-context-2d">2d</code>", "<code
data-x="canvas-context-bitmaprenderer">bitmaprenderer</code>", "<code
data-x="canvas-context-webgl">webgl</code>", or "<code
data-x="canvas-context-webgl2">webgl2</code>". <var>options</var> is handled by that API.</p>
data-x="canvas-context-webgl">webgl</code>", "<code
data-x="canvas-context-webgl2">webgl2</code>", or "<code
data-x="canvas-context-webgpu">webgpu</code>". <var>options</var> is handled by that API.</p>

<p>This specification defines the "<code data-x="canvas-context-2d">2d</code>" and "<code
data-x="canvas-context-bitmaprenderer">bitmaprenderer</code>" contexts below. The WebGL
specifications define the "<code data-x="canvas-context-webgl">webgl</code>" and "<code
data-x="canvas-context-webgl2">webgl2</code>" contexts. <ref spec=WEBGL></p>
data-x="canvas-context-webgl2">webgl2</code>" contexts. <cite>WebGPU</cite> defines the "<code
data-x="canvas-context-webgpu">webgpu</code>" context. <ref spec=WEBGL> <ref spec=WEBGPU></p>

<p>Returns null if <var>contextId</var> is not supported, or if the canvas has already been
initialized with another context type (e.g., trying to get a "<code
Expand Down Expand Up @@ -60523,6 +60544,7 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
<th><span data-x="concept-canvas-bitmaprenderer">bitmaprenderer</span>
<th><span data-x="concept-canvas-webgl">webgl</span> or <span
data-x="concept-canvas-webgl2">webgl2</span>
<th><span data-x="concept-canvas-webgpu">webgpu</span>
<th><span data-x="concept-canvas-placeholder">placeholder</span>
<tbody>
<tr>
Expand All @@ -60541,6 +60563,8 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
Return null.
<td>
Return null.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
Expand All @@ -60559,6 +60583,8 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
first argument.
<td>
Return null.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
Expand All @@ -60581,6 +60607,30 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
<td>
Return the same object as was returned the last time the method was invoked with this same
first argument.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
<th>"<dfn><code data-x="canvas-context-webgpu">webgpu</code></dfn>", if the user
agent supports the WebGPU feature in its current configuration
<td>
Follow the instructions given in <cite>WebGPU</cite>'s <a
href="https://gpuweb.github.io/gpuweb/#canvas-rendering">Canvas Rendering</a> section to
obtain a <code>GPUCanvasContext</code> or null; if the returned value is null, then return
null; otherwise, set this <code>canvas</code> element's <span
data-x="concept-canvas-context-mode">context mode</span> to <span
data-x="concept-canvas-webgpu">webgpu</span> and return the
<code>GPUCanvasContext</code> object. <ref spec=WEBGPU>
<td>
Return null.
<td>
Return null.
<td>
Return null.
<td>
Return the same object as was returned the last time the method was invoked with this same
first argument.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
Expand All @@ -60593,6 +60643,8 @@ callback <dfn callback>BlobCallback</dfn> = undefined (<span>Blob</span>? blob);
Return null.
<td>
Return null.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
</table>
Expand Down Expand Up @@ -66422,14 +66474,14 @@ dictionary <dfn dictionary>ImageBitmapRenderingContextSettings</dfn> {

<h5>The <code>OffscreenCanvas</code> interface</h5>

<pre><code class="idl">typedef (<span>OffscreenCanvasRenderingContext2D</span> or <span>ImageBitmapRenderingContext</span> or <span>WebGLRenderingContext</span> or <span>WebGL2RenderingContext</span>) <dfn typedef>OffscreenRenderingContext</dfn>;
<pre><code class="idl">typedef (<span>OffscreenCanvasRenderingContext2D</span> or <span>ImageBitmapRenderingContext</span> or <span>WebGLRenderingContext</span> or <span>WebGL2RenderingContext</span> or <span>GPUCanvasContext</span>) <dfn typedef>OffscreenRenderingContext</dfn>;

dictionary <dfn dictionary>ImageEncodeOptions</dfn> {
DOMString <span data-x="image-encode-options-type">type</span> = "image/png";
unrestricted double <span data-x="image-encode-options-quality">quality</span>;
};

enum <dfn enum>OffscreenRenderingContextId</dfn> { "<span data-x="offscreen-context-type-2d">2d</span>", "<span data-x="offscreen-context-type-bitmaprenderer">bitmaprenderer</span>", "<span data-x="offscreen-context-type-webgl">webgl</span>", "<span data-x="offscreen-context-type-webgl2">webgl2</span>" };
enum <dfn enum>OffscreenRenderingContextId</dfn> { "<span data-x="offscreen-context-type-2d">2d</span>", "<span data-x="offscreen-context-type-bitmaprenderer">bitmaprenderer</span>", "<span data-x="offscreen-context-type-webgl">webgl</span>", "<span data-x="offscreen-context-type-webgl2">webgl2</span>", "<span data-x="offscreen-context-type-webgpu">webgpu</span>" };

[Exposed=(Window,Worker), <span>Transferable</span>]
interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
Expand Down Expand Up @@ -66482,15 +66534,18 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
object. <var>contextId</var> specifies the desired API: "<code
data-x="offscreen-context-type-2d">2d</code>", "<code
data-x="offscreen-context-type-bitmaprenderer">bitmaprenderer</code>", "<code
data-x="offscreen-context-type-webgl">webgl</code>", or "<code
data-x="offscreen-context-type-webgl2">webgl2</code>". <var>options</var> is handled by that
API.</p>
data-x="offscreen-context-type-webgl">webgl</code>", "<code
data-x="offscreen-context-type-webgl2">webgl2</code>", or "<code
data-x="offscreen-context-type-webgpu">webgpu</code>". <var>options</var> is handled by
that API.</p>

<p>This specification defines the "<code data-x="canvas-context-2d">2d</code>" context below,
which is similar but distinct from the "<code data-x="offscreen-context-type-2d">2d</code>"
context that is created from a <code>canvas</code> element. The WebGL specifications define the
"<code data-x="offscreen-context-type-webgl">webgl</code>" and "<code
data-x="offscreen-context-type-webgl2">webgl2</code>" contexts. <ref spec=WEBGL></p>
data-x="offscreen-context-type-webgl2">webgl2</code>" contexts. <cite>WebGPU</cite> defines the
"<code data-x="offscreen-context-type-webgpu">webgpu</code>" context. <ref spec=WEBGL> <ref
spec=WEBGPU></p>

<p>Returns null if the canvas has already been initialized with another context type (e.g.,
trying to get a "<code data-x="offscreen-context-type-2d">2d</code>" context after getting a
Expand All @@ -66515,7 +66570,8 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
data-x="offscreencanvas-context-2d">2d</dfn>, <dfn
data-x="offscreencanvas-context-bitmaprenderer">bitmaprenderer</dfn>, <dfn
data-x="offscreencanvas-context-webgl">webgl</dfn>, <dfn
data-x="offscreencanvas-context-webgl2">webgl2</dfn>, or <dfn
data-x="offscreencanvas-context-webgl2">webgl2</dfn>, <dfn
data-x="offscreencanvas-context-webgpu">webgpu</dfn>, or <dfn
data-x="offscreencanvas-context-detached">detached</dfn> by algorithms defined in this
specification.</p>

Expand Down Expand Up @@ -66597,6 +66653,7 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
<th><span data-x="offscreencanvas-context-bitmaprenderer">bitmaprenderer</span>
<th><span data-x="offscreencanvas-context-webgl">webgl</span> or <span
data-x="offscreencanvas-context-webgl2">webgl2</span>
<th><span data-x="offscreencanvas-context-webgpu">webgpu</span>
<th><span data-x="offscreencanvas-context-detached">detached</span>
<tbody>
<tr>
Expand All @@ -66617,6 +66674,8 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
Return null.
<td>
Return null.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
Expand All @@ -66637,6 +66696,8 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
first argument.
<td>
Return null.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
Expand All @@ -66658,6 +66719,29 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
<td>
Return the same value as was returned the last time the method was invoked with this same
first argument.
<td>
Return null.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
<tr>
<th>"<dfn><code data-x="offscreen-context-type-webgpu">webgpu</code></dfn>"
<td>
Follow the instructions given in <cite>WebGPU</cite>'s <a
href="https://gpuweb.github.io/gpuweb/#canvas-rendering">Canvas Rendering</a> section to
obtain a <code>GPUCanvasContext</code> or null; if the returned value is null, then return
null; otherwise, set this <code>OffscreenCanvas</code> object's <span
data-x="offscreencanvas-context-mode">context mode</span> to <span
data-x="offscreencanvas-context-webgpu">webgpu</span> and return the
<code>GPUCanvasContext</code> object. <ref spec=WEBGPU>
<td>
Return null.
<td>
Return null.
<td>
Return null.
<td>
Return the same value as was returned the last time the method was invoked with this same
first argument.
<td>
Throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.
</table>
Expand Down Expand Up @@ -66702,6 +66786,9 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
data-x="offscreen-context-type-webgl2">webgl2</code>" contexts is defined in the WebGL
specifications. <ref spec=WEBGL></p>

<p>The resizing behavior for "<code data-x="offscreen-context-type-webgpu">webgpu</code>"
context is defined in <cite>WebGPU</cite>. <ref spec=WEBGPU></p>

</div>

<p class="note">If an <code>OffscreenCanvas</code> object whose dimensions were changed has
Expand Down Expand Up @@ -125604,6 +125691,9 @@ INSERT INTERFACES HERE
<dt id="refsWEBGL">[WEBGL]</dt>
<dd><cite><a href="https://www.khronos.org/registry/webgl/specs/latest/">WebGL Specifications</a></cite>, D. Jackson, J. Gilbert. Khronos Group.</dd>

<dt id="refsWEBGPU">[WEBGPU]</dt>
<dd><cite><a href="https://gpuweb.github.io/gpuweb/">WebGPU</a></cite>, D. Malyshau, K. Ninomiya. W3C.</dd>

<dt id="refsWEBIDL">[WEBIDL]</dt>
<dd><cite><a href="https://heycam.github.io/webidl/">Web IDL</a></cite>, C. McCormack. W3C.</dd>

Expand Down

0 comments on commit 74a7491

Please sign in to comment.