Own Apple platform services and thin Win32 lifecycle shell
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
#include "platform_apple/apple_platform_services.h"
|
||||
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "objc_utils.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace pp::platform::apple {
|
||||
@@ -31,6 +40,25 @@ void invoke_picked_path_if_selected(
|
||||
callback(path);
|
||||
}
|
||||
|
||||
[[nodiscard]] AppleDocumentPlatformServices& active_document_platform_services() noexcept
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
return active_legacy_apple_document_platform_services();
|
||||
#else
|
||||
static AppleDocumentPlatformServices services(PlatformFamily::macos, {});
|
||||
return services;
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] PlatformFamily active_platform_family() noexcept
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
return legacy_apple_platform_family();
|
||||
#else
|
||||
return PlatformFamily::macos;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AppleDocumentPlatformServices::AppleDocumentPlatformServices(
|
||||
@@ -254,4 +282,305 @@ void AppleDocumentPlatformServices::save_ui_state() const
|
||||
#endif
|
||||
}
|
||||
|
||||
PlatformStoragePaths ApplePlatformServices::prepare_storage_paths()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
return prepare_legacy_apple_storage_paths();
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::log_stacktrace()
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
NSString* callstack = [[NSThread callStackSymbols] componentsJoinedByString:@"\n"];
|
||||
LOG("callstack:\n%s", [callstack cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::trigger_crash_test()
|
||||
{
|
||||
active_document_platform_services().trigger_crash_test();
|
||||
}
|
||||
|
||||
std::string ApplePlatformServices::clipboard_text()
|
||||
{
|
||||
return active_document_platform_services().clipboard_text();
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::set_clipboard_text(std::string_view text)
|
||||
{
|
||||
return active_document_platform_services().set_clipboard_text(text);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::set_cursor_visible(bool visible)
|
||||
{
|
||||
active_document_platform_services().set_cursor_visible(visible);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::set_virtual_keyboard_visible(bool visible)
|
||||
{
|
||||
active_document_platform_services().set_virtual_keyboard_visible(visible);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::attach_ui_thread()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplePlatformServices::detach_ui_thread()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplePlatformServices::acquire_render_context()
|
||||
{
|
||||
active_document_platform_services().acquire_render_context();
|
||||
}
|
||||
|
||||
void ApplePlatformServices::release_render_context()
|
||||
{
|
||||
active_document_platform_services().release_render_context();
|
||||
}
|
||||
|
||||
void ApplePlatformServices::present_render_context()
|
||||
{
|
||||
active_document_platform_services().present_render_context();
|
||||
}
|
||||
|
||||
void ApplePlatformServices::bind_default_render_target()
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
pp::legacy::ui_gl::bind_opengl_framebuffer(
|
||||
pp::renderer::gl::framebuffer_target(),
|
||||
pp::renderer::gl::default_framebuffer_id());
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::bind_main_render_target()
|
||||
{
|
||||
#if defined(__IOS__)
|
||||
active_document_platform_services().bind_main_render_target();
|
||||
#else
|
||||
bind_default_render_target();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::apply_render_platform_hints()
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
const auto status = pp::renderer::gl::apply_opengl_render_platform_hints(
|
||||
pp::renderer::gl::OpenGlRenderPlatformHintDispatch {
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL legacy render platform hints failed: %s", status.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::install_render_debug_callback()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplePlatformServices::begin_render_capture_frame()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplePlatformServices::end_render_capture_frame()
|
||||
{
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::deletes_recorded_files_on_clear()
|
||||
{
|
||||
return platform_deletes_recorded_files_on_clear(active_platform_family());
|
||||
}
|
||||
|
||||
void ApplePlatformServices::clear_recorded_files(std::string_view recording_path)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
delete_all_files_in_path(std::string(recording_path));
|
||||
#else
|
||||
(void)recording_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::publish_exported_image(std::string_view path)
|
||||
{
|
||||
if (!platform_publishes_exported_images(active_platform_family()))
|
||||
return;
|
||||
#if defined(__IOS__)
|
||||
save_image_library(std::string(path));
|
||||
#else
|
||||
(void)path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplePlatformServices::flush_persistent_storage()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> ApplePlatformServices::document_browse_roots(
|
||||
std::string_view work_path,
|
||||
std::string_view data_path)
|
||||
{
|
||||
return active_document_platform_services().document_browse_roots(work_path, data_path);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::save_ui_state()
|
||||
{
|
||||
if (!platform_saves_native_ui_state(active_platform_family()))
|
||||
return;
|
||||
active_document_platform_services().save_ui_state();
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::enables_live_asset_reloading()
|
||||
{
|
||||
return platform_enables_live_asset_reloading(active_platform_family());
|
||||
}
|
||||
|
||||
void ApplePlatformServices::update_platform_frame(float delta_time_seconds)
|
||||
{
|
||||
(void)delta_time_seconds;
|
||||
}
|
||||
|
||||
void ApplePlatformServices::report_rendered_frames(int frames)
|
||||
{
|
||||
(void)frames;
|
||||
}
|
||||
|
||||
void ApplePlatformServices::pick_image(PickedPathCallback callback)
|
||||
{
|
||||
active_document_platform_services().pick_image(std::move(callback));
|
||||
}
|
||||
|
||||
void ApplePlatformServices::pick_file(std::vector<std::string> file_types, PickedPathCallback callback)
|
||||
{
|
||||
active_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
}
|
||||
|
||||
void ApplePlatformServices::pick_save_file(std::vector<std::string> file_types, PickedPathCallback callback)
|
||||
{
|
||||
active_document_platform_services().pick_save_file(std::move(file_types), std::move(callback));
|
||||
}
|
||||
|
||||
void ApplePlatformServices::pick_directory(PickedPathCallback callback)
|
||||
{
|
||||
active_document_platform_services().pick_directory(std::move(callback));
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::supports_working_directory_picker()
|
||||
{
|
||||
return active_document_platform_services().supports_working_directory_picker();
|
||||
}
|
||||
|
||||
std::string ApplePlatformServices::format_working_directory_path(std::string_view path)
|
||||
{
|
||||
return active_document_platform_services().format_working_directory_path(path);
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::uses_prepared_file_writes()
|
||||
{
|
||||
return platform_uses_prepared_file_writes(active_platform_family());
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::uses_work_directory_document_export_collections()
|
||||
{
|
||||
return platform_uses_work_directory_document_export_collections(active_platform_family());
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::disables_network_tls_verification()
|
||||
{
|
||||
return default_disables_network_tls_verification();
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::uses_ppbr_export_data_directory_override()
|
||||
{
|
||||
return platform_uses_ppbr_export_data_directory_override(active_platform_family());
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::supports_sonarpen()
|
||||
{
|
||||
return platform_supports_sonarpen(active_platform_family());
|
||||
}
|
||||
|
||||
void ApplePlatformServices::start_sonarpen()
|
||||
{
|
||||
active_document_platform_services().start_sonarpen();
|
||||
}
|
||||
|
||||
int ApplePlatformServices::default_canvas_resolution()
|
||||
{
|
||||
return platform_default_canvas_resolution(active_platform_family());
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::draws_canvas_tip_for_pointer(
|
||||
bool is_mouse,
|
||||
bool is_stylus,
|
||||
bool is_left_button_release)
|
||||
{
|
||||
return platform_draws_canvas_tip_for_pointer(
|
||||
active_platform_family(),
|
||||
is_mouse,
|
||||
is_stylus,
|
||||
is_left_button_release);
|
||||
}
|
||||
|
||||
float ApplePlatformServices::adjust_canvas_input_pressure(float pressure)
|
||||
{
|
||||
return pressure;
|
||||
}
|
||||
|
||||
PreparedFileTarget ApplePlatformServices::prepare_writable_file(
|
||||
std::string_view type,
|
||||
std::string_view default_name,
|
||||
std::string_view data_path,
|
||||
std::string_view temporary_path)
|
||||
{
|
||||
return plan_platform_writable_file(
|
||||
active_platform_family(),
|
||||
type,
|
||||
default_name,
|
||||
data_path,
|
||||
temporary_path);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::display_file(std::string_view path)
|
||||
{
|
||||
active_document_platform_services().display_file(path);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::share_file(std::string_view path)
|
||||
{
|
||||
active_document_platform_services().share_file(path);
|
||||
}
|
||||
|
||||
void ApplePlatformServices::request_app_close()
|
||||
{
|
||||
active_document_platform_services().request_app_close();
|
||||
}
|
||||
|
||||
bool ApplePlatformServices::start_vr_mode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ApplePlatformServices::stop_vr_mode()
|
||||
{
|
||||
}
|
||||
|
||||
void ApplePlatformServices::save_prepared_file(
|
||||
std::string_view path,
|
||||
std::string_view suggested_name,
|
||||
PreparedFileCallback callback)
|
||||
{
|
||||
active_document_platform_services().save_prepared_file(
|
||||
path,
|
||||
suggested_name,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformServices> create_apple_platform_services()
|
||||
{
|
||||
return std::make_unique<ApplePlatformServices>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -95,6 +96,74 @@ private:
|
||||
AppleDocumentPickerBridge bridge_;
|
||||
};
|
||||
|
||||
class ApplePlatformServices final : public PlatformServices {
|
||||
public:
|
||||
ApplePlatformServices() = default;
|
||||
|
||||
[[nodiscard]] PlatformStoragePaths prepare_storage_paths() override;
|
||||
void log_stacktrace() override;
|
||||
void trigger_crash_test() override;
|
||||
[[nodiscard]] std::string clipboard_text() override;
|
||||
[[nodiscard]] bool set_clipboard_text(std::string_view text) override;
|
||||
void set_cursor_visible(bool visible) override;
|
||||
void set_virtual_keyboard_visible(bool visible) override;
|
||||
void attach_ui_thread() override;
|
||||
void detach_ui_thread() override;
|
||||
void acquire_render_context() override;
|
||||
void release_render_context() override;
|
||||
void present_render_context() override;
|
||||
void bind_default_render_target() override;
|
||||
void bind_main_render_target() override;
|
||||
void apply_render_platform_hints() override;
|
||||
void install_render_debug_callback() override;
|
||||
void begin_render_capture_frame() override;
|
||||
void end_render_capture_frame() override;
|
||||
[[nodiscard]] bool deletes_recorded_files_on_clear() override;
|
||||
void clear_recorded_files(std::string_view recording_path) override;
|
||||
void publish_exported_image(std::string_view path) override;
|
||||
void flush_persistent_storage() override;
|
||||
[[nodiscard]] std::vector<std::string> document_browse_roots(
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) override;
|
||||
void save_ui_state() override;
|
||||
[[nodiscard]] bool enables_live_asset_reloading() override;
|
||||
void update_platform_frame(float delta_time_seconds) override;
|
||||
void report_rendered_frames(int frames) override;
|
||||
void pick_image(PickedPathCallback callback) override;
|
||||
void pick_file(std::vector<std::string> file_types, PickedPathCallback callback) override;
|
||||
void pick_save_file(std::vector<std::string> file_types, PickedPathCallback callback) override;
|
||||
void pick_directory(PickedPathCallback callback) override;
|
||||
[[nodiscard]] bool supports_working_directory_picker() override;
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) override;
|
||||
[[nodiscard]] bool uses_prepared_file_writes() override;
|
||||
[[nodiscard]] bool uses_work_directory_document_export_collections() override;
|
||||
[[nodiscard]] bool disables_network_tls_verification() override;
|
||||
[[nodiscard]] bool uses_ppbr_export_data_directory_override() override;
|
||||
[[nodiscard]] bool supports_sonarpen() override;
|
||||
void start_sonarpen() override;
|
||||
[[nodiscard]] int default_canvas_resolution() override;
|
||||
[[nodiscard]] bool draws_canvas_tip_for_pointer(
|
||||
bool is_mouse,
|
||||
bool is_stylus,
|
||||
bool is_left_button_release) override;
|
||||
[[nodiscard]] float adjust_canvas_input_pressure(float pressure) override;
|
||||
[[nodiscard]] PreparedFileTarget prepare_writable_file(
|
||||
std::string_view type,
|
||||
std::string_view default_name,
|
||||
std::string_view data_path,
|
||||
std::string_view temporary_path) override;
|
||||
void display_file(std::string_view path) override;
|
||||
void share_file(std::string_view path) override;
|
||||
void request_app_close() override;
|
||||
[[nodiscard]] bool start_vr_mode() override;
|
||||
void stop_vr_mode() override;
|
||||
void save_prepared_file(
|
||||
std::string_view path,
|
||||
std::string_view suggested_name,
|
||||
PreparedFileCallback callback) override;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_apple_platform_services();
|
||||
[[nodiscard]] RetainedLegacyAppleState& active_legacy_apple_state();
|
||||
[[nodiscard]] AppleDocumentPlatformServices&
|
||||
active_legacy_apple_document_platform_services();
|
||||
|
||||
@@ -5,19 +5,12 @@
|
||||
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "platform_apple/apple_platform_services.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "main.h"
|
||||
#elif __APPLE__
|
||||
#include <Foundation/Foundation.h>
|
||||
void delete_all_files_in_path(const std::string& source_path);
|
||||
#ifdef __IOS__
|
||||
void save_image_library(const std::string& path);
|
||||
#endif
|
||||
#elif __LINUX__
|
||||
#include <tinyfiledialogs.h>
|
||||
#include "platform_linux/linux_platform_services.h"
|
||||
@@ -45,17 +38,12 @@ public:
|
||||
, android_storage_paths_(std::move(config.android_storage_paths))
|
||||
#endif
|
||||
, web_platform_services_(config.web_platform_services)
|
||||
, apple_document_services_(std::move(config.apple_document_services))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_storage_paths() override
|
||||
{
|
||||
#if defined(__IOS__)
|
||||
return pp::platform::apple::prepare_legacy_apple_storage_paths();
|
||||
#elif defined(__OSX__)
|
||||
return pp::platform::apple::prepare_legacy_apple_storage_paths();
|
||||
#elif __LINUX__
|
||||
#if __LINUX__
|
||||
const std::string data_path = linux_home_path() + "/PanoPainter";
|
||||
mkpath(data_path + "/brushes");
|
||||
mkpath(data_path + "/brushes/thumbs");
|
||||
@@ -93,19 +81,11 @@ public:
|
||||
|
||||
void log_stacktrace() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
NSString* callstack = [[NSThread callStackSymbols] componentsJoinedByString:@"\n"];
|
||||
LOG("callstack:\n%s", [callstack cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger_crash_test() override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
active_apple_document_platform_services().trigger_crash_test();
|
||||
#elif __OSX__
|
||||
active_apple_document_platform_services().trigger_crash_test();
|
||||
#elif defined(__ANDROID__)
|
||||
#if defined(__ANDROID__)
|
||||
int *x = nullptr; *x = 42;
|
||||
LOG("%d", *x);
|
||||
#endif
|
||||
@@ -113,11 +93,6 @@ public:
|
||||
|
||||
[[nodiscard]] std::string clipboard_text() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
if (family == pp::platform::PlatformFamily::ios || family == pp::platform::PlatformFamily::macos)
|
||||
return active_apple_document_platform_services().clipboard_text();
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
if (android_bridge_.clipboard_text)
|
||||
return android_bridge_.clipboard_text();
|
||||
@@ -129,11 +104,6 @@ public:
|
||||
|
||||
[[nodiscard]] bool set_clipboard_text(std::string_view text) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
const auto family = pp::platform::current_platform_family();
|
||||
if (family == pp::platform::PlatformFamily::ios || family == pp::platform::PlatformFamily::macos)
|
||||
return active_apple_document_platform_services().set_clipboard_text(text);
|
||||
#endif
|
||||
const std::string value(text);
|
||||
#ifdef __ANDROID__
|
||||
if (android_bridge_.set_clipboard_text)
|
||||
@@ -147,18 +117,12 @@ public:
|
||||
|
||||
void set_cursor_visible(bool visible) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().set_cursor_visible(visible);
|
||||
#else
|
||||
(void)visible;
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_virtual_keyboard_visible(bool visible) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
active_apple_document_platform_services().set_virtual_keyboard_visible(visible);
|
||||
#elif __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
if (android_bridge_.set_virtual_keyboard_visible)
|
||||
android_bridge_.set_virtual_keyboard_visible(visible);
|
||||
#else
|
||||
@@ -184,9 +148,7 @@ public:
|
||||
|
||||
void acquire_render_context() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().acquire_render_context();
|
||||
#elif __ANDROID__
|
||||
#if __ANDROID__
|
||||
if (android_bridge_.acquire_render_context)
|
||||
android_bridge_.acquire_render_context();
|
||||
#elif __LINUX__ || __WEB__
|
||||
@@ -196,9 +158,7 @@ public:
|
||||
|
||||
void release_render_context() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().release_render_context();
|
||||
#elif __ANDROID__
|
||||
#if __ANDROID__
|
||||
if (android_bridge_.release_render_context)
|
||||
android_bridge_.release_render_context();
|
||||
#endif
|
||||
@@ -206,9 +166,7 @@ public:
|
||||
|
||||
void present_render_context() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().present_render_context();
|
||||
#elif __ANDROID__
|
||||
#if __ANDROID__
|
||||
if (android_bridge_.present_render_context)
|
||||
android_bridge_.present_render_context();
|
||||
#elif __LINUX__ || __WEB__
|
||||
@@ -225,23 +183,11 @@ public:
|
||||
|
||||
void bind_main_render_target() override
|
||||
{
|
||||
#if __IOS__
|
||||
active_apple_document_platform_services().bind_main_render_target();
|
||||
#else
|
||||
bind_default_render_target();
|
||||
#endif
|
||||
}
|
||||
|
||||
void apply_render_platform_hints() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
const auto status = pp::renderer::gl::apply_opengl_render_platform_hints(
|
||||
pp::renderer::gl::OpenGlRenderPlatformHintDispatch {
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL legacy render platform hints failed: %s", status.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void install_render_debug_callback() override
|
||||
@@ -264,11 +210,7 @@ public:
|
||||
|
||||
void clear_recorded_files(std::string_view recording_path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
delete_all_files_in_path(std::string(recording_path));
|
||||
#else
|
||||
(void)recording_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void publish_exported_image(std::string_view path) override
|
||||
@@ -284,11 +226,7 @@ public:
|
||||
(void)path;
|
||||
return;
|
||||
}
|
||||
#ifdef __IOS__
|
||||
save_image_library(std::string(path));
|
||||
#else
|
||||
(void)path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void flush_persistent_storage() override
|
||||
@@ -307,23 +245,16 @@ public:
|
||||
std::string_view work_path,
|
||||
std::string_view data_path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return active_apple_document_platform_services().document_browse_roots(work_path, data_path);
|
||||
#else
|
||||
return pp::platform::platform_document_browse_roots(
|
||||
pp::platform::current_platform_family(),
|
||||
work_path,
|
||||
data_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
void save_ui_state() override
|
||||
{
|
||||
if (!pp::platform::platform_saves_native_ui_state(pp::platform::current_platform_family()))
|
||||
return;
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().save_ui_state();
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] bool enables_live_asset_reloading() override
|
||||
@@ -348,11 +279,7 @@ public:
|
||||
|
||||
void pick_image(pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
active_apple_document_platform_services().pick_image(std::move(callback));
|
||||
#elif __OSX__
|
||||
active_apple_document_platform_services().pick_image(std::move(callback));
|
||||
#elif __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
if (android_bridge_.pick_file)
|
||||
android_bridge_.pick_file(std::move(callback));
|
||||
#elif __LINUX__
|
||||
@@ -367,11 +294,7 @@ public:
|
||||
|
||||
void pick_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
#elif __OSX__
|
||||
active_apple_document_platform_services().pick_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
if (android_bridge_.pick_file)
|
||||
android_bridge_.pick_file(std::move(callback));
|
||||
#elif __LINUX__
|
||||
@@ -387,9 +310,7 @@ public:
|
||||
|
||||
void pick_save_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#if __OSX__
|
||||
active_apple_document_platform_services().pick_save_file(std::move(file_types), std::move(callback));
|
||||
#elif __ANDROID__
|
||||
#if __ANDROID__
|
||||
if (android_bridge_.pick_save_file)
|
||||
android_bridge_.pick_save_file(std::move(callback));
|
||||
#else
|
||||
@@ -400,11 +321,7 @@ public:
|
||||
|
||||
void pick_directory(pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
#ifdef __IOS__
|
||||
(void)callback;
|
||||
#elif __OSX__
|
||||
active_apple_document_platform_services().pick_directory(std::move(callback));
|
||||
#elif __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
(void)callback;
|
||||
#else
|
||||
(void)callback;
|
||||
@@ -413,19 +330,12 @@ public:
|
||||
|
||||
[[nodiscard]] bool supports_working_directory_picker() override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return active_apple_document_platform_services().supports_working_directory_picker();
|
||||
#else
|
||||
return pp::platform::platform_supports_working_directory_picker(
|
||||
pp::platform::current_platform_family());
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string format_working_directory_path(std::string_view path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
return active_apple_document_platform_services().format_working_directory_path(path);
|
||||
#endif
|
||||
return std::string(path);
|
||||
}
|
||||
|
||||
@@ -459,9 +369,6 @@ public:
|
||||
|
||||
void start_sonarpen() override
|
||||
{
|
||||
#if __IOS__
|
||||
active_apple_document_platform_services().start_sonarpen();
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] int default_canvas_resolution() override
|
||||
@@ -505,27 +412,17 @@ public:
|
||||
|
||||
void display_file(std::string_view path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().display_file(path);
|
||||
#else
|
||||
(void)path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void share_file(std::string_view path) override
|
||||
{
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
active_apple_document_platform_services().share_file(path);
|
||||
#else
|
||||
(void)path;
|
||||
#endif
|
||||
}
|
||||
|
||||
void request_app_close() override
|
||||
{
|
||||
#ifdef __OSX__
|
||||
active_apple_document_platform_services().request_app_close();
|
||||
#elif __LINUX__
|
||||
#ifdef __LINUX__
|
||||
invoke_legacy_glfw_shell_callback(glfw_shell_.request_app_close);
|
||||
#endif
|
||||
}
|
||||
@@ -556,25 +453,11 @@ public:
|
||||
|
||||
const std::string value(path);
|
||||
const std::string name(suggested_name);
|
||||
#ifdef __IOS__
|
||||
active_apple_document_platform_services().save_prepared_file(
|
||||
value,
|
||||
name,
|
||||
std::move(callback));
|
||||
#else
|
||||
(void)name;
|
||||
callback(value, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices& active_apple_document_platform_services() const noexcept
|
||||
{
|
||||
if (apple_document_services_)
|
||||
return apple_document_services_();
|
||||
return pp::platform::apple::active_legacy_apple_document_platform_services();
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::WebPlatformServices& active_web_platform_services() const noexcept
|
||||
{
|
||||
if (web_platform_services_)
|
||||
@@ -594,7 +477,6 @@ private:
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths_;
|
||||
#endif
|
||||
pp::platform::WebPlatformServices* web_platform_services_ = nullptr;
|
||||
std::function<pp::platform::apple::AppleDocumentPlatformServices&()> apple_document_services_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "platform_api/platform_services.h"
|
||||
|
||||
namespace pp::platform::apple {
|
||||
class AppleDocumentPlatformServices;
|
||||
}
|
||||
|
||||
namespace pp::platform::legacy {
|
||||
|
||||
struct LegacyGlfwPlatformShell {
|
||||
@@ -35,7 +31,6 @@ struct LegacyPlatformServicesConfig {
|
||||
LegacyAndroidPlatformBridge android_bridge;
|
||||
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths;
|
||||
pp::platform::WebPlatformServices* web_platform_services = nullptr;
|
||||
std::function<pp::platform::apple::AppleDocumentPlatformServices&()> apple_document_services;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
|
||||
#include "platform_windows/windows_lifecycle_shell.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "legacy_preference_storage.h"
|
||||
#include "platform_windows/windows_lifecycle_state.h"
|
||||
#include "platform_windows/windows_main_window_session.h"
|
||||
#include "platform_windows/windows_runtime_shell.h"
|
||||
#include "platform_windows/windows_runtime_state.h"
|
||||
#include "platform_windows/windows_stylus_input.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
@@ -19,17 +16,7 @@ void request_window_close(HWND hWnd)
|
||||
|
||||
void handle_window_close_message(VrShellState& vr)
|
||||
{
|
||||
auto* app = bound_app();
|
||||
auto* runtime = retained_bound_runtime();
|
||||
mark_lifecycle_stopped();
|
||||
request_stop_and_join_vr_thread(vr);
|
||||
if (runtime)
|
||||
{
|
||||
runtime->ui_thread_stop();
|
||||
runtime->render_thread_stop();
|
||||
}
|
||||
app->terminate();
|
||||
release_bound_app();
|
||||
shutdown_bound_lifecycle(vr);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
@@ -64,12 +51,12 @@ void save_window_preferences(HWND hWnd)
|
||||
|
||||
bool start_window_vr(VrShellState& vr, bool sandboxed)
|
||||
{
|
||||
return start_vr_shell(vr, sandboxed, retained_lifecycle_running_state());
|
||||
return start_bound_lifecycle_vr(vr, sandboxed);
|
||||
}
|
||||
|
||||
void stop_window_vr(VrShellState& vr)
|
||||
{
|
||||
stop_vr_shell(vr);
|
||||
stop_bound_lifecycle_vr(vr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "platform_windows/windows_lifecycle_state.h"
|
||||
|
||||
#include "platform_windows/windows_runtime_state.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
namespace {
|
||||
|
||||
@@ -37,4 +39,21 @@ std::atomic<int>& retained_lifecycle_running_state() noexcept
|
||||
return retained_window_lifecycle_state().running;
|
||||
}
|
||||
|
||||
void shutdown_bound_lifecycle(VrShellState& vr)
|
||||
{
|
||||
mark_lifecycle_stopped();
|
||||
request_stop_and_join_vr_thread(vr);
|
||||
shutdown_bound_app_runtime();
|
||||
}
|
||||
|
||||
bool start_bound_lifecycle_vr(VrShellState& vr, bool sandboxed)
|
||||
{
|
||||
return start_vr_shell(vr, sandboxed, retained_lifecycle_running_state());
|
||||
}
|
||||
|
||||
void stop_bound_lifecycle_vr(VrShellState& vr)
|
||||
{
|
||||
stop_vr_shell(vr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "platform_windows/windows_vr_shell.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
|
||||
void mark_lifecycle_running() noexcept;
|
||||
void mark_lifecycle_stopped() noexcept;
|
||||
[[nodiscard]] bool lifecycle_is_running() noexcept;
|
||||
[[nodiscard]] std::atomic<int>& retained_lifecycle_running_state() noexcept;
|
||||
void shutdown_bound_lifecycle(VrShellState& vr);
|
||||
[[nodiscard]] bool start_bound_lifecycle_vr(VrShellState& vr, bool sandboxed);
|
||||
void stop_bound_lifecycle_vr(VrShellState& vr);
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,20 @@ void release_bound_app() noexcept
|
||||
retained_owned_app().reset();
|
||||
}
|
||||
|
||||
void shutdown_bound_app_runtime() noexcept
|
||||
{
|
||||
if (auto* runtime = retained_bound_runtime())
|
||||
{
|
||||
runtime->ui_thread_stop();
|
||||
runtime->render_thread_stop();
|
||||
}
|
||||
|
||||
if (auto* app = bound_app())
|
||||
app->terminate();
|
||||
|
||||
release_bound_app();
|
||||
}
|
||||
|
||||
WacomTablet* bound_wacom_tablet() noexcept
|
||||
{
|
||||
return &retained_wacom_tablet();
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace pp::platform::windows {
|
||||
void bind_app(App* app) noexcept;
|
||||
[[nodiscard]] App* bound_app() noexcept;
|
||||
void release_bound_app() noexcept;
|
||||
void shutdown_bound_app_runtime() noexcept;
|
||||
[[nodiscard]] WacomTablet* bound_wacom_tablet() noexcept;
|
||||
[[nodiscard]] std::unique_ptr<App>& retained_owned_app() noexcept;
|
||||
[[nodiscard]] WacomTablet& retained_wacom_tablet() noexcept;
|
||||
|
||||
Reference in New Issue
Block a user