From 0cf6a6ea4f94bb051a34c300e98a8b023b8fb257 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 17 Jun 2026 11:34:14 +0200 Subject: [PATCH] Extract Win32 runtime state storage --- cmake/PanoPainterSources.cmake | 2 ++ docs/modernization/roadmap.md | 6 ++++ docs/modernization/tasks.md | 4 +++ .../windows_runtime_shell.cpp | 24 ++++--------- .../windows_runtime_state.cpp | 34 +++++++++++++++++++ src/platform_windows/windows_runtime_state.h | 13 +++++++ 6 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 src/platform_windows/windows_runtime_state.cpp create mode 100644 src/platform_windows/windows_runtime_state.h diff --git a/cmake/PanoPainterSources.cmake b/cmake/PanoPainterSources.cmake index 14114140..059be81e 100644 --- a/cmake/PanoPainterSources.cmake +++ b/cmake/PanoPainterSources.cmake @@ -247,6 +247,8 @@ set(PP_WINDOWS_PLATFORM_SOURCES src/platform_windows/windows_platform_services.h src/platform_windows/windows_runtime_shell.cpp src/platform_windows/windows_runtime_shell.h + src/platform_windows/windows_runtime_state.cpp + src/platform_windows/windows_runtime_state.h src/platform_windows/windows_splash.cpp src/platform_windows/windows_splash.h src/platform_windows/windows_stylus_input.cpp diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index a5c07dbf..e625f9fb 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,12 @@ What is already real: - `pp_app_core` Latest slice: +- `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`. +- `src/platform_windows/windows_runtime_shell.cpp` now orchestrates startup and + shutdown over the Windows runtime-state helper instead of directly owning the + retained runtime pocket. - `src/platform_windows/windows_platform_services.cpp` now owns the retained Win32 VR shell state directly behind `platform_vr_state()`. - `src/platform_windows/windows_window_shell.cpp` no longer exposes or owns a diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 631d93c4..7d2aad28 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_runtime_state.*` now owns the retained Win32 + runtime object lifetime (`App`, `WacomTablet`). +- `src/platform_windows/windows_runtime_shell.cpp` no longer carries that + retained runtime-state storage directly. - `src/platform_windows/windows_platform_services.cpp` now owns the retained Win32 VR shell state directly behind `platform_vr_state()`. - `src/platform_windows/windows_window_shell.cpp` no longer keeps a separate diff --git a/src/platform_windows/windows_runtime_shell.cpp b/src/platform_windows/windows_runtime_shell.cpp index f658d2cb..458e808e 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -8,6 +8,7 @@ #include "platform_windows/windows_lifecycle_state.h" #include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_platform_services.h" +#include "platform_windows/windows_runtime_state.h" #include "platform_windows/windows_stylus_input.h" #include "platform_windows/windows_window_shell.h" #include "wacom.h" @@ -17,17 +18,6 @@ namespace pp::platform::windows { namespace { -struct RetainedWindowsRuntimeState final { - std::unique_ptr owned_app; - WacomTablet tablet; -}; - -[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() -{ - static RetainedWindowsRuntimeState state; - return state; -} - void register_touch_window(HWND hWnd) { // link: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registertouchwindow @@ -110,7 +100,7 @@ void run_main_message_loop() void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTANCE hInst) { - retained_runtime_state().tablet.terminate(); + retained_wacom_tablet().terminate(); UnregisterClass(startup.window_class.lpszClassName, hInst); LogRemote::I.stop(); } @@ -130,21 +120,21 @@ App* bound_app() noexcept void release_bound_app() noexcept { bind_app(nullptr); - retained_runtime_state().owned_app.reset(); + retained_owned_app().reset(); } WacomTablet* bound_wacom_tablet() noexcept { - return &retained_runtime_state().tablet; + return &retained_wacom_tablet(); } int run_main_application(int argc, char** argv) { const auto instance = GetModuleHandle(NULL); - auto& runtime_state = retained_runtime_state(); - runtime_state.owned_app = std::make_unique(); - auto* app = runtime_state.owned_app.get(); + auto& owned_app = retained_owned_app(); + owned_app = std::make_unique(); + auto* app = owned_app.get(); bind_app(app); 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 new file mode 100644 index 00000000..fd730f5e --- /dev/null +++ b/src/platform_windows/windows_runtime_state.cpp @@ -0,0 +1,34 @@ +#include "pch.h" + +#include "platform_windows/windows_runtime_state.h" + +#include "app.h" +#include "wacom.h" + +namespace pp::platform::windows { +namespace { + +struct RetainedWindowsRuntimeState final { + std::unique_ptr owned_app; + WacomTablet tablet; +}; + +[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() noexcept +{ + static RetainedWindowsRuntimeState state; + return state; +} + +} + +std::unique_ptr& retained_owned_app() noexcept +{ + return retained_runtime_state().owned_app; +} + +WacomTablet& retained_wacom_tablet() noexcept +{ + return retained_runtime_state().tablet; +} + +} diff --git a/src/platform_windows/windows_runtime_state.h b/src/platform_windows/windows_runtime_state.h new file mode 100644 index 00000000..72017a22 --- /dev/null +++ b/src/platform_windows/windows_runtime_state.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +class App; +class WacomTablet; + +namespace pp::platform::windows { + +[[nodiscard]] std::unique_ptr& retained_owned_app() noexcept; +[[nodiscard]] WacomTablet& retained_wacom_tablet() noexcept; + +}