Own Apple platform services and thin Win32 lifecycle shell

This commit is contained in:
2026-06-17 14:39:18 +02:00
parent 065717f89b
commit 2f33b00b2a
14 changed files with 517 additions and 191 deletions

View File

@@ -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_;
};
}

View File

@@ -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(