DocumentAnimationScheduler.cpp [plain text]
#include "config.h"
#include "DocumentAnimationScheduler.h"
#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
#include "Chrome.h"
#include "ChromeClient.h"
#include "DOMWindow.h"
#include "DisplayRefreshMonitor.h"
#include "DisplayRefreshMonitorManager.h"
#include "Document.h"
#include "DocumentTimeline.h"
#include "Page.h"
#include "ScriptedAnimationController.h"
namespace WebCore {
Ref<DocumentAnimationScheduler> DocumentAnimationScheduler::create(Document& document, PlatformDisplayID displayID)
{
return adoptRef(*new DocumentAnimationScheduler(document, displayID));
}
DocumentAnimationScheduler::DocumentAnimationScheduler(Document& document, PlatformDisplayID displayID)
: m_document(&document)
{
windowScreenDidChange(displayID);
}
DocumentAnimationScheduler::~DocumentAnimationScheduler() = default;
void DocumentAnimationScheduler::detachFromDocument()
{
m_document = nullptr;
}
bool DocumentAnimationScheduler::scheduleWebAnimationsResolution()
{
m_scheduledWebAnimationsResolution = true;
return DisplayRefreshMonitorManager::sharedManager().scheduleAnimation(*this);
}
bool DocumentAnimationScheduler::scheduleScriptedAnimationResolution()
{
m_scheduledScriptedAnimationResolution = true;
return DisplayRefreshMonitorManager::sharedManager().scheduleAnimation(*this);
}
void DocumentAnimationScheduler::displayRefreshFired()
{
if (!m_document || !m_document->domWindow())
return;
auto protectedThis = makeRef(*this);
m_isFiring = true;
m_lastTimestamp = Seconds(m_document->domWindow()->nowTimestamp());
if (m_scheduledWebAnimationsResolution) {
m_scheduledWebAnimationsResolution = false;
m_document->timeline().documentAnimationSchedulerDidFire();
}
if (m_scheduledScriptedAnimationResolution) {
m_scheduledScriptedAnimationResolution = false;
if (auto* scriptedAnimationController = m_document->scriptedAnimationController())
scriptedAnimationController->documentAnimationSchedulerDidFire();
}
m_isFiring = false;
}
void DocumentAnimationScheduler::windowScreenDidChange(PlatformDisplayID displayID)
{
DisplayRefreshMonitorManager::sharedManager().windowScreenDidChange(displayID, *this);
}
RefPtr<DisplayRefreshMonitor> DocumentAnimationScheduler::createDisplayRefreshMonitor(PlatformDisplayID displayID) const
{
if (!m_document || !m_document->page())
return nullptr;
if (auto monitor = m_document->page()->chrome().client().createDisplayRefreshMonitor(displayID))
return monitor;
return DisplayRefreshMonitor::createDefaultDisplayRefreshMonitor(displayID);
}
}
#endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)