#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/atomic_sequence_num.h"
#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
namespace viz {
namespace {
constexpr double kDoubleTickDivisor = …;
base::AtomicSequenceNumber g_next_source_id;
uint64_t GenerateSourceId(uint32_t restart_id) { … }
void FilterAndIssueBeginFrame(BeginFrameObserver* observer,
const BeginFrameArgs& args) { … }
bool CheckBeginFrameContinuity(BeginFrameObserver* observer,
const BeginFrameArgs& args) { … }
}
bool BeginFrameObserver::IsRoot() const { … }
BeginFrameObserverBase::BeginFrameObserverBase() = default;
BeginFrameObserverBase::~BeginFrameObserverBase() = default;
const BeginFrameArgs& BeginFrameObserverBase::LastUsedBeginFrameArgs() const { … }
bool BeginFrameObserverBase::WantsAnimateOnlyBeginFrames() const { … }
void BeginFrameObserverBase::OnBeginFrame(const BeginFrameArgs& args) { … }
void BeginFrameObserverBase::AsProtozeroInto(
perfetto::EventContext& ctx,
perfetto::protos::pbzero::BeginFrameObserverStateV2* state) const { … }
BeginFrameArgs
BeginFrameSource::BeginFrameArgsGenerator::GenerateBeginFrameArgs(
uint64_t source_id,
base::TimeTicks frame_time,
base::TimeTicks deadline,
base::TimeDelta vsync_interval) { … }
uint64_t BeginFrameSource::BeginFrameArgsGenerator::EstimateTickCountsBetween(
base::TimeTicks frame_time,
base::TimeTicks next_expected_frame_time,
base::TimeDelta vsync_interval) { … }
constexpr uint32_t BeginFrameSource::kNotRestartableId;
BeginFrameSource::BeginFrameSource(uint32_t restart_id)
: … { … }
BeginFrameSource::~BeginFrameSource() = default;
void BeginFrameSource::SetIsGpuBusy(bool busy) { … }
bool BeginFrameSource::RequestCallbackOnGpuAvailable() { … }
void BeginFrameSource::AsProtozeroInto(
perfetto::EventContext&,
perfetto::protos::pbzero::BeginFrameSourceStateV2* state) const { … }
#if BUILDFLAG(IS_MAC)
void BeginFrameSource::RecordBeginFrameSourceAccuracy(base::TimeDelta delta) {
total_delta_ += delta.magnitude();
frames_since_last_recording_++;
constexpr int kFramesToEmitHistogram = 3600;
if (frames_since_last_recording_ < kFramesToEmitHistogram) {
return;
}
UMA_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(
"Viz.BeginFrameSource.Accuracy.AverageDelta2",
total_delta_ / kFramesToEmitHistogram,
base::Microseconds(100),
base::Milliseconds(33), 30);
frames_since_last_recording_ = 0;
total_delta_ = base::TimeDelta();
}
#endif
StubBeginFrameSource::StubBeginFrameSource()
: … { … }
SyntheticBeginFrameSource::SyntheticBeginFrameSource(uint32_t restart_id)
: … { … }
SyntheticBeginFrameSource::~SyntheticBeginFrameSource() = default;
BackToBackBeginFrameSource::BackToBackBeginFrameSource(
std::unique_ptr<DelayBasedTimeSource> time_source)
: … { … }
BackToBackBeginFrameSource::~BackToBackBeginFrameSource() = default;
void BackToBackBeginFrameSource::AddObserver(BeginFrameObserver* obs) { … }
void BackToBackBeginFrameSource::RemoveObserver(BeginFrameObserver* obs) { … }
void BackToBackBeginFrameSource::DidFinishFrame(BeginFrameObserver* obs) { … }
void BackToBackBeginFrameSource::OnGpuNoLongerBusy() { … }
void BackToBackBeginFrameSource::OnUpdateVSyncParameters(
base::TimeTicks timebase,
base::TimeDelta interval) { … }
void BackToBackBeginFrameSource::SetMaxVrrInterval(
const std::optional<base::TimeDelta>& max_vrr_interval) { … }
void BackToBackBeginFrameSource::OnTimerTick() { … }
DelayBasedBeginFrameSource::DelayBasedBeginFrameSource(
std::unique_ptr<DelayBasedTimeSource> time_source,
uint32_t restart_id)
: … { … }
DelayBasedBeginFrameSource::~DelayBasedBeginFrameSource() { … }
void DelayBasedBeginFrameSource::OnUpdateVSyncParameters(
base::TimeTicks timebase,
base::TimeDelta interval) { … }
BeginFrameArgs DelayBasedBeginFrameSource::CreateBeginFrameArgs(
base::TimeTicks frame_time) { … }
void DelayBasedBeginFrameSource::AddObserver(BeginFrameObserver* obs) { … }
void DelayBasedBeginFrameSource::RemoveObserver(BeginFrameObserver* obs) { … }
void DelayBasedBeginFrameSource::OnGpuNoLongerBusy() { … }
void DelayBasedBeginFrameSource::SetMaxVrrInterval(
const std::optional<base::TimeDelta>& max_vrr_interval) { … }
void DelayBasedBeginFrameSource::OnTimerTick() { … }
void DelayBasedBeginFrameSource::IssueBeginFrameToObserver(
BeginFrameObserver* obs,
const BeginFrameArgs& args) { … }
void DelayBasedBeginFrameSource::SetActive(bool active) { … }
ExternalBeginFrameSource::ExternalBeginFrameSource(
ExternalBeginFrameSourceClient* client,
uint32_t restart_id)
: … { … }
ExternalBeginFrameSource::~ExternalBeginFrameSource() { … }
void ExternalBeginFrameSource::AsProtozeroInto(
perfetto::EventContext& ctx,
perfetto::protos::pbzero::BeginFrameSourceStateV2* state) const { … }
void ExternalBeginFrameSource::AddObserver(BeginFrameObserver* obs) { … }
void ExternalBeginFrameSource::RemoveObserver(BeginFrameObserver* obs) { … }
void ExternalBeginFrameSource::OnGpuNoLongerBusy() { … }
void ExternalBeginFrameSource::OnSetBeginFrameSourcePaused(bool paused) { … }
void ExternalBeginFrameSource::OnBeginFrame(const BeginFrameArgs& args) { … }
BeginFrameArgs ExternalBeginFrameSource::GetMissedBeginFrameArgs(
BeginFrameObserver* obs) { … }
base::TimeDelta ExternalBeginFrameSource::GetMaximumRefreshFrameInterval() { … }
base::flat_set<base::TimeDelta>
ExternalBeginFrameSource::GetSupportedFrameIntervals(base::TimeDelta interval) { … }
}