12019-03-06 Said Abou-Hallawa <sabouhallawa@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 Simon Fraser.
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
20 driven by a "RenderingUpdateScheduler", which only triggers paints once
21 per 16.7ms frame.
22
23 Code that previously scheduled a compositing layer flush now schedules a
24 "RenderingUpdate", and that update is driven by a DisplayRefreshMonitor
25 callback. When the render happens, we service requestAnimationFrame callbacks,
26 Web Animations and intersection observations per the "Update the rendering"
27 step of the HTML Event Loop specification
28 <https://html.spec.whatwg.org/multipage/webappapis.html#update-the-rendering>.
29
30 In the future, more rendering steps will be added to this code.
31
32 * Sources.txt:
33 * WebCore.xcodeproj/project.pbxproj:
34 * accessibility/mac/AXObjectCacheMac.mm:
35 Fix layout tests by adding null check.
36
37 * animation/DocumentAnimationScheduler.cpp: Removed.
38 * animation/DocumentAnimationScheduler.h: Removed.
39 * animation/DocumentTimeline.cpp:
40 (WebCore::DocumentTimeline::DocumentTimeline):
41 (WebCore::DocumentTimeline::updateThrottlingState):
42 (WebCore::DocumentTimeline::resumeAnimations):
43 (WebCore::DocumentTimeline::liveCurrentTime const):
44 (WebCore::DocumentTimeline::currentTime):
45 (WebCore::DocumentTimeline::animationTimingDidChange):
46 (WebCore::DocumentTimeline::scheduleAnimationResolution):
47 (WebCore::DocumentTimeline::unscheduleAnimationResolution):
48 (WebCore::DocumentTimeline::updateAnimationsAndSendEvents):
49 (WebCore::DocumentTimeline::internalUpdateAnimationsAndSendEvents):
50 (WebCore::DocumentTimeline::scheduleNextTick):
51 (WebCore::DocumentTimeline::updateListOfElementsWithRunningAcceleratedAnimationsForElement):
52 Simplify this function by handling the case of no-animations separately.
53
54 (WebCore::DocumentTimeline::resolveAnimationsForElement):
55 Simplify the loop and delete hasPendingAcceleratedAnimations because it
56 is initialized to true and is not changed inside the loop.
57
58 (WebCore::DocumentTimeline::scheduleAnimationResolutionIfNeeded): Deleted.
59 (WebCore::DocumentTimeline::animationResolutionTimerFired): Deleted.
60 * animation/DocumentTimeline.h:
61 * dom/Document.cpp:
62 (WebCore::Document::resolveStyle):
63 There is no need to force update in resolveStyle(). notifyFlushRequired()
64 will be called eventually which will scheduleRenderingUpdate().
65
66 (WebCore::Document::prepareForDestruction):
67 (WebCore::Document::updateAnimationsAndSendEvents):
68 (WebCore::Document::serviceRequestAnimationFrameCallbacks):
69 (WebCore::Document::windowScreenDidChange):
70 (WebCore::Document::updateIntersectionObservations):
71 (WebCore::Document::scheduleForcedIntersectionObservationUpdate): Deleted.
72 (WebCore::Document::animationScheduler): Deleted.
73 * dom/Document.h:
74 (WebCore::Document::numberOfIntersectionObservers const):
75 * dom/ScriptedAnimationController.cpp:
76 (WebCore::ScriptedAnimationController::serviceRequestAnimationFrameCallbacks):
77 (WebCore::ScriptedAnimationController::scheduleAnimation):
78 (WebCore::ScriptedAnimationController::animationTimerFired):
79 (WebCore::ScriptedAnimationController::serviceScriptedAnimations): Deleted.
80 (WebCore::ScriptedAnimationController::documentAnimationSchedulerDidFire): Deleted.
81 * dom/ScriptedAnimationController.h:
82 * page/FrameView.cpp:
83 (WebCore::FrameView::viewportContentsChanged):
84 * page/IntersectionObserver.cpp:
85 (WebCore::IntersectionObserver::observe):
86 * page/Page.cpp:
87 (WebCore::Page::Page):
88 (WebCore::Page::layoutIfNeeded):
89 (WebCore::Page::renderingUpdate):
90 (WebCore::Page::renderingUpdateScheduler):
91 (WebCore::Page::willDisplayPage): Deleted.
92 (WebCore::Page::addDocumentNeedingIntersectionObservationUpdate): Deleted.
93 (WebCore::Page::updateIntersectionObservations): Deleted.
94 (WebCore::Page::scheduleForcedIntersectionObservationUpdate): Deleted.
95 * page/Page.h:
96 * page/PageOverlayController.cpp:
97 (WebCore::PageOverlayController::didChangeViewExposedRect):
98 (WebCore::PageOverlayController::notifyFlushRequired):
99 * page/ResourceUsageData.h:
100 Include header files that become missing because of adding
101 RenderingUpdateScheduler.cpp.
102
103 * page/RenderingUpdateScheduler.cpp: Added.
104 (WebCore::RenderingUpdateScheduler::RenderingUpdateScheduler):
105 (WebCore::RenderingUpdateScheduler::scheduleRenderingUpdate):
106 (WebCore::RenderingUpdateScheduler::startTimer):
107 (WebCore::RenderingUpdateScheduler::clearTimer):
108 (WebCore::RenderingUpdateScheduler::windowScreenDidChange):
109 (WebCore::RenderingUpdateScheduler::createDisplayRefreshMonitor const):
110 (WebCore::RenderingUpdateScheduler::displayRefreshFired):
111 * page/RenderingUpdateScheduler.h: Added.
112 (WebCore::RenderingUpdateScheduler::create):
113 * page/ios/ContentChangeObserver.h:
114 Include header files that become missing because of adding
115 RenderingUpdateScheduler.cpp.
116
117 * page/mac/ServicesOverlayController.mm:
118 (WebCore::ServicesOverlayController::Highlight::notifyFlushRequired):
119 * rendering/RenderLayerCompositor.cpp:
120 (WebCore::RenderLayerCompositor::scheduleLayerFlushNow):
121