ThreadedDisplayRefreshMonitor.cpp [plain text]
#include "config.h"
#include "ThreadedDisplayRefreshMonitor.h"
#if USE(COORDINATED_GRAPHICS_THREADED) && USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
#include "CompositingRunLoop.h"
#include "ThreadedCompositor.h"
#if USE(GLIB_EVENT_LOOP)
#include <wtf/glib/RunLoopSourcePriority.h>
#endif
namespace WebKit {
ThreadedDisplayRefreshMonitor::ThreadedDisplayRefreshMonitor(WebCore::PlatformDisplayID displayID, Client& client)
: WebCore::DisplayRefreshMonitor(displayID)
, m_displayRefreshTimer(RunLoop::main(), this, &ThreadedDisplayRefreshMonitor::displayRefreshCallback)
, m_client(&client)
{
#if USE(GLIB_EVENT_LOOP)
m_displayRefreshTimer.setPriority(RunLoopSourcePriority::DisplayRefreshMonitorTimer);
m_displayRefreshTimer.setName("[WebKit] ThreadedDisplayRefreshMonitor");
#endif
}
bool ThreadedDisplayRefreshMonitor::requestRefreshCallback()
{
if (!m_client)
return false;
bool previousFrameDone { false };
{
LockHolder locker(mutex());
setIsScheduled(true);
previousFrameDone = isPreviousFrameDone();
}
if (previousFrameDone)
m_client->requestDisplayRefreshMonitorUpdate();
return true;
}
bool ThreadedDisplayRefreshMonitor::requiresDisplayRefreshCallback()
{
LockHolder locker(mutex());
return isScheduled() && isPreviousFrameDone();
}
void ThreadedDisplayRefreshMonitor::dispatchDisplayRefreshCallback()
{
if (!m_client)
return;
m_displayRefreshTimer.startOneShot(0_s);
}
void ThreadedDisplayRefreshMonitor::invalidate()
{
m_displayRefreshTimer.stop();
m_client = nullptr;
}
void ThreadedDisplayRefreshMonitor::displayRefreshCallback()
{
bool shouldHandleDisplayRefreshNotification { false };
{
LockHolder locker(mutex());
shouldHandleDisplayRefreshNotification = isScheduled() && isPreviousFrameDone();
if (shouldHandleDisplayRefreshNotification)
setIsPreviousFrameDone(false);
}
if (shouldHandleDisplayRefreshNotification)
DisplayRefreshMonitor::handleDisplayRefreshedNotificationOnMainThread(this);
bool hasBeenRescheduled { false };
{
LockHolder locker(mutex());
hasBeenRescheduled = isScheduled();
}
if (m_client)
m_client->handleDisplayRefreshMonitorUpdate(hasBeenRescheduled);
}
}
#endif // USE(COORDINATED_GRAPHICS_THREADED) && USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)