Own Web platform services and remove legacy web state

This commit is contained in:
2026-06-17 15:42:03 +02:00
parent 9750c418bc
commit ab6436a38d
18 changed files with 165 additions and 194 deletions

View File

@@ -14,7 +14,6 @@
#ifdef _WIN32
#include "platform_windows/windows_platform_services.h"
#endif
#include "platform_legacy/legacy_platform_state.h"
#include "renderer_gl/opengl_capabilities.h"
namespace {

View File

@@ -7,7 +7,6 @@
#include "legacy_gl_runtime_dispatch.h"
#include "legacy_preference_storage.h"
#include "legacy_ui_gl_dispatch.h"
#include "platform_legacy/legacy_platform_state.h"
#include "platform_api/platform_services.h"
#include "renderer_gl/opengl_capabilities.h"

View File

@@ -1,6 +1,5 @@
#include "pch.h"
#include "platform_apple/apple_platform_services.h"
#include "platform_legacy/legacy_platform_state.h"
#include <memory>

View File

@@ -9,15 +9,6 @@
#include "platform_api/platform_policy.h"
#include "renderer_gl/opengl_capabilities.h"
#ifdef __WEB__
void webgl_pick_file(std::function<void(std::string)> callback);
void webgl_pick_file_save(
const std::string& path,
const std::string& name,
std::function<void(bool)> callback);
void webgl_sync();
#endif
namespace {
// DEBT-0017: retained non-Windows fallback adapter until each platform owns a
@@ -25,31 +16,13 @@ namespace {
class LegacyPlatformServices final : public pp::platform::PlatformServices {
public:
explicit LegacyPlatformServices(pp::platform::legacy::LegacyPlatformServicesConfig config = {})
: glfw_shell_(std::move(config.glfw_shell))
, web_platform_services_(config.web_platform_services)
{
(void)config;
}
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
{
#if __WEB__
const std::string data_path = "/PanoPainter";
mkdir(data_path.c_str(), 0777);
mkdir((data_path + "/brushes").c_str(), 0777);
mkdir((data_path + "/brushes/thumbs").c_str(), 0777);
mkdir((data_path + "/patterns").c_str(), 0777);
mkdir((data_path + "/patterns/thumbs").c_str(), 0777);
mkdir((data_path + "/settings").c_str(), 0777);
mkdir((data_path + "/frames").c_str(), 0777);
return {
data_path,
data_path,
data_path + "/frames",
{},
};
#else
return {};
#endif
}
void log_stacktrace() override
@@ -92,9 +65,6 @@ public:
void acquire_render_context() override
{
#if __WEB__
invoke_legacy_glfw_shell_callback(glfw_shell_.acquire_render_context);
#endif
}
void release_render_context() override
@@ -103,9 +73,6 @@ public:
void present_render_context() override
{
#if __WEB__
invoke_legacy_glfw_shell_callback(glfw_shell_.present_render_context);
#endif
}
void bind_default_render_target() override
@@ -150,11 +117,6 @@ public:
void publish_exported_image(std::string_view path) override
{
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_web_platform_services().publish_exported_image(path);
return;
}
if (!pp::platform::platform_publishes_exported_images(family))
{
(void)path;
@@ -166,11 +128,6 @@ public:
void flush_persistent_storage() override
{
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_web_platform_services().flush_persistent_storage();
return;
}
if (!pp::platform::platform_flushes_persistent_storage(family))
return;
}
@@ -209,21 +166,13 @@ public:
void pick_image(pp::platform::PickedPathCallback callback) override
{
#ifdef __WEB__
webgl_pick_file(callback);
#else
(void)callback;
#endif
}
void pick_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
{
#ifdef __WEB__
webgl_pick_file(callback);
#else
(void)file_types;
(void)callback;
#endif
}
void pick_save_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
@@ -286,10 +235,8 @@ public:
[[nodiscard]] int default_canvas_resolution() override
{
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
return active_web_platform_services().default_canvas_resolution();
return pp::platform::platform_default_canvas_resolution(family);
return pp::platform::platform_default_canvas_resolution(
pp::platform::current_platform_family());
}
[[nodiscard]] bool draws_canvas_tip_for_pointer(
@@ -335,9 +282,6 @@ public:
void request_app_close() override
{
#if __WEB__
invoke_legacy_glfw_shell_callback(glfw_shell_.request_app_close);
#endif
}
[[nodiscard]] bool start_vr_mode() override
@@ -354,38 +298,12 @@ public:
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback) override
{
const auto family = pp::platform::current_platform_family();
if (family == pp::platform::PlatformFamily::webgl)
{
active_web_platform_services().save_prepared_file(
path,
suggested_name,
std::move(callback));
return;
}
const std::string value(path);
const std::string name(suggested_name);
(void)name;
callback(value, false);
}
private:
[[nodiscard]] pp::platform::WebPlatformServices& active_web_platform_services() const noexcept
{
if (web_platform_services_)
return *web_platform_services_;
return pp::platform::active_web_platform_services();
}
static void invoke_legacy_glfw_shell_callback(const std::function<void()>& callback)
{
if (callback)
callback();
}
pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell_;
pp::platform::WebPlatformServices* web_platform_services_ = nullptr;
};
}

View File

@@ -1,21 +1,12 @@
#pragma once
#include <functional>
#include <memory>
#include "platform_api/platform_services.h"
namespace pp::platform::legacy {
struct LegacyGlfwPlatformShell {
std::function<void()> acquire_render_context;
std::function<void()> present_render_context;
std::function<void()> request_app_close;
};
struct LegacyPlatformServicesConfig {
LegacyGlfwPlatformShell glfw_shell;
pp::platform::WebPlatformServices* web_platform_services = nullptr;
};
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(

View File

@@ -1,58 +0,0 @@
#include "pch.h"
#include "platform_legacy/legacy_platform_state.h"
#include "platform_api/platform_policy.h"
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 {
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
}
};
}
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_legacy_web_platform_services()
{
return std::make_unique<RetainedWebPlatformServices>();
}
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include <memory>
#include "platform_api/platform_services.h"
namespace pp::platform::legacy {
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_legacy_web_platform_services();
}

View File

@@ -0,0 +1,61 @@
#include "platform_web/web_platform_services.h"
#include "platform_api/platform_policy.h"
#include <memory>
#include <string>
#include <utility>
#if defined(__WEB__)
void webgl_pick_file_save(
const std::string& path,
const std::string& name,
std::function<void(bool)> callback);
void webgl_sync();
#endif
namespace pp::platform::web {
void WebPlatformServices::publish_exported_image(std::string_view path)
{
(void)path;
}
void WebPlatformServices::flush_persistent_storage()
{
#if defined(__WEB__)
webgl_sync();
#endif
}
[[nodiscard]] int WebPlatformServices::default_canvas_resolution()
{
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::webgl);
}
void WebPlatformServices::save_prepared_file(
std::string_view path,
std::string_view suggested_name,
PreparedFileCallback callback)
{
const std::string value(path);
const std::string name(suggested_name);
#if defined(__WEB__)
webgl_pick_file_save(
value,
name,
[callback = std::move(callback), value](bool success) {
callback(value, success);
});
#else
(void)name;
callback(value, false);
#endif
}
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_web_platform_services()
{
return std::make_unique<WebPlatformServices>();
}
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include "platform_api/platform_services.h"
#include <memory>
#include <string_view>
namespace pp::platform::web {
class WebPlatformServices final : public pp::platform::WebPlatformServices {
public:
void publish_exported_image(std::string_view path) override;
void flush_persistent_storage() override;
[[nodiscard]] int default_canvas_resolution() override;
void save_prepared_file(
std::string_view path,
std::string_view suggested_name,
PreparedFileCallback callback) override;
};
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_web_platform_services();
}