Own Web legacy platform services explicitly
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "pch.h"
|
||||
#include "platform_legacy/legacy_platform_services.h"
|
||||
#include "platform_legacy/legacy_platform_state.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -54,6 +53,7 @@ public:
|
||||
#ifdef __ANDROID__
|
||||
, android_storage_paths_(std::move(config.android_storage_paths))
|
||||
#endif
|
||||
, web_platform_services_(config.web_platform_services)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -272,8 +272,11 @@ public:
|
||||
void publish_exported_image(std::string_view path) override
|
||||
{
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
if (pp::platform::legacy::try_publish_legacy_web_exported_image(family, path))
|
||||
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;
|
||||
@@ -289,8 +292,11 @@ public:
|
||||
void flush_persistent_storage() override
|
||||
{
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
if (pp::platform::legacy::try_flush_legacy_web_persistent_storage(family))
|
||||
if (family == pp::platform::PlatformFamily::webgl)
|
||||
{
|
||||
active_web_platform_services().flush_persistent_storage();
|
||||
return;
|
||||
}
|
||||
if (!pp::platform::platform_flushes_persistent_storage(family))
|
||||
return;
|
||||
}
|
||||
@@ -456,9 +462,8 @@ public:
|
||||
[[nodiscard]] int default_canvas_resolution() override
|
||||
{
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
int resolution = 0;
|
||||
if (pp::platform::legacy::try_default_legacy_web_canvas_resolution(family, resolution))
|
||||
return resolution;
|
||||
if (family == pp::platform::PlatformFamily::webgl)
|
||||
return active_web_platform_services().default_canvas_resolution();
|
||||
return pp::platform::platform_default_canvas_resolution(family);
|
||||
}
|
||||
|
||||
@@ -535,12 +540,14 @@ public:
|
||||
pp::platform::PreparedFileCallback callback) override
|
||||
{
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
if (pp::platform::legacy::try_save_legacy_web_prepared_file(
|
||||
family,
|
||||
if (family == pp::platform::PlatformFamily::webgl)
|
||||
{
|
||||
active_web_platform_services().save_prepared_file(
|
||||
path,
|
||||
suggested_name,
|
||||
std::move(callback)))
|
||||
std::move(callback));
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string value(path);
|
||||
const std::string name(suggested_name);
|
||||
@@ -556,6 +563,13 @@ public:
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -566,6 +580,7 @@ private:
|
||||
#ifdef __ANDROID__
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths_;
|
||||
#endif
|
||||
pp::platform::WebPlatformServices* web_platform_services_ = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ struct LegacyGlfwPlatformShell {
|
||||
struct LegacyPlatformServicesConfig {
|
||||
LegacyGlfwPlatformShell glfw_shell;
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths;
|
||||
pp::platform::WebPlatformServices* web_platform_services = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(
|
||||
|
||||
@@ -50,90 +50,9 @@ public:
|
||||
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_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>();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept
|
||||
{
|
||||
return family == pp::platform::PlatformFamily::webgl;
|
||||
}
|
||||
|
||||
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,
|
||||
pp::platform::PreparedFileCallback callback)
|
||||
{
|
||||
active_legacy_web_platform_services().save_prepared_file(
|
||||
path,
|
||||
suggested_name,
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,33 +2,10 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
namespace pp::platform::legacy {
|
||||
|
||||
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();
|
||||
[[nodiscard]] std::unique_ptr<pp::platform::WebPlatformServices> create_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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user