Repository navigation
Worker.requestAnimationFrame spec - #3677
Conversation
|
cc @whatwg/canvas |
|
|
||
| <li><p>Append the method's argument to <var>document</var>'s <span>list of animation frame | ||
| callbacks</span>, associated with <var>document</var>'s <span>animation frame callback | ||
| <li><p>Append the method's argument to <var>object</var>'s <span>list of animation frame |
There was a problem hiding this comment.
In the case of the Window interface, these internal slots are being moved from the document object to the window object. I think this is fine, but it raises the question: Why were they on the document in the first place? Is there a special use case where this makes a difference?
There was a problem hiding this comment.
Yeah, initial about:blank replaces the document but keeps the window around. Is that tested? (There's also document.open() which keeps the document, but allocates a new window, but that is not consistent across browsers and will likely go away.)
There was a problem hiding this comment.
That makes sense. I've introduced a new description for target object to clear this up.
|
Other that the question raised above, this looks good to me. |
annevk
left a comment
There was a problem hiding this comment.
Thanks for working on this! I don't think this is quite ready. There's quite a lot of inconsistencies in the new model.
| the bitmap of the <span data-x="offscreencanvas-placeholder">placeholder <code>canvas</code> | ||
| element</span> of the <span>associated <code>OffscreenCanvas</code> object</span>. The copy | ||
| operation is asynchronous.</p> | ||
| operation is synchronous. Calling this method is <!--non-normative-->optional for the |
There was a problem hiding this comment.
How about "not needed" instead of "optional"?
|
|
||
| <p>The <dfn><code data-x="offscreencontext2d-commit">commit()</code></dfn> method, when invoked, | ||
| must run the following steps:</p> | ||
| has to run the following steps:</p> |
There was a problem hiding this comment.
lint complained about it, maybe I misunderstood the line. Reverted.
|
|
||
| <li><p>If this is a <a href="#workers">worker</a> <span>event loop</span> (i.e. one running for a | ||
| <code>WorkerGlobalScope</code>), but there are no <span data-x="concept-task">tasks</span> in the | ||
| <li><p>If that is a <a href="#workers">worker</a> <span>event loop</span> (i.e. one running for a |
There was a problem hiding this comment.
The formatting in this block is a little off.
| passing in <var>now</var> as the timestamp.</p></li> | ||
|
|
||
| <li><p>Update the rendering or user interface of that <code>Worker</code> to reflect the | ||
| current state.</p></li> |
There was a problem hiding this comment.
Workers don't have a user interface so I don't think we should mention that here.
|
|
||
| <li><p>Append the method's argument to <var>document</var>'s <span>list of animation frame | ||
| callbacks</span>, associated with <var>document</var>'s <span>animation frame callback | ||
| <li><p>Append the method's argument to <var>object</var>'s <span>list of animation frame |
There was a problem hiding this comment.
Yeah, initial about:blank replaces the document but keeps the window around. Is that tested? (There's also document.open() which keeps the document, but allocates a new window, but that is not consistent across browsers and will likely go away.)
| <div itemscope itemtype="http://n.whatwg.org/work"> | ||
| <p>The <code data-x=""><flag-icon></code> example was inspired by <a itemprop="work" | ||
| href="https://github.com/stevenrskelton/flag-icon">a custom element</a> by <a | ||
| href="https://github.com/stevenrskelton/flag-icon">a custom Element</a> by <a |
There was a problem hiding this comment.
no idea how that happened. done.
|
|
||
| </ol> | ||
|
|
||
| <p>Currently <code>Window</code> and <code>WorkerGlobalScope</code> implement <code>AnimationFrameProvider</code>.</p> |
There was a problem hiding this comment.
Are there plans for other interfaces? Note that they include it, not implement.
There was a problem hiding this comment.
There are plans for WebXR to include it too.
| unsigned long <span data-x="dom-window-requestAnimationFrame">requestAnimationFrame</span>(<span>FrameRequestCallback</span> callback); | ||
| void <span data-x="dom-window-cancelAnimationFrame">cancelAnimationFrame</span>(unsigned long handle); | ||
| unsigned long <span data-x="AnimationFrameProvider-requestAnimationFrame">requestAnimationFrame</span>(<span>FrameRequestCallback</span> callback); | ||
| void <span data-x="AnimationFrameProvider-cancelAnimationFrame">cancelAnimationFrame</span>(unsigned long handle); |
There was a problem hiding this comment.
Why do you keep these around as well as defining a mixin with a different signature? That contradicts the statement below that Window and WorkerGlobalScope include the same mixin.
There was a problem hiding this comment.
makes sense. Removed.
| <li><p>Set <var>object</var>'s <span>list of animation frame callbacks</span> to the empty list.</p></li> | ||
|
|
||
| <li><p>For each entry in <var>callbacks</var>, in order: <span data-x="es-invoking-callback-functions">invoke the callback</span>, passing | ||
| <var>now</var> as the only argument, and if an exception is thrown, <span>report the |
There was a problem hiding this comment.
You define the callback as taking two arguments. This contradicts that.
There was a problem hiding this comment.
ahn, sorry. The IDL update was wrong. In the future there may be a second argument, but not now.
|
Done. PTAL. :) |
| interface AnimationFrameProvider { | ||
| unsigned long requestAnimationFrame(FrameRequestCallback callback); | ||
| void cancelAnimationFrame(unsigned long handle); | ||
| } |
There was a problem hiding this comment.
You need to add something like this here:
Window includes AnimationFrameProvider;
WorkerGlobalScope includes AnimationFrameProvider;
|
|
||
| </ol> | ||
|
|
||
| <p>Currently <code>Window</code> and <code>WorkerGlobalScope</code> include the <code>AnimationFrameProvider</code> interface.</p> |
There was a problem hiding this comment.
Is there a plan beyond these objects? If not, should we just put them on WindowOrWorkerGlobalScope?
There was a problem hiding this comment.
You answered this above already with WebXR. I guess that means we best keep it separate from Window/WorkerGlobalScope.
| <li><p>Update the rendering of that <code>Worker</code> to reflect the current state.</p></li> | ||
|
|
||
| <li><p class="note">The same note described above regarding update frequency applies | ||
| to <code>Worker</code>.</p></li> |
There was a problem hiding this comment.
That note is about "would not benefit from having their rendering updated" which isn't used here. I guess this should actually be more complex so we don't run this step for each task necessarily?
There was a problem hiding this comment.
I'm not sure what you mean by more complex. I've updated the note slightly. Would that work?
| } | ||
| </pre> | ||
|
|
||
| <p>Each <var>object</var> implementing the <code>AnimationFrameProvider</code> interface |
There was a problem hiding this comment.
I don't think this should be a variable since you never really assigned it. In the algorithm below you can use "this object" instead. Here you can use "object".
There was a problem hiding this comment.
I guess you also need to change the language here since these days objects include mixins.
|
|
||
| callback FrameRequestCallback = void (DOMHighResTimeStamp); | ||
|
|
||
| interface AnimationFrameProvider { |
| <h3>Animation frames</h3> | ||
|
|
||
| <p>Each <code>Document</code> has a <dfn>list of animation frame callbacks</dfn>, which must be | ||
| <p>Some objects implement the <dfn>AnimationFrameProvider</dfn> mixin.</p> |
| <pre class="idl"> | ||
| interface FrameRequestData { | ||
| // Empty base interface | ||
| } |
|
|
||
| <li><p>Let <var>document</var> be this <code>Window</code> object's <span | ||
| data-x="concept-document-window">associated <code>Document</code></span>.</p></li> | ||
| <li><p>Consider the <var>target object</var> the <var>object</var> that stores <code>AnimationFrameProvider</code>'s internal state. If the interface is implemented by <code>Window</code>, then <var>target object</var> is <code>Document</code>. If is implemented by <code>WorkerGlobalScope</code>, then <var>target object</var> is <code>WorkerGlobalScope</code>.</p></li> |
There was a problem hiding this comment.
You need to keep the language of "associated Document". Otherwise it's unclear where the document comes from.
There was a problem hiding this comment.
And also not use "implemented", but "includes".
|
Done. PTAL. :) |
|
Yeah, so the worker event loop changes seems incorrect. In particular, you run the substeps for each task processed by a worker, whereas you only want to run them sometimes, say, at 60Hz. In particular, you want something like substep 3 of "Update the rendering" (the one for documents) where you do an early return if the worker does not require a rendering update. And there you want to attach the note. Is this logic of when you skip a rendering update for a worker tied to its owners by the way? If it has an owner document that is not displayed, is it valid to not give it rendering updates? Should this be exposed in service workers by the way? This API does not make much sense to me there given how it be quit early and such. |
|
Gotcha! :) |
|
|
||
| </ol> | ||
|
|
||
| <p>Currently <code>Window</code> and <code>DedicatedWorkerGlobalScope</code> include the <code>AnimationFrameProvider</code> interface.</p> |
There was a problem hiding this comment.
I suggest we drop this sentence since it's already clear from the IDL.
|
|
||
| <li><p>Update the rendering of that <code>Worker</code> to reflect the current state.</p></li> | ||
| </ol> | ||
| </li> |
There was a problem hiding this comment.
These first two steps should be conditional on it being a dedicated worker.
| <li><p>If the user agent believes that the <code>Worker</code> would benefit from having their | ||
| rendering updated at this time, then: | ||
| <ol> | ||
| <li><p><span>run the animation frame callbacks</span> for that <code>Worker</code>, |
There was a problem hiding this comment.
This should be DedicatedWorkerGlobalScope I think.
|
All done. :) |
|
Where is the How does it relate btw that |
|
Anne, good point. I had the commit changes here, but I somehow split them when sending. Is it ok if I leave this as only the RAF and send a separate one for commit? OffscreenCanvas works fine with other types of workers. The commit/renderloop changes are only needed for OffscreenCanvases that are "transferedToOffscreen" from a regular canvas (i.e., that are sent to DedicatedWorker). For cases where an OffscreenCanvas is just posted back and forth, there's no need for the commit/render loop changes, so everything should work fine. Does this make sense? |
|
Yeah, we could discuss Do you mean |
|
Review status: this needs various editorial changes to comply with the formatting guidelines, as well as rebasing on top of #3707 once that lands so it can use the same underlying concept rather than invoking |
|
Yes, I'll send a For the |
|
I'll give a try at the formatting guidelines, although I thought the linter got them all. I can easily update to #3707 once it lands. |
|
Fixed formatting. |
|
|
annevk
left a comment
There was a problem hiding this comment.
No need to address these comments right away, as at least one depends on other work. I think this is mostly done, but we'll need tests and the commit() PR. And I guess some indication that this is indeed what everyone wants to ship.
| <code>DedicatedWorkerGlobalScope</code>, passing in <var>now</var> as the | ||
| timestamp.</p></li> | ||
|
|
||
| <li><p>Update the rendering of that <code>Worker</code> to reflect the current state.</p> |
There was a problem hiding this comment.
This should talk about the dedicated worker, not the object used to talk to a dedicated worker.
| described in the <a href="#workers">Web workers</a> section below.</p></li> | ||
| </ol> | ||
| <p class="note">Similar to the <span data-x="nested browsing context">nested browsing contexts</span> | ||
| note above, a user agent can consider updating <code>Worker</code> rendering infrequently or never.</p> |
| steps:</p> | ||
|
|
||
| <ol> | ||
| <li><p>Consider <var>target object</var> as above.</p></li> |
There was a problem hiding this comment.
This is too informal. We should either duplicate or create some kind of abstraction.
There was a problem hiding this comment.
I've moved the notion of a target object above.
| a <code>WorkerGlobalScope</code>): | ||
| <ol> | ||
| <li><p>Let <var>now</var> be the value that would be returned by the <code>Performance</code> | ||
| object's <code data-x="dom-Performance-now">now()</code> method. <ref spec=HRT></p> |
There was a problem hiding this comment.
This should use the primitive from the other PR as discussed. This step should also be conditional on it being a dedicated worker.
There was a problem hiding this comment.
I'll update once that one is submitted.
Fixes some problems with the new text, and some problems with the old text. - "list of animation frame callbacks" should have been an ordered map. Now, it is. Rewrote all manipulation text to use Infra map operations. - Note about refresh rate should refer to the entire "update the rendering" step, not just the nested browsing contexts step. - "target object" and "not supported" need to be <dfn>s, not variables. - animation frame callbacks and animation frame callback identifier need to be associated with the target object, not with the AnimationFrameProvider - Run the animation frame callbacks needs to operate on a target object, not on a Document - Run the animation frame callbacks for some reason inlined most of the Web IDL "invoke" algorithm? Reverted that. - Run the animation frame callbacks for some reason changed to bail early if any callbacks threw an exception? Reverted that. - Updated algorithm and method definition boilerplate to modern concise style. - Editorial issues (e.g. repeated words) - Source formatting
|
Fixed the build problem. :) |
This was added in #3677. As discovered in w3c/reffy#125, this is the only case that isn't wrapped in <code> in addition to <pre>.
This was added in #3677. As discovered in w3c/reffy#125, this is the only case that isn't wrapped in <code> in addition to <pre>.
This was added in whatwg#3677. As discovered in w3c/reffy#125, this is the only case that isn't wrapped in <code> in addition to <pre>.
This was added in whatwg#3677. As discovered in w3c/reffy#125, this is the only case that isn't wrapped in <code> in addition to <pre>.
Takes over whatwg#3872 This removes the `OffscreenCanvas.commit()` method which has became obsoleted by whatwg#3677 This mainly handles the review comments left on the original PR. Note that I "hide" the merge-commit to make it clear what's changed from current upstream.
This goes beyond whatwg#3872 and removes the OffscreenCanvas contexts' commit(), method which has been superseded by requestAnimationFrame() since whatwg#3677 and is thus not strictly necessary anymore and might conflict with this new model. Closes whatwg#3872.
Draft change to: #3587
/canvas.html ( diff )
/embedded-content.html ( diff )
/imagebitmap-and-animations.html ( diff )
/infrastructure.html ( diff )
/timers-and-user-prompts.html ( diff )
/webappapis.html ( diff )
/window-object.html ( diff )