Extract platform policy catalog
This commit is contained in:
133
src/platform_api/platform_policy.cpp
Normal file
133
src/platform_api/platform_policy.cpp
Normal 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 {};
|
||||
}
|
||||
|
||||
}
|
||||
51
src/platform_api/platform_policy.h
Normal file
51
src/platform_api/platform_policy.h
Normal 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);
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "log.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@@ -288,11 +289,8 @@ public:
|
||||
|
||||
[[nodiscard]] bool deletes_recorded_files_on_clear() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_deletes_recorded_files_on_clear(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
void clear_recorded_files(std::string_view recording_path) override
|
||||
@@ -306,6 +304,11 @@ public:
|
||||
|
||||
void publish_exported_image(std::string_view path) override
|
||||
{
|
||||
if (!pp::platform::platform_publishes_exported_images(pp::platform::current_platform_family()))
|
||||
{
|
||||
(void)path;
|
||||
return;
|
||||
}
|
||||
#ifdef __IOS__
|
||||
save_image_library(std::string(path));
|
||||
#else
|
||||
@@ -315,6 +318,8 @@ public:
|
||||
|
||||
void flush_persistent_storage() override
|
||||
{
|
||||
if (!pp::platform::platform_flushes_persistent_storage(pp::platform::current_platform_family()))
|
||||
return;
|
||||
#ifdef __WEB__
|
||||
webgl_sync();
|
||||
#endif
|
||||
@@ -324,15 +329,10 @@ public:
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
return {
|
||||
std::string(work_path),
|
||||
std::string(data_path) + "/Inbox",
|
||||
};
|
||||
#else
|
||||
(void)data_path;
|
||||
return { std::string(work_path) };
|
||||
#endif
|
||||
return pp::platform::platform_document_browse_roots(
|
||||
pp::platform::current_platform_family(),
|
||||
work_path,
|
||||
data_path);
|
||||
}
|
||||
|
||||
void save_ui_state() override
|
||||
@@ -344,11 +344,8 @@ public:
|
||||
|
||||
[[nodiscard]] bool enables_live_asset_reloading() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_enables_live_asset_reloading(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
void update_platform_frame(float delta_time_seconds) override
|
||||
@@ -455,11 +452,8 @@ public:
|
||||
|
||||
[[nodiscard]] bool supports_working_directory_picker() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_supports_working_directory_picker(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) override
|
||||
@@ -474,20 +468,14 @@ public:
|
||||
|
||||
[[nodiscard]] bool uses_prepared_file_writes() override
|
||||
{
|
||||
#if __IOS__ || __WEB__
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_uses_prepared_file_writes(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
[[nodiscard]] bool uses_work_directory_document_export_collections() override
|
||||
{
|
||||
#if __IOS__
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_uses_work_directory_document_export_collections(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
[[nodiscard]] bool disables_network_tls_verification() override
|
||||
@@ -497,20 +485,13 @@ public:
|
||||
|
||||
[[nodiscard]] bool uses_ppbr_export_data_directory_override() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_uses_ppbr_export_data_directory_override(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
[[nodiscard]] bool supports_sonarpen() override
|
||||
{
|
||||
#if __IOS__
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return pp::platform::platform_supports_sonarpen(pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
void start_sonarpen() override
|
||||
@@ -522,11 +503,8 @@ public:
|
||||
|
||||
[[nodiscard]] int default_canvas_resolution() override
|
||||
{
|
||||
#if __WEB__
|
||||
return 512;
|
||||
#else
|
||||
return 1536;
|
||||
#endif
|
||||
return pp::platform::platform_default_canvas_resolution(
|
||||
pp::platform::current_platform_family());
|
||||
}
|
||||
|
||||
[[nodiscard]] bool draws_canvas_tip_for_pointer(
|
||||
@@ -534,13 +512,11 @@ public:
|
||||
bool is_stylus,
|
||||
bool is_left_button_release) override
|
||||
{
|
||||
#if defined(__IOS__)
|
||||
(void)is_stylus;
|
||||
return is_mouse && !is_left_button_release;
|
||||
#else
|
||||
(void)is_left_button_release;
|
||||
return is_mouse || is_stylus;
|
||||
#endif
|
||||
return pp::platform::platform_draws_canvas_tip_for_pointer(
|
||||
pp::platform::current_platform_family(),
|
||||
is_mouse,
|
||||
is_stylus,
|
||||
is_left_button_release);
|
||||
}
|
||||
|
||||
[[nodiscard]] float adjust_canvas_input_pressure(float pressure) override
|
||||
@@ -554,26 +530,12 @@ public:
|
||||
std::string_view data_path,
|
||||
std::string_view temporary_path) override
|
||||
{
|
||||
const std::string name = std::string(default_name) + "." + std::string(type);
|
||||
#ifdef __IOS__
|
||||
(void)data_path;
|
||||
return {
|
||||
std::string(temporary_path) + "/" + name,
|
||||
name,
|
||||
true,
|
||||
};
|
||||
#elif __WEB__
|
||||
(void)temporary_path;
|
||||
return {
|
||||
std::string(data_path) + "/" + name,
|
||||
name,
|
||||
false,
|
||||
};
|
||||
#else
|
||||
(void)data_path;
|
||||
(void)temporary_path;
|
||||
return {};
|
||||
#endif
|
||||
return pp::platform::plan_platform_writable_file(
|
||||
pp::platform::current_platform_family(),
|
||||
type,
|
||||
default_name,
|
||||
data_path,
|
||||
temporary_path);
|
||||
}
|
||||
|
||||
void display_file(std::string_view path) override
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#include <deque>
|
||||
@@ -368,7 +369,7 @@ public:
|
||||
|
||||
[[nodiscard]] bool deletes_recorded_files_on_clear() override
|
||||
{
|
||||
return false;
|
||||
return pp::platform::platform_deletes_recorded_files_on_clear(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
void clear_recorded_files(std::string_view recording_path) override
|
||||
@@ -378,19 +379,28 @@ public:
|
||||
|
||||
void publish_exported_image(std::string_view path) override
|
||||
{
|
||||
if (!pp::platform::platform_publishes_exported_images(pp::platform::PlatformFamily::windows))
|
||||
{
|
||||
(void)path;
|
||||
return;
|
||||
}
|
||||
(void)path;
|
||||
}
|
||||
|
||||
void flush_persistent_storage() override
|
||||
{
|
||||
if (!pp::platform::platform_flushes_persistent_storage(pp::platform::PlatformFamily::windows))
|
||||
return;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<std::string> document_browse_roots(
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) override
|
||||
{
|
||||
(void)data_path;
|
||||
return { std::string(work_path) };
|
||||
return pp::platform::platform_document_browse_roots(
|
||||
pp::platform::PlatformFamily::windows,
|
||||
work_path,
|
||||
data_path);
|
||||
}
|
||||
|
||||
void save_ui_state() override
|
||||
@@ -400,7 +410,7 @@ public:
|
||||
|
||||
[[nodiscard]] bool enables_live_asset_reloading() override
|
||||
{
|
||||
return true;
|
||||
return pp::platform::platform_enables_live_asset_reloading(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
void update_platform_frame(float delta_time_seconds) override
|
||||
@@ -466,7 +476,7 @@ public:
|
||||
|
||||
[[nodiscard]] bool supports_working_directory_picker() override
|
||||
{
|
||||
return true;
|
||||
return pp::platform::platform_supports_working_directory_picker(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) override
|
||||
@@ -484,12 +494,13 @@ public:
|
||||
|
||||
[[nodiscard]] bool uses_prepared_file_writes() override
|
||||
{
|
||||
return false;
|
||||
return pp::platform::platform_uses_prepared_file_writes(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool uses_work_directory_document_export_collections() override
|
||||
{
|
||||
return false;
|
||||
return pp::platform::platform_uses_work_directory_document_export_collections(
|
||||
pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool disables_network_tls_verification() override
|
||||
@@ -499,12 +510,13 @@ public:
|
||||
|
||||
[[nodiscard]] bool uses_ppbr_export_data_directory_override() override
|
||||
{
|
||||
return false;
|
||||
return pp::platform::platform_uses_ppbr_export_data_directory_override(
|
||||
pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool supports_sonarpen() override
|
||||
{
|
||||
return false;
|
||||
return pp::platform::platform_supports_sonarpen(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
void start_sonarpen() override
|
||||
@@ -513,7 +525,7 @@ public:
|
||||
|
||||
[[nodiscard]] int default_canvas_resolution() override
|
||||
{
|
||||
return 1536;
|
||||
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::windows);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool draws_canvas_tip_for_pointer(
|
||||
@@ -521,8 +533,11 @@ public:
|
||||
bool is_stylus,
|
||||
bool is_left_button_release) override
|
||||
{
|
||||
(void)is_left_button_release;
|
||||
return is_mouse || is_stylus;
|
||||
return pp::platform::platform_draws_canvas_tip_for_pointer(
|
||||
pp::platform::PlatformFamily::windows,
|
||||
is_mouse,
|
||||
is_stylus,
|
||||
is_left_button_release);
|
||||
}
|
||||
|
||||
[[nodiscard]] float adjust_canvas_input_pressure(float pressure) override
|
||||
@@ -539,11 +554,12 @@ public:
|
||||
std::string_view data_path,
|
||||
std::string_view temporary_path) override
|
||||
{
|
||||
(void)type;
|
||||
(void)default_name;
|
||||
(void)data_path;
|
||||
(void)temporary_path;
|
||||
return {};
|
||||
return pp::platform::plan_platform_writable_file(
|
||||
pp::platform::PlatformFamily::windows,
|
||||
type,
|
||||
default_name,
|
||||
data_path,
|
||||
temporary_path);
|
||||
}
|
||||
|
||||
void save_prepared_file(
|
||||
|
||||
Reference in New Issue
Block a user