Thin Windows runtime globals and legacy GLFW hooks

This commit is contained in:
2026-06-17 09:51:25 +02:00
parent 25eff166f6
commit 4c91701e11
9 changed files with 43 additions and 54 deletions

View File

@@ -70,6 +70,9 @@ What is already real:
- `pp_app_core` - `pp_app_core`
Latest slice: Latest slice:
- `src/platform_windows/windows_runtime_shell.cpp` no longer keeps a separate
retained `AppRuntime*` binding; the touched Windows shell and platform
helpers now derive runtime ownership directly from the owned `App`.
- `src/platform_windows/windows_runtime_shell.cpp` now explicitly owns the - `src/platform_windows/windows_runtime_shell.cpp` now explicitly owns the
Windows `App` lifetime through a retained `std::unique_ptr<App>` instead of Windows `App` lifetime through a retained `std::unique_ptr<App>` instead of
raw `new`/`delete` plus shutdown-side manual cleanup in the lifecycle shell. raw `new`/`delete` plus shutdown-side manual cleanup in the lifecycle shell.
@@ -79,6 +82,10 @@ Latest slice:
- `src/platform_windows/windows_window_shell.cpp` now routes the touched - `src/platform_windows/windows_window_shell.cpp` now routes the touched
key-map and VR-state reads through narrow helpers instead of keeping the key-map and VR-state reads through narrow helpers instead of keeping the
broader retained-state bundle live across the main window-proc body. broader retained-state bundle live across the main window-proc body.
- `src/platform_legacy/legacy_platform_state.*` no longer exposes the mutable
retained GLFW hook bundle; Linux/Web fallback render-context/present/close
calls now go through narrow GLFW helper functions instead of an exported hook
struct.
- `scripts/automation/quiet-validate.ps1` is now the bundled checkpoint path - `scripts/automation/quiet-validate.ps1` is now the bundled checkpoint path
for Windows build/test plus optional platform and Apple remote validation, for Windows build/test plus optional platform and Apple remote validation,
with one compact JSON summary under `out/logs/quiet-validation`. with one compact JSON summary under `out/logs/quiet-validation`.

View File

@@ -78,6 +78,9 @@ Completed, blocked, and superseded task history moved to
the queue is now ordered by code movement instead. the queue is now ordered by code movement instead.
Current slice: Current slice:
- `src/platform_windows/windows_runtime_shell.cpp` no longer keeps a separate
retained `AppRuntime*`; the touched Windows lifecycle and main-thread task
dispatch paths now derive runtime ownership directly from the owned app.
- `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows `App` - `src/platform_windows/windows_runtime_shell.cpp` now owns the Windows `App`
through a retained `std::unique_ptr<App>`, so startup/early-return/convert through a retained `std::unique_ptr<App>`, so startup/early-return/convert
paths no longer manage raw `new`/`delete` app lifetime manually. paths no longer manage raw `new`/`delete` app lifetime manually.
@@ -87,6 +90,9 @@ Current slice:
- `src/platform_windows/windows_window_shell.cpp` now routes the touched - `src/platform_windows/windows_window_shell.cpp` now routes the touched
key-map synchronization and VR close state through narrow helpers instead of key-map synchronization and VR close state through narrow helpers instead of
carrying the broader retained window bundle live across the window-proc path. carrying the broader retained window bundle live across the window-proc path.
- `src/platform_legacy/legacy_platform_state.*` no longer exports the mutable
retained GLFW hook bundle; Linux/Web fallback render-context, present, and
app-close paths now route through narrow GLFW helper functions instead.
- `scripts/automation/quiet-validate.ps1` now owns the recommended quiet - `scripts/automation/quiet-validate.ps1` now owns the recommended quiet
checkpoint path and can bundle Windows build/test, Android/platform sweeps, checkpoint path and can bundle Windows build/test, Android/platform sweeps,
and Apple remote compile gates into one compact JSON summary with and Apple remote compile gates into one compact JSON summary with

View File

@@ -177,7 +177,7 @@ public:
#elif __ANDROID__ #elif __ANDROID__
android_async_lock(); android_async_lock();
#elif __LINUX__ || __WEB__ #elif __LINUX__ || __WEB__
pp::platform::legacy::active_legacy_glfw_window_hooks().acquire_render_context(); pp::platform::legacy::acquire_legacy_glfw_render_context();
#endif #endif
} }
@@ -197,7 +197,7 @@ public:
#elif __ANDROID__ #elif __ANDROID__
android_async_swap(); android_async_swap();
#elif __LINUX__ || __WEB__ #elif __LINUX__ || __WEB__
pp::platform::legacy::active_legacy_glfw_window_hooks().present_render_context(); pp::platform::legacy::present_legacy_glfw_render_context();
#endif #endif
} }
@@ -508,7 +508,7 @@ public:
#ifdef __OSX__ #ifdef __OSX__
pp::platform::apple::active_legacy_apple_document_platform_services().request_app_close(); pp::platform::apple::active_legacy_apple_document_platform_services().request_app_close();
#elif __LINUX__ #elif __LINUX__
pp::platform::legacy::active_legacy_glfw_window_hooks().request_app_close(); pp::platform::legacy::request_legacy_glfw_app_close();
#endif #endif
} }

View File

@@ -71,24 +71,24 @@ public:
return state; return state;
} }
[[nodiscard]] RetainedLegacyGlfwWindowHooks& active_legacy_glfw_window_hooks()
{
return active_legacy_glfw_window_state().hooks;
}
void set_legacy_glfw_window(GLFWwindow* window) void set_legacy_glfw_window(GLFWwindow* window)
{ {
auto& retained = active_legacy_glfw_window_state(); active_legacy_glfw_window_state().window = window;
retained.window = window; }
retained.hooks.acquire_render_context = [window] {
glfwMakeContextCurrent(window); void acquire_legacy_glfw_render_context()
}; {
retained.hooks.present_render_context = [window] { glfwMakeContextCurrent(active_legacy_glfw_window_state().window);
glfwSwapBuffers(window); }
};
retained.hooks.request_app_close = [window] { void present_legacy_glfw_render_context()
glfwSetWindowShouldClose(window, GLFW_TRUE); {
}; glfwSwapBuffers(active_legacy_glfw_window_state().window);
}
void request_legacy_glfw_app_close()
{
glfwSetWindowShouldClose(active_legacy_glfw_window_state().window, GLFW_TRUE);
} }
#endif #endif

View File

@@ -9,20 +9,15 @@ struct GLFWwindow;
namespace pp::platform::legacy { namespace pp::platform::legacy {
#if defined(__LINUX__) || defined(__WEB__) #if defined(__LINUX__) || defined(__WEB__)
struct RetainedLegacyGlfwWindowHooks final {
std::function<void()> acquire_render_context;
std::function<void()> present_render_context;
std::function<void()> request_app_close;
};
struct RetainedLegacyGlfwWindowState final { struct RetainedLegacyGlfwWindowState final {
GLFWwindow* window = nullptr; GLFWwindow* window = nullptr;
RetainedLegacyGlfwWindowHooks hooks;
}; };
[[nodiscard]] RetainedLegacyGlfwWindowState& active_legacy_glfw_window_state(); [[nodiscard]] RetainedLegacyGlfwWindowState& active_legacy_glfw_window_state();
[[nodiscard]] RetainedLegacyGlfwWindowHooks& active_legacy_glfw_window_hooks();
void set_legacy_glfw_window(GLFWwindow* window); void set_legacy_glfw_window(GLFWwindow* window);
void acquire_legacy_glfw_render_context();
void present_legacy_glfw_render_context();
void request_legacy_glfw_app_close();
#endif #endif
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services(); [[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();

View File

@@ -47,11 +47,10 @@ void request_window_close(HWND hWnd)
void handle_window_close_message(VrShellState& vr) void handle_window_close_message(VrShellState& vr)
{ {
auto* app = bound_app(); auto* app = bound_app();
auto* runtime = bound_runtime();
mark_lifecycle_stopped(); mark_lifecycle_stopped();
request_stop_and_join_vr_thread(vr); request_stop_and_join_vr_thread(vr);
runtime->ui_thread_stop(); app->runtime().ui_thread_stop();
runtime->render_thread_stop(); app->runtime().render_thread_stop();
app->terminate(); app->terminate();
release_bound_app(); release_bound_app();
PostQuitMessage(0); PostQuitMessage(0);

View File

@@ -186,9 +186,9 @@ void swap_async_render_context()
void enqueue_main_thread_task(std::packaged_task<void()> task) void enqueue_main_thread_task(std::packaged_task<void()> task)
{ {
if (auto* runtime = bound_runtime()) if (auto* app = bound_app())
{ {
runtime->main_thread_task(std::move(task)); app->runtime().main_thread_task(std::move(task));
return; return;
} }
@@ -200,9 +200,9 @@ void enqueue_main_thread_task(std::packaged_task<void()> task)
void drain_main_thread_tasks() void drain_main_thread_tasks()
{ {
if (auto* runtime = bound_runtime()) if (auto* app = bound_app())
{ {
runtime->drain_main_thread_tasks(); app->runtime().drain_main_thread_tasks();
return; return;
} }
} }

View File

@@ -3,7 +3,6 @@
#include "platform_windows/windows_runtime_shell.h" #include "platform_windows/windows_runtime_shell.h"
#include "app.h" #include "app.h"
#include "app_runtime.h"
#include "log.h" #include "log.h"
#include "platform_windows/windows_bootstrap_helpers.h" #include "platform_windows/windows_bootstrap_helpers.h"
#include "platform_windows/windows_lifecycle_shell.h" #include "platform_windows/windows_lifecycle_shell.h"
@@ -20,7 +19,6 @@ namespace {
struct RetainedWindowsRuntimeState final { struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app; std::unique_ptr<App> owned_app;
App* app = nullptr; App* app = nullptr;
AppRuntime* runtime = nullptr;
WacomTablet* tablet = nullptr; WacomTablet* tablet = nullptr;
}; };
@@ -42,10 +40,9 @@ void register_touch_window(HWND hWnd)
void initialize_runtime_threads() void initialize_runtime_threads()
{ {
auto* app = bound_app(); auto* app = bound_app();
auto* runtime = bound_runtime();
mark_lifecycle_running(); mark_lifecycle_running();
runtime->render_thread_start(*app); app->runtime().render_thread_start(*app);
runtime->ui_thread_start(*app); app->runtime().ui_thread_start(*app);
} }
void install_debug_gl_callbacks() void install_debug_gl_callbacks()
@@ -136,21 +133,10 @@ App* bound_app() noexcept
void release_bound_app() noexcept void release_bound_app() noexcept
{ {
auto& state = retained_runtime_state(); auto& state = retained_runtime_state();
bind_runtime(nullptr);
bind_app(nullptr); bind_app(nullptr);
state.owned_app.reset(); state.owned_app.reset();
} }
void bind_runtime(AppRuntime* runtime) noexcept
{
retained_runtime_state().runtime = runtime;
}
AppRuntime* bound_runtime() noexcept
{
return retained_runtime_state().runtime;
}
void bind_wacom_tablet(WacomTablet* tablet) noexcept void bind_wacom_tablet(WacomTablet* tablet) noexcept
{ {
retained_runtime_state().tablet = tablet; retained_runtime_state().tablet = tablet;
@@ -190,7 +176,6 @@ int run_main_application(int argc, char** argv)
runtime_state.owned_app = std::make_unique<App>(); runtime_state.owned_app = std::make_unique<App>();
auto* app = runtime_state.owned_app.get(); auto* app = runtime_state.owned_app.get();
bind_app(app); bind_app(app);
bind_runtime(&app->runtime());
bind_wacom_tablet(&WacomTablet::I); bind_wacom_tablet(&WacomTablet::I);
app->set_platform_services(&pp::platform::windows::platform_services()); app->set_platform_services(&pp::platform::windows::platform_services());
app->initLog(); app->initLog();

View File

@@ -4,7 +4,6 @@
#include "platform_windows/windows_splash.h" #include "platform_windows/windows_splash.h"
class App; class App;
class AppRuntime;
class WacomTablet; class WacomTablet;
namespace pp::platform::windows { namespace pp::platform::windows {
@@ -14,8 +13,6 @@ void run_main_window_runtime(const MainWindowStartupState& startup, bool start_i
void bind_app(App* app) noexcept; void bind_app(App* app) noexcept;
[[nodiscard]] App* bound_app() noexcept; [[nodiscard]] App* bound_app() noexcept;
void release_bound_app() noexcept; void release_bound_app() noexcept;
void bind_runtime(AppRuntime* runtime) noexcept;
[[nodiscard]] AppRuntime* bound_runtime() noexcept;
void bind_wacom_tablet(WacomTablet* tablet) noexcept; void bind_wacom_tablet(WacomTablet* tablet) noexcept;
[[nodiscard]] WacomTablet* bound_wacom_tablet() noexcept; [[nodiscard]] WacomTablet* bound_wacom_tablet() noexcept;
[[nodiscard]] HWND main_window_handle() noexcept; [[nodiscard]] HWND main_window_handle() noexcept;