From af2901e78a14684fc09981cca21ce33e7b73b695 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 17 Jun 2026 10:17:55 +0200 Subject: [PATCH] Own Web fallback services and trim Win32 session state --- docs/modernization/roadmap.md | 8 +++++++ docs/modernization/tasks.md | 9 ++++++++ src/platform_legacy/legacy_platform_state.cpp | 23 +++++++++++++++++++ src/platform_legacy/legacy_platform_state.h | 4 ++++ .../windows_runtime_shell.cpp | 13 +++++------ src/platform_windows/windows_runtime_shell.h | 2 +- webgl/src/main.cpp | 3 +++ 7 files changed, 54 insertions(+), 8 deletions(-) diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 4465d373..935fa9ea 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,14 @@ What is already real: - `pp_app_core` Latest slice: +- `src/platform_legacy/legacy_platform_state.*` now exposes an ownable Web + platform-services entrypoint plus an explicit binding hook instead of only a + retained fallback object. +- `webgl/src/main.cpp` now owns the Web platform-services implementation and + seeds that owned instance into legacy platform state during startup. +- `src/platform_windows/windows_runtime_shell.*` no longer keeps `HINSTANCE` + in the retained main-window session state; the startup/shutdown path now + threads the module handle explicitly. - `webgl/src/main.cpp` now owns a TU-local legacy `PlatformServices` instance and binds that owned service into `App` during `StartApp()`. - `android/src/cpp/main.cpp` now owns a function-lifetime legacy diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index bd54fcdb..1d002926 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,15 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/platform_legacy/legacy_platform_state.*` now exposes + `create_legacy_web_platform_services()` plus an explicit binding hook for the + retained Web service surface. +- `webgl/src/main.cpp` now owns and binds the Web platform-services + implementation explicitly instead of relying only on the retained fallback + object in legacy platform state. +- `src/platform_windows/windows_runtime_shell.*` now threads `HINSTANCE` + through the startup/runtime path explicitly instead of keeping it in the + retained main-window session state. - `webgl/src/main.cpp` now binds an owned legacy `PlatformServices` instance instead of reading the process-global fallback directly during `StartApp()`. - `android/src/cpp/main.cpp` now binds a function-lifetime owned legacy diff --git a/src/platform_legacy/legacy_platform_state.cpp b/src/platform_legacy/legacy_platform_state.cpp index 7aae6791..78f24ca4 100644 --- a/src/platform_legacy/legacy_platform_state.cpp +++ b/src/platform_legacy/legacy_platform_state.cpp @@ -19,12 +19,22 @@ struct RetainedLegacyStoragePaths final { pp::platform::PlatformStoragePaths storage_paths; }; +struct RetainedLegacyWebPlatformServicesBinding final { + pp::platform::WebPlatformServices* services = nullptr; +}; + [[nodiscard]] RetainedLegacyStoragePaths& retained_legacy_storage_paths() { static RetainedLegacyStoragePaths state; return state; } +[[nodiscard]] RetainedLegacyWebPlatformServicesBinding& retained_legacy_web_platform_services_binding() +{ + static RetainedLegacyWebPlatformServicesBinding state; + return state; +} + class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices { public: void publish_exported_image(std::string_view path) override @@ -94,10 +104,23 @@ void request_legacy_glfw_app_close() [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services() { + if (auto* services = retained_legacy_web_platform_services_binding().services) + return *services; + static RetainedWebPlatformServices services; return pp::platform::resolve_web_platform_services(services); } +[[nodiscard]] std::unique_ptr create_legacy_web_platform_services() +{ + return std::make_unique(); +} + +void set_legacy_web_platform_services(pp::platform::WebPlatformServices* services) +{ + retained_legacy_web_platform_services_binding().services = services; +} + [[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept { return family == pp::platform::PlatformFamily::webgl; diff --git a/src/platform_legacy/legacy_platform_state.h b/src/platform_legacy/legacy_platform_state.h index 335a93d7..ef93ada7 100644 --- a/src/platform_legacy/legacy_platform_state.h +++ b/src/platform_legacy/legacy_platform_state.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "platform_api/platform_policy.h" #include "platform_api/platform_services.h" @@ -22,6 +24,8 @@ void request_legacy_glfw_app_close(); #endif [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services(); +[[nodiscard]] std::unique_ptr create_legacy_web_platform_services(); +void set_legacy_web_platform_services(pp::platform::WebPlatformServices* services); [[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept; void publish_legacy_web_exported_image(std::string_view path); [[nodiscard]] bool try_publish_legacy_web_exported_image( diff --git a/src/platform_windows/windows_runtime_shell.cpp b/src/platform_windows/windows_runtime_shell.cpp index 01fd544a..8b723732 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -17,7 +17,6 @@ namespace pp::platform::windows { namespace { struct RetainedMainWindowSessionState final { - HINSTANCE instance{}; HWND handle{}; wchar_t title[512]{}; bool sandboxed = false; @@ -175,8 +174,8 @@ void set_main_window_sandboxed(bool sandboxed) noexcept int run_main_application(int argc, char** argv) { + const auto instance = GetModuleHandle(NULL); auto& main_window_state = retained_main_window_session_state(); - main_window_state.instance = GetModuleHandle(NULL); auto& runtime_state = retained_runtime_state(); runtime_state.owned_app = std::make_unique(); @@ -193,7 +192,7 @@ int run_main_application(int argc, char** argv) pp::platform::windows::ensure_runtime_data_directory(); - pp::platform::windows::SplashScreen splash(main_window_state.instance); + pp::platform::windows::SplashScreen splash(instance); pp::platform::windows::initialize_retained_input_state(); @@ -208,7 +207,7 @@ int run_main_application(int argc, char** argv) switch (pp::platform::windows::initialize_main_window_and_gl( startup, main_window_state.handle, - main_window_state.instance, + instance, main_window_state.title, context)) { @@ -242,12 +241,12 @@ int run_main_application(int argc, char** argv) } } - pp::platform::windows::run_main_window_runtime(startup, start_in_vr, splash); + pp::platform::windows::run_main_window_runtime(startup, start_in_vr, instance, splash); release_bound_app(); return 0; } -void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash) +void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, HINSTANCE instance, SplashScreen& splash) { auto& main_window_state = retained_main_window_session_state(); auto* app = bound_app(); @@ -272,7 +271,7 @@ void run_main_window_runtime(const MainWindowStartupState& startup, bool start_i splash.dismiss(); run_main_message_loop(); - shutdown_main_window_runtime(startup, main_window_state.instance); + shutdown_main_window_runtime(startup, instance); } } diff --git a/src/platform_windows/windows_runtime_shell.h b/src/platform_windows/windows_runtime_shell.h index d521ef0e..fb113c05 100644 --- a/src/platform_windows/windows_runtime_shell.h +++ b/src/platform_windows/windows_runtime_shell.h @@ -9,7 +9,7 @@ class WacomTablet; namespace pp::platform::windows { int run_main_application(int argc, char** argv); -void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash); +void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, HINSTANCE instance, SplashScreen& splash); void bind_app(App* app) noexcept; [[nodiscard]] App* bound_app() noexcept; void release_bound_app() noexcept; diff --git a/webgl/src/main.cpp b/webgl/src/main.cpp index d9712b15..57661e7a 100644 --- a/webgl/src/main.cpp +++ b/webgl/src/main.cpp @@ -17,6 +17,7 @@ GLFWwindow* wnd; float theta = 0; glm::vec2 g_cursor_pos; std::unique_ptr g_platform_services; +std::unique_ptr g_web_platform_services; template class TaskCallback @@ -121,6 +122,7 @@ void StartApp() { App::I = &app; pp::platform::legacy::set_legacy_glfw_window(wnd); + pp::platform::legacy::set_legacy_web_platform_services(g_web_platform_services.get()); app.set_platform_services(g_platform_services.get()); app.initLog(); app.create(); @@ -199,6 +201,7 @@ void main_loop() int main() { g_platform_services = pp::platform::legacy::create_platform_services(); + g_web_platform_services = pp::platform::legacy::create_legacy_web_platform_services(); if (glfwInit() != GL_TRUE) printf("Failed to init GLFW");