From f98e4f48891c7811a80a7d969bde4b8f9cf15f13 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 17 Jun 2026 10:02:58 +0200 Subject: [PATCH] Bind non-Windows platform services explicitly --- android/src/cpp/main.cpp | 2 + docs/modernization/roadmap.md | 7 +++ docs/modernization/tasks.md | 6 +++ linux/src/main.cpp | 2 + src/app_events.cpp | 11 ++--- .../legacy_platform_services.cpp | 24 ++++------ src/platform_legacy/legacy_platform_state.cpp | 44 +++++++++++++++++ src/platform_legacy/legacy_platform_state.h | 13 +++++ .../windows_runtime_shell.cpp | 48 +++++++++++++------ src/platform_windows/windows_window_shell.h | 4 -- webgl/src/main.cpp | 2 + 11 files changed, 123 insertions(+), 40 deletions(-) diff --git a/android/src/cpp/main.cpp b/android/src/cpp/main.cpp index e57d0c2a..4c827efd 100644 --- a/android/src/cpp/main.cpp +++ b/android/src/cpp/main.cpp @@ -31,6 +31,7 @@ #include "pch.h" #include "app.h" +#include "platform_legacy/legacy_platform_services.h" #include "platform_legacy/legacy_platform_state.h" #include "asset.h" #include "keymap.h" @@ -1091,6 +1092,7 @@ void android_main(struct android_app* state) { app_dummy(); App::I = new App; + App::I->set_platform_services(&pp::platform::legacy::platform_services()); memset(&g_engine, 0, sizeof(g_engine)); state->userData = &g_engine; diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 8171db93..d4496874 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/app_events.cpp` no longer silently falls back to + `pp::platform::legacy::platform_services()` when `App` has no bound platform + services; the live app path now expects explicit platform-service ownership. +- `linux/src/main.cpp`, `webgl/src/main.cpp`, and `android/src/cpp/main.cpp` + now bind `pp::platform::legacy::platform_services()` explicitly at app + creation instead of relying on the hidden fallback in `App` event/platform + dispatch. - `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. diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 5146a95d..493fbfda 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,12 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/app_events.cpp` no longer hides a fallback to + `pp::platform::legacy::platform_services()`; touched app platform dispatch + now expects an explicitly bound platform-services pointer. +- `linux/src/main.cpp`, `webgl/src/main.cpp`, and `android/src/cpp/main.cpp` + now bind `pp::platform::legacy::platform_services()` explicitly at app + creation, removing the hidden fallback path from live non-Windows entrypoints. - `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. diff --git a/linux/src/main.cpp b/linux/src/main.cpp index 4bb24c3a..06324274 100644 --- a/linux/src/main.cpp +++ b/linux/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -120,6 +121,7 @@ int main(int argc, char** args) App::I = &app; pp::platform::legacy::set_legacy_glfw_window(wnd); + app.set_platform_services(&pp::platform::legacy::platform_services()); app.initLog(); app.create(); app.width = 800; diff --git a/src/app_events.cpp b/src/app_events.cpp index ae6b0bb2..ac186946 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -16,7 +16,6 @@ #include "platform_windows/windows_platform_services.h" #endif #include "platform_legacy/legacy_platform_state.h" -#include "platform_legacy/legacy_platform_services.h" #include "renderer_gl/opengl_capabilities.h" namespace { @@ -48,12 +47,10 @@ namespace { [[nodiscard]] pp::platform::PlatformServices& active_platform_services(const App* app) { - if (app) - { - if (auto* services = app->platform_services()) - return *services; - } - return pp::platform::legacy::platform_services(); + assert(app); + auto* services = app->platform_services(); + assert(services); + return *services; } } diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index 73d3a555..fa6fc42c 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -259,11 +259,8 @@ public: void publish_exported_image(std::string_view path) override { const auto family = pp::platform::current_platform_family(); - if (pp::platform::legacy::handles_legacy_web_platform_family(family)) - { - pp::platform::legacy::publish_legacy_web_exported_image(path); + if (pp::platform::legacy::try_publish_legacy_web_exported_image(family, path)) return; - } if (!pp::platform::platform_publishes_exported_images(family)) { (void)path; @@ -279,11 +276,8 @@ public: void flush_persistent_storage() override { const auto family = pp::platform::current_platform_family(); - if (pp::platform::legacy::handles_legacy_web_platform_family(family)) - { - pp::platform::legacy::flush_legacy_web_persistent_storage(); + if (pp::platform::legacy::try_flush_legacy_web_persistent_storage(family)) return; - } if (!pp::platform::platform_flushes_persistent_storage(family)) return; } @@ -449,8 +443,9 @@ public: [[nodiscard]] int default_canvas_resolution() override { const auto family = pp::platform::current_platform_family(); - if (pp::platform::legacy::handles_legacy_web_platform_family(family)) - return pp::platform::legacy::default_legacy_web_canvas_resolution(); + int resolution = 0; + if (pp::platform::legacy::try_default_legacy_web_canvas_resolution(family, resolution)) + return resolution; return pp::platform::platform_default_canvas_resolution(family); } @@ -527,11 +522,12 @@ public: pp::platform::PreparedFileCallback callback) override { const auto family = pp::platform::current_platform_family(); - if (pp::platform::legacy::handles_legacy_web_platform_family(family)) - { - pp::platform::legacy::save_legacy_web_prepared_file(path, suggested_name, std::move(callback)); + if (pp::platform::legacy::try_save_legacy_web_prepared_file( + family, + path, + suggested_name, + std::move(callback))) return; - } const std::string value(path); const std::string name(suggested_name); diff --git a/src/platform_legacy/legacy_platform_state.cpp b/src/platform_legacy/legacy_platform_state.cpp index a0f8d12a..7aae6791 100644 --- a/src/platform_legacy/legacy_platform_state.cpp +++ b/src/platform_legacy/legacy_platform_state.cpp @@ -108,16 +108,47 @@ void publish_legacy_web_exported_image(std::string_view path) active_legacy_web_platform_services().publish_exported_image(path); } +[[nodiscard]] bool try_publish_legacy_web_exported_image( + pp::platform::PlatformFamily family, + std::string_view path) +{ + if (!handles_legacy_web_platform_family(family)) + return false; + + publish_legacy_web_exported_image(path); + return true; +} + void flush_legacy_web_persistent_storage() { active_legacy_web_platform_services().flush_persistent_storage(); } +[[nodiscard]] bool try_flush_legacy_web_persistent_storage(pp::platform::PlatformFamily family) +{ + if (!handles_legacy_web_platform_family(family)) + return false; + + flush_legacy_web_persistent_storage(); + return true; +} + [[nodiscard]] int default_legacy_web_canvas_resolution() noexcept { return active_legacy_web_platform_services().default_canvas_resolution(); } +[[nodiscard]] bool try_default_legacy_web_canvas_resolution( + pp::platform::PlatformFamily family, + int& resolution) noexcept +{ + if (!handles_legacy_web_platform_family(family)) + return false; + + resolution = default_legacy_web_canvas_resolution(); + return true; +} + void save_legacy_web_prepared_file( std::string_view path, std::string_view suggested_name, @@ -129,6 +160,19 @@ void save_legacy_web_prepared_file( std::move(callback)); } +[[nodiscard]] bool try_save_legacy_web_prepared_file( + pp::platform::PlatformFamily family, + std::string_view path, + std::string_view suggested_name, + pp::platform::PreparedFileCallback callback) +{ + if (!handles_legacy_web_platform_family(family)) + return false; + + save_legacy_web_prepared_file(path, suggested_name, std::move(callback)); + return true; +} + [[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 06f0408f..335a93d7 100644 --- a/src/platform_legacy/legacy_platform_state.h +++ b/src/platform_legacy/legacy_platform_state.h @@ -24,12 +24,25 @@ void request_legacy_glfw_app_close(); [[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); +[[nodiscard]] bool try_publish_legacy_web_exported_image( + pp::platform::PlatformFamily family, + std::string_view path); void flush_legacy_web_persistent_storage(); +[[nodiscard]] bool try_flush_legacy_web_persistent_storage( + pp::platform::PlatformFamily family); [[nodiscard]] int default_legacy_web_canvas_resolution() noexcept; +[[nodiscard]] bool try_default_legacy_web_canvas_resolution( + pp::platform::PlatformFamily family, + int& resolution) noexcept; void save_legacy_web_prepared_file( std::string_view path, std::string_view suggested_name, pp::platform::PreparedFileCallback callback); +[[nodiscard]] bool try_save_legacy_web_prepared_file( + pp::platform::PlatformFamily family, + 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 d3ac7b55..01fd544a 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -16,12 +16,25 @@ namespace pp::platform::windows { namespace { +struct RetainedMainWindowSessionState final { + HINSTANCE instance{}; + HWND handle{}; + wchar_t title[512]{}; + bool sandboxed = false; +}; + struct RetainedWindowsRuntimeState final { std::unique_ptr owned_app; App* app = nullptr; WacomTablet tablet; }; +[[nodiscard]] RetainedMainWindowSessionState& retained_main_window_session_state() +{ + static RetainedMainWindowSessionState state; + return state; +} + [[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() { static RetainedWindowsRuntimeState state; @@ -142,28 +155,28 @@ WacomTablet* bound_wacom_tablet() noexcept HWND main_window_handle() noexcept { - return retained_state().hWnd; + return retained_main_window_session_state().handle; } const wchar_t* main_window_title() noexcept { - return retained_state().window_title; + return retained_main_window_session_state().title; } bool main_window_sandboxed() noexcept { - return retained_state().sandboxed; + return retained_main_window_session_state().sandboxed; } void set_main_window_sandboxed(bool sandboxed) noexcept { - retained_state().sandboxed = sandboxed; + retained_main_window_session_state().sandboxed = sandboxed; } int run_main_application(int argc, char** argv) { - auto& state = retained_state(); - state.hInst = 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(); @@ -180,7 +193,7 @@ int run_main_application(int argc, char** argv) pp::platform::windows::ensure_runtime_data_directory(); - pp::platform::windows::SplashScreen splash(state.hInst); + pp::platform::windows::SplashScreen splash(main_window_state.instance); pp::platform::windows::initialize_retained_input_state(); @@ -192,7 +205,12 @@ int run_main_application(int argc, char** argv) auto startup = pp::platform::windows::initialize_main_window_startup_state(*app); auto context = pp::platform::windows::OpenGlWindowContext {}; - switch (pp::platform::windows::initialize_main_window_and_gl(startup, state.hWnd, state.hInst, state.window_title, context)) + switch (pp::platform::windows::initialize_main_window_and_gl( + startup, + main_window_state.handle, + main_window_state.instance, + main_window_state.title, + context)) { case pp::platform::windows::MainStartupResult::Ok: break; @@ -231,30 +249,30 @@ int run_main_application(int argc, char** argv) void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash) { - auto& state = retained_state(); + auto& main_window_state = retained_main_window_session_state(); auto* app = bound_app(); - register_touch_window(state.hWnd); + register_touch_window(main_window_state.handle); wglMakeCurrent(NULL, NULL); initialize_runtime_threads(); install_debug_gl_callbacks(); - initialize_wintab(state.hWnd, state.sandboxed); - set_main_window_icon(state.hWnd); + initialize_wintab(main_window_state.handle, main_window_state.sandboxed); + set_main_window_icon(main_window_state.handle); app->ui_sync(); - restore_window_placement(state.hWnd, startup.show_command); + restore_window_placement(main_window_state.handle, startup.show_command); if (start_in_vr) app->vr_start(); LOG("show main window"); - SetForegroundWindow(state.hWnd); + SetForegroundWindow(main_window_state.handle); splash.dismiss(); run_main_message_loop(); - shutdown_main_window_runtime(startup, state.hInst); + shutdown_main_window_runtime(startup, main_window_state.instance); } } diff --git a/src/platform_windows/windows_window_shell.h b/src/platform_windows/windows_window_shell.h index c4456a27..e1849251 100644 --- a/src/platform_windows/windows_window_shell.h +++ b/src/platform_windows/windows_window_shell.h @@ -8,12 +8,8 @@ struct RetainedState { - HINSTANCE hInst{}; - HWND hWnd{}; bool keys[256]{}; std::map vkey_map; - wchar_t window_title[512]{}; - bool sandboxed = false; pp::platform::windows::VrShellState vr; }; diff --git a/webgl/src/main.cpp b/webgl/src/main.cpp index fc2aaa4e..d51d1de8 100644 --- a/webgl/src/main.cpp +++ b/webgl/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -119,6 +120,7 @@ void StartApp() { App::I = &app; pp::platform::legacy::set_legacy_glfw_window(wnd); + app.set_platform_services(&pp::platform::legacy::platform_services()); app.initLog(); app.create(); app.width = 1024;