Bind non-Windows platform services explicitly
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
#include "platform_legacy/legacy_platform_services.h"
|
||||
#include "platform_legacy/legacy_platform_state.h"
|
||||
#include "asset.h"
|
||||
#include "keymap.h"
|
||||
@@ -1091,6 +1092,7 @@ void android_main(struct android_app* state) {
|
||||
app_dummy();
|
||||
|
||||
App::I = new App;
|
||||
App::I->set_platform_services(&pp::platform::legacy::platform_services());
|
||||
|
||||
memset(&g_engine, 0, sizeof(g_engine));
|
||||
state->userData = &g_engine;
|
||||
|
||||
@@ -70,6 +70,13 @@ What is already real:
|
||||
- `pp_app_core`
|
||||
|
||||
Latest slice:
|
||||
- `src/app_events.cpp` no longer silently falls back to
|
||||
`pp::platform::legacy::platform_services()` when `App` has no bound platform
|
||||
services; the live app path now expects explicit platform-service ownership.
|
||||
- `linux/src/main.cpp`, `webgl/src/main.cpp`, and `android/src/cpp/main.cpp`
|
||||
now bind `pp::platform::legacy::platform_services()` explicitly at app
|
||||
creation instead of relying on the hidden fallback in `App` event/platform
|
||||
dispatch.
|
||||
- `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows tablet
|
||||
object directly; the composition edge no longer binds `&WacomTablet::I` into
|
||||
the Windows runtime path.
|
||||
|
||||
@@ -78,6 +78,12 @@ Completed, blocked, and superseded task history moved to
|
||||
the queue is now ordered by code movement instead.
|
||||
|
||||
Current slice:
|
||||
- `src/app_events.cpp` no longer hides a fallback to
|
||||
`pp::platform::legacy::platform_services()`; touched app platform dispatch
|
||||
now expects an explicitly bound platform-services pointer.
|
||||
- `linux/src/main.cpp`, `webgl/src/main.cpp`, and `android/src/cpp/main.cpp`
|
||||
now bind `pp::platform::legacy::platform_services()` explicitly at app
|
||||
creation, removing the hidden fallback path from live non-Windows entrypoints.
|
||||
- `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows tablet
|
||||
object directly, removing the composition-edge `WacomTablet::I` binding from
|
||||
the touched Windows runtime path.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <app.h>
|
||||
#include <platform_legacy/legacy_platform_state.h>
|
||||
#include <platform_legacy/legacy_platform_services.h>
|
||||
#include <libgen.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
@@ -120,6 +121,7 @@ int main(int argc, char** args)
|
||||
|
||||
App::I = &app;
|
||||
pp::platform::legacy::set_legacy_glfw_window(wnd);
|
||||
app.set_platform_services(&pp::platform::legacy::platform_services());
|
||||
app.initLog();
|
||||
app.create();
|
||||
app.width = 800;
|
||||
|
||||
@@ -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,13 +47,11 @@ namespace {
|
||||
|
||||
[[nodiscard]] pp::platform::PlatformServices& active_platform_services(const App* app)
|
||||
{
|
||||
if (app)
|
||||
{
|
||||
if (auto* services = app->platform_services())
|
||||
assert(app);
|
||||
auto* services = app->platform_services();
|
||||
assert(services);
|
||||
return *services;
|
||||
}
|
||||
return pp::platform::legacy::platform_services();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <chrono>
|
||||
#include <app.h>
|
||||
#include <platform_legacy/legacy_platform_state.h>
|
||||
#include <platform_legacy/legacy_platform_services.h>
|
||||
#include <fstream>
|
||||
#include <keymap.h>
|
||||
|
||||
@@ -119,6 +120,7 @@ void StartApp()
|
||||
{
|
||||
App::I = &app;
|
||||
pp::platform::legacy::set_legacy_glfw_window(wnd);
|
||||
app.set_platform_services(&pp::platform::legacy::platform_services());
|
||||
app.initLog();
|
||||
app.create();
|
||||
app.width = 1024;
|
||||
|
||||
Reference in New Issue
Block a user