Split Apple platform target and move platform state ownership
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#include "platform_legacy/legacy_platform_services.h"
|
||||
#include "platform_legacy/legacy_platform_state.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "platform_apple/apple_platform_services.h"
|
||||
@@ -36,13 +35,11 @@ void delete_all_files_in_path(const std::string& source_path);
|
||||
void save_image_library(const std::string& path);
|
||||
#endif
|
||||
#elif __LINUX__
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <tinyfiledialogs.h>
|
||||
#include "platform_linux/linux_platform_services.h"
|
||||
std::string linux_home_path();
|
||||
int mkpath(const std::string& dir, mode_t mode = DEFFILEMODE);
|
||||
#elif __WEB__
|
||||
#include <GLFW/glfw3.h>
|
||||
void webgl_pick_file(std::function<void(std::string)> callback);
|
||||
void webgl_pick_file_save(
|
||||
const std::string& path,
|
||||
@@ -95,43 +92,6 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__LINUX__) || defined(__WEB__)
|
||||
struct RetainedLegacyGlfwWindowHooks final {
|
||||
std::function<void()> acquire_render_context;
|
||||
std::function<void()> present_render_context;
|
||||
std::function<void()> request_app_close;
|
||||
};
|
||||
|
||||
struct RetainedLegacyGlfwWindowState final {
|
||||
decltype(App::I->glfw_window) window = nullptr;
|
||||
RetainedLegacyGlfwWindowHooks hooks;
|
||||
};
|
||||
|
||||
[[nodiscard]] RetainedLegacyGlfwWindowState& active_legacy_glfw_window_state()
|
||||
{
|
||||
static RetainedLegacyGlfwWindowState state = [] {
|
||||
RetainedLegacyGlfwWindowState retained;
|
||||
retained.window = App::I->glfw_window;
|
||||
retained.hooks.acquire_render_context = [window = retained.window] {
|
||||
glfwMakeContextCurrent(window);
|
||||
};
|
||||
retained.hooks.present_render_context = [window = retained.window] {
|
||||
glfwSwapBuffers(window);
|
||||
};
|
||||
retained.hooks.request_app_close = [window = retained.window] {
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
};
|
||||
return retained;
|
||||
}();
|
||||
return state;
|
||||
}
|
||||
|
||||
[[nodiscard]] RetainedLegacyGlfwWindowHooks& active_legacy_glfw_window_hooks()
|
||||
{
|
||||
return active_legacy_glfw_window_state().hooks;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
[[nodiscard]] NSMutableArray<NSString*>* apple_file_types_array(const std::vector<std::string>& file_types)
|
||||
{
|
||||
@@ -143,47 +103,21 @@ struct RetainedLegacyGlfwWindowState final {
|
||||
return types;
|
||||
}
|
||||
|
||||
struct RetainedLegacyAppleState final {
|
||||
#ifdef __IOS__
|
||||
decltype(App::I->ios_view) ios_view = nullptr;
|
||||
decltype(App::I->ios_app) ios_app = nullptr;
|
||||
#elif defined(__OSX__)
|
||||
decltype(App::I->osx_view) osx_view = nullptr;
|
||||
decltype(App::I->osx_app) osx_app = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
[[nodiscard]] RetainedLegacyAppleState& active_legacy_apple_state()
|
||||
{
|
||||
static RetainedLegacyAppleState state = [] {
|
||||
RetainedLegacyAppleState retained;
|
||||
#ifdef __IOS__
|
||||
retained.ios_view = App::I->ios_view;
|
||||
retained.ios_app = App::I->ios_app;
|
||||
#elif defined(__OSX__)
|
||||
retained.osx_view = App::I->osx_view;
|
||||
retained.osx_app = App::I->osx_app;
|
||||
#endif
|
||||
return retained;
|
||||
}();
|
||||
return state;
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::PlatformStoragePaths prepare_legacy_apple_storage_paths()
|
||||
{
|
||||
const auto& apple_state = active_legacy_apple_state();
|
||||
const auto& apple_state = pp::platform::legacy::active_legacy_apple_state();
|
||||
#ifdef __IOS__
|
||||
[apple_state.ios_view init_dirs];
|
||||
#elif defined(__OSX__)
|
||||
[apple_state.osx_app init_dirs];
|
||||
#endif
|
||||
return active_legacy_storage_paths();
|
||||
return pp::platform::legacy::active_legacy_storage_paths();
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::platform::apple::AppleDocumentPlatformServices& active_apple_document_platform_services()
|
||||
{
|
||||
#ifdef __IOS__
|
||||
const auto& apple_state = active_legacy_apple_state();
|
||||
const auto& apple_state = pp::platform::legacy::active_legacy_apple_state();
|
||||
auto* const ios_view = apple_state.ios_view;
|
||||
auto* const ios_app = apple_state.ios_app;
|
||||
static pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
@@ -259,7 +193,7 @@ struct RetainedLegacyAppleState final {
|
||||
}());
|
||||
return services;
|
||||
#else
|
||||
const auto& apple_state = active_legacy_apple_state();
|
||||
const auto& apple_state = pp::platform::legacy::active_legacy_apple_state();
|
||||
auto* const osx_view = apple_state.osx_view;
|
||||
auto* const osx_app = apple_state.osx_app;
|
||||
static pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
@@ -470,7 +404,7 @@ public:
|
||||
#elif __ANDROID__
|
||||
android_async_lock();
|
||||
#elif __LINUX__ || __WEB__
|
||||
active_legacy_glfw_window_hooks().acquire_render_context();
|
||||
pp::platform::legacy::active_legacy_glfw_window_hooks().acquire_render_context();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -490,7 +424,7 @@ public:
|
||||
#elif __ANDROID__
|
||||
android_async_swap();
|
||||
#elif __LINUX__ || __WEB__
|
||||
active_legacy_glfw_window_hooks().present_render_context();
|
||||
pp::platform::legacy::active_legacy_glfw_window_hooks().present_render_context();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -801,7 +735,7 @@ public:
|
||||
#ifdef __OSX__
|
||||
active_apple_document_platform_services().request_app_close();
|
||||
#elif __LINUX__
|
||||
active_legacy_glfw_window_hooks().request_app_close();
|
||||
pp::platform::legacy::active_legacy_glfw_window_hooks().request_app_close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user