new_editor: close legacy d2d host path

This commit is contained in:
2026-04-22 02:14:26 +08:00
parent 35e7602eb8
commit 36c4ae414b
19 changed files with 876 additions and 1894 deletions

View File

@@ -1,6 +1,5 @@
#include "AutoScreenshot.h"
#include "NativeRenderer.h"
#include "Support/EnvironmentFlags.h"
#include "Support/ExecutablePath.h"
@@ -29,6 +28,7 @@ void AutoScreenshotController::Initialize(const std::filesystem::path& captureRo
m_captureRoot = ResolveBuildCaptureRoot(captureRoot);
m_historyRoot = (m_captureRoot / "history").lexically_normal();
m_latestCapturePath = (m_captureRoot / "latest.png").lexically_normal();
m_activeHistoryCapturePath.clear();
m_captureCount = 0;
m_capturePending = false;
m_pendingReason.clear();
@@ -40,6 +40,7 @@ void AutoScreenshotController::Initialize(const std::filesystem::path& captureRo
}
void AutoScreenshotController::Shutdown() {
m_activeHistoryCapturePath.clear();
m_capturePending = false;
m_pendingReason.clear();
}
@@ -49,19 +50,10 @@ void AutoScreenshotController::RequestCapture(std::string reason) {
m_capturePending = true;
}
void AutoScreenshotController::CaptureIfRequested(
NativeRenderer& renderer,
D3D12WindowRenderer& windowRenderer,
const ::XCEngine::UI::UIDrawData& drawData,
unsigned int width,
unsigned int height,
bool framePresented) {
bool AutoScreenshotController::TryBeginCapture(std::filesystem::path& outHistoryPath) {
outHistoryPath.clear();
if (!m_capturePending) {
return;
}
if (!framePresented || drawData.Empty() || width == 0u || height == 0u) {
return;
return false;
}
std::error_code errorCode = {};
@@ -69,52 +61,70 @@ void AutoScreenshotController::CaptureIfRequested(
if (errorCode) {
m_lastCaptureError = "Failed to create screenshot directory: " + m_captureRoot.string();
m_lastCaptureSummary = "AutoShot failed";
m_capturePending = false;
return;
ResetPendingRequest();
return false;
}
std::filesystem::create_directories(m_historyRoot, errorCode);
if (errorCode) {
m_lastCaptureError = "Failed to create screenshot directory: " + m_historyRoot.string();
m_lastCaptureSummary = "AutoShot failed";
m_capturePending = false;
ResetPendingRequest();
return false;
}
m_activeHistoryCapturePath = BuildHistoryCapturePath(m_pendingReason);
outHistoryPath = m_activeHistoryCapturePath;
return true;
}
void AutoScreenshotController::CompleteCaptureSuccess(const std::filesystem::path& historyPath) {
const std::filesystem::path resolvedHistoryPath =
historyPath.empty() ? m_activeHistoryCapturePath : historyPath;
if (resolvedHistoryPath.empty()) {
CompleteCaptureFailure("Capture completed without a valid history path.");
return;
}
std::string captureError = {};
const std::filesystem::path historyPath = BuildHistoryCapturePath(m_pendingReason);
if (!renderer.CaptureToPng(
&windowRenderer,
drawData,
width,
height,
historyPath,
captureError)) {
m_lastCaptureError = std::move(captureError);
m_lastCaptureSummary = "AutoShot failed";
m_capturePending = false;
std::error_code errorCode = {};
const std::uintmax_t historyFileSize =
std::filesystem::file_size(resolvedHistoryPath, errorCode);
if (errorCode || historyFileSize == 0u) {
CompleteCaptureFailure("Capture completed without a valid PNG payload.");
return;
}
errorCode.clear();
std::filesystem::copy_file(
historyPath,
resolvedHistoryPath,
m_latestCapturePath,
std::filesystem::copy_options::overwrite_existing,
errorCode);
if (errorCode) {
m_lastCaptureError = "Failed to update latest screenshot: " + m_latestCapturePath.string();
m_lastCaptureSummary = "AutoShot failed";
m_capturePending = false;
ResetPendingRequest();
return;
}
++m_captureCount;
m_lastCaptureError.clear();
m_lastCaptureSummary =
"Shot: latest.png | " + historyPath.filename().string();
m_capturePending = false;
m_pendingReason.clear();
"Shot: latest.png | " + resolvedHistoryPath.filename().string();
ResetPendingRequest();
}
void AutoScreenshotController::CompleteCaptureFailure(std::string error) {
if (!m_activeHistoryCapturePath.empty()) {
std::error_code deleteError = {};
std::filesystem::remove(m_activeHistoryCapturePath, deleteError);
}
m_lastCaptureError = error.empty()
? "Screenshot capture failed."
: std::move(error);
m_lastCaptureSummary = "AutoShot failed";
ResetPendingRequest();
}
bool AutoScreenshotController::HasPendingCapture() const {
@@ -133,6 +143,12 @@ const std::string& AutoScreenshotController::GetLastCaptureError() const {
return m_lastCaptureError;
}
void AutoScreenshotController::ResetPendingRequest() {
m_capturePending = false;
m_pendingReason.clear();
m_activeHistoryCapturePath.clear();
}
std::filesystem::path AutoScreenshotController::BuildHistoryCapturePath(std::string_view reason) const {
std::ostringstream filename;
filename << BuildTimestampString()