12019-02-23 Said Abou-Hallawa <said@apple.com>
2
3 requestAnimationFrame should execute before the next frame
4 https://bugs.webkit.org/show_bug.cgi?id=177484
5
6 Reviewed by NOBODY (OOPS!).
7
8 This change fixes two issues with animation timing:
9
10 1. Calling the requestAnimationFrame callbacks would have happened when
11 the DisplayLink fires. This may have happened even if the frame is
12 missed and no display is committed.
13
14 2. Style changes and layout triggered by script could trigger painting
15 at more than 60fps. CoreAnimation commits could happen at more than
16 60fps, although WindowServer will throttle those, and only some will
17 be shown on the screen.
18
19 This change introduces a new paint scheduling model where painting is driven
20 by a "RenderingScheduler", which only triggers paints once per 16.7ms frame.
21
22 Code that previously scheduled a compositing layer flush now schedules a
23 "render", and that render is driven by a DisplayRefreshMonitor callback.
24 When the render happens, we service requestAnimationFrame callbacks,
25 intersection observations and Web Animations per the "Update the rendering"
26 step of the HTML Event Loop specification
27 <https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering>.
28
29 In the future, more rendering steps will be added to this code.
30
31 * Sources.txt:
32 * WebCore.xcodeproj/project.pbxproj:
33 * animation/DocumentAnimationScheduler.cpp: Removed.
34 * animation/DocumentTimeline.cpp:
35 (WebCore::DocumentTimeline::DocumentTimeline):
36 (WebCore::DocumentTimeline::detachFromDocument):
37 (WebCore::DocumentTimeline::liveCurrentTime const):
38 (WebCore::DocumentTimeline::currentTime):
39 (WebCore::DocumentTimeline::scheduleAnimationResolution):
40 (WebCore::DocumentTimeline::unscheduleAnimationResolution):
41 (WebCore::DocumentTimeline::updateAnimationsAndSendEvents):
42 (WebCore::DocumentTimeline::internalUpdateAnimationsAndSendEvents):
43 (WebCore::DocumentTimeline::animationResolutionTimerFired): Deleted.
44 * animation/DocumentTimeline.h:
45 * dom/Document.cpp:
46 (WebCore::Document::resolveStyle):
47 (WebCore::Document::prepareForDestruction):
48 (WebCore::Document::updateAnimationsAndSendEvents):
49 (WebCore::Document::serviceRequestAnimationFrameCallbacks):
50 (WebCore::Document::windowScreenDidChange):
51 (WebCore::Document::updateIntersectionObservations):
52 (WebCore::Document::scheduleForcedIntersectionObservationUpdate): Deleted.
53 (WebCore::Document::animationScheduler): Deleted.
54 * dom/Document.h:
55 (WebCore::Document::numberOfIntersectionObservers const):
56 * dom/ScriptedAnimationController.cpp:
57 (WebCore::ScriptedAnimationController::serviceRequestAnimationFrameCallbacks):
58 (WebCore::ScriptedAnimationController::scheduleAnimation):
59 (WebCore::ScriptedAnimationController::animationTimerFired):
60 (WebCore::ScriptedAnimationController::serviceScriptedAnimations): Deleted.
61 (WebCore::ScriptedAnimationController::documentAnimationSchedulerDidFire): Deleted.
62 * dom/ScriptedAnimationController.h:
63 * page/FrameTree.cpp:
64 * page/FrameView.cpp:
65 (WebCore::FrameView::viewportContentsChanged):
66 * page/IntersectionObserver.cpp:
67 (WebCore::IntersectionObserver::observe):
68 * page/Page.cpp:
69 (WebCore::Page::Page):
70 (WebCore::Page::layoutIfNeeded):
71 (WebCore::Page::updateRendering):
72 (WebCore::Page::renderingScheduler):
73 (WebCore::Page::willDisplayPage): Deleted.
74 (WebCore::Page::addDocumentNeedingIntersectionObservationUpdate): Deleted.
75 (WebCore::Page::updateIntersectionObservations): Deleted.
76 (WebCore::Page::scheduleForcedIntersectionObservationUpdate): Deleted.
77 * page/Page.h:
78 * page/PageOverlayController.cpp:
79 (WebCore::PageOverlayController::didChangeViewExposedRect):
80 (WebCore::PageOverlayController::notifyFlushRequired):
81 * page/RenderingScheduler.cpp: Added.
82 (WebCore::RenderingScheduler::RenderingScheduler):
83 (WebCore::RenderingScheduler::scheduleRender):
84 (WebCore::RenderingScheduler::startTimer):
85 (WebCore::RenderingScheduler::clearTimer):
86 (WebCore::RenderingScheduler::windowScreenDidChange):
87 (WebCore::RenderingScheduler::createDisplayRefreshMonitor const):
88 (WebCore::RenderingScheduler::displayRefreshFired):
89 * page/RenderingScheduler.h: Renamed from Source/WebCore/animation/DocumentAnimationScheduler.h.
90 (WebCore::RenderingScheduler::create):
91 * page/mac/ServicesOverlayController.mm:
92 (WebCore::ServicesOverlayController::Highlight::notifyFlushRequired):
93 * rendering/RenderLayerCompositor.cpp:
94 (WebCore::RenderLayerCompositor::scheduleLayerFlushNow):
95