Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
glfw_event_loop.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/glfw/glfw_event_loop.h"
6
7#include <GLFW/glfw3.h>
8
9#include <atomic>
10#include <utility>
11
12namespace flutter {
13
14GLFWEventLoop::GLFWEventLoop(std::thread::id main_thread_id,
15 const TaskExpiredCallback& on_task_expired)
16 : EventLoop(main_thread_id, on_task_expired) {}
17
19
21 const auto now = TaskTimePoint::clock::now();
22
23 // Make sure the seconds are not integral.
24 using Seconds = std::chrono::duration<double, std::ratio<1>>;
25 const auto duration_to_wait = std::chrono::duration_cast<Seconds>(time - now);
26
27 if (duration_to_wait.count() > 0.0) {
28 ::glfwWaitEventsTimeout(duration_to_wait.count());
29 } else {
30 // Avoid engine task priority inversion by making sure GLFW events are
31 // always processed even when there is no need to wait for pending engine
32 // tasks.
33 ::glfwPollEvents();
34 }
35}
36
38 ::glfwPostEmptyEvent();
39}
40
41} // namespace flutter
std::function< void(const FlutterTask *)> TaskExpiredCallback
Definition event_loop.h:22
std::chrono::steady_clock::time_point TaskTimePoint
Definition event_loop.h:50
GLFWEventLoop(std::thread::id main_thread_id, const TaskExpiredCallback &on_task_expired)
void WaitUntil(const TaskTimePoint &time) override