Bug 97918 - [Chromium] Smoother animation for non-RAF 2D canvas animations
Summary: [Chromium] Smoother animation for non-RAF 2D canvas animations
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Justin Novosad
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-28 08:39 PDT by Justin Novosad
Modified: 2012-10-10 19:05 PDT (History)
5 users (show)

See Also:


Attachments
Patch (17.89 KB, patch)
2012-09-28 10:49 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch (16.51 KB, patch)
2012-10-02 14:01 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch (16.50 KB, patch)
2012-10-03 10:56 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch (17.14 KB, patch)
2012-10-03 13:39 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch (16.81 KB, patch)
2012-10-04 07:59 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch for landing (16.47 KB, patch)
2012-10-04 10:06 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff
Patch (16.70 KB, patch)
2012-10-10 13:57 PDT, Justin Novosad
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Novosad 2012-09-28 08:39:38 PDT
[Chromium] Smoother animation for non-RAF 2D canvas animations
Comment 1 Justin Novosad 2012-09-28 10:49:33 PDT
Created attachment 166277 [details]
Patch
Comment 2 Stephen White 2012-09-28 11:41:22 PDT
Comment on attachment 166277 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166277&action=review

> Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp:139
> +    m_flushNeeded = false;
> +    switch (m_state) {
> +    case FreshState:
> +        if (m_didRecordDrawCommand && !isFreshFrame())
> +            m_state = StaleState;
> +        break;
> +    case StaleState:
> +        if (m_didRecordDrawCommand) {
> +            if (isFreshFrame())
> +                m_state = FreshState;
> +            else {
> +                if (!m_didFlushSinceLastRecordedFrame)
> +                    m_flushNeeded = true;
> +            }
> +        }
> +        break;
> +    }
> +    if (m_didRecordDrawCommand)
> +        m_didFlushSinceLastRecordedFrame = false;
> +    m_didRecordDrawCommand = false;

As discussed, I think this logic would be a lot clearer if we replaced isFreshFrame() with a "skippedPendingCommands()" notification from the deferred canvas.

Then we could simply have a counter on the bridge which counts the frames-since-last-flush, which is reset to zero on flushedPendingCommands() or skippedPendingCommands(), and we don't need this state machine at all.

> Source/WebCore/platform/graphics/chromium/Canvas2DLayerManager.cpp:89
> +        for (Canvas2DLayerBridge* layer = m_layerList.head(); layer; layer = layer->next())
> +            layer->flush();

As discussed, I think we can get away with only flushing the one layer, since the rest of the layers will be taken care of at commit time.
Comment 3 Justin Novosad 2012-10-02 14:01:46 PDT
Created attachment 166746 [details]
Patch
Comment 4 Stephen White 2012-10-02 14:27:53 PDT
Comment on attachment 166746 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166746&action=review

Thanks, this seems much cleaner to me.  Just some naming and we're done, I think.

> Source/WebCore/platform/graphics/chromium/Canvas2DLayerManager.cpp:82
> +        layer->didDrawFrame();

<bikeshed> Perhaps didDrawFrame() is misnamed?  It seems to be called regardless of whether that particular canvas drew anything or not. Unless we mean a compositor frame, in which case maybe it should be didDrawCompositorFrame()? </bikeshed>
Comment 5 Justin Novosad 2012-10-03 06:54:54 PDT
(In reply to comment #4)
> (From update of attachment 166746 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=166746&action=review
> 
> Thanks, this seems much cleaner to me.  Just some naming and we're done, I think.
> 
> > Source/WebCore/platform/graphics/chromium/Canvas2DLayerManager.cpp:82
> > +        layer->didDrawFrame();
> 
> <bikeshed> Perhaps didDrawFrame() is misnamed?  It seems to be called regardless of whether that particular canvas drew anything or not. Unless we mean a compositor frame, in which case maybe it should be didDrawCompositorFrame()? </bikeshed>

This does not refer to a compositor frame, but to a frame in the atomic JS execution sense.  Since we are just propagating the task observer signal, we could just use the same name as the observer interface: didProcessTask, The it would be up to the Canvas2DLayerBridge to figure out whether the task drew a new canvas frame.
Comment 6 Stephen White 2012-10-03 07:21:14 PDT
Comment on attachment 166746 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166746&action=review

>>> Source/WebCore/platform/graphics/chromium/Canvas2DLayerManager.cpp:82
>>> +        layer->didDrawFrame();
>> 
>> <bikeshed> Perhaps didDrawFrame() is misnamed?  It seems to be called regardless of whether that particular canvas drew anything or not. Unless we mean a compositor frame, in which case maybe it should be didDrawCompositorFrame()? </bikeshed>
> 
> This does not refer to a compositor frame, but to a frame in the atomic JS execution sense.  Since we are just propagating the task observer signal, we could just use the same name as the observer interface: didProcessTask, The it would be up to the Canvas2DLayerBridge to figure out whether the task drew a new canvas frame.

You're right; it's not a compositor frame.    didProcessTask() is a bit generic, though, and I usually prefer to name things by what they do, rather than when they're called.  Maybe flushFrameBacklog()?  rateLimit()?  limitPendingFrames()?  flushExcessiveFrames()?

> Source/WebCore/platform/graphics/chromium/Canvas2DLayerManager.cpp:96
> +        m_deferredFrameStarted = true;

More bikeshedding, just 'cause I'm annoying that way:  m_taskObserverStarted?
Comment 7 Justin Novosad 2012-10-03 10:56:24 PDT
Created attachment 166922 [details]
Patch
Comment 8 Stephen White 2012-10-03 11:46:17 PDT
Comment on attachment 166922 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166922&action=review

> Source/WebCore/platform/graphics/chromium/Canvas2DLayerBridge.cpp:139
>      storageAllocatedForRecordingChanged(deferredCanvas()->storageAllocatedForRecording());

As discussed, let's mock storageAllocatedForRecordingChanged() itself, instead of creating didFlushPendingCommands() for mocking purposes.
Comment 9 Justin Novosad 2012-10-03 13:39:45 PDT
Created attachment 166952 [details]
Patch
Comment 10 Stephen White 2012-10-03 13:50:31 PDT
Comment on attachment 166952 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=166952&action=review

> Source/WebKit/chromium/tests/Canvas2DLayerManagerTest.cpp:88
> +    size_t m_fakeStorageAllocatedForRecording;

This member variable seems to be unused.
Comment 11 Justin Novosad 2012-10-04 07:59:36 PDT
Created attachment 167105 [details]
Patch
Comment 12 Stephen White 2012-10-04 09:11:48 PDT
Comment on attachment 167105 [details]
Patch

Looks good.  Looks like the patch has conflicts, but I trust you to fix them.  :)  r=me
Comment 13 Justin Novosad 2012-10-04 10:06:20 PDT
Created attachment 167116 [details]
Patch for landing
Comment 14 WebKit Review Bot 2012-10-04 11:12:42 PDT
Comment on attachment 167116 [details]
Patch for landing

Rejecting attachment 167116 [details] from commit-queue.

New failing tests:
Canvas2DLayerManagerTest.testDeferredFrame
Full output: http://queues.webkit.org/results/14183038
Comment 15 Justin Novosad 2012-10-10 13:57:51 PDT
Created attachment 168067 [details]
Patch
Comment 16 Justin Novosad 2012-10-10 13:59:59 PDT
Comment on attachment 168067 [details]
Patch

Fixed release build test failure caused by uninitialized m_taskObserverActive in Canvas2DLayerManager
Comment 17 Stephen White 2012-10-10 14:00:57 PDT
Comment on attachment 168067 [details]
Patch

Looks good (bots willing).  r=me
Comment 18 WebKit Review Bot 2012-10-10 19:05:13 PDT
Comment on attachment 168067 [details]
Patch

Clearing flags on attachment: 168067

Committed r130994: <http://trac.webkit.org/changeset/130994>
Comment 19 WebKit Review Bot 2012-10-10 19:05:17 PDT
All reviewed patches have been landed.  Closing bug.