112 lines
2.7 KiB
C++
112 lines
2.7 KiB
C++
#include "pch.h"
|
|
#include "platform_legacy/legacy_platform_state.h"
|
|
#include "platform_api/platform_policy.h"
|
|
|
|
#if defined(__LINUX__) || defined(__WEB__)
|
|
#include <GLFW/glfw3.h>
|
|
#endif
|
|
|
|
void webgl_pick_file_save(
|
|
const std::string& path,
|
|
const std::string& name,
|
|
std::function<void(bool)> callback);
|
|
void webgl_sync();
|
|
|
|
namespace pp::platform::legacy {
|
|
namespace {
|
|
|
|
struct RetainedLegacyStoragePaths final {
|
|
pp::platform::PlatformStoragePaths storage_paths;
|
|
};
|
|
|
|
[[nodiscard]] RetainedLegacyStoragePaths& retained_legacy_storage_paths()
|
|
{
|
|
static RetainedLegacyStoragePaths state;
|
|
return state;
|
|
}
|
|
|
|
class RetainedWebPlatformServices final : public pp::platform::WebPlatformServices {
|
|
public:
|
|
void publish_exported_image(std::string_view path) override
|
|
{
|
|
(void)path;
|
|
}
|
|
|
|
void flush_persistent_storage() override
|
|
{
|
|
#ifdef __WEB__
|
|
webgl_sync();
|
|
#endif
|
|
}
|
|
|
|
[[nodiscard]] int default_canvas_resolution() override
|
|
{
|
|
return pp::platform::platform_default_canvas_resolution(pp::platform::PlatformFamily::webgl);
|
|
}
|
|
|
|
void save_prepared_file(
|
|
std::string_view path,
|
|
std::string_view suggested_name,
|
|
pp::platform::PreparedFileCallback callback) override
|
|
{
|
|
const std::string value(path);
|
|
const std::string name(suggested_name);
|
|
#ifdef __WEB__
|
|
webgl_pick_file_save(value, name, [callback = std::move(callback), value](bool success) {
|
|
callback(value, success);
|
|
});
|
|
#else
|
|
(void)name;
|
|
callback(value, false);
|
|
#endif
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#if defined(__LINUX__) || defined(__WEB__)
|
|
[[nodiscard]] RetainedLegacyGlfwWindowState& active_legacy_glfw_window_state()
|
|
{
|
|
static RetainedLegacyGlfwWindowState state;
|
|
return state;
|
|
}
|
|
|
|
void set_legacy_glfw_window(GLFWwindow* window)
|
|
{
|
|
active_legacy_glfw_window_state().window = window;
|
|
}
|
|
|
|
void acquire_legacy_glfw_render_context()
|
|
{
|
|
glfwMakeContextCurrent(active_legacy_glfw_window_state().window);
|
|
}
|
|
|
|
void present_legacy_glfw_render_context()
|
|
{
|
|
glfwSwapBuffers(active_legacy_glfw_window_state().window);
|
|
}
|
|
|
|
void request_legacy_glfw_app_close()
|
|
{
|
|
glfwSetWindowShouldClose(active_legacy_glfw_window_state().window, GLFW_TRUE);
|
|
}
|
|
#endif
|
|
|
|
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services()
|
|
{
|
|
static RetainedWebPlatformServices services;
|
|
return pp::platform::resolve_web_platform_services(services);
|
|
}
|
|
|
|
[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths()
|
|
{
|
|
return retained_legacy_storage_paths().storage_paths;
|
|
}
|
|
|
|
void set_legacy_storage_paths(pp::platform::PlatformStoragePaths paths)
|
|
{
|
|
retained_legacy_storage_paths().storage_paths = std::move(paths);
|
|
}
|
|
|
|
}
|