From ea1845d924bf5b233d201c8b016bec4c53449e27 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 17 Jun 2026 09:55:13 +0200 Subject: [PATCH] Own Windows tablet path and thin legacy web fallback --- docs/modernization/roadmap.md | 7 +++++ docs/modernization/tasks.md | 7 +++++ .../legacy_platform_services.cpp | 19 +++++------- src/platform_legacy/legacy_platform_state.cpp | 31 +++++++++++++++++++ src/platform_legacy/legacy_platform_state.h | 9 ++++++ .../windows_runtime_shell.cpp | 18 ++--------- src/platform_windows/windows_runtime_shell.h | 1 - 7 files changed, 65 insertions(+), 27 deletions(-) diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 045bd86f..8171db93 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,13 @@ What is already real: - `pp_app_core` Latest slice: +- `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows tablet + object directly; the composition edge no longer binds `&WacomTablet::I` into + the Windows runtime path. +- `src/platform_legacy/legacy_platform_state.*` now exposes narrow Web helper + functions for the touched publish/flush/default-canvas/prepared-file paths, + so less of the Web fallback behavior lives inline in the legacy platform + singleton implementation. - `src/platform_windows/windows_runtime_shell.cpp` no longer keeps a separate retained `AppRuntime*` binding; the touched Windows shell and platform helpers now derive runtime ownership directly from the owned `App`. diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index f46bebb5..5146a95d 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,13 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows tablet + object directly, removing the composition-edge `WacomTablet::I` binding from + the touched Windows runtime path. +- `src/platform_legacy/legacy_platform_state.*` now exposes narrow Web helper + functions for the touched publish/flush/default-canvas/prepared-file paths, + so less of that fallback behavior stays inline in the legacy platform + singleton. - `src/platform_windows/windows_runtime_shell.cpp` no longer keeps a separate retained `AppRuntime*`; the touched Windows lifecycle and main-thread task dispatch paths now derive runtime ownership directly from the owned app. diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index 2590d280..73d3a555 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -259,9 +259,9 @@ public: void publish_exported_image(std::string_view path) override { const auto family = pp::platform::current_platform_family(); - if (family == pp::platform::PlatformFamily::webgl) + if (pp::platform::legacy::handles_legacy_web_platform_family(family)) { - pp::platform::legacy::active_legacy_web_platform_services().publish_exported_image(path); + pp::platform::legacy::publish_legacy_web_exported_image(path); return; } if (!pp::platform::platform_publishes_exported_images(family)) @@ -279,9 +279,9 @@ public: void flush_persistent_storage() override { const auto family = pp::platform::current_platform_family(); - if (family == pp::platform::PlatformFamily::webgl) + if (pp::platform::legacy::handles_legacy_web_platform_family(family)) { - pp::platform::legacy::active_legacy_web_platform_services().flush_persistent_storage(); + pp::platform::legacy::flush_legacy_web_persistent_storage(); return; } if (!pp::platform::platform_flushes_persistent_storage(family)) @@ -449,8 +449,8 @@ public: [[nodiscard]] int default_canvas_resolution() override { const auto family = pp::platform::current_platform_family(); - if (family == pp::platform::PlatformFamily::webgl) - return pp::platform::legacy::active_legacy_web_platform_services().default_canvas_resolution(); + if (pp::platform::legacy::handles_legacy_web_platform_family(family)) + return pp::platform::legacy::default_legacy_web_canvas_resolution(); return pp::platform::platform_default_canvas_resolution(family); } @@ -527,12 +527,9 @@ public: pp::platform::PreparedFileCallback callback) override { const auto family = pp::platform::current_platform_family(); - if (family == pp::platform::PlatformFamily::webgl) + if (pp::platform::legacy::handles_legacy_web_platform_family(family)) { - pp::platform::legacy::active_legacy_web_platform_services().save_prepared_file( - path, - suggested_name, - std::move(callback)); + pp::platform::legacy::save_legacy_web_prepared_file(path, suggested_name, std::move(callback)); return; } diff --git a/src/platform_legacy/legacy_platform_state.cpp b/src/platform_legacy/legacy_platform_state.cpp index dd5945cb..a0f8d12a 100644 --- a/src/platform_legacy/legacy_platform_state.cpp +++ b/src/platform_legacy/legacy_platform_state.cpp @@ -98,6 +98,37 @@ void request_legacy_glfw_app_close() return pp::platform::resolve_web_platform_services(services); } +[[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept +{ + return family == pp::platform::PlatformFamily::webgl; +} + +void publish_legacy_web_exported_image(std::string_view path) +{ + active_legacy_web_platform_services().publish_exported_image(path); +} + +void flush_legacy_web_persistent_storage() +{ + active_legacy_web_platform_services().flush_persistent_storage(); +} + +[[nodiscard]] int default_legacy_web_canvas_resolution() noexcept +{ + return active_legacy_web_platform_services().default_canvas_resolution(); +} + +void save_legacy_web_prepared_file( + std::string_view path, + std::string_view suggested_name, + pp::platform::PreparedFileCallback callback) +{ + active_legacy_web_platform_services().save_prepared_file( + path, + suggested_name, + std::move(callback)); +} + [[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths() { return retained_legacy_storage_paths().storage_paths; diff --git a/src/platform_legacy/legacy_platform_state.h b/src/platform_legacy/legacy_platform_state.h index 1437b427..06f0408f 100644 --- a/src/platform_legacy/legacy_platform_state.h +++ b/src/platform_legacy/legacy_platform_state.h @@ -1,5 +1,6 @@ #pragma once +#include "platform_api/platform_policy.h" #include "platform_api/platform_services.h" #if __LINUX__ || __WEB__ @@ -21,6 +22,14 @@ void request_legacy_glfw_app_close(); #endif [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services(); +[[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept; +void publish_legacy_web_exported_image(std::string_view path); +void flush_legacy_web_persistent_storage(); +[[nodiscard]] int default_legacy_web_canvas_resolution() noexcept; +void save_legacy_web_prepared_file( + std::string_view path, + std::string_view suggested_name, + pp::platform::PreparedFileCallback callback); [[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths(); void set_legacy_storage_paths(pp::platform::PlatformStoragePaths paths); diff --git a/src/platform_windows/windows_runtime_shell.cpp b/src/platform_windows/windows_runtime_shell.cpp index e6d10c8e..d3ac7b55 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -19,7 +19,7 @@ namespace { struct RetainedWindowsRuntimeState final { std::unique_ptr owned_app; App* app = nullptr; - WacomTablet* tablet = nullptr; + WacomTablet tablet; }; [[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() @@ -56,7 +56,6 @@ void install_debug_gl_callbacks() void initialize_wintab(HWND hWnd, bool sandboxed) { auto* tablet = bound_wacom_tablet(); - assert(tablet); if (!sandboxed) { LOG("init WinTab"); @@ -111,8 +110,7 @@ void run_main_message_loop() void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTANCE hInst) { - if (auto* tablet = retained_runtime_state().tablet) - tablet->terminate(); + retained_runtime_state().tablet.terminate(); UnregisterClass(startup.window_class.lpszClassName, hInst); LogRemote::I.stop(); } @@ -137,14 +135,9 @@ void release_bound_app() noexcept state.owned_app.reset(); } -void bind_wacom_tablet(WacomTablet* tablet) noexcept -{ - retained_runtime_state().tablet = tablet; -} - WacomTablet* bound_wacom_tablet() noexcept { - return retained_runtime_state().tablet; + return &retained_runtime_state().tablet; } HWND main_window_handle() noexcept @@ -176,7 +169,6 @@ int run_main_application(int argc, char** argv) runtime_state.owned_app = std::make_unique(); auto* app = runtime_state.owned_app.get(); bind_app(app); - bind_wacom_tablet(&WacomTablet::I); app->set_platform_services(&pp::platform::windows::platform_services()); app->initLog(); @@ -206,11 +198,9 @@ int run_main_application(int argc, char** argv) break; case pp::platform::windows::MainStartupResult::GladLoadFailure: release_bound_app(); - bind_wacom_tablet(nullptr); return 0; case pp::platform::windows::MainStartupResult::MissingCoreContextSupport: release_bound_app(); - bind_wacom_tablet(nullptr); return -1; } @@ -225,7 +215,6 @@ int run_main_application(int argc, char** argv) app->initShaders(); app->cmd_convert(argv[2], argv[3]); release_bound_app(); - bind_wacom_tablet(nullptr); return 0; case const_hash("-vrmode"): start_in_vr = true; @@ -237,7 +226,6 @@ int run_main_application(int argc, char** argv) pp::platform::windows::run_main_window_runtime(startup, start_in_vr, splash); release_bound_app(); - bind_wacom_tablet(nullptr); return 0; } diff --git a/src/platform_windows/windows_runtime_shell.h b/src/platform_windows/windows_runtime_shell.h index a0a99928..d521ef0e 100644 --- a/src/platform_windows/windows_runtime_shell.h +++ b/src/platform_windows/windows_runtime_shell.h @@ -13,7 +13,6 @@ void run_main_window_runtime(const MainWindowStartupState& startup, bool start_i void bind_app(App* app) noexcept; [[nodiscard]] App* bound_app() noexcept; void release_bound_app() noexcept; -void bind_wacom_tablet(WacomTablet* tablet) noexcept; [[nodiscard]] WacomTablet* bound_wacom_tablet() noexcept; [[nodiscard]] HWND main_window_handle() noexcept; [[nodiscard]] const wchar_t* main_window_title() noexcept;