[GTK] Use the DisplayRefreshMonitor facilities
[WebKit-https.git] / Source / WebKit2 / Shared / CoordinatedGraphics / threadedcompositor / CompositingRunLoop.cpp
index 5617bba..8acf506 100644 (file)
@@ -112,6 +112,8 @@ CompositingRunLoop::CompositingRunLoop(std::function<void ()>&& updateFunction)
     : m_updateTimer(WorkQueuePool::singleton().runLoop(this), this, &CompositingRunLoop::updateTimerFired)
     , m_updateFunction(WTFMove(updateFunction))
 {
+    m_updateState.store(UpdateState::Completed);
+
 #if USE(GLIB_EVENT_LOOP)
     m_updateTimer.setPriority(RunLoopSourcePriority::CompositingThreadUpdateTimer);
 #endif
@@ -144,28 +146,44 @@ void CompositingRunLoop::performTaskSync(Function<void ()>&& function)
     m_dispatchSyncCondition.wait(m_dispatchSyncConditionMutex);
 }
 
-void CompositingRunLoop::startUpdateTimer(UpdateTiming timing)
+bool CompositingRunLoop::isActive()
 {
-    if (m_updateTimer.isActive())
-        return;
+    return m_updateState.load() != UpdateState::Completed;
+}
 
-    const static double targetFPS = 60;
-    double nextUpdateTime = 0;
-    if (timing == WaitUntilNextFrame)
-        nextUpdateTime = std::max((1 / targetFPS) - (monotonicallyIncreasingTime() - m_lastUpdateTime), 0.0);
+void CompositingRunLoop::scheduleUpdate()
+{
+    if (m_updateState.compareExchangeStrong(UpdateState::Completed, UpdateState::InProgress) == UpdateState::Completed) {
+        m_updateTimer.startOneShot(0);
+        return;
+    }
 
-    m_updateTimer.startOneShot(1_s * nextUpdateTime);
+    if (m_updateState.compareExchangeStrong(UpdateState::InProgress, UpdateState::PendingAfterCompletion) == UpdateState::InProgress)
+        return;
 }
 
-void CompositingRunLoop::stopUpdateTimer()
+void CompositingRunLoop::stopUpdates()
 {
     m_updateTimer.stop();
+    m_updateState.store(UpdateState::Completed);
+}
+
+void CompositingRunLoop::updateCompleted()
+{
+    if (m_updateState.compareExchangeStrong(UpdateState::InProgress, UpdateState::Completed) == UpdateState::InProgress)
+        return;
+
+    if (m_updateState.compareExchangeStrong(UpdateState::PendingAfterCompletion, UpdateState::InProgress) == UpdateState::PendingAfterCompletion) {
+        m_updateTimer.startOneShot(0);
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
 }
 
 void CompositingRunLoop::updateTimerFired()
 {
     m_updateFunction();
-    m_lastUpdateTime = monotonicallyIncreasingTime();
 }
 
 } // namespace WebKit