From 9602196e99f687a2c6743edcc73b147192e61272 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 17 Jun 2026 11:38:43 +0200 Subject: [PATCH] Bind Win32 main-thread queue to runtime state --- docs/modernization/roadmap.md | 5 +++++ docs/modernization/tasks.md | 4 ++++ src/platform_windows/windows_platform_services.cpp | 9 +++++---- src/platform_windows/windows_runtime_shell.cpp | 2 ++ src/platform_windows/windows_runtime_state.cpp | 12 ++++++++++++ src/platform_windows/windows_runtime_state.h | 3 +++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index e625f9fb..5c72b97e 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,11 @@ What is already real: - `pp_app_core` Latest slice: +- `src/platform_windows/windows_platform_services.cpp` no longer brokers the + Win32 main-thread queue through `bound_app()->runtime()`; it now uses an + explicit Windows runtime binding. +- `src/platform_windows/windows_runtime_state.*` now carries the active + `AppRuntime*` binding beside the retained Windows-owned runtime objects. - `src/platform_windows/windows_runtime_state.*` now owns the retained Win32 runtime object lifetime (`App`, `WacomTablet`) instead of leaving that storage inside `windows_runtime_shell.cpp`. diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 7d2aad28..517901d4 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,10 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/platform_windows/windows_platform_services.cpp` no longer uses + `bound_app()->runtime()` for main-thread task brokering. +- `src/platform_windows/windows_runtime_state.*` now carries the active + `AppRuntime*` binding used by that queue hook. - `src/platform_windows/windows_runtime_state.*` now owns the retained Win32 runtime object lifetime (`App`, `WacomTablet`). - `src/platform_windows/windows_runtime_shell.cpp` no longer carries that diff --git a/src/platform_windows/windows_platform_services.cpp b/src/platform_windows/windows_platform_services.cpp index c24efc7e..00c5d6e5 100644 --- a/src/platform_windows/windows_platform_services.cpp +++ b/src/platform_windows/windows_platform_services.cpp @@ -5,6 +5,7 @@ #include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_platform_services.h" #include "platform_windows/windows_runtime_shell.h" +#include "platform_windows/windows_runtime_state.h" #include "keymap.h" #include "platform_windows/windows_stylus_input.h" #include "platform_windows/windows_window_shell.h" @@ -142,9 +143,9 @@ namespace { void enqueue_main_thread_task(std::packaged_task task) { - if (auto* app = bound_app()) + if (auto* runtime = retained_bound_runtime()) { - app->runtime().main_thread_task(std::move(task)); + runtime->main_thread_task(std::move(task)); return; } @@ -156,9 +157,9 @@ void enqueue_main_thread_task(std::packaged_task task) void drain_main_thread_tasks() { - if (auto* app = bound_app()) + if (auto* runtime = retained_bound_runtime()) { - app->runtime().drain_main_thread_tasks(); + runtime->drain_main_thread_tasks(); return; } } diff --git a/src/platform_windows/windows_runtime_shell.cpp b/src/platform_windows/windows_runtime_shell.cpp index 458e808e..1fa10413 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -120,6 +120,7 @@ App* bound_app() noexcept void release_bound_app() noexcept { bind_app(nullptr); + bind_runtime(nullptr); retained_owned_app().reset(); } @@ -136,6 +137,7 @@ int run_main_application(int argc, char** argv) owned_app = std::make_unique(); auto* app = owned_app.get(); bind_app(app); + bind_runtime(&app->runtime()); app->set_platform_services(&pp::platform::windows::platform_services()); app->initLog(); diff --git a/src/platform_windows/windows_runtime_state.cpp b/src/platform_windows/windows_runtime_state.cpp index fd730f5e..46847b4c 100644 --- a/src/platform_windows/windows_runtime_state.cpp +++ b/src/platform_windows/windows_runtime_state.cpp @@ -3,6 +3,7 @@ #include "platform_windows/windows_runtime_state.h" #include "app.h" +#include "app_runtime.h" #include "wacom.h" namespace pp::platform::windows { @@ -10,6 +11,7 @@ namespace { struct RetainedWindowsRuntimeState final { std::unique_ptr owned_app; + AppRuntime* runtime = nullptr; WacomTablet tablet; }; @@ -31,4 +33,14 @@ WacomTablet& retained_wacom_tablet() noexcept return retained_runtime_state().tablet; } +AppRuntime* retained_bound_runtime() noexcept +{ + return retained_runtime_state().runtime; +} + +void bind_runtime(AppRuntime* runtime) noexcept +{ + retained_runtime_state().runtime = runtime; +} + } diff --git a/src/platform_windows/windows_runtime_state.h b/src/platform_windows/windows_runtime_state.h index 72017a22..48e25f33 100644 --- a/src/platform_windows/windows_runtime_state.h +++ b/src/platform_windows/windows_runtime_state.h @@ -3,11 +3,14 @@ #include class App; +class AppRuntime; class WacomTablet; namespace pp::platform::windows { [[nodiscard]] std::unique_ptr& retained_owned_app() noexcept; [[nodiscard]] WacomTablet& retained_wacom_tablet() noexcept; +[[nodiscard]] AppRuntime* retained_bound_runtime() noexcept; +void bind_runtime(AppRuntime* runtime) noexcept; }