1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/viz/service/input/fling_scheduler_android.h"
#include "components/input/fling_controller.h"
#include "components/input/render_input_router.h"
namespace viz {
FlingSchedulerAndroid::FlingSchedulerAndroid(input::RenderInputRouter* rir,
const FrameSinkId& frame_sink_id)
: rir_(*rir), frame_sink_id_(frame_sink_id) {}
FlingSchedulerAndroid::~FlingSchedulerAndroid() {
StopObservingBeginFrames();
}
void FlingSchedulerAndroid::ScheduleFlingProgress(
base::WeakPtr<input::FlingController> fling_controller) {
DCHECK(fling_controller);
fling_controller_ = fling_controller;
if (observing_begin_frame_source_) {
return;
}
StartObservingBeginFrames();
}
void FlingSchedulerAndroid::DidStopFlingingOnBrowser(
base::WeakPtr<input::FlingController> fling_controller) {
DCHECK(fling_controller);
StopObservingBeginFrames();
fling_controller_ = nullptr;
rir_->DidStopFlinging();
}
bool FlingSchedulerAndroid::NeedsBeginFrameForFlingProgress() {
// Viz never receives an OnAnimate call since it don't have access to
// WindowAndroid. Hence, it always fall back to BeginFrames notifications
// coming from corresponding CompositorFrameSinkSupport's BeginFrameSource in
// Viz.
return true;
}
bool FlingSchedulerAndroid::ShouldUseMobileFlingCurve() {
return true;
}
gfx::Vector2dF FlingSchedulerAndroid::GetPixelsPerInch(
const gfx::PointF& position_in_screen) {
return gfx::Vector2dF(input::kDefaultPixelsPerInch,
input::kDefaultPixelsPerInch);
}
void FlingSchedulerAndroid::ProgressFlingOnBeginFrameIfneeded(
base::TimeTicks current_time) {
// Called from synchronous compositor, which is used by WebView, which is not
// covered by InputVizard currently.
NOTREACHED();
}
void FlingSchedulerAndroid::SetBeginFrameSource(
BeginFrameSource* begin_frame_source) {
if (!begin_frame_source) {
StopObservingBeginFrames();
}
CHECK(!observing_begin_frame_source_);
begin_frame_source_ = begin_frame_source;
}
BeginFrameSource* FlingSchedulerAndroid::GetBeginFrameSource() {
return begin_frame_source_;
}
void FlingSchedulerAndroid::StartObservingBeginFrames() {
if (!fling_controller_) {
return;
}
if (observing_begin_frame_source_) {
return;
}
if (GetBeginFrameSource()) {
observing_begin_frame_source_ = true;
GetBeginFrameSource()->AddObserver(this);
}
}
void FlingSchedulerAndroid::StopObservingBeginFrames() {
if (!observing_begin_frame_source_) {
return;
}
GetBeginFrameSource()->RemoveObserver(this);
observing_begin_frame_source_ = false;
}
bool FlingSchedulerAndroid::OnBeginFrameDerivedImpl(
const BeginFrameArgs& args) {
DCHECK(observing_begin_frame_source_);
if (!fling_controller_) {
StopObservingBeginFrames();
return false;
}
if (args.type == BeginFrameArgs::MISSED) {
return false;
}
fling_controller_->ProgressFling(args.frame_time);
return true;
}
bool FlingSchedulerAndroid::IsRoot() const {
return false;
}
} // namespace viz
|