forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsync_waiter.h
64 lines (46 loc) · 1.95 KB
/
vsync_waiter.h
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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_COMMON_VSYNC_WAITER_H_
#define FLUTTER_SHELL_COMMON_VSYNC_WAITER_H_
#include <functional>
#include <memory>
#include <mutex>
#include "flutter/common/task_runners.h"
#include "flutter/fml/time/time_point.h"
namespace flutter {
/// Abstract Base Class that represents a platform specific mechanism for
/// getting callbacks when a vsync event happens.
class VsyncWaiter : public std::enable_shared_from_this<VsyncWaiter> {
public:
using Callback = std::function<void(fml::TimePoint frame_start_time,
fml::TimePoint frame_target_time)>;
virtual ~VsyncWaiter();
void AsyncWaitForVsync(const Callback& callback);
/// Add a secondary callback for the next vsync.
///
/// See also |PointerDataDispatcher::ScheduleSecondaryVsyncCallback|.
void ScheduleSecondaryCallback(const fml::closure& callback);
protected:
// On some backends, the |FireCallback| needs to be made from a static C
// method.
friend class VsyncWaiterAndroid;
friend class VsyncWaiterEmbedder;
const TaskRunners task_runners_;
VsyncWaiter(TaskRunners task_runners);
// Implementations are meant to override this method and arm their vsync
// latches when in response to this invocation. On vsync, they are meant to
// invoke the |FireCallback| method once (and only once) with the appropriate
// arguments. This method should not block the current thread.
virtual void AwaitVSync() = 0;
void FireCallback(fml::TimePoint frame_start_time,
fml::TimePoint frame_target_time);
private:
std::mutex callback_mutex_;
Callback callback_;
std::mutex secondary_callback_mutex_;
fml::closure secondary_callback_;
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiter);
};
} // namespace flutter
#endif // FLUTTER_SHELL_COMMON_VSYNC_WAITER_H_