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

@@ -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<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
{
return family == pp::platform::PlatformFamily::webgl;

View File

@@ -1,5 +1,7 @@
#pragma once
#include <memory>
#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<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;
void publish_legacy_web_exported_image(std::string_view path);
[[nodiscard]] bool try_publish_legacy_web_exported_image(

View File

@@ -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<App>();
@@ -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);
}
}

View File

@@ -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;