12020-01-23 Said Abou-Hallawa <sabouhallawa@apple.com>
2
3 Throttling requestAnimationFrame should be controlled by RenderingUpdateScheduler
4 https://bugs.webkit.org/show_bug.cgi?id=204713
5
6 Reviewed by Simon Fraser.
7
8 Test: fast/animation/request-animation-frame-throttling-outside-viewport.html
9
10 requestAnimationFrame is throttled by a timer although its callback are
11 serviced by the page RenderingUpdate. This led to excessive rAF firing
12 which makes it more than the preferred frame per seconds.
13
14 The solution is to have two throttling types:
15
16 1) Page throttling (or full throttling) which slows down all the steps of
17 RenderingUpdate for the main document and all the sub-documents.
18 2) Document throttling (or partial throttling) which only slows down the
19 rAF of a certain document.
20
21 * Headers.cmake:
22 * WebCore.xcodeproj/project.pbxproj:
23
24 * animation/DocumentTimeline.cpp:
25 (WebCore::DocumentTimeline::animationInterval const):
26 (WebCore::DocumentTimeline::updateThrottlingState): Deleted.
27 * animation/DocumentTimeline.h:
28 There is no need to have DocumentTimeline throttling. It is throttled
29 when the page RenderingUpdate is throttled.
30
31 * dom/Document.cpp:
32 (WebCore::Document::requestAnimationFrame):
33 (WebCore::Document::updateLastHandledUserGestureTimestamp):
34 LowPowerMode throttling is now handled by the page. So remove its handling
35 in the Document side.
36
37 * dom/ScriptedAnimationController.cpp:
38 (WebCore::ScriptedAnimationController::ScriptedAnimationController):
39 (WebCore::ScriptedAnimationController::page const):
40 (WebCore::ScriptedAnimationController::interval const):
41 (WebCore::ScriptedAnimationController::isThrottled const):
42 (WebCore::ScriptedAnimationController::registerCallback):
43 (WebCore::ScriptedAnimationController::cancelCallback):
44 (WebCore::ScriptedAnimationController::serviceRequestAnimationFrameCallbacks):
45 (WebCore::ScriptedAnimationController::scheduleAnimation):
46 (WebCore::throttlingReasonToString): Deleted.
47 (WebCore::throttlingReasonsToString): Deleted.
48 (WebCore::ScriptedAnimationController::addThrottlingReason): Deleted.
49 (WebCore::ScriptedAnimationController::removeThrottlingReason): Deleted.
50 (WebCore::ScriptedAnimationController::animationTimerFired): Deleted.
51 * dom/ScriptedAnimationController.h:
52 (WebCore::ScriptedAnimationController::addThrottlingReason):
53 (WebCore::ScriptedAnimationController::removeThrottlingReason):
54 Get rid of the rAF throttling timer. Service the rAF callback only when
55 the period from the current time stamp till the last service time stamp
56 is greater than the preferred rAF interval .
57
58 * page/FrameView.cpp:
59 (WebCore::FrameView::updateScriptedAnimationsAndTimersThrottlingState):
60 ThrottlingReason is now defined outside ScriptedAnimationController.
61
62 * page/Page.cpp:
63 (WebCore::Page::suspendScriptedAnimations):
64 (WebCore::Page::resumeScriptedAnimations):
65 Use forEachDocument().
66
67 (WebCore::Page::preferredRenderingUpdateInterval const):
68 Calculate the preferred RenderingUpdate interval from the throttling
69 reasons.
70
71 (WebCore::Page::setIsVisuallyIdleInternal):
72 (WebCore::Page::handleLowModePowerChange):
73 Call adjustRenderingUpdateFrequency() when isLowPowerModeEnabled or
74 IsVisuallyIdle is toggled.
75
76 (WebCore::updateScriptedAnimationsThrottlingReason): Deleted.
77 * page/Page.h:
78 (WebCore::Page::isRenderingUpdateThrottled const):
79
80 * page/RenderingUpdateScheduler.cpp:
81 (WebCore::RenderingUpdateScheduler::adjustFramesPerSecond):
82 (WebCore::RenderingUpdateScheduler::adjustRenderingUpdateFrequency):
83 Change the preferredFramesPerSecond of the DisplayRefreshMonitor if the
84 throttling is not aggressive e.g. 10_s. Otherwise use the timer.
85
86 (WebCore::RenderingUpdateScheduler::scheduleTimedRenderingUpdate):
87 Call adjustFramesPerSecond() when DisplayRefreshMonitor is created.
88
89 (WebCore::RenderingUpdateScheduler::startTimer):
90 * page/RenderingUpdateScheduler.h:
91
92 * platform/graphics/AnimationFrameRate.h: Added.
93 (WebCore::preferredFrameInterval):
94 (WebCore::preferredFramesPerSecond):
95 * platform/graphics/DisplayRefreshMonitor.h:
96 (WebCore::DisplayRefreshMonitor::setPreferredFramesPerSecond):
97
98 * platform/graphics/DisplayRefreshMonitorManager.cpp:
99 (WebCore::DisplayRefreshMonitorManager::monitorForClient):
100 Rename createMonitorForClient() to monitorForClient() since it may return
101 a cached DisplayRefreshMonitor.
102
103 (WebCore::DisplayRefreshMonitorManager::setPreferredFramesPerSecond):
104 (WebCore::DisplayRefreshMonitorManager::scheduleAnimation):
105 (WebCore::DisplayRefreshMonitorManager::displayDidRefresh):
106 No need to call registerClient(). This function was just ensuring the
107 DisplayRefreshMonitor is created. scheduleAnimation() does the same thing.
108
109 (WebCore::DisplayRefreshMonitorManager::createMonitorForClient): Deleted.
110 (WebCore::DisplayRefreshMonitorManager::registerClient): Deleted.
111 * platform/graphics/DisplayRefreshMonitorManager.h:
112 (WebCore::DisplayRefreshMonitorManager::DisplayRefreshMonitorManager): Deleted.
113
114 * platform/graphics/GraphicsLayerUpdater.cpp:
115 (WebCore::GraphicsLayerUpdater::GraphicsLayerUpdater):
116 * platform/graphics/ios/DisplayRefreshMonitorIOS.mm:
117 (-[WebDisplayLinkHandler setPreferredFramesPerSecond:]):
118 Set the preferredFramesPerSecond of the CADisplayLink.
119