Flutter Engine
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 
12 namespace flutter {
13 
15  const TaskExpiredCallback& on_task_expired)
16  : EventLoop(main_thread_id, std::move(on_task_expired)) {}
17 
19 
20 void GLFWEventLoop::WaitUntil(const TaskTimePoint& time) {
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 
37 void GLFWEventLoop::Wake() {
38  ::glfwPostEmptyEvent();
39 }
40 
41 } // namespace flutter
std::chrono::steady_clock::time_point TaskTimePoint
Definition: event_loop.h:50
Definition: ref_ptr.h:252
std::function< void(const FlutterTask *)> TaskExpiredCallback
Definition: event_loop.h:22
int32_t id
GLFWEventLoop(std::thread::id main_thread_id, const TaskExpiredCallback &on_task_expired)