Extract Win32 runtime state storage

This commit is contained in:
2026-06-17 11:34:14 +02:00
parent ba94785eda
commit 0cf6a6ea4f
6 changed files with 66 additions and 17 deletions

View File

@@ -247,6 +247,8 @@ set(PP_WINDOWS_PLATFORM_SOURCES
src/platform_windows/windows_platform_services.h src/platform_windows/windows_platform_services.h
src/platform_windows/windows_runtime_shell.cpp src/platform_windows/windows_runtime_shell.cpp
src/platform_windows/windows_runtime_shell.h 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.cpp
src/platform_windows/windows_splash.h src/platform_windows/windows_splash.h
src/platform_windows/windows_stylus_input.cpp src/platform_windows/windows_stylus_input.cpp

View File

@@ -70,6 +70,12 @@ What is already real:
- `pp_app_core` - `pp_app_core`
Latest slice: 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 - `src/platform_windows/windows_platform_services.cpp` now owns the retained
Win32 VR shell state directly behind `platform_vr_state()`. Win32 VR shell state directly behind `platform_vr_state()`.
- `src/platform_windows/windows_window_shell.cpp` no longer exposes or owns a - `src/platform_windows/windows_window_shell.cpp` no longer exposes or owns a

View File

@@ -78,6 +78,10 @@ Completed, blocked, and superseded task history moved to
the queue is now ordered by code movement instead. the queue is now ordered by code movement instead.
Current slice: 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 - `src/platform_windows/windows_platform_services.cpp` now owns the retained
Win32 VR shell state directly behind `platform_vr_state()`. Win32 VR shell state directly behind `platform_vr_state()`.
- `src/platform_windows/windows_window_shell.cpp` no longer keeps a separate - `src/platform_windows/windows_window_shell.cpp` no longer keeps a separate

View File

@@ -8,6 +8,7 @@
#include "platform_windows/windows_lifecycle_state.h" #include "platform_windows/windows_lifecycle_state.h"
#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_main_window_session.h"
#include "platform_windows/windows_platform_services.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_stylus_input.h"
#include "platform_windows/windows_window_shell.h" #include "platform_windows/windows_window_shell.h"
#include "wacom.h" #include "wacom.h"
@@ -17,17 +18,6 @@ namespace pp::platform::windows {
namespace { namespace {
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
WacomTablet tablet;
};
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state()
{
static RetainedWindowsRuntimeState state;
return state;
}
void register_touch_window(HWND hWnd) void register_touch_window(HWND hWnd)
{ {
// link: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registertouchwindow // 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) 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); UnregisterClass(startup.window_class.lpszClassName, hInst);
LogRemote::I.stop(); LogRemote::I.stop();
} }
@@ -130,21 +120,21 @@ App* bound_app() noexcept
void release_bound_app() noexcept void release_bound_app() noexcept
{ {
bind_app(nullptr); bind_app(nullptr);
retained_runtime_state().owned_app.reset(); retained_owned_app().reset();
} }
WacomTablet* bound_wacom_tablet() noexcept WacomTablet* bound_wacom_tablet() noexcept
{ {
return &retained_runtime_state().tablet; return &retained_wacom_tablet();
} }
int run_main_application(int argc, char** argv) int run_main_application(int argc, char** argv)
{ {
const auto instance = GetModuleHandle(NULL); const auto instance = GetModuleHandle(NULL);
auto& runtime_state = retained_runtime_state(); auto& owned_app = retained_owned_app();
runtime_state.owned_app = std::make_unique<App>(); owned_app = std::make_unique<App>();
auto* app = runtime_state.owned_app.get(); auto* app = owned_app.get();
bind_app(app); bind_app(app);
app->set_platform_services(&pp::platform::windows::platform_services()); app->set_platform_services(&pp::platform::windows::platform_services());
app->initLog(); app->initLog();

View File

@@ -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<App> owned_app;
WacomTablet tablet;
};
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() noexcept
{
static RetainedWindowsRuntimeState state;
return state;
}
}
std::unique_ptr<App>& retained_owned_app() noexcept
{
return retained_runtime_state().owned_app;
}
WacomTablet& retained_wacom_tablet() noexcept
{
return retained_runtime_state().tablet;
}
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include <memory>
class App;
class WacomTablet;
namespace pp::platform::windows {
[[nodiscard]] std::unique_ptr<App>& retained_owned_app() noexcept;
[[nodiscard]] WacomTablet& retained_wacom_tablet() noexcept;
}