Move Windows main task queue into platform services
This commit is contained in:
@@ -22,11 +22,28 @@ void win32_save_window_state();
|
||||
bool win32_vr_start();
|
||||
void win32_vr_stop();
|
||||
HWND pp_windows_main_window_handle();
|
||||
void pp_windows_enqueue_main_task(std::packaged_task<void()> task);
|
||||
|
||||
namespace pp::platform::windows {
|
||||
namespace {
|
||||
|
||||
struct RetainedMainTaskQueue final {
|
||||
std::deque<std::packaged_task<void()>> tasklist;
|
||||
std::mutex task_mutex;
|
||||
};
|
||||
|
||||
[[nodiscard]] RetainedMainTaskQueue& retained_main_task_queue()
|
||||
{
|
||||
static RetainedMainTaskQueue queue;
|
||||
return queue;
|
||||
}
|
||||
|
||||
void enqueue_main_task(std::packaged_task<void()> task)
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
queue.tasklist.emplace_back(std::move(task));
|
||||
}
|
||||
|
||||
struct RetainedWin32AsyncRenderContextState final {
|
||||
HDC hdc{};
|
||||
HGLRC hrc{};
|
||||
@@ -96,6 +113,27 @@ void swap_async_render_context()
|
||||
{
|
||||
SwapBuffers(retained_win32_async_render_context_state().hdc);
|
||||
}
|
||||
|
||||
void enqueue_main_thread_task(std::packaged_task<void()> task)
|
||||
{
|
||||
enqueue_main_task(std::move(task));
|
||||
}
|
||||
|
||||
void drain_main_thread_tasks()
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
auto& queue = retained_main_task_queue();
|
||||
std::lock_guard<std::mutex> lock(queue.task_mutex);
|
||||
working_list = std::move(queue.tasklist);
|
||||
}
|
||||
|
||||
while (!working_list.empty())
|
||||
{
|
||||
working_list.front()();
|
||||
working_list.pop_front();
|
||||
}
|
||||
}
|
||||
} // namespace pp::platform::windows
|
||||
|
||||
namespace {
|
||||
@@ -159,7 +197,7 @@ void handle_gl_callback(
|
||||
|
||||
void show_cursor(bool visible)
|
||||
{
|
||||
pp_windows_enqueue_main_task(std::packaged_task<void()>([=] {
|
||||
pp::platform::windows::enqueue_main_thread_task(std::packaged_task<void()>([=] {
|
||||
if (visible)
|
||||
while (ShowCursor(true) < 0);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user