AnimationFrameRate.h [plain text]
#pragma once
#include <wtf/OptionSet.h>
#include <wtf/Seconds.h>
namespace WebCore {
using FramesPerSecond = unsigned;
enum class ThrottlingReason {
VisuallyIdle = 1 << 0,
OutsideViewport = 1 << 1,
LowPowerMode = 1 << 2,
NonInteractedCrossOriginFrame = 1 << 3,
};
constexpr const Seconds FullSpeedAnimationInterval { 15_ms };
constexpr const Seconds HalfSpeedThrottlingAnimationInterval { 30_ms };
constexpr const Seconds AggressiveThrottlingAnimationInterval { 10_s };
constexpr const FramesPerSecond FullSpeedFramesPerSecond = 60;
constexpr const FramesPerSecond HalfSpeedThrottlingFramesPerSecond = 30;
constexpr const FramesPerSecond ZeroFramesPerSecond = 0;
inline Seconds preferredFrameInterval(const OptionSet<ThrottlingReason>& throttlingReasons)
{
if (throttlingReasons.containsAny({ ThrottlingReason::VisuallyIdle, ThrottlingReason::OutsideViewport }))
return AggressiveThrottlingAnimationInterval;
if (throttlingReasons.containsAny({ ThrottlingReason::LowPowerMode, ThrottlingReason::NonInteractedCrossOriginFrame }))
return HalfSpeedThrottlingAnimationInterval;
ASSERT(throttlingReasons.isEmpty());
return FullSpeedAnimationInterval;
}
inline FramesPerSecond preferredFramesPerSecond(Seconds preferredFrameInterval)
{
if (preferredFrameInterval == FullSpeedAnimationInterval)
return FullSpeedFramesPerSecond;
if (preferredFrameInterval == HalfSpeedThrottlingAnimationInterval)
return HalfSpeedThrottlingFramesPerSecond;
ASSERT_NOT_REACHED();
return ZeroFramesPerSecond;
}
}