diff --git a/android/src/cpp/main.cpp b/android/src/cpp/main.cpp index e2745bd1..0734aac6 100644 --- a/android/src/cpp/main.cpp +++ b/android/src/cpp/main.cpp @@ -71,6 +71,8 @@ std::recursive_mutex mutex; int mutex_count = 0; struct engine g_engine; thread_local JNIEnv* jni; +std::shared_ptr g_android_storage_paths = + std::make_shared(); jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) { @@ -276,12 +278,12 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCal App::I->data_path = file_path; App::I->work_path = file_path; App::I->rec_path = file_path + "/frames"; - pp::platform::legacy::set_legacy_android_storage_paths({ + *g_android_storage_paths = { App::I->data_path, App::I->work_path, App::I->rec_path, App::I->tmp_path, - }); + }; App::I->initLog(); } @@ -716,12 +718,12 @@ static int engine_init_display(struct engine* engine) { if (App::I->data_path.empty() || App::I->data_path == ".") App::I->data_path = get_data_path(); LOG("data_path %s", App::I->data_path.c_str()); - pp::platform::legacy::set_legacy_android_storage_paths({ + *g_android_storage_paths = { App::I->data_path, App::I->work_path.empty() ? App::I->data_path : App::I->work_path, App::I->rec_path, App::I->tmp_path, - }); + }; #ifdef __QUEST__ @@ -1090,7 +1092,9 @@ void android_main(struct android_app* state) { // Make sure glue isn't stripped. // DON'T REMOVE, even if the compiler say it's deprecated app_dummy(); - auto platform_services = pp::platform::legacy::create_platform_services(); + auto platform_services = pp::platform::legacy::create_platform_services({ + .android_storage_paths = g_android_storage_paths, + }); App::I = new App; App::I->set_platform_services(platform_services.get()); diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index f33ea3da..f3c9a59a 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,13 @@ What is already real: - `pp_app_core` Latest slice: +- `src/platform_legacy/legacy_platform_services.*` now owns Android storage + paths through explicit `create_platform_services(...)` configuration instead + of reading them from a shared legacy singleton. +- `android/src/cpp/main.cpp` now seeds Android storage paths into its owned + legacy `PlatformServices` instance. +- `src/platform_legacy/legacy_platform_state.*` no longer carries the Android + storage-path singleton API. - `src/platform_legacy/legacy_platform_state.*` no longer keeps its own retained Web platform-service binding; the legacy Web helper path now uses the shared `platform_api` injection surface instead. diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 3602099c..52f39eea 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,13 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/platform_legacy/legacy_platform_services.*` now takes Android storage + paths through explicit `create_platform_services(...)` config instead of the + legacy singleton state. +- `android/src/cpp/main.cpp` now seeds Android storage paths into its owned + legacy `PlatformServices` instance. +- `src/platform_legacy/legacy_platform_state.*` no longer keeps the Android + storage-path singleton API. - `src/platform_legacy/legacy_platform_state.*` no longer keeps a separate retained Web platform-service binding; the Web helper path now uses the shared `platform_api` injection hook. diff --git a/linux/src/main.cpp b/linux/src/main.cpp index 4fe4d3bc..b226f745 100644 --- a/linux/src/main.cpp +++ b/linux/src/main.cpp @@ -68,9 +68,11 @@ int main(int argc, char** args) glfwSetWindowTitle(wnd, title.c_str()); }); auto platform_services = pp::platform::legacy::create_platform_services({ - .acquire_render_context = [wnd] { glfwMakeContextCurrent(wnd); }, - .present_render_context = [wnd] { glfwSwapBuffers(wnd); }, - .request_app_close = [wnd] { glfwSetWindowShouldClose(wnd, GLFW_TRUE); }, + .glfw_shell = { + .acquire_render_context = [wnd] { glfwMakeContextCurrent(wnd); }, + .present_render_context = [wnd] { glfwSwapBuffers(wnd); }, + .request_app_close = [wnd] { glfwSetWindowShouldClose(wnd, GLFW_TRUE); }, + }, }); glfwSetCursorPosCallback(wnd, [](GLFWwindow* wnd, double x, double y){ diff --git a/src/legacy_app_startup_services.cpp b/src/legacy_app_startup_services.cpp index 28551c9a..4edcd240 100644 --- a/src/legacy_app_startup_services.cpp +++ b/src/legacy_app_startup_services.cpp @@ -135,15 +135,6 @@ void execute_legacy_app_init_log(App& app) // TODO: save this path somewhere in the settings, don't overwrite every start app.work_path = paths.work_path.empty() ? app.data_path : paths.work_path; -#ifdef __ANDROID__ - pp::platform::legacy::set_legacy_android_storage_paths({ - app.data_path, - app.work_path, - app.rec_path, - app.tmp_path, - }); -#endif - //LogRemote::I.start(); LogRemote::I.file_init(); LOG("%s", g_version); diff --git a/src/platform_legacy/legacy_platform_services.cpp b/src/platform_legacy/legacy_platform_services.cpp index 3acdaa79..5d6e01e7 100644 --- a/src/platform_legacy/legacy_platform_services.cpp +++ b/src/platform_legacy/legacy_platform_services.cpp @@ -48,8 +48,11 @@ namespace { // DEBT-0017: fallback for platforms that do not inject PlatformServices yet. class LegacyPlatformServices final : public pp::platform::PlatformServices { public: - explicit LegacyPlatformServices(pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell = {}) - : glfw_shell_(std::move(glfw_shell)) + explicit LegacyPlatformServices(pp::platform::legacy::LegacyPlatformServicesConfig config = {}) + : glfw_shell_(std::move(config.glfw_shell)) +#ifdef __ANDROID__ + , android_storage_paths_(std::move(config.android_storage_paths)) +#endif { } @@ -89,7 +92,7 @@ public: {}, }; #elif defined(__ANDROID__) - return pp::platform::legacy::active_legacy_android_storage_paths(); + return android_storage_paths_ ? *android_storage_paths_ : pp::platform::PlatformStoragePaths {}; #else return {}; #endif @@ -559,6 +562,9 @@ private: } pp::platform::legacy::LegacyGlfwPlatformShell glfw_shell_; +#ifdef __ANDROID__ + std::shared_ptr android_storage_paths_; +#endif }; } @@ -572,8 +578,8 @@ PlatformServices& platform_services() } std::unique_ptr create_platform_services( - LegacyGlfwPlatformShell glfw_shell) + LegacyPlatformServicesConfig config) { - return std::make_unique(std::move(glfw_shell)); + return std::make_unique(std::move(config)); } } diff --git a/src/platform_legacy/legacy_platform_services.h b/src/platform_legacy/legacy_platform_services.h index 933948b9..acac4cb0 100644 --- a/src/platform_legacy/legacy_platform_services.h +++ b/src/platform_legacy/legacy_platform_services.h @@ -13,8 +13,13 @@ struct LegacyGlfwPlatformShell { std::function request_app_close; }; +struct LegacyPlatformServicesConfig { + LegacyGlfwPlatformShell glfw_shell; + std::shared_ptr android_storage_paths; +}; + [[nodiscard]] PlatformServices& platform_services(); [[nodiscard]] std::unique_ptr create_platform_services( - LegacyGlfwPlatformShell glfw_shell = {}); + LegacyPlatformServicesConfig config = {}); } diff --git a/src/platform_legacy/legacy_platform_state.cpp b/src/platform_legacy/legacy_platform_state.cpp index 883157de..c8832237 100644 --- a/src/platform_legacy/legacy_platform_state.cpp +++ b/src/platform_legacy/legacy_platform_state.cpp @@ -11,20 +11,6 @@ void webgl_sync(); namespace pp::platform::legacy { namespace { -#ifdef __ANDROID__ -struct RetainedLegacyAndroidStoragePaths final { - pp::platform::PlatformStoragePaths storage_paths; -}; -#endif - -#ifdef __ANDROID__ -[[nodiscard]] RetainedLegacyAndroidStoragePaths& retained_legacy_android_storage_paths() -{ - static RetainedLegacyAndroidStoragePaths state; - return state; -} -#endif - class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices { public: void publish_exported_image(std::string_view path) override @@ -150,16 +136,4 @@ void save_legacy_web_prepared_file( return true; } -#ifdef __ANDROID__ -[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_android_storage_paths() -{ - return retained_legacy_android_storage_paths().storage_paths; -} - -void set_legacy_android_storage_paths(pp::platform::PlatformStoragePaths paths) -{ - retained_legacy_android_storage_paths().storage_paths = std::move(paths); -} -#endif - } diff --git a/src/platform_legacy/legacy_platform_state.h b/src/platform_legacy/legacy_platform_state.h index b6cac9f7..d1bf4bf8 100644 --- a/src/platform_legacy/legacy_platform_state.h +++ b/src/platform_legacy/legacy_platform_state.h @@ -31,9 +31,4 @@ void save_legacy_web_prepared_file( std::string_view suggested_name, pp::platform::PreparedFileCallback callback); -#ifdef __ANDROID__ -[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_android_storage_paths(); -void set_legacy_android_storage_paths(pp::platform::PlatformStoragePaths paths); -#endif - } diff --git a/webgl/src/main.cpp b/webgl/src/main.cpp index 16efb3e0..9ded244a 100644 --- a/webgl/src/main.cpp +++ b/webgl/src/main.cpp @@ -204,8 +204,10 @@ int main() printf("Failed to init GLFW"); wnd = glfwCreateWindow(1024, 768, "PanoPainter", nullptr, nullptr); g_platform_services = pp::platform::legacy::create_platform_services({ - .acquire_render_context = [wnd] { glfwMakeContextCurrent(wnd); }, - .present_render_context = [wnd] { glfwSwapBuffers(wnd); }, + .glfw_shell = { + .acquire_render_context = [wnd] { glfwMakeContextCurrent(wnd); }, + .present_render_context = [wnd] { glfwSwapBuffers(wnd); }, + }, }); g_web_platform_services = pp::platform::legacy::create_legacy_web_platform_services(); glfwMakeContextCurrent(wnd);