Flutter Engine
The Flutter Engine
vsync_waiter_embedder.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/platform/embedder/vsync_waiter_embedder.h"
6
7namespace flutter {
8
10 const VsyncCallback& vsync_callback,
11 const flutter::TaskRunners& task_runners)
12 : VsyncWaiter(task_runners), vsync_callback_(vsync_callback) {
13 FML_DCHECK(vsync_callback_);
14}
15
17
18// |VsyncWaiter|
19void VsyncWaiterEmbedder::AwaitVSync() {
20 auto* weak_waiter = new std::weak_ptr<VsyncWaiter>(shared_from_this());
21 intptr_t baton = reinterpret_cast<intptr_t>(weak_waiter);
22 vsync_callback_(baton);
23}
24
25// static
27 const flutter::TaskRunners& task_runners,
28 intptr_t baton,
29 fml::TimePoint frame_start_time,
30 fml::TimePoint frame_target_time) {
31 if (baton == 0) {
32 return false;
33 }
34
35 // If the time here is in the future, the contract for `FlutterEngineOnVsync`
36 // says that the engine will only process the frame when the time becomes
37 // current.
38 task_runners.GetUITaskRunner()->PostTaskForTime(
39 [frame_start_time, frame_target_time, baton]() {
40 std::weak_ptr<VsyncWaiter>* weak_waiter =
41 reinterpret_cast<std::weak_ptr<VsyncWaiter>*>(baton);
42 auto vsync_waiter = weak_waiter->lock();
43 delete weak_waiter;
44 if (vsync_waiter) {
45 vsync_waiter->FireCallback(frame_start_time, frame_target_time);
46 }
47 },
48 frame_start_time);
49
50 return true;
51}
52
53} // namespace flutter
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
Definition: task_runners.cc:34
static bool OnEmbedderVsync(const flutter::TaskRunners &task_runners, intptr_t baton, fml::TimePoint frame_start_time, fml::TimePoint frame_target_time)
std::function< void(intptr_t)> VsyncCallback
friend class VsyncWaiterEmbedder
Definition: vsync_waiter.h:42
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
Definition: task_runner.cc:28
#define FML_DCHECK(condition)
Definition: logging.h:103