Refactor editor window runtime ownership
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "Windowing/Coordinator/EditorWindowLifecycleCoordinator.h"
|
||||
#include "Windowing/Coordinator/EditorUtilityWindowCoordinator.h"
|
||||
#include "Windowing/Coordinator/EditorWindowWorkspaceCoordinator.h"
|
||||
#include "Windowing/EditorWindowInstance.h"
|
||||
#include "Windowing/Runtime/EditorWindowRuntimeController.h"
|
||||
|
||||
#include <Rendering/Host/EditorWindowRenderRuntime.h>
|
||||
@@ -12,6 +13,7 @@
|
||||
#include <XCEditor/Workspace/UIEditorWindowWorkspaceModel.h>
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -30,6 +32,7 @@ EditorWindowManager::EditorWindowManager(
|
||||
std::make_unique<EditorWindowWorkspaceCoordinator>(
|
||||
m_editorContext,
|
||||
m_hostRuntime,
|
||||
*this,
|
||||
windowSystem,
|
||||
m_renderRuntimeFactory,
|
||||
*m_contentFactory);
|
||||
@@ -37,6 +40,7 @@ EditorWindowManager::EditorWindowManager(
|
||||
std::make_unique<EditorUtilityWindowCoordinator>(
|
||||
m_editorContext,
|
||||
m_hostRuntime,
|
||||
*this,
|
||||
m_renderRuntimeFactory,
|
||||
*m_contentFactory);
|
||||
m_lifecycleCoordinator = std::make_unique<EditorWindowLifecycleCoordinator>(
|
||||
@@ -62,12 +66,21 @@ EditorHostWindow* EditorWindowManager::CreateWorkspaceWindow(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EditorHostWindow* const window = m_hostRuntime.CreateHostWindow(
|
||||
auto windowInstance = CreateEditorWindowInstance(
|
||||
params.windowId,
|
||||
params.title,
|
||||
params.category,
|
||||
params.chromePolicy,
|
||||
params.primary,
|
||||
std::make_unique<EditorWindowRuntimeController>(
|
||||
m_editorContext,
|
||||
m_contentFactory->CreateWorkspaceContentController(windowState),
|
||||
m_renderRuntimeFactory.CreateWindowRenderRuntime()),
|
||||
params);
|
||||
m_renderRuntimeFactory.CreateWindowRenderRuntime()));
|
||||
EditorHostWindow* const window = windowInstance.get();
|
||||
if (!m_hostRuntime.CreateHostWindow(*window, params)) {
|
||||
return nullptr;
|
||||
}
|
||||
m_windows.push_back(std::move(windowInstance));
|
||||
if (window != nullptr) {
|
||||
m_workspaceCoordinator->RegisterExistingWindow(*window);
|
||||
}
|
||||
@@ -81,12 +94,21 @@ EditorHostWindow* EditorWindowManager::CreateUtilityWindow(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EditorHostWindow* const window = m_hostRuntime.CreateHostWindow(
|
||||
auto windowInstance = CreateEditorWindowInstance(
|
||||
params.windowId,
|
||||
params.title,
|
||||
params.category,
|
||||
params.chromePolicy,
|
||||
params.primary,
|
||||
std::make_unique<EditorWindowRuntimeController>(
|
||||
m_editorContext,
|
||||
m_contentFactory->CreateUtilityContentController(descriptor),
|
||||
m_renderRuntimeFactory.CreateWindowRenderRuntime()),
|
||||
params);
|
||||
m_renderRuntimeFactory.CreateWindowRenderRuntime()));
|
||||
EditorHostWindow* const window = windowInstance.get();
|
||||
if (!m_hostRuntime.CreateHostWindow(*window, params)) {
|
||||
return nullptr;
|
||||
}
|
||||
m_windows.push_back(std::move(windowInstance));
|
||||
if (window != nullptr) {
|
||||
m_workspaceCoordinator->RegisterExistingWindow(*window);
|
||||
}
|
||||
@@ -96,6 +118,8 @@ EditorHostWindow* EditorWindowManager::CreateUtilityWindow(
|
||||
void EditorWindowManager::Shutdown() {
|
||||
m_workspaceCoordinator->EndGlobalTabDragSession();
|
||||
m_lifecycleCoordinator->ShutdownAllWindows();
|
||||
ReapDestroyedWindows();
|
||||
m_windows.clear();
|
||||
}
|
||||
|
||||
bool EditorWindowManager::RequestPrimaryWindowClose() {
|
||||
@@ -103,7 +127,7 @@ bool EditorWindowManager::RequestPrimaryWindowClose() {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (EditorHostWindow* window : m_hostRuntime.GetWindows()) {
|
||||
for (const std::unique_ptr<EditorWindowInstance>& window : m_windows) {
|
||||
if (window == nullptr || !window->IsPrimary()) {
|
||||
continue;
|
||||
}
|
||||
@@ -116,11 +140,11 @@ bool EditorWindowManager::RequestPrimaryWindowClose() {
|
||||
}
|
||||
|
||||
bool EditorWindowManager::HasWindows() const {
|
||||
return !m_hostRuntime.GetWindows().empty();
|
||||
return !m_windows.empty();
|
||||
}
|
||||
|
||||
void EditorWindowManager::DestroyClosedWindows() {
|
||||
m_lifecycleCoordinator->ReapDestroyedWindows();
|
||||
ReapDestroyedWindows();
|
||||
}
|
||||
|
||||
void EditorWindowManager::RenderAllWindows() {
|
||||
@@ -130,7 +154,13 @@ void EditorWindowManager::RenderAllWindows() {
|
||||
};
|
||||
|
||||
std::vector<WindowFrameTransferBatch> transferBatches = {};
|
||||
const std::vector<EditorHostWindow*> windows = m_hostRuntime.GetWindows();
|
||||
std::vector<EditorHostWindow*> windows = {};
|
||||
windows.reserve(m_windows.size());
|
||||
for (const std::unique_ptr<EditorWindowInstance>& window : m_windows) {
|
||||
if (window != nullptr) {
|
||||
windows.push_back(window.get());
|
||||
}
|
||||
}
|
||||
transferBatches.reserve(windows.size());
|
||||
|
||||
for (EditorHostWindow* window : windows) {
|
||||
@@ -274,6 +304,14 @@ void EditorWindowManager::ReapDestroyedWindows() {
|
||||
if (m_lifecycleCoordinator != nullptr) {
|
||||
m_lifecycleCoordinator->ReapDestroyedWindows();
|
||||
}
|
||||
m_windows.erase(
|
||||
std::remove_if(
|
||||
m_windows.begin(),
|
||||
m_windows.end(),
|
||||
[](const std::unique_ptr<EditorWindowInstance>& window) {
|
||||
return window == nullptr || window->IsDestroyed();
|
||||
}),
|
||||
m_windows.end());
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
Reference in New Issue
Block a user