Own Android storage paths in legacy platform services

This commit is contained in:
2026-06-17 11:11:17 +02:00
parent cf2fcd36e4
commit 81a998436d
10 changed files with 49 additions and 56 deletions

View File

@@ -71,6 +71,8 @@ std::recursive_mutex mutex;
int mutex_count = 0;
struct engine g_engine;
thread_local JNIEnv* jni;
std::shared_ptr<pp::platform::PlatformStoragePaths> g_android_storage_paths =
std::make_shared<pp::platform::PlatformStoragePaths>();
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());

View File

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

View File

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

View File

@@ -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){

View File

@@ -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);

View File

@@ -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<pp::platform::PlatformStoragePaths> android_storage_paths_;
#endif
};
}
@@ -572,8 +578,8 @@ PlatformServices& platform_services()
}
std::unique_ptr<PlatformServices> create_platform_services(
LegacyGlfwPlatformShell glfw_shell)
LegacyPlatformServicesConfig config)
{
return std::make_unique<LegacyPlatformServices>(std::move(glfw_shell));
return std::make_unique<LegacyPlatformServices>(std::move(config));
}
}

View File

@@ -13,8 +13,13 @@ struct LegacyGlfwPlatformShell {
std::function<void()> request_app_close;
};
struct LegacyPlatformServicesConfig {
LegacyGlfwPlatformShell glfw_shell;
std::shared_ptr<pp::platform::PlatformStoragePaths> android_storage_paths;
};
[[nodiscard]] PlatformServices& platform_services();
[[nodiscard]] std::unique_ptr<PlatformServices> create_platform_services(
LegacyGlfwPlatformShell glfw_shell = {});
LegacyPlatformServicesConfig config = {});
}

View File

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

View File

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

View File

@@ -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);