new_editor: stabilize resize lifecycle groundwork

This commit is contained in:
2026-04-23 00:36:28 +08:00
parent c10367a42e
commit 03e0b362f7
19 changed files with 439 additions and 161 deletions

View File

@@ -2,6 +2,7 @@
#include "Bootstrap/EditorResources.h"
#include "Platform/Win32/EditorWindowChromeController.h"
#include "Platform/Win32/EditorWindowContentController.h"
#include "Platform/Win32/EditorWindowFrameDriver.h"
#include "Platform/Win32/EditorWindowSupport.h"
#include "Platform/Win32/EditorWindowFrameOrchestrator.h"
#include "Platform/Win32/EditorWindowInputController.h"
@@ -103,12 +104,20 @@ bool EditorWindow::HasHwnd() const {
return m_state->window.hwnd != nullptr;
}
EditorWindowLifecycleState EditorWindow::GetLifecycleState() const {
return m_state->window.lifecycle;
}
bool EditorWindow::IsPrimary() const {
return m_state->window.primary;
}
bool EditorWindow::IsClosing() const {
return m_state->window.closing;
return m_state->window.lifecycle == EditorWindowLifecycleState::Closing;
}
bool EditorWindow::IsDestroyed() const {
return m_state->window.lifecycle == EditorWindowLifecycleState::Destroyed;
}
bool EditorWindow::IsRenderReady() const {
@@ -159,21 +168,25 @@ void EditorWindow::ClearExternalDockHostDropPreview() {
void EditorWindow::AttachHwnd(HWND hwnd) {
m_state->window.hwnd = hwnd;
m_state->window.closing = false;
m_state->window.lifecycle = EditorWindowLifecycleState::NativeAttached;
}
void EditorWindow::MarkInitializing() {
m_state->window.lifecycle = EditorWindowLifecycleState::Initializing;
}
void EditorWindow::MarkRunning() {
m_state->window.lifecycle = EditorWindowLifecycleState::Running;
}
void EditorWindow::MarkDestroyed() {
m_state->window.hwnd = nullptr;
m_state->window.closing = false;
m_state->window.lifecycle = EditorWindowLifecycleState::Destroyed;
m_inputController->ResetWindowState();
}
void EditorWindow::MarkClosing() {
m_state->window.closing = true;
}
void EditorWindow::ClearClosing() {
m_state->window.closing = false;
m_state->window.lifecycle = EditorWindowLifecycleState::Closing;
}
void EditorWindow::SetPrimary(bool primary) {
@@ -219,12 +232,19 @@ bool EditorWindow::Initialize(
<< " scale=" << GetDpiScale();
LogRuntimeTrace("window", dpiTrace.str());
return m_runtime->Initialize(
MarkInitializing();
const bool initialized = m_runtime->Initialize(
m_state->window.hwnd,
repoRoot,
editorContext,
captureRoot,
autoCaptureOnStartup);
if (initialized) {
MarkRunning();
} else {
m_state->window.lifecycle = EditorWindowLifecycleState::NativeAttached;
}
return initialized;
}
void EditorWindow::Shutdown() {
@@ -234,7 +254,7 @@ void EditorWindow::Shutdown() {
<< reinterpret_cast<std::uintptr_t>(GetHwnd())
<< std::dec
<< " primary=" << (IsPrimary() ? 1 : 0)
<< " closing=" << (IsClosing() ? 1 : 0)
<< " lifecycle=" << GetEditorWindowLifecycleStateName(GetLifecycleState())
<< " runtimeReady=" << (m_runtime->IsReady() ? 1 : 0);
LogRuntimeTrace("window-close", trace.str());
ForceReleasePointerCapture();
@@ -655,12 +675,44 @@ EditorWindowFrameTransferRequests EditorWindow::OnPaintMessage(
PAINTSTRUCT paintStruct = {};
BeginPaint(m_state->window.hwnd, &paintStruct);
const EditorWindowFrameTransferRequests transferRequests =
RenderFrame(editorContext, globalTabDragActive);
m_chromeController->RequestSkipNextSteadyStateFrame();
EditorWindowFrameDriver::DriveImmediateFrame(
*this,
editorContext,
globalTabDragActive);
EndPaint(m_state->window.hwnd, &paintStruct);
return transferRequests;
}
void EditorWindow::QueueCompletedImmediateFrame(
EditorWindowFrameTransferRequests transferRequests) {
m_hasQueuedCompletedImmediateFrame = true;
if (transferRequests.beginGlobalTabDrag.has_value()) {
m_queuedImmediateFrameTransferRequests.beginGlobalTabDrag =
std::move(transferRequests.beginGlobalTabDrag);
}
if (transferRequests.detachPanel.has_value()) {
m_queuedImmediateFrameTransferRequests.detachPanel =
std::move(transferRequests.detachPanel);
}
if (transferRequests.openUtilityWindow.has_value()) {
m_queuedImmediateFrameTransferRequests.openUtilityWindow =
std::move(transferRequests.openUtilityWindow);
}
}
bool EditorWindow::HasQueuedCompletedImmediateFrame() const {
return m_hasQueuedCompletedImmediateFrame;
}
EditorWindowFrameTransferRequests
EditorWindow::ConsumeQueuedCompletedImmediateFrameTransferRequests() {
m_hasQueuedCompletedImmediateFrame = false;
EditorWindowFrameTransferRequests transferRequests =
std::move(m_queuedImmediateFrameTransferRequests);
m_queuedImmediateFrameTransferRequests = {};
return transferRequests;
}
UIRect EditorWindow::ResolveWorkspaceBounds(float clientWidthDips, float clientHeightDips) const {
if (!IsBorderlessWindowEnabled()) {
return UIRect(0.0f, 0.0f, clientWidthDips, clientHeightDips);