Bind non-Windows platform services explicitly

This commit is contained in:
2026-06-17 10:02:58 +02:00
parent ea1845d924
commit f98e4f4889
11 changed files with 123 additions and 40 deletions

View File

@@ -16,7 +16,6 @@
#include "platform_windows/windows_platform_services.h"
#endif
#include "platform_legacy/legacy_platform_state.h"
#include "platform_legacy/legacy_platform_services.h"
#include "renderer_gl/opengl_capabilities.h"
namespace {
@@ -48,12 +47,10 @@ namespace {
[[nodiscard]] pp::platform::PlatformServices& active_platform_services(const App* app)
{
if (app)
{
if (auto* services = app->platform_services())
return *services;
}
return pp::platform::legacy::platform_services();
assert(app);
auto* services = app->platform_services();
assert(services);
return *services;
}
}

View File

@@ -259,11 +259,8 @@ public:
void publish_exported_image(std::string_view path) override
{
const auto family = pp::platform::current_platform_family();
if (pp::platform::legacy::handles_legacy_web_platform_family(family))
{
pp::platform::legacy::publish_legacy_web_exported_image(path);
if (pp::platform::legacy::try_publish_legacy_web_exported_image(family, path))
return;
}
if (!pp::platform::platform_publishes_exported_images(family))
{
(void)path;
@@ -279,11 +276,8 @@ public:
void flush_persistent_storage() override
{
const auto family = pp::platform::current_platform_family();
if (pp::platform::legacy::handles_legacy_web_platform_family(family))
{
pp::platform::legacy::flush_legacy_web_persistent_storage();
if (pp::platform::legacy::try_flush_legacy_web_persistent_storage(family))
return;
}
if (!pp::platform::platform_flushes_persistent_storage(family))
return;
}
@@ -449,8 +443,9 @@ public:
[[nodiscard]] int default_canvas_resolution() override
{
const auto family = pp::platform::current_platform_family();
if (pp::platform::legacy::handles_legacy_web_platform_family(family))
return pp::platform::legacy::default_legacy_web_canvas_resolution();
int resolution = 0;
if (pp::platform::legacy::try_default_legacy_web_canvas_resolution(family, resolution))
return resolution;
return pp::platform::platform_default_canvas_resolution(family);
}
@@ -527,11 +522,12 @@ public:
pp::platform::PreparedFileCallback callback) override
{
const auto family = pp::platform::current_platform_family();
if (pp::platform::legacy::handles_legacy_web_platform_family(family))
{
pp::platform::legacy::save_legacy_web_prepared_file(path, suggested_name, std::move(callback));
if (pp::platform::legacy::try_save_legacy_web_prepared_file(
family,
path,
suggested_name,
std::move(callback)))
return;
}
const std::string value(path);
const std::string name(suggested_name);

View File

@@ -108,16 +108,47 @@ void publish_legacy_web_exported_image(std::string_view path)
active_legacy_web_platform_services().publish_exported_image(path);
}
[[nodiscard]] bool try_publish_legacy_web_exported_image(
pp::platform::PlatformFamily family,
std::string_view path)
{
if (!handles_legacy_web_platform_family(family))
return false;
publish_legacy_web_exported_image(path);
return true;
}
void flush_legacy_web_persistent_storage()
{
active_legacy_web_platform_services().flush_persistent_storage();
}
[[nodiscard]] bool try_flush_legacy_web_persistent_storage(pp::platform::PlatformFamily family)
{
if (!handles_legacy_web_platform_family(family))
return false;
flush_legacy_web_persistent_storage();
return true;
}
[[nodiscard]] int default_legacy_web_canvas_resolution() noexcept
{
return active_legacy_web_platform_services().default_canvas_resolution();
}
[[nodiscard]] bool try_default_legacy_web_canvas_resolution(
pp::platform::PlatformFamily family,
int& resolution) noexcept
{
if (!handles_legacy_web_platform_family(family))
return false;
resolution = default_legacy_web_canvas_resolution();
return true;
}
void save_legacy_web_prepared_file(
std::string_view path,
std::string_view suggested_name,
@@ -129,6 +160,19 @@ void save_legacy_web_prepared_file(
std::move(callback));
}
[[nodiscard]] bool try_save_legacy_web_prepared_file(
pp::platform::PlatformFamily family,
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback)
{
if (!handles_legacy_web_platform_family(family))
return false;
save_legacy_web_prepared_file(path, suggested_name, std::move(callback));
return true;
}
[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths()
{
return retained_legacy_storage_paths().storage_paths;

View File

@@ -24,12 +24,25 @@ void request_legacy_glfw_app_close();
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();
[[nodiscard]] bool handles_legacy_web_platform_family(pp::platform::PlatformFamily family) noexcept;
void publish_legacy_web_exported_image(std::string_view path);
[[nodiscard]] bool try_publish_legacy_web_exported_image(
pp::platform::PlatformFamily family,
std::string_view path);
void flush_legacy_web_persistent_storage();
[[nodiscard]] bool try_flush_legacy_web_persistent_storage(
pp::platform::PlatformFamily family);
[[nodiscard]] int default_legacy_web_canvas_resolution() noexcept;
[[nodiscard]] bool try_default_legacy_web_canvas_resolution(
pp::platform::PlatformFamily family,
int& resolution) noexcept;
void save_legacy_web_prepared_file(
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback);
[[nodiscard]] bool try_save_legacy_web_prepared_file(
pp::platform::PlatformFamily family,
std::string_view path,
std::string_view suggested_name,
pp::platform::PreparedFileCallback callback);
[[nodiscard]] const pp::platform::PlatformStoragePaths& active_legacy_storage_paths();
void set_legacy_storage_paths(pp::platform::PlatformStoragePaths paths);

View File

@@ -16,12 +16,25 @@ namespace pp::platform::windows {
namespace {
struct RetainedMainWindowSessionState final {
HINSTANCE instance{};
HWND handle{};
wchar_t title[512]{};
bool sandboxed = false;
};
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
App* app = nullptr;
WacomTablet tablet;
};
[[nodiscard]] RetainedMainWindowSessionState& retained_main_window_session_state()
{
static RetainedMainWindowSessionState state;
return state;
}
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state()
{
static RetainedWindowsRuntimeState state;
@@ -142,28 +155,28 @@ WacomTablet* bound_wacom_tablet() noexcept
HWND main_window_handle() noexcept
{
return retained_state().hWnd;
return retained_main_window_session_state().handle;
}
const wchar_t* main_window_title() noexcept
{
return retained_state().window_title;
return retained_main_window_session_state().title;
}
bool main_window_sandboxed() noexcept
{
return retained_state().sandboxed;
return retained_main_window_session_state().sandboxed;
}
void set_main_window_sandboxed(bool sandboxed) noexcept
{
retained_state().sandboxed = sandboxed;
retained_main_window_session_state().sandboxed = sandboxed;
}
int run_main_application(int argc, char** argv)
{
auto& state = retained_state();
state.hInst = GetModuleHandle(NULL);
auto& main_window_state = retained_main_window_session_state();
main_window_state.instance = GetModuleHandle(NULL);
auto& runtime_state = retained_runtime_state();
runtime_state.owned_app = std::make_unique<App>();
@@ -180,7 +193,7 @@ int run_main_application(int argc, char** argv)
pp::platform::windows::ensure_runtime_data_directory();
pp::platform::windows::SplashScreen splash(state.hInst);
pp::platform::windows::SplashScreen splash(main_window_state.instance);
pp::platform::windows::initialize_retained_input_state();
@@ -192,7 +205,12 @@ int run_main_application(int argc, char** argv)
auto startup = pp::platform::windows::initialize_main_window_startup_state(*app);
auto context = pp::platform::windows::OpenGlWindowContext {};
switch (pp::platform::windows::initialize_main_window_and_gl(startup, state.hWnd, state.hInst, state.window_title, context))
switch (pp::platform::windows::initialize_main_window_and_gl(
startup,
main_window_state.handle,
main_window_state.instance,
main_window_state.title,
context))
{
case pp::platform::windows::MainStartupResult::Ok:
break;
@@ -231,30 +249,30 @@ int run_main_application(int argc, char** argv)
void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash)
{
auto& state = retained_state();
auto& main_window_state = retained_main_window_session_state();
auto* app = bound_app();
register_touch_window(state.hWnd);
register_touch_window(main_window_state.handle);
wglMakeCurrent(NULL, NULL);
initialize_runtime_threads();
install_debug_gl_callbacks();
initialize_wintab(state.hWnd, state.sandboxed);
set_main_window_icon(state.hWnd);
initialize_wintab(main_window_state.handle, main_window_state.sandboxed);
set_main_window_icon(main_window_state.handle);
app->ui_sync();
restore_window_placement(state.hWnd, startup.show_command);
restore_window_placement(main_window_state.handle, startup.show_command);
if (start_in_vr)
app->vr_start();
LOG("show main window");
SetForegroundWindow(state.hWnd);
SetForegroundWindow(main_window_state.handle);
splash.dismiss();
run_main_message_loop();
shutdown_main_window_runtime(startup, state.hInst);
shutdown_main_window_runtime(startup, main_window_state.instance);
}
}

View File

@@ -8,12 +8,8 @@
struct RetainedState
{
HINSTANCE hInst{};
HWND hWnd{};
bool keys[256]{};
std::map<kKey, int> vkey_map;
wchar_t window_title[512]{};
bool sandboxed = false;
pp::platform::windows::VrShellState vr;
};