#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/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_point.h"
namespace flutter {
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);
static constexpr float kUnknownRefreshRateFPS = 0.0;
virtual float GetDisplayRefreshRate() const;
protected:
friend class VsyncWaiterAndroid;
friend class VsyncWaiterEmbedder;
const TaskRunners task_runners_;
VsyncWaiter(TaskRunners task_runners);
virtual void AwaitVSync() = 0;
void FireCallback(fml::TimePoint frame_start_time,
fml::TimePoint frame_target_time);
private:
std::mutex callback_mutex_;
Callback callback_ FML_GUARDED_BY(callback_mutex_);
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiter);
};
}
#endif