Flutter Engine
The Flutter Engine
vsync_waiter_fallback.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/common/vsync_waiter_fallback.h"
6
7#include <memory>
8
9#include "flutter/fml/logging.h"
10#include "flutter/fml/message_loop.h"
11#include "flutter/fml/trace_event.h"
12
13namespace flutter {
14namespace {
15
16static fml::TimePoint SnapToNextTick(fml::TimePoint value,
17 fml::TimePoint tick_phase,
18 fml::TimeDelta tick_interval) {
19 fml::TimeDelta offset = (tick_phase - value) % tick_interval;
21 offset = offset + tick_interval;
22 }
23 return value + offset;
24}
25
26} // namespace
27
29 bool for_testing)
30 : VsyncWaiter(task_runners),
31 phase_(fml::TimePoint::Now()),
32 for_testing_(for_testing) {}
33
35
36// |VsyncWaiter|
37void VsyncWaiterFallback::AwaitVSync() {
38 constexpr fml::TimeDelta kSingleFrameInterval =
40 auto frame_start_time =
41 SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
42 auto frame_target_time = frame_start_time + kSingleFrameInterval;
43
44 TRACE_EVENT2_INT("flutter", "PlatformVsync", "frame_start_time",
45 frame_start_time.ToEpochDelta().ToMicroseconds(),
46 "frame_target_time",
47 frame_target_time.ToEpochDelta().ToMicroseconds());
48
49 std::weak_ptr<VsyncWaiterFallback> weak_this =
50 std::static_pointer_cast<VsyncWaiterFallback>(shared_from_this());
51
53 [frame_start_time, frame_target_time, weak_this]() {
54 if (auto vsync_waiter = weak_this.lock()) {
55 vsync_waiter->FireCallback(frame_start_time, frame_target_time,
56 !vsync_waiter->for_testing_);
57 }
58 },
59 frame_start_time);
60}
61
62} // namespace flutter
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
Definition: task_runners.cc:34
VsyncWaiterFallback(const TaskRunners &task_runners, bool for_testing=false)
const TaskRunners task_runners_
Definition: vsync_waiter.h:44
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
Definition: task_runner.cc:28
static constexpr TimeDelta FromSecondsF(double seconds)
Definition: time_delta.h:53
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
static TimePoint Now()
Definition: time_point.cc:49
uint8_t value
Definition: ascii_trie.cc:9
std::chrono::time_point< std::chrono::high_resolution_clock > TimePoint
Definition: timing.h:15
SeparatedVector2 offset
#define TRACE_EVENT2_INT(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
Definition: trace_event.h:202