W3C home > Mailing lists > Public > public-web-perf@w3.org > May 2012

Re: Semantics of the time argument on rAF's FrameRequestCallback

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 09 May 2012 19:42:42 -0400
Message-ID: <4FAB00F2.9090106@mit.edu>
To: Nat Duca <nduca@google.com>
CC: Yehuda Katz <yehuda.katz@jquery.com>, Jatinder Mann <jmann@microsoft.com>, "public-web-perf@w3.org" <public-web-perf@w3.org>
On 5/9/12 6:23 PM, Nat Duca wrote:
> function Animation(duration) {
>     this.startTime = window.performance.now();

First bug here.  The right thing to set startTime to in this situation 
is the time of the last refresh tick, not now()....

>        assert(window.performance.now() - a.startTime>= a.duration);

If startTime were not tied to now() (which it shouldn't be), this assert 
would be completely nonsensical....

>     var a= new Animation(1000.0);
>     a.addEventListener('animationEnded', function() {
>        assert(window.performance.now() - a.startTime>= a.duration);
>        aEnded = true;
>        checkBothEnded();
>     });
>     var b= new Animation(1000.0);
>     b.addEventListener('animationEnded', function() {
>        assert(window.performance.now() - b.startTime>= b.duration);
>        bEnded = true;
>        checkBothEnded();
>     });
>     checkBothEnded() {
>       if (!checkTaskEnqueued) window.postTask(checkBothEnded);
>       assert (aEnded&&  bEnded);
>     }

As written, this will always fail the assert in checkBothEnded, so I 
assume you meant something different from what you wrote.  Not sure 
what, though.

> I think that this is why most animation systems pass a frame begin
> time as well as a present time.

So in terms of rAF, "present time" would be the animation sample time 
and "frame begin time" would be the time it was before all the code for 
this frame started running?

How would having both help the use cases here?

> (CVDisplayLink is documented here, though it doesn't explain the
> rationale for the design:
> http://developer.apple.com/library/mac/documentation/QuartzCore/Reference/CVDisplayLinkRef/Reference/reference.html#//apple_ref/c/tdef/CVDisplayLinkOutputCallback)

This looks like it's passing in an "inOutputTime" which is the animation 
sample time and the "inNow" which is .. not really all that 
well-defined.  Is the same for different output callbacks, or does it 

Received on Wednesday, 9 May 2012 23:43:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:01:12 UTC