DrawingAreaMac.cpp [plain text]
#include "config.h"
#include "DrawingArea.h"
#include "WebProcess.h"
#include "WebProcessProxy.h"
#include "WebProcessProxyMessages.h"
#include <WebCore/DisplayRefreshMonitor.h>
#include <WebCore/RunLoopObserver.h>
namespace WebKit {
using namespace WebCore;
#if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
class DisplayRefreshMonitorMac : public DisplayRefreshMonitor {
public:
static Ref<DisplayRefreshMonitorMac> create(PlatformDisplayID displayID)
{
return adoptRef(*new DisplayRefreshMonitorMac(displayID));
}
virtual ~DisplayRefreshMonitorMac();
void displayLinkFired() override;
bool requestRefreshCallback() override;
private:
explicit DisplayRefreshMonitorMac(PlatformDisplayID);
bool hasRequestedRefreshCallback() const override { return m_hasSentMessage; }
DisplayLinkObserverID m_observerID;
std::unique_ptr<RunLoopObserver> m_runLoopObserver;
bool m_hasSentMessage { false };
bool m_firstCallbackInCurrentRunloop { false };
};
DisplayRefreshMonitorMac::DisplayRefreshMonitorMac(PlatformDisplayID displayID)
: DisplayRefreshMonitor(displayID)
, m_observerID(DisplayLinkObserverID::generate())
{
}
DisplayRefreshMonitorMac::~DisplayRefreshMonitorMac()
{
WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::StopDisplayLink(m_observerID, displayID()), 0);
}
bool DisplayRefreshMonitorMac::requestRefreshCallback()
{
if (!isActive())
return false;
if (!m_hasSentMessage) {
WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::StartDisplayLink(m_observerID, displayID()), 0);
m_hasSentMessage = true;
m_runLoopObserver = makeUnique<RunLoopObserver>(kCFRunLoopEntry, [this]() {
this->m_firstCallbackInCurrentRunloop = true;
});
m_runLoopObserver->schedule(CFRunLoopGetCurrent());
}
setIsScheduled(true);
return true;
}
void DisplayRefreshMonitorMac::displayLinkFired()
{
ASSERT(isMainThread());
if (!m_firstCallbackInCurrentRunloop)
return;
m_firstCallbackInCurrentRunloop = false;
handleDisplayRefreshedNotificationOnMainThread(this);
}
RefPtr<WebCore::DisplayRefreshMonitor> DrawingArea::createDisplayRefreshMonitor(PlatformDisplayID displayID)
{
return DisplayRefreshMonitorMac::create(displayID);
}
#endif // ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
}