ScriptedAnimationController.h [plain text]
#pragma once
#include "AnimationFrameRate.h"
#include "DOMHighResTimeStamp.h"
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class Document;
class Page;
class RequestAnimationFrameCallback;
class ScriptedAnimationController : public RefCounted<ScriptedAnimationController>
{
public:
static Ref<ScriptedAnimationController> create(Document& document)
{
return adoptRef(*new ScriptedAnimationController(document));
}
~ScriptedAnimationController();
void clearDocumentPointer() { m_document = nullptr; }
bool requestAnimationFrameEnabled() const;
WEBCORE_EXPORT Seconds interval() const;
typedef int CallbackId;
CallbackId registerCallback(Ref<RequestAnimationFrameCallback>&&);
void cancelCallback(CallbackId);
void serviceRequestAnimationFrameCallbacks(DOMHighResTimeStamp timestamp);
void suspend();
void resume();
void addThrottlingReason(ThrottlingReason reason) { m_throttlingReasons.add(reason); }
void removeThrottlingReason(ThrottlingReason reason) { m_throttlingReasons.remove(reason); }
WEBCORE_EXPORT bool isThrottled() const;
private:
ScriptedAnimationController(Document&);
Page* page() const;
Seconds preferredScriptedAnimationInterval() const;
bool isThrottledRelativeToPage() const;
bool shouldRescheduleRequestAnimationFrame(DOMHighResTimeStamp) const;
void scheduleAnimation();
using CallbackList = Vector<RefPtr<RequestAnimationFrameCallback>>;
CallbackList m_callbacks;
DOMHighResTimeStamp m_lastAnimationFrameTimestamp { 0 };
WeakPtr<Document> m_document;
CallbackId m_nextCallbackId { 0 };
int m_suspendCount { 0 };
OptionSet<ThrottlingReason> m_throttlingReasons;
};
}