Own Web fallback services and trim Win32 session state

This commit is contained in:
2026-06-17 10:17:55 +02:00
parent 2cb7046a56
commit af2901e78a
7 changed files with 54 additions and 8 deletions

View File

@@ -70,6 +70,14 @@ What is already real:
- `pp_app_core` - `pp_app_core`
Latest slice: 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` - `webgl/src/main.cpp` now owns a TU-local legacy `PlatformServices`
instance and binds that owned service into `App` during `StartApp()`. instance and binds that owned service into `App` during `StartApp()`.
- `android/src/cpp/main.cpp` now owns a function-lifetime legacy - `android/src/cpp/main.cpp` now owns a function-lifetime legacy

View File

@@ -78,6 +78,15 @@ 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_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 - `webgl/src/main.cpp` now binds an owned legacy `PlatformServices` instance
instead of reading the process-global fallback directly during `StartApp()`. instead of reading the process-global fallback directly during `StartApp()`.
- `android/src/cpp/main.cpp` now binds a function-lifetime owned legacy - `android/src/cpp/main.cpp` now binds a function-lifetime owned legacy

View File

@@ -19,12 +19,22 @@ struct RetainedLegacyStoragePaths final {
pp::platform::PlatformStoragePaths storage_paths; pp::platform::PlatformStoragePaths storage_paths;
}; };
struct RetainedLegacyWebPlatformServicesBinding final {
pp::platform::WebPlatformServices* services = nullptr;
};
[[nodiscard]] RetainedLegacyStoragePaths& retained_legacy_storage_paths() [[nodiscard]] RetainedLegacyStoragePaths& retained_legacy_storage_paths()
{ {
static RetainedLegacyStoragePaths state; static RetainedLegacyStoragePaths state;
return state; return state;
} }
[[nodiscard]] RetainedLegacyWebPlatformServicesBinding& retained_legacy_web_platform_services_binding()
{
static RetainedLegacyWebPlatformServicesBinding state;
return state;
}
class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices { class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices {
public: public:
void publish_exported_image(std::string_view path) override 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() [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services()
{ {
if (auto* services = retained_legacy_web_platform_services_binding().services)
return *services;
static RetainedWebPlatformServices services; static RetainedWebPlatformServices services;
return pp::platform::resolve_web_platform_services(services); return pp::platform::resolve_web_platform_services(services);
} }
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_legacy_web_platform_services()
{
return std::make_unique<RetainedWebPlatformServices>();
}
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 [[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept
{ {
return family == pp::platform::PlatformFamily::webgl; return family == pp::platform::PlatformFamily::webgl;

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <memory>
#include "platform_api/platform_policy.h" #include "platform_api/platform_policy.h"
#include "platform_api/platform_services.h" #include "platform_api/platform_services.h"
@@ -22,6 +24,8 @@ void request_legacy_glfw_app_close();
#endif #endif
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services(); [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> 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; [[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept;
void publish_legacy_web_exported_image(std::string_view path); void publish_legacy_web_exported_image(std::string_view path);
[[nodiscard]] bool try_publish_legacy_web_exported_image( [[nodiscard]] bool try_publish_legacy_web_exported_image(

View File

@@ -17,7 +17,6 @@ namespace pp::platform::windows {
namespace { namespace {
struct RetainedMainWindowSessionState final { struct RetainedMainWindowSessionState final {
HINSTANCE instance{};
HWND handle{}; HWND handle{};
wchar_t title[512]{}; wchar_t title[512]{};
bool sandboxed = false; bool sandboxed = false;
@@ -175,8 +174,8 @@ void set_main_window_sandboxed(bool sandboxed) noexcept
int run_main_application(int argc, char** argv) int run_main_application(int argc, char** argv)
{ {
const auto instance = GetModuleHandle(NULL);
auto& main_window_state = retained_main_window_session_state(); auto& main_window_state = retained_main_window_session_state();
main_window_state.instance = GetModuleHandle(NULL);
auto& runtime_state = retained_runtime_state(); auto& runtime_state = retained_runtime_state();
runtime_state.owned_app = std::make_unique<App>(); runtime_state.owned_app = std::make_unique<App>();
@@ -193,7 +192,7 @@ int run_main_application(int argc, char** argv)
pp::platform::windows::ensure_runtime_data_directory(); 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(); 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( switch (pp::platform::windows::initialize_main_window_and_gl(
startup, startup,
main_window_state.handle, main_window_state.handle,
main_window_state.instance, instance,
main_window_state.title, main_window_state.title,
context)) 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(); release_bound_app();
return 0; 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& main_window_state = retained_main_window_session_state();
auto* app = bound_app(); auto* app = bound_app();
@@ -272,7 +271,7 @@ void run_main_window_runtime(const MainWindowStartupState& startup, bool start_i
splash.dismiss(); splash.dismiss();
run_main_message_loop(); run_main_message_loop();
shutdown_main_window_runtime(startup, main_window_state.instance); shutdown_main_window_runtime(startup, instance);
} }
} }

View File

@@ -9,7 +9,7 @@ class WacomTablet;
namespace pp::platform::windows { namespace pp::platform::windows {
int run_main_application(int argc, char** argv); 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; void bind_app(App* app) noexcept;
[[nodiscard]] App* bound_app() noexcept; [[nodiscard]] App* bound_app() noexcept;
void release_bound_app() noexcept; void release_bound_app() noexcept;

View File

@@ -17,6 +17,7 @@ GLFWwindow* wnd;
float theta = 0; float theta = 0;
glm::vec2 g_cursor_pos; glm::vec2 g_cursor_pos;
std::unique_ptr<pp::platform::PlatformServices> g_platform_services; std::unique_ptr<pp::platform::PlatformServices> g_platform_services;
std::unique_ptr<pp::platform::WebPlatformServices> g_web_platform_services;
template<typename F> template<typename F>
class TaskCallback class TaskCallback
@@ -121,6 +122,7 @@ void StartApp()
{ {
App::I = &app; App::I = &app;
pp::platform::legacy::set_legacy_glfw_window(wnd); 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.set_platform_services(g_platform_services.get());
app.initLog(); app.initLog();
app.create(); app.create();
@@ -199,6 +201,7 @@ void main_loop()
int main() int main()
{ {
g_platform_services = pp::platform::legacy::create_platform_services(); 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) if (glfwInit() != GL_TRUE)
printf("Failed to init GLFW"); printf("Failed to init GLFW");