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 
7 namespace flutter {
8 
10  flutter::TaskRunners task_runners)
11  : VsyncWaiter(std::move(task_runners)), vsync_callback_(vsync_callback) {
12  FML_DCHECK(vsync_callback_);
13 }
14 
16 
17 // |VsyncWaiter|
18 void VsyncWaiterEmbedder::AwaitVSync() {
19  auto* weak_waiter = new std::weak_ptr<VsyncWaiter>(shared_from_this());
20  vsync_callback_(reinterpret_cast<intptr_t>(weak_waiter));
21 }
22 
23 // static
25  fml::TimePoint frame_start_time,
26  fml::TimePoint frame_target_time) {
27  if (baton == 0) {
28  return false;
29  }
30 
31  auto* weak_waiter = reinterpret_cast<std::weak_ptr<VsyncWaiter>*>(baton);
32  auto strong_waiter = weak_waiter->lock();
33  delete weak_waiter;
34 
35  if (!strong_waiter) {
36  return false;
37  }
38 
39  strong_waiter->FireCallback(frame_start_time, frame_target_time);
40  return true;
41 }
42 
43 } // namespace flutter
#define FML_DCHECK(condition)
Definition: logging.h:86
Definition: ref_ptr.h:252
static bool OnEmbedderVsync(intptr_t baton, fml::TimePoint frame_start_time, fml::TimePoint frame_target_time)
VsyncWaiterEmbedder(const VsyncCallback &callback, flutter::TaskRunners task_runners)
std::function< void(intptr_t)> VsyncCallback