File: fling_scheduler_android.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 3,234 bytes parent folder | download | duplicates (5)
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