Changeset 208982 in webkit


Ignore:
Timestamp:
Nov 26, 2016, 6:27:55 PM (9 years ago)
Author:
Simon Fraser
Message:

Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
https://bugs.webkit.org/show_bug.cgi?id=164992

Reviewed by Darin Adler.
Source/WebCore:

std::chrono::milliseconds -> Seconds.

Rename Document::elapsedTime() to timeSinceDocumentCreation() which is more explicit.

Replace INSTRUMENT_LAYOUT_SCHEDULING with LOG(Layout...).

  • dom/Document.cpp:

(WebCore::Document::Document):
(WebCore::Document::implicitClose):
(WebCore::Document::isLayoutTimerActive):
(WebCore::Document::minimumLayoutDelay):
(WebCore::Document::timeSinceDocumentCreation):
(WebCore::Document::elapsedTime): Deleted.

  • dom/Document.h:
  • page/ChromeClient.h:
  • page/FrameView.cpp:

(WebCore::FrameView::layout):
(WebCore::FrameView::scrollPositionChanged):
(WebCore::FrameView::layoutTimerFired):
(WebCore::FrameView::scheduleRelayout):
(WebCore::FrameView::scheduleRelayoutOfSubtree):
(WebCore::FrameView::unscheduleRelayout):

  • page/Settings.cpp:

(WebCore::Settings::setLayoutInterval):

  • page/Settings.h:

(WebCore::Settings::layoutInterval):

  • style/StyleScope.cpp:

(WebCore::Style::Scope::removePendingSheet):

  • workers/WorkerRunLoop.cpp:

(WebCore::WorkerRunLoop::runInMode):

Source/WebKit2:

No more ugly conversion from seconds to milliseconds.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::updatePreferences):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::eventThrottlingDelay):

Source/WTF:

Add Seconds::zero() as a nicer way to express Seconds(0).

  • wtf/Seconds.h:

(WTF::Seconds::zero):

Tools:

Use Seconds::zero().

  • TestWebKitAPI/Tests/WTF/Condition.cpp:
Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/AtomicsObject.cpp

    r208415 r208982  
    316316    // so NaN is the only special case.
    317317    if (timeout == timeout)
    318         timeout = std::max(Seconds(0), timeout);
     318        timeout = std::max(0_s, timeout);
    319319    else
    320320        timeout = Seconds::infinity();
  • trunk/Source/WTF/ChangeLog

    r208979 r208982  
     12016-11-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
     4        https://bugs.webkit.org/show_bug.cgi?id=164992
     5
     6        Reviewed by Darin Adler.
     7
     8        Add Seconds::zero() as a nicer way to express Seconds(0).
     9
     10        * wtf/Seconds.h:
     11        (WTF::Seconds::zero):
     12
    1132016-11-26  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/WTF/wtf/AutomaticThread.cpp

    r208415 r208982  
    182182                        // Shut the thread down after one second.
    183183                        bool awokenByNotify =
    184                             m_condition->m_condition.waitFor(*m_lock, Seconds(1));
     184                            m_condition->m_condition.waitFor(*m_lock, 1_s);
    185185                        if (!awokenByNotify) {
    186186                            if (verbose)
  • trunk/Source/WTF/wtf/Seconds.h

    r208979 r208982  
    202202};
    203203
     204inline namespace seconds_literals {
     205
    204206constexpr Seconds operator"" _min(long double minutes)
    205207{
     
    252254}
    253255
     256} // inline seconds_literals
     257
    254258WTF_EXPORT_PRIVATE void sleep(Seconds);
    255259
    256 } // namespae WTF
    257 
     260} // namespace WTF
     261
     262using namespace WTF::seconds_literals;
    258263using WTF::Seconds;
    259264
  • trunk/Source/WebCore/ChangeLog

    r208981 r208982  
     12016-11-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
     4        https://bugs.webkit.org/show_bug.cgi?id=164992
     5
     6        Reviewed by Darin Adler.
     7
     8        std::chrono::milliseconds -> Seconds.
     9       
     10        Rename Document::elapsedTime() to timeSinceDocumentCreation() which is more explicit.
     11       
     12        Replace INSTRUMENT_LAYOUT_SCHEDULING with LOG(Layout...).
     13
     14        * dom/Document.cpp:
     15        (WebCore::Document::Document):
     16        (WebCore::Document::implicitClose):
     17        (WebCore::Document::isLayoutTimerActive):
     18        (WebCore::Document::minimumLayoutDelay):
     19        (WebCore::Document::timeSinceDocumentCreation):
     20        (WebCore::Document::elapsedTime): Deleted.
     21        * dom/Document.h:
     22        * page/ChromeClient.h:
     23        * page/FrameView.cpp:
     24        (WebCore::FrameView::layout):
     25        (WebCore::FrameView::scrollPositionChanged):
     26        (WebCore::FrameView::layoutTimerFired):
     27        (WebCore::FrameView::scheduleRelayout):
     28        (WebCore::FrameView::scheduleRelayoutOfSubtree):
     29        (WebCore::FrameView::unscheduleRelayout):
     30        * page/Settings.cpp:
     31        (WebCore::Settings::setLayoutInterval):
     32        * page/Settings.h:
     33        (WebCore::Settings::layoutInterval):
     34        * style/StyleScope.cpp:
     35        (WebCore::Style::Scope::removePendingSheet):
     36        * workers/WorkerRunLoop.cpp:
     37        (WebCore::WorkerRunLoop::runInMode):
     38
    1392016-11-26  Simon Fraser  <simon.fraser@apple.com>
    240
  • trunk/Source/WebCore/dom/Document.cpp

    r208903 r208982  
    469469    , m_processingLoadEvent(false)
    470470    , m_loadEventFinished(false)
    471     , m_startTime(std::chrono::steady_clock::now())
     471    , m_documentCreationTime(MonotonicTime::now())
    472472    , m_overMinimumLayoutThreshold(false)
    473473    , m_scriptRunner(std::make_unique<ScriptRunner>(*this))
     
    26972697    // If they wanna cheat, we can too. -dwh
    26982698
    2699     if (frame()->navigationScheduler().locationChangePending() && elapsedTime() < settings()->layoutInterval()) {
     2699    if (frame()->navigationScheduler().locationChangePending() && timeSinceDocumentCreation() < settings()->layoutInterval()) {
    27002700        // Just bail out. Before or during the onload we were shifted to another page.
    27012701        // The old i-Bench suite does this. When this happens don't bother painting or laying out.       
     
    27712771bool Document::isLayoutTimerActive()
    27722772{
    2773     return view() && view()->layoutPending() && !minimumLayoutDelay().count();
    2774 }
    2775 
    2776 std::chrono::milliseconds Document::minimumLayoutDelay()
     2773    return view() && view()->layoutPending() && !minimumLayoutDelay();
     2774}
     2775
     2776Seconds Document::minimumLayoutDelay()
    27772777{
    27782778    if (m_overMinimumLayoutThreshold)
    2779         return 0ms;
     2779        return 0_s;
    27802780   
    2781     auto elapsed = elapsedTime();
     2781    auto elapsed = timeSinceDocumentCreation();
    27822782    m_overMinimumLayoutThreshold = elapsed > settings()->layoutInterval();
    27832783
    27842784    // We'll want to schedule the timer to fire at the minimum layout threshold.
    2785     return std::max(0ms, settings()->layoutInterval() - elapsed);
    2786 }
    2787 
    2788 std::chrono::milliseconds Document::elapsedTime() const
    2789 {
    2790     auto elapsedTime = std::chrono::steady_clock::now() - m_startTime;
    2791 
    2792     return std::chrono::duration_cast<std::chrono::milliseconds>(elapsedTime);
     2785    return std::max(0_s, settings()->layoutInterval() - elapsed);
     2786}
     2787
     2788Seconds Document::timeSinceDocumentCreation() const
     2789{
     2790    return MonotonicTime::now() - m_documentCreationTime;
    27932791}
    27942792
  • trunk/Source/WebCore/dom/Document.h

    r208828 r208982  
    672672    void setParsing(bool);
    673673    bool parsing() const { return m_bParsing; }
    674     std::chrono::milliseconds minimumLayoutDelay();
     674    Seconds minimumLayoutDelay();
    675675
    676676    bool shouldScheduleLayout();
    677677    bool isLayoutTimerActive();
    678     std::chrono::milliseconds elapsedTime() const;
     678    Seconds timeSinceDocumentCreation() const;
    679679   
    680680    void setTextColor(const Color& color) { m_textColor = color; }
     
    15281528
    15291529    RefPtr<SerializedScriptValue> m_pendingStateObject;
    1530     std::chrono::steady_clock::time_point m_startTime;
     1530    MonotonicTime m_documentCreationTime;
    15311531    bool m_overMinimumLayoutThreshold;
    15321532   
  • trunk/Source/WebCore/page/ChromeClient.h

    r208916 r208982  
    234234#endif
    235235
    236     virtual Seconds eventThrottlingDelay() { return Seconds(0); };
     236    virtual Seconds eventThrottlingDelay() { return 0_s; };
    237237
    238238#if PLATFORM(IOS)
  • trunk/Source/WebCore/page/FrameView.cpp

    r208927 r208982  
    13991399            }
    14001400
    1401 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
     1401#if !LOG_DISABLED
    14021402            if (m_firstLayout && !frame().ownerElement())
    1403                 printf("Elapsed time before first layout: %lld\n", document.elapsedTime().count());
     1403                LOG(Layout, "FrameView %p elapsed time before first layout: %.3fs\n", this, document.timeSinceDocumentCreation().value());
    14041404#endif
    14051405        }
     
    24382438{
    24392439    Page* page = frame().page();
    2440     Seconds throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : Seconds(0);
    2441 
    2442     if (throttlingDelay == Seconds(0)) {
     2440    Seconds throttlingDelay = page ? page->chrome().client().eventThrottlingDelay() : 0_s;
     2441
     2442    if (throttlingDelay == 0_s) {
    24432443        m_delayedScrollEventTimer.stop();
    24442444        sendScrollEvent();
     
    28752875void FrameView::layoutTimerFired()
    28762876{
    2877 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
     2877#if !LOG_DISABLED
    28782878    if (!frame().document()->ownerElement())
    2879         printf("Layout timer fired at %lld\n", frame().document()->elapsedTime().count());
     2879        LOG(Layout, "FrameView %p layout timer fired at %.3fs", this, frame().document()->timeSinceDocumentCreation().value());
    28802880#endif
    28812881    layout();
     
    29022902        frame().ownerRenderer()->setNeedsLayout(MarkContainingBlockChain);
    29032903
    2904     std::chrono::milliseconds delay = frame().document()->minimumLayoutDelay();
    2905     if (m_layoutTimer.isActive() && m_delayedLayout && !delay.count())
     2904    Seconds delay = frame().document()->minimumLayoutDelay();
     2905    if (m_layoutTimer.isActive() && m_delayedLayout && !delay)
    29062906        unscheduleRelayout();
     2907
    29072908    if (m_layoutTimer.isActive())
    29082909        return;
    29092910
    2910     m_delayedLayout = delay.count();
    2911 
    2912 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
     2911    m_delayedLayout = delay.value();
     2912
     2913#if !LOG_DISABLED
    29132914    if (!frame().document()->ownerElement())
    2914         printf("Scheduling layout for %d\n", delay);
     2915        LOG(Layout, "FrameView %p scheduling layout for %.3fs", this, delay.value());
    29152916#endif
    29162917
     
    29452946
    29462947    if (!layoutPending() && m_layoutSchedulingEnabled) {
    2947         std::chrono::milliseconds delay = renderView.document().minimumLayoutDelay();
     2948        Seconds delay = renderView.document().minimumLayoutDelay();
    29482949        ASSERT(!newRelayoutRoot.container() || is<RenderView>(newRelayoutRoot.container()) || !newRelayoutRoot.container()->needsLayout());
    29492950        m_layoutRoot = &newRelayoutRoot;
    29502951        InspectorInstrumentation::didInvalidateLayout(frame());
    2951         m_delayedLayout = delay.count();
     2952        m_delayedLayout = delay.value();
    29522953        m_layoutTimer.startOneShot(delay);
    29532954        return;
     
    30423043        return;
    30433044
    3044 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
     3045#if !LOG_DISABLED
    30453046    if (!frame().document()->ownerElement())
    3046         printf("Layout timer unscheduled at %d\n", frame().document()->elapsedTime());
     3047        LOG(Layout, "FrameView %p layout timer unscheduled at %.3fs", this, frame().document()->timeSinceDocumentCreation().value());
    30473048#endif
    30483049   
  • trunk/Source/WebCore/page/Settings.cpp

    r208249 r208982  
    185185// FIXME: For faster machines this value can really be lowered to 200. 250 is adequate, but a little high
    186186// for dual G5s. :)
    187 static const auto layoutScheduleThreshold = 250ms;
     187static const Seconds layoutScheduleThreshold = 250_ms;
    188188
    189189Settings::Settings(Page* page)
     
    462462}
    463463
    464 void Settings::setLayoutInterval(std::chrono::milliseconds layoutInterval)
     464void Settings::setLayoutInterval(Seconds layoutInterval)
    465465{
    466466    // FIXME: It seems weird that this function may disregard the specified layout interval.
  • trunk/Source/WebCore/page/Settings.h

    r208899 r208982  
    173173    std::chrono::milliseconds minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
    174174
    175     WEBCORE_EXPORT void setLayoutInterval(std::chrono::milliseconds);
    176     std::chrono::milliseconds layoutInterval() const { return m_layoutInterval; }
     175    WEBCORE_EXPORT void setLayoutInterval(Seconds);
     176    Seconds layoutInterval() const { return m_layoutInterval; }
    177177
    178178    bool hiddenPageDOMTimerThrottlingEnabled() const { return m_hiddenPageDOMTimerThrottlingEnabled; }
     
    326326    const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies;
    327327    SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy;
    328     std::chrono::milliseconds m_layoutInterval;
     328    Seconds m_layoutInterval;
    329329    std::chrono::milliseconds m_minimumDOMTimerInterval;
    330330
  • trunk/Source/WebCore/style/StyleScope.cpp

    r208967 r208982  
    150150
    151151    m_pendingStyleSheetCount--;
    152    
    153 #ifdef INSTRUMENT_LAYOUT_SCHEDULING
    154     if (!ownerElement())
    155         printf("Stylesheet loaded at time %d. %d stylesheets still remain.\n", elapsedTime(), m_pendingStylesheets);
    156 #endif
    157 
    158152    if (m_pendingStyleSheetCount)
    159153        return;
  • trunk/Source/WebCore/workers/WorkerRunLoop.cpp

    r208725 r208982  
    164164    CFAbsoluteTime nextCFRunLoopTimerFireDate = CFRunLoopGetNextTimerFireDate(CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    165165    double timeUntilNextCFRunLoopTimerInSeconds = nextCFRunLoopTimerFireDate - CFAbsoluteTimeGetCurrent();
    166     deadline = WallTime::now() + std::max(
    167         Seconds(0), Seconds(timeUntilNextCFRunLoopTimerInSeconds));
     166    deadline = WallTime::now() + std::max(0_s, Seconds(timeUntilNextCFRunLoopTimerInSeconds));
    168167#endif
    169168
  • trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h

    r208903 r208982  
    340340- (void)_setAlwaysUseAcceleratedOverflowScroll:(BOOL)flag;
    341341- (BOOL)_alwaysUseAcceleratedOverflowScroll;
    342 - (void)_setLayoutInterval:(int)l;
    343 - (int)_layoutInterval;
     342- (void)_setLayoutInterval:(int)milliseconds;
     343- (int)_layoutInterval; // Milliseonds.
    344344- (void)_setMaxParseDuration:(float)d;
    345345- (float)_maxParseDuration;
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r208949 r208982  
    27372737    settings.setTelephoneNumberParsingEnabled([preferences _telephoneNumberParsingEnabled]);
    27382738    settings.setAllowMultiElementImplicitSubmission([preferences _allowMultiElementImplicitFormSubmission]);
    2739     settings.setLayoutInterval(std::chrono::milliseconds([preferences _layoutInterval]));
     2739    settings.setLayoutInterval(Seconds::fromMilliseconds([preferences _layoutInterval]));
    27402740    settings.setMaxParseDuration([preferences _maxParseDuration]);
    27412741    settings.setAlwaysUseAcceleratedOverflowScroll([preferences _alwaysUseAcceleratedOverflowScroll]);
  • trunk/Source/WebKit2/ChangeLog

    r208977 r208982  
     12016-11-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
     4        https://bugs.webkit.org/show_bug.cgi?id=164992
     5
     6        Reviewed by Darin Adler.
     7       
     8        No more ugly conversion from seconds to milliseconds.
     9
     10        * WebProcess/WebPage/WebPage.cpp:
     11        (WebKit::WebPage::updatePreferences):
     12        * WebProcess/WebPage/ios/WebPageIOS.mm:
     13        (WebKit::WebPage::eventThrottlingDelay):
     14
    1152016-11-25  Michael Catanzaro  <mcatanzaro@igalia.com>
    216
  • trunk/Source/WebKit2/UIProcess/ChildProcessProxy.h

    r208415 r208982  
    4545
    4646    template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<IPC::SendOption> sendOptions = { });
    47     template<typename T> bool sendSync(T&& message, typename T::Reply&&, uint64_t destinationID, Seconds timeout = Seconds(1), OptionSet<IPC::SendSyncOption> sendSyncOptions = { });
     47    template<typename T> bool sendSync(T&& message, typename T::Reply&&, uint64_t destinationID, Seconds timeout = 1_s, OptionSet<IPC::SendSyncOption> sendSyncOptions = { });
    4848
    4949    IPC::Connection* connection() const
  • trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp

    r208959 r208982  
    367367
    368368    bool handled = false;
    369     sendSync(Messages::NetworkProcess::ProcessWillSuspendImminently(), Messages::NetworkProcess::ProcessWillSuspendImminently::Reply(handled), 0, Seconds(1));
     369    sendSync(Messages::NetworkProcess::ProcessWillSuspendImminently(), Messages::NetworkProcess::ProcessWillSuspendImminently::Reply(handled), 0, 1_s);
    370370}
    371371   
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp

    r208941 r208982  
    901901
    902902    bool handled = false;
    903     sendSync(Messages::WebProcess::ProcessWillSuspendImminently(), Messages::WebProcess::ProcessWillSuspendImminently::Reply(handled), 0, Seconds(1));
     903    sendSync(Messages::WebProcess::ProcessWillSuspendImminently(), Messages::WebProcess::ProcessWillSuspendImminently::Reply(handled), 0, 1_s);
    904904}
    905905
  • trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

    r208748 r208982  
    314314        FloatPoint newScrollPosition;
    315315        uint64_t nextValidLayerTreeTransactionID;
    316         if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, Seconds(2))) {
     316        if (m_process->sendSync(Messages::WebPage::SynchronizeDynamicViewportUpdate(), Messages::WebPage::SynchronizeDynamicViewportUpdate::Reply(newScale, newScrollPosition, nextValidLayerTreeTransactionID), m_pageID, 2_s)) {
    317317            m_dynamicViewportSizeUpdateWaitingForTarget = false;
    318318            m_dynamicViewportSizeUpdateLayerTreeTransactionID = nextValidLayerTreeTransactionID;
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r208939 r208982  
    31133113    settings.setPasswordEchoDurationInSeconds(store.getDoubleValueForKey(WebPreferencesKey::passwordEchoDurationKey()));
    31143114   
    3115     settings.setLayoutInterval(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(store.getDoubleValueForKey(WebPreferencesKey::layoutIntervalKey()))));
     3115    settings.setLayoutInterval(Seconds(store.getDoubleValueForKey(WebPreferencesKey::layoutIntervalKey())));
    31163116    settings.setMaxParseDuration(store.getDoubleValueForKey(WebPreferencesKey::maxParseDurationKey()));
    31173117
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r208927 r208982  
    21292129        switch (behaviorOverride.value()) {
    21302130        case EventThrottlingBehavior::Responsive:
    2131             return Seconds(0);
     2131            return 0_s;
    21322132        case EventThrottlingBehavior::Unresponsive:
    2133             return Seconds(1);
     2133            return 1_s;
    21342134        }
    21352135    }
    21362136
    21372137    if (m_isInStableState || m_estimatedLatency <= Seconds(1.0 / 60))
    2138         return Seconds(0);
    2139 
    2140     return Seconds(std::min<double>(m_estimatedLatency.value() * 2, 1));
     2138        return 0_s;
     2139
     2140    return std::min(m_estimatedLatency.value() * 2, 1_s);
    21412141}
    21422142
  • trunk/Tools/ChangeLog

    r208979 r208982  
     12016-11-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Migrate some layout timer-related code from std::chrono to Seconds and MonotonicTime
     4        https://bugs.webkit.org/show_bug.cgi?id=164992
     5
     6        Reviewed by Darin Adler.
     7       
     8        Use Seconds::zero().
     9
     10        * TestWebKitAPI/Tests/WTF/Condition.cpp:
     11
    1122016-11-26  Simon Fraser  <simon.fraser@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/Condition.cpp

    r208415 r208982  
    8282    NotifyStyle notifyStyle,
    8383    Seconds timeout = Seconds::infinity(),
    84     Seconds delay = Seconds(0))
     84    Seconds delay = 0_s)
    8585{
    8686    Deque<unsigned> queue;
Note: See TracChangeset for help on using the changeset viewer.