Bind Win32 app shell and move more legacy platform state

This commit is contained in:
2026-06-17 01:54:59 +02:00
parent 3cbc88fe78
commit 5c8a87faa0
11 changed files with 185 additions and 123 deletions

View File

@@ -43,70 +43,15 @@ void webgl_sync();
namespace {
#ifdef __WEB__
class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices {
public:
void publish_exported_image(std::string_view path) override
{
(void)path;
}
void flush_persistent_storage() override
{
webgl_sync();
}
[[nodiscard]] int default_canvas_resolution() override
{
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::webgl);
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback) override
{
const std::string value(path);
const std::string name(suggested_name);
webgl_pick_file_save(value, name, [callback = std::move(callback), value](bool success) {
callback(value, success);
});
}
};
#endif
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services()
{
#ifdef __WEB__
static RetainedWebPlatformServices services;
return pp::platform::resolve_web_platform_services(services);
#else
return pp::platform::active_web_platform_services();
#endif
}
#if defined(__IOS__) || defined(__OSX__)
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_legacy_apple_storage_paths()
{
const auto& apple_state = pp::platform::legacy::active_legacy_apple_state();
#ifdef __IOS__
[apple_state.ios_view init_dirs];
#elif defined(__OSX__)
[apple_state.osx_app init_dirs];
#endif
return pp::platform::legacy::active_legacy_storage_paths();
}
#endif
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
class LegacyPlatformServices final : public pp::platform::PlatformServices {
public:
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
{
#if defined(__IOS__)
return prepare_legacy_apple_storage_paths();
return pp::platform::legacy::prepare_legacy_apple_storage_paths();
#elif defined(__OSX__)
return prepare_legacy_apple_storage_paths();
return pp::platform::legacy::prepare_legacy_apple_storage_paths();
#elif __LINUX__
const std::string data_path = linux_home_path() + "/PanoPainter";
mkpath(data_path + "/brushes");
@@ -316,7 +261,7 @@ public:
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_legacy_web_platform_services().publish_exported_image(path);
pp::platform::legacy::active_legacy_web_platform_services().publish_exported_image(path);
return;
}
if (!pp::platform::platform_publishes_exported_images(family))
@@ -336,7 +281,7 @@ public:
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_legacy_web_platform_services().flush_persistent_storage();
pp::platform::legacy::active_legacy_web_platform_services().flush_persistent_storage();
return;
}
if (!pp::platform::platform_flushes_persistent_storage(family))
@@ -505,7 +450,7 @@ public:
{
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
return active_legacy_web_platform_services().default_canvas_resolution();
return pp::platform::legacy::active_legacy_web_platform_services().default_canvas_resolution();
return pp::platform::platform_default_canvas_resolution(family);
}
@@ -584,7 +529,7 @@ public:
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_legacy_web_platform_services().save_prepared_file(
pp::platform::legacy::active_legacy_web_platform_services().save_prepared_file(
path,
suggested_name,
std::move(callback));

View File

@@ -10,6 +10,12 @@
#include <GLFW/glfw3.h>
#endif
void webgl_pick_file_save(
const std::string& path,
const std::string& name,
std::function<void(bool)> callback);
void webgl_sync();
namespace pp::platform::legacy {
namespace {
@@ -204,6 +210,43 @@ struct RetainedLegacyAppleDocumentPlatformState final {
}
#endif
class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices {
public:
void publish_exported_image(std::string_view path) override
{
(void)path;
}
void flush_persistent_storage() override
{
#ifdef __WEB__
webgl_sync();
#endif
}
[[nodiscard]] int default_canvas_resolution() override
{
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::webgl);
}
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback) override
{
const std::string value(path);
const std::string name(suggested_name);
#ifdef __WEB__
webgl_pick_file_save(value, name, [callback = std::move(callback), value](bool success) {
callback(value, success);
});
#else
(void)name;
callback(value, false);
#endif
}
};
}
#if defined(__LINUX__) || defined(__WEB__)
@@ -254,6 +297,17 @@ active_legacy_apple_document_platform_services()
return *retained.services;
}
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_legacy_apple_storage_paths()
{
const auto& apple_state = active_legacy_apple_state();
#ifdef __IOS__
[apple_state.ios_view init_dirs];
#elif defined(__OSX__)
[apple_state.osx_app init_dirs];
#endif
return active_legacy_storage_paths();
}
void set_legacy_apple_state(
#ifdef __IOS__
GameViewController* ios_view,
@@ -294,6 +348,12 @@ void set_legacy_apple_state(
}
#endif
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services()
{
static RetainedWebPlatformServices services;
return pp::platform::resolve_web_platform_services(services);
}
[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths()
{
return retained_legacy_storage_paths().storage_paths;

View File

@@ -50,6 +50,7 @@ struct RetainedLegacyAppleState final {
[[nodiscard]] RetainedLegacyAppleState& active_legacy_apple_state();
[[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices&
active_legacy_apple_document_platform_services();
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_legacy_apple_storage_paths();
void set_legacy_apple_state(
#ifdef __IOS__
GameViewController* ios_view,
@@ -61,6 +62,8 @@ void set_legacy_apple_state(
);
#endif
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();
[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths();
void set_legacy_storage_paths(pp::platform::PlatformStoragePaths paths);