Skip to content

Allow cancelling rAF callbacks from within rAF #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ callback XRFrameRequestCallback = void (DOMHighResTimeStamp time, XRFrame frame)

Each {{XRFrameRequestCallback}} object has a <dfn for="XRFrameRequestCallback">cancelled</dfn> boolean initially set to <code>false</code>.

Each {{XRSession}} has a <dfn>list of animation frame callbacks</dfn>, which is initially empty, and an <dfn>animation frame callback identifier</dfn>, which is a number which is initially zero.
Each {{XRSession}} has a <dfn>list of animation frame callbacks</dfn>, which is initially empty, a <dfn>list of currently running animation frame callbacks</dfn>, which is also initially empty, and an <dfn>animation frame callback identifier</dfn>, which is a number which is initially zero.

<div class="algorithm" data-algorithm="request-animation-frame">

Expand All @@ -879,7 +879,7 @@ The <dfn method for="XRSession">cancelAnimationFrame(|handle|)</dfn> method canc
When this method is invoked, the user agent MUST run the following steps:

1. Let |session| be the target {{XRSession}} object.
1. Find the entry in |session|'s [=list of animation frame callbacks=] that is associated with the value |handle|.
1. Find the entry in |session|'s [=list of animation frame callbacks=] and |session|'s [=list of currently running animation frame callbacks=] that is associated with the value |handle|.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This could be an "or", since the value should not exist in both at once.

1. If there is such an entry, set its [=cancelled=] boolean to <code>true</code> and remove it from |session|'s [=list of animation frame callbacks=].

</div>
Expand All @@ -892,15 +892,16 @@ When an {{XRSession}} |session| receives updated [=viewer=] state for timestamp
1. If |session|'s [=pending render state=] is not <code>null</code>, [=apply the pending render state=].
1. If |session|'s {{XRSession/renderState}}'s {{XRRenderState/baseLayer}} is <code>null</code>, abort these steps.
1. If |session|'s [=XRSession/mode=] is {{XRSessionMode/"inline"}} and |session|'s {{XRSession/renderState}}'s [=XRRenderState/output canvas=] is <code>null</code>, abort these steps.
1. Let |callbacks| be a list of the entries in |session|'s [=list of animation frame callback=], in the order in which they were added to the list.
1. Set |session|'s [=list of currently running animation frame callbacks=] to be a copy of the list of the entries in |session|'s [=list of animation frame callbacks=], in the order in which they were added to the list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind the new copy here? We should be able to just move the pointer around, so to speak, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to preserve the clause that that list is in order of append, but really that's how lists work anyway so i don't think this is necessary.

1. Set |session|'s [=list of animation frame callbacks=] to the empty list.
1. Set |frame|'s [=active=] boolean to <code>true</code>.
1. Set |frame|'s [=animationFrame=] boolean to <code>true</code>.
1. [=XRFrame/Apply frame updates=] for |frame|.
1. For each entry in |callbacks|, in order:
1. If the entry's [=cancelled=] boolean is <code>true</code>, continue to the next entry.
1. [=Invoke the Web IDL callback function=], passing |now| and |frame| as the arguments
1. For each |entry| in |session|'s [=list of currently running animation frame callbacks=], in order:
1. If the |entry|'s [=cancelled=] boolean is <code>true</code>, continue to the next entry.
1. [=Invoke the Web IDL callback function=] for |entry|, passing |now| and |frame| as the arguments
1. If an exception is thrown, [=report the exception=].
1. Set |session|'s [=list of currently running animation frame callbacks=] to the empty [=/list=].
1. Set |frame|'s [=active=] boolean to <code>false</code>.

</div>
Expand Down