mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
The current implementation only deals with Android devices and we'll add iOS devices support soon.
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
// 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 shell {
|
|
|
|
constexpr float kUnknownRefreshRateFPS = 0.0;
|
|
|
|
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(Callback callback);
|
|
|
|
void FireCallback(fml::TimePoint frame_start_time,
|
|
fml::TimePoint frame_target_time);
|
|
|
|
// Get the display's maximum refresh rate in the unit of frame per second.
|
|
// Return 0.0 if the refresh rate is unkonwn.
|
|
virtual float GetDisplayRefreshRate() const { return 0.0; }
|
|
|
|
protected:
|
|
const blink::TaskRunners task_runners_;
|
|
std::mutex callback_mutex_;
|
|
Callback callback_;
|
|
|
|
VsyncWaiter(blink::TaskRunners task_runners);
|
|
|
|
virtual void AwaitVSync() = 0;
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiter);
|
|
};
|
|
|
|
} // namespace shell
|
|
|
|
#endif // FLUTTER_SHELL_COMMON_VSYNC_WAITER_H_
|