Extract Win32 lifecycle state
This commit is contained in:
@@ -239,6 +239,8 @@ set(PP_WINDOWS_PLATFORM_SOURCES
|
|||||||
src/platform_windows/windows_async_render_context.h
|
src/platform_windows/windows_async_render_context.h
|
||||||
src/platform_windows/windows_lifecycle_shell.cpp
|
src/platform_windows/windows_lifecycle_shell.cpp
|
||||||
src/platform_windows/windows_lifecycle_shell.h
|
src/platform_windows/windows_lifecycle_shell.h
|
||||||
|
src/platform_windows/windows_lifecycle_state.cpp
|
||||||
|
src/platform_windows/windows_lifecycle_state.h
|
||||||
src/platform_windows/windows_main_window_session.cpp
|
src/platform_windows/windows_main_window_session.cpp
|
||||||
src/platform_windows/windows_main_window_session.h
|
src/platform_windows/windows_main_window_session.h
|
||||||
src/platform_windows/windows_platform_services.cpp
|
src/platform_windows/windows_platform_services.cpp
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ What is already real:
|
|||||||
- `pp_app_core`
|
- `pp_app_core`
|
||||||
|
|
||||||
Latest slice:
|
Latest slice:
|
||||||
|
- `src/platform_windows/windows_lifecycle_state.*` now owns the retained
|
||||||
|
Win32 lifecycle running flag and FPS-title scratch buffer instead of leaving
|
||||||
|
them inside `windows_lifecycle_shell.cpp`.
|
||||||
|
- `src/platform_windows/windows_lifecycle_shell.cpp` now keeps lifecycle/VR
|
||||||
|
control behavior without also owning the retained lifecycle state pocket.
|
||||||
- `src/platform_windows/windows_async_render_context.*` now owns the retained
|
- `src/platform_windows/windows_async_render_context.*` now owns the retained
|
||||||
Win32 async OpenGL context lock/swap state instead of leaving it inside
|
Win32 async OpenGL context lock/swap state instead of leaving it inside
|
||||||
`windows_platform_services.cpp`.
|
`windows_platform_services.cpp`.
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ 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_lifecycle_state.*` now owns the retained
|
||||||
|
Win32 lifecycle running flag and FPS-title scratch buffer.
|
||||||
|
- `src/platform_windows/windows_lifecycle_shell.cpp` no longer carries that
|
||||||
|
retained lifecycle state pocket.
|
||||||
- `src/platform_windows/windows_async_render_context.*` now owns the retained
|
- `src/platform_windows/windows_async_render_context.*` now owns the retained
|
||||||
Win32 async GL context lock/swap state.
|
Win32 async GL context lock/swap state.
|
||||||
- `src/platform_windows/windows_platform_services.cpp` no longer carries the
|
- `src/platform_windows/windows_platform_services.cpp` no longer carries the
|
||||||
|
|||||||
@@ -4,42 +4,13 @@
|
|||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "legacy_preference_storage.h"
|
#include "legacy_preference_storage.h"
|
||||||
|
#include "platform_windows/windows_lifecycle_state.h"
|
||||||
#include "platform_windows/windows_main_window_session.h"
|
#include "platform_windows/windows_main_window_session.h"
|
||||||
#include "platform_windows/windows_runtime_shell.h"
|
#include "platform_windows/windows_runtime_shell.h"
|
||||||
#include "platform_windows/windows_stylus_input.h"
|
#include "platform_windows/windows_stylus_input.h"
|
||||||
|
|
||||||
namespace pp::platform::windows {
|
namespace pp::platform::windows {
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
[[nodiscard]] std::atomic<int>& retained_running_state() noexcept
|
|
||||||
{
|
|
||||||
static std::atomic<int> running{-1};
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::atomic<int>& 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)
|
void request_window_close(HWND hWnd)
|
||||||
{
|
{
|
||||||
PostMessage(hWnd, kUserCloseMessage, 0, 0);
|
PostMessage(hWnd, kUserCloseMessage, 0, 0);
|
||||||
@@ -64,12 +35,12 @@ void update_stylus_frame(float dt)
|
|||||||
|
|
||||||
void update_window_fps(HWND hWnd, const wchar_t* window_title, VrShellState& vr, int frames)
|
void update_window_fps(HWND hWnd, const wchar_t* window_title, VrShellState& vr, int frames)
|
||||||
{
|
{
|
||||||
static wchar_t title_fps[512];
|
auto* title_fps = retained_window_fps_title_buffer();
|
||||||
const int vr_fps = current_vr_fps(vr);
|
const int vr_fps = current_vr_fps(vr);
|
||||||
if (read_vr_session_snapshot(vr).vr_active)
|
if (read_vr_session_snapshot(vr).vr_active)
|
||||||
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps);
|
swprintf_s(title_fps, 512, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps);
|
||||||
else
|
else
|
||||||
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
|
swprintf_s(title_fps, 512, L"%s - %d fps", window_title, frames);
|
||||||
|
|
||||||
SetWindowText(hWnd, title_fps);
|
SetWindowText(hWnd, title_fps);
|
||||||
PostMessage(hWnd, kUserWakeupMessage, 0, 0);
|
PostMessage(hWnd, kUserWakeupMessage, 0, 0);
|
||||||
@@ -88,7 +59,7 @@ void save_window_preferences(HWND hWnd)
|
|||||||
|
|
||||||
bool start_window_vr(VrShellState& vr, bool sandboxed)
|
bool start_window_vr(VrShellState& vr, bool sandboxed)
|
||||||
{
|
{
|
||||||
return start_vr_shell(vr, sandboxed, retained_running_state());
|
return start_vr_shell(vr, sandboxed, retained_lifecycle_running_state());
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_window_vr(VrShellState& vr)
|
void stop_window_vr(VrShellState& vr)
|
||||||
|
|||||||
51
src/platform_windows/windows_lifecycle_state.cpp
Normal file
51
src/platform_windows/windows_lifecycle_state.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
#include "platform_windows/windows_lifecycle_state.h"
|
||||||
|
|
||||||
|
namespace pp::platform::windows {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct RetainedWindowLifecycleState final {
|
||||||
|
std::atomic<int> running{-1};
|
||||||
|
wchar_t title_fps[512]{};
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] RetainedWindowLifecycleState& retained_window_lifecycle_state() noexcept
|
||||||
|
{
|
||||||
|
static RetainedWindowLifecycleState state;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::atomic<int>& lifecycle_running_state() noexcept
|
||||||
|
{
|
||||||
|
return retained_lifecycle_running_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
void mark_lifecycle_running() noexcept
|
||||||
|
{
|
||||||
|
retained_lifecycle_running_state().store(1, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mark_lifecycle_stopped() noexcept
|
||||||
|
{
|
||||||
|
retained_lifecycle_running_state().store(0, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lifecycle_is_running() noexcept
|
||||||
|
{
|
||||||
|
return retained_lifecycle_running_state().load(std::memory_order_relaxed) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::atomic<int>& retained_lifecycle_running_state() noexcept
|
||||||
|
{
|
||||||
|
return retained_window_lifecycle_state().running;
|
||||||
|
}
|
||||||
|
|
||||||
|
wchar_t* retained_window_fps_title_buffer() noexcept
|
||||||
|
{
|
||||||
|
return retained_window_lifecycle_state().title_fps;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
src/platform_windows/windows_lifecycle_state.h
Normal file
16
src/platform_windows/windows_lifecycle_state.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
namespace pp::platform::windows {
|
||||||
|
|
||||||
|
[[nodiscard]] std::atomic<int>& lifecycle_running_state() noexcept;
|
||||||
|
void mark_lifecycle_running() noexcept;
|
||||||
|
void mark_lifecycle_stopped() noexcept;
|
||||||
|
[[nodiscard]] bool lifecycle_is_running() noexcept;
|
||||||
|
[[nodiscard]] std::atomic<int>& retained_lifecycle_running_state() noexcept;
|
||||||
|
[[nodiscard]] wchar_t* retained_window_fps_title_buffer() noexcept;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user