#include "pch.h" #include "platform_windows/windows_lifecycle_shell.h" #include "app.h" #include "legacy_preference_storage.h" #include "platform_windows/windows_runtime_shell.h" #include "platform_windows/windows_stylus_input.h" namespace pp::platform::windows { namespace { [[nodiscard]] std::atomic& retained_running_state() noexcept { static std::atomic running{-1}; return running; } } std::atomic& lifecycle_running_state() noexcept { return retained_running_state(); } void mark_lifecycle_running() noexcept { retained_running_state().store(1, std::memory_order_relaxed); } void mark_lifecycle_stopped() noexcept { retained_running_state().store(0, std::memory_order_relaxed); } bool lifecycle_is_running() noexcept { return retained_running_state().load(std::memory_order_relaxed) == 1; } void request_window_close(HWND hWnd) { PostMessage(hWnd, kUserCloseMessage, 0, 0); } void handle_window_close_message(VrShellState& vr) { auto* app = bound_app(); auto* runtime = bound_runtime(); mark_lifecycle_stopped(); request_stop_and_join_vr_thread(vr); runtime->ui_thread_stop(); runtime->render_thread_stop(); app->terminate(); App::I = nullptr; bind_app(nullptr); bind_runtime(nullptr); delete app; PostQuitMessage(0); } void update_stylus_frame(float dt) { update_stylus_state(dt); } void update_window_fps(HWND hWnd, const wchar_t* window_title, VrShellState& vr, int frames) { static wchar_t title_fps[512]; const int vr_fps = current_vr_fps(vr); if (read_vr_session_snapshot(vr).vr_active) swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps); else swprintf_s(title_fps, L"%s - %d fps", window_title, frames); SetWindowText(hWnd, title_fps); PostMessage(hWnd, kUserWakeupMessage, 0, 0); } void save_window_preferences(HWND hWnd) { WINDOWPLACEMENT placement{}; GetWindowPlacement(hWnd, &placement); pp::panopainter::set_legacy_window_preferences(placement.showCmd, { placement.rcNormalPosition.left, placement.rcNormalPosition.top, placement.rcNormalPosition.right, placement.rcNormalPosition.bottom }); } bool start_window_vr(VrShellState& vr, bool sandboxed) { return start_vr_shell(vr, sandboxed, retained_running_state()); } void stop_window_vr(VrShellState& vr) { stop_vr_shell(vr); } }