Changeset 245892 in webkit


Ignore:
Timestamp:
May 30, 2019, 10:02:19 AM (7 years ago)
Author:
Simon Fraser
Message:

Move some HistoricalVelocityData code into the cpp file
https://bugs.webkit.org/show_bug.cgi?id=198353

Reviewed by Tim Horton.

Now that we have VelocityData.cpp put the non-trivial HistoricalVelocityData::velocityForNewData()
into it. append() can become a lambda function.

  • platform/graphics/VelocityData.cpp:

(WebCore::HistoricalVelocityData::velocityForNewData):

  • platform/graphics/VelocityData.h:

(WebCore::HistoricalVelocityData::velocityForNewData): Deleted.
(WebCore::HistoricalVelocityData::append): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r245890 r245892  
     12019-05-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Move some HistoricalVelocityData code into the cpp file
     4        https://bugs.webkit.org/show_bug.cgi?id=198353
     5
     6        Reviewed by Tim Horton.
     7       
     8        Now that we have VelocityData.cpp put the non-trivial HistoricalVelocityData::velocityForNewData()
     9        into it. append() can become a lambda function.
     10
     11        * platform/graphics/VelocityData.cpp:
     12        (WebCore::HistoricalVelocityData::velocityForNewData):
     13        * platform/graphics/VelocityData.h:
     14        (WebCore::HistoricalVelocityData::velocityForNewData): Deleted.
     15        (WebCore::HistoricalVelocityData::append): Deleted.
     16
    1172019-05-30  Truitt Savell  <tsavell@apple.com>
    218
  • trunk/Source/WebCore/platform/graphics/VelocityData.cpp

    r245787 r245892  
    3131namespace WebCore {
    3232
     33VelocityData HistoricalVelocityData::velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime timestamp)
     34{
     35    auto append = [&](FloatPoint newPosition, double scale, MonotonicTime timestamp)
     36    {
     37        m_latestDataIndex = (m_latestDataIndex + 1) % maxHistoryDepth;
     38        m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
     39        m_historySize = std::min(m_historySize + 1, maxHistoryDepth);
     40        m_lastAppendTimestamp = timestamp;
     41    };
     42
     43    // Due to all the source of rect update, the input is very noisy. To smooth the output, we accumulate all changes
     44    // within 1 frame as a single update. No speed computation is ever done on data within the same frame.
     45    const Seconds filteringThreshold(1.0 / 60);
     46
     47    VelocityData velocityData;
     48    if (m_historySize > 0) {
     49        unsigned oldestDataIndex;
     50        unsigned distanceToLastHistoricalData = m_historySize - 1;
     51        if (distanceToLastHistoricalData <= m_latestDataIndex)
     52            oldestDataIndex = m_latestDataIndex - distanceToLastHistoricalData;
     53        else
     54            oldestDataIndex = m_historySize - (distanceToLastHistoricalData - m_latestDataIndex);
     55
     56        Seconds timeDelta = timestamp - m_positionHistory[oldestDataIndex].timestamp;
     57        if (timeDelta > filteringThreshold) {
     58            Data& oldestData = m_positionHistory[oldestDataIndex];
     59            velocityData = VelocityData((newPosition.x() - oldestData.position.x()) / timeDelta.seconds(), (newPosition.y() - oldestData.position.y()) / timeDelta.seconds(), (scale - oldestData.scale) / timeDelta.seconds(), timestamp);
     60        }
     61    }
     62
     63    Seconds timeSinceLastAppend = timestamp - m_lastAppendTimestamp;
     64    if (timeSinceLastAppend > filteringThreshold)
     65        append(newPosition, scale, timestamp);
     66    else
     67        m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
     68
     69    return velocityData;
     70}
     71
    3372TextStream& operator<<(TextStream& ts, const VelocityData& velocityData)
    3473{
  • trunk/Source/WebCore/platform/graphics/VelocityData.h

    r245787 r245892  
    6969    HistoricalVelocityData() = default;
    7070
    71     VelocityData velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime timestamp)
    72     {
    73         // Due to all the source of rect update, the input is very noisy. To smooth the output, we accumulate all changes
    74         // within 1 frame as a single update. No speed computation is ever done on data within the same frame.
    75         const Seconds filteringThreshold(1.0 / 60);
    76 
    77         VelocityData velocityData;
    78         if (m_historySize > 0) {
    79             unsigned oldestDataIndex;
    80             unsigned distanceToLastHistoricalData = m_historySize - 1;
    81             if (distanceToLastHistoricalData <= m_latestDataIndex)
    82                 oldestDataIndex = m_latestDataIndex - distanceToLastHistoricalData;
    83             else
    84                 oldestDataIndex = m_historySize - (distanceToLastHistoricalData - m_latestDataIndex);
    85 
    86             Seconds timeDelta = timestamp - m_positionHistory[oldestDataIndex].timestamp;
    87             if (timeDelta > filteringThreshold) {
    88                 Data& oldestData = m_positionHistory[oldestDataIndex];
    89                 velocityData = VelocityData((newPosition.x() - oldestData.position.x()) / timeDelta.seconds(), (newPosition.y() - oldestData.position.y()) / timeDelta.seconds(), (scale - oldestData.scale) / timeDelta.seconds(), timestamp);
    90             }
    91         }
    92 
    93         Seconds timeSinceLastAppend = timestamp - m_lastAppendTimestamp;
    94         if (timeSinceLastAppend > filteringThreshold)
    95             append(newPosition, scale, timestamp);
    96         else
    97             m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
    98 
    99         return velocityData;
    100     }
    101 
     71    WEBCORE_EXPORT VelocityData velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime);
    10272    void clear() { m_historySize = 0; }
    10373
    10474private:
    105     void append(FloatPoint newPosition, double scale, MonotonicTime timestamp)
    106     {
    107         m_latestDataIndex = (m_latestDataIndex + 1) % maxHistoryDepth;
    108         m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
    109         m_historySize = std::min(m_historySize + 1, maxHistoryDepth);
    110         m_lastAppendTimestamp = timestamp;
    111     }
    112 
    11375    static constexpr unsigned maxHistoryDepth = 3;
    11476
Note: See TracChangeset for help on using the changeset viewer.