flutter_flutter/shell/platform/glfw/headless_event_loop.cc
stuartmorgan 716dbf00c8
Refactor GLFW embedding to support headless mode (#18205)
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.
2020-05-07 17:10:11 -07:00

29 lines
851 B
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/headless_event_loop.h"
#include <atomic>
#include <utility>
namespace flutter {
HeadlessEventLoop::HeadlessEventLoop(std::thread::id main_thread_id,
const TaskExpiredCallback& on_task_expired)
: EventLoop(main_thread_id, std::move(on_task_expired)) {}
HeadlessEventLoop::~HeadlessEventLoop() = default;
void HeadlessEventLoop::WaitUntil(const TaskTimePoint& time) {
std::mutex& mutex = GetTaskQueueMutex();
std::unique_lock<std::mutex> lock(mutex);
task_queue_condition_.wait_until(lock, time);
}
void HeadlessEventLoop::Wake() {
task_queue_condition_.notify_one();
}
} // namespace flutter