Extract platform policy catalog

This commit is contained in:
2026-06-05 11:39:21 +02:00
parent ab3637af9c
commit b1d71f2621
9 changed files with 401 additions and 100 deletions

View File

@@ -0,0 +1,133 @@
#include "platform_api/platform_policy.h"
#include <string>
namespace pp::platform {
PlatformFamily current_platform_family() noexcept
{
#if defined(__IOS__)
return PlatformFamily::ios;
#elif defined(__OSX__)
return PlatformFamily::macos;
#elif defined(__ANDROID__)
return PlatformFamily::android;
#elif defined(__LINUX__)
return PlatformFamily::linux;
#elif defined(__WEB__)
return PlatformFamily::webgl;
#elif defined(_WIN32)
return PlatformFamily::windows;
#else
return PlatformFamily::generic_desktop;
#endif
}
bool platform_deletes_recorded_files_on_clear(PlatformFamily family) noexcept
{
return family == PlatformFamily::ios || family == PlatformFamily::macos;
}
bool platform_publishes_exported_images(PlatformFamily family) noexcept
{
return family == PlatformFamily::ios;
}
bool platform_flushes_persistent_storage(PlatformFamily family) noexcept
{
return family == PlatformFamily::webgl;
}
bool platform_enables_live_asset_reloading(PlatformFamily family) noexcept
{
return family == PlatformFamily::windows || family == PlatformFamily::macos;
}
bool platform_supports_working_directory_picker(PlatformFamily family) noexcept
{
return family == PlatformFamily::windows || family == PlatformFamily::macos;
}
bool platform_uses_prepared_file_writes(PlatformFamily family) noexcept
{
return family == PlatformFamily::ios || family == PlatformFamily::webgl;
}
bool platform_uses_work_directory_document_export_collections(PlatformFamily family) noexcept
{
return family == PlatformFamily::ios;
}
bool platform_uses_ppbr_export_data_directory_override(PlatformFamily family) noexcept
{
return family == PlatformFamily::macos;
}
bool platform_supports_sonarpen(PlatformFamily family) noexcept
{
return family == PlatformFamily::ios;
}
int platform_default_canvas_resolution(PlatformFamily family) noexcept
{
return family == PlatformFamily::webgl ? 512 : 1536;
}
bool platform_draws_canvas_tip_for_pointer(
PlatformFamily family,
bool is_mouse,
bool is_stylus,
bool is_left_button_release) noexcept
{
if (family == PlatformFamily::ios)
return is_mouse && !is_left_button_release;
return is_mouse || is_stylus;
}
std::vector<std::string> platform_document_browse_roots(
PlatformFamily family,
std::string_view work_path,
std::string_view data_path)
{
if (family == PlatformFamily::ios)
{
return {
std::string(work_path),
std::string(data_path) + "/Inbox",
};
}
return { std::string(work_path) };
}
PreparedFileTarget plan_platform_writable_file(
PlatformFamily family,
std::string_view type,
std::string_view default_name,
std::string_view data_path,
std::string_view temporary_path)
{
const std::string name = std::string(default_name) + "." + std::string(type);
if (family == PlatformFamily::ios)
{
return {
std::string(temporary_path) + "/" + name,
name,
true,
};
}
if (family == PlatformFamily::webgl)
{
return {
std::string(data_path) + "/" + name,
name,
false,
};
}
return {};
}
}

View File

@@ -0,0 +1,51 @@
#pragma once
#include "platform_api/platform_services.h"
#include <string_view>
#include <vector>
namespace pp::platform {
enum class PlatformFamily {
generic_desktop,
windows,
macos,
ios,
android,
linux,
webgl,
};
[[nodiscard]] PlatformFamily current_platform_family() noexcept;
[[nodiscard]] bool platform_deletes_recorded_files_on_clear(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_publishes_exported_images(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_flushes_persistent_storage(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_enables_live_asset_reloading(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_supports_working_directory_picker(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_uses_prepared_file_writes(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_uses_work_directory_document_export_collections(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_uses_ppbr_export_data_directory_override(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_supports_sonarpen(PlatformFamily family) noexcept;
[[nodiscard]] int platform_default_canvas_resolution(PlatformFamily family) noexcept;
[[nodiscard]] bool platform_draws_canvas_tip_for_pointer(
PlatformFamily family,
bool is_mouse,
bool is_stylus,
bool is_left_button_release) noexcept;
[[nodiscard]] std::vector<std::string> platform_document_browse_roots(
PlatformFamily family,
std::string_view work_path,
std::string_view data_path);
[[nodiscard]] PreparedFileTarget plan_platform_writable_file(
PlatformFamily family,
std::string_view type,
std::string_view default_name,
std::string_view data_path,
std::string_view temporary_path);
}