Title: [245892] trunk/Source/WebCore
Revision
245892
Author
[email protected]
Date
2019-05-30 10:02:19 -0700 (Thu, 30 May 2019)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (245891 => 245892)


--- trunk/Source/WebCore/ChangeLog	2019-05-30 16:58:54 UTC (rev 245891)
+++ trunk/Source/WebCore/ChangeLog	2019-05-30 17:02:19 UTC (rev 245892)
@@ -1,3 +1,19 @@
+2019-05-30  Simon Fraser  <[email protected]>
+
+        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.
+
 2019-05-30  Truitt Savell  <[email protected]>
 
         Fix the iOS build after r245887

Modified: trunk/Source/WebCore/platform/graphics/VelocityData.cpp (245891 => 245892)


--- trunk/Source/WebCore/platform/graphics/VelocityData.cpp	2019-05-30 16:58:54 UTC (rev 245891)
+++ trunk/Source/WebCore/platform/graphics/VelocityData.cpp	2019-05-30 17:02:19 UTC (rev 245892)
@@ -30,6 +30,45 @@
 
 namespace WebCore {
 
+VelocityData HistoricalVelocityData::velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime timestamp)
+{
+    auto append = [&](FloatPoint newPosition, double scale, MonotonicTime timestamp)
+    {
+        m_latestDataIndex = (m_latestDataIndex + 1) % maxHistoryDepth;
+        m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
+        m_historySize = std::min(m_historySize + 1, maxHistoryDepth);
+        m_lastAppendTimestamp = timestamp;
+    };
+
+    // Due to all the source of rect update, the input is very noisy. To smooth the output, we accumulate all changes
+    // within 1 frame as a single update. No speed computation is ever done on data within the same frame.
+    const Seconds filteringThreshold(1.0 / 60);
+
+    VelocityData velocityData;
+    if (m_historySize > 0) {
+        unsigned oldestDataIndex;
+        unsigned distanceToLastHistoricalData = m_historySize - 1;
+        if (distanceToLastHistoricalData <= m_latestDataIndex)
+            oldestDataIndex = m_latestDataIndex - distanceToLastHistoricalData;
+        else
+            oldestDataIndex = m_historySize - (distanceToLastHistoricalData - m_latestDataIndex);
+
+        Seconds timeDelta = timestamp - m_positionHistory[oldestDataIndex].timestamp;
+        if (timeDelta > filteringThreshold) {
+            Data& oldestData = m_positionHistory[oldestDataIndex];
+            velocityData = VelocityData((newPosition.x() - oldestData.position.x()) / timeDelta.seconds(), (newPosition.y() - oldestData.position.y()) / timeDelta.seconds(), (scale - oldestData.scale) / timeDelta.seconds(), timestamp);
+        }
+    }
+
+    Seconds timeSinceLastAppend = timestamp - m_lastAppendTimestamp;
+    if (timeSinceLastAppend > filteringThreshold)
+        append(newPosition, scale, timestamp);
+    else
+        m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
+
+    return velocityData;
+}
+
 TextStream& operator<<(TextStream& ts, const VelocityData& velocityData)
 {
     ts.dumpProperty("timestamp", velocityData.lastUpdateTime.secondsSinceEpoch().value());

Modified: trunk/Source/WebCore/platform/graphics/VelocityData.h (245891 => 245892)


--- trunk/Source/WebCore/platform/graphics/VelocityData.h	2019-05-30 16:58:54 UTC (rev 245891)
+++ trunk/Source/WebCore/platform/graphics/VelocityData.h	2019-05-30 17:02:19 UTC (rev 245892)
@@ -68,48 +68,10 @@
 public:
     HistoricalVelocityData() = default;
 
-    VelocityData velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime timestamp)
-    {
-        // Due to all the source of rect update, the input is very noisy. To smooth the output, we accumulate all changes
-        // within 1 frame as a single update. No speed computation is ever done on data within the same frame.
-        const Seconds filteringThreshold(1.0 / 60);
-
-        VelocityData velocityData;
-        if (m_historySize > 0) {
-            unsigned oldestDataIndex;
-            unsigned distanceToLastHistoricalData = m_historySize - 1;
-            if (distanceToLastHistoricalData <= m_latestDataIndex)
-                oldestDataIndex = m_latestDataIndex - distanceToLastHistoricalData;
-            else
-                oldestDataIndex = m_historySize - (distanceToLastHistoricalData - m_latestDataIndex);
-
-            Seconds timeDelta = timestamp - m_positionHistory[oldestDataIndex].timestamp;
-            if (timeDelta > filteringThreshold) {
-                Data& oldestData = m_positionHistory[oldestDataIndex];
-                velocityData = VelocityData((newPosition.x() - oldestData.position.x()) / timeDelta.seconds(), (newPosition.y() - oldestData.position.y()) / timeDelta.seconds(), (scale - oldestData.scale) / timeDelta.seconds(), timestamp);
-            }
-        }
-
-        Seconds timeSinceLastAppend = timestamp - m_lastAppendTimestamp;
-        if (timeSinceLastAppend > filteringThreshold)
-            append(newPosition, scale, timestamp);
-        else
-            m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
-
-        return velocityData;
-    }
-
+    WEBCORE_EXPORT VelocityData velocityForNewData(FloatPoint newPosition, double scale, MonotonicTime);
     void clear() { m_historySize = 0; }
 
 private:
-    void append(FloatPoint newPosition, double scale, MonotonicTime timestamp)
-    {
-        m_latestDataIndex = (m_latestDataIndex + 1) % maxHistoryDepth;
-        m_positionHistory[m_latestDataIndex] = { timestamp, newPosition, scale };
-        m_historySize = std::min(m_historySize + 1, maxHistoryDepth);
-        m_lastAppendTimestamp = timestamp;
-    }
-
     static constexpr unsigned maxHistoryDepth = 3;
 
     unsigned m_historySize { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to