mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This does some long-overdue refactoring of the spaghetti code that grew in the GLFW embedding to begin providing a clearer separation between the engine and the window. It is now possible to register plugins, and run the runloop, on a headless engine, which makes headless mode much more usable. This is useful in some automated testing environments. There is more refactoring that should be done in the future, but this is a good incremental point to stop as the PR is already large, and it provides useful new functionality as-is.
42 lines
1.2 KiB
C++
42 lines
1.2 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.
|
|
|
|
#include "flutter/shell/platform/glfw/glfw_event_loop.h"
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <atomic>
|
|
#include <utility>
|
|
|
|
namespace flutter {
|
|
|
|
GLFWEventLoop::GLFWEventLoop(std::thread::id main_thread_id,
|
|
const TaskExpiredCallback& on_task_expired)
|
|
: EventLoop(main_thread_id, std::move(on_task_expired)) {}
|
|
|
|
GLFWEventLoop::~GLFWEventLoop() = default;
|
|
|
|
void GLFWEventLoop::WaitUntil(const TaskTimePoint& time) {
|
|
const auto now = TaskTimePoint::clock::now();
|
|
|
|
// Make sure the seconds are not integral.
|
|
using Seconds = std::chrono::duration<double, std::ratio<1>>;
|
|
const auto duration_to_wait = std::chrono::duration_cast<Seconds>(time - now);
|
|
|
|
if (duration_to_wait.count() > 0.0) {
|
|
::glfwWaitEventsTimeout(duration_to_wait.count());
|
|
} else {
|
|
// Avoid engine task priority inversion by making sure GLFW events are
|
|
// always processed even when there is no need to wait for pending engine
|
|
// tasks.
|
|
::glfwPollEvents();
|
|
}
|
|
}
|
|
|
|
void GLFWEventLoop::Wake() {
|
|
::glfwPostEmptyEvent();
|
|
}
|
|
|
|
} // namespace flutter
|