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

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

View File

@@ -71,24 +71,24 @@ public:
return state;
}
[[nodiscard]] RetainedLegacyGlfwWindowHooks& active_legacy_glfw_window_hooks()
{
return active_legacy_glfw_window_state().hooks;
}
void set_legacy_glfw_window(GLFWwindow* window)
{
auto& retained = active_legacy_glfw_window_state();
retained.window = window;
retained.hooks.acquire_render_context = [window] {
glfwMakeContextCurrent(window);
};
retained.hooks.present_render_context = [window] {
glfwSwapBuffers(window);
};
retained.hooks.request_app_close = [window] {
glfwSetWindowShouldClose(window, GLFW_TRUE);
};
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

View File

@@ -9,20 +9,15 @@ struct GLFWwindow;
namespace pp::platform::legacy {
#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 {
GLFWwindow* window = nullptr;
RetainedLegacyGlfwWindowHooks hooks;
};
[[nodiscard]] RetainedLegacyGlfwWindowState& active_legacy_glfw_window_state();
[[nodiscard]] RetainedLegacyGlfwWindowHooks& active_legacy_glfw_window_hooks();
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
[[nodiscard]] pp::platform::WebPlatformServices& active_legacy_web_platform_services();