From 0e7bf8d16e94ce289bd0091acf9aa47b71102a1a Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 15 Apr 2026 08:45:04 +0800 Subject: [PATCH] refactor(new_editor/app): split frame support and texture decoding --- new_editor/CMakeLists.txt | 2 + .../app/Platform/Win32/EditorWindowFrame.cpp | 57 ------- .../Win32/EditorWindowFrameSupport.cpp | 71 +++++++++ .../Native/NativeRendererTextureDecoding.cpp | 150 ++++++++++++++++++ .../Native/NativeRendererTextures.cpp | 142 ----------------- 5 files changed, 223 insertions(+), 199 deletions(-) create mode 100644 new_editor/app/Platform/Win32/EditorWindowFrameSupport.cpp create mode 100644 new_editor/app/Rendering/Native/NativeRendererTextureDecoding.cpp diff --git a/new_editor/CMakeLists.txt b/new_editor/CMakeLists.txt index 4683a9fc..27af0914 100644 --- a/new_editor/CMakeLists.txt +++ b/new_editor/CMakeLists.txt @@ -181,6 +181,7 @@ set(XCUI_EDITOR_HOST_RENDERING_SOURCES app/Rendering/Native/NativeRendererLifecycle.cpp app/Rendering/Native/NativeRendererRendering.cpp app/Rendering/Native/NativeRendererText.cpp + app/Rendering/Native/NativeRendererTextureDecoding.cpp app/Rendering/Native/NativeRendererTextures.cpp ) @@ -270,6 +271,7 @@ if(XCENGINE_BUILD_XCUI_EDITOR_APP) app/Platform/Win32/EditorWindowBorderlessPlacement.cpp app/Platform/Win32/EditorWindowBorderlessResize.cpp app/Platform/Win32/EditorWindowFrame.cpp + app/Platform/Win32/EditorWindowFrameSupport.cpp app/Platform/Win32/EditorWindowTitleBar.cpp app/Platform/Win32/EditorWindowTitleBarDragRestore.cpp app/Platform/Win32/EditorWindowTitleBarInteraction.cpp diff --git a/new_editor/app/Platform/Win32/EditorWindowFrame.cpp b/new_editor/app/Platform/Win32/EditorWindowFrame.cpp index 842b64bf..1606d6f3 100644 --- a/new_editor/app/Platform/Win32/EditorWindowFrame.cpp +++ b/new_editor/app/Platform/Win32/EditorWindowFrame.cpp @@ -175,61 +175,4 @@ UIRect EditorWindow::ResolveWorkspaceBounds(float clientWidthDips, float clientH (std::max)(0.0f, clientHeightDips - titleBarHeight)); } -std::string EditorWindow::BuildCaptureStatusText() const { - if (m_render.autoScreenshot.HasPendingCapture()) { - return "Shot pending..."; - } - - if (!m_render.autoScreenshot.GetLastCaptureError().empty()) { - return TruncateText(m_render.autoScreenshot.GetLastCaptureError(), 38u); - } - - if (!m_render.autoScreenshot.GetLastCaptureSummary().empty()) { - return TruncateText(m_render.autoScreenshot.GetLastCaptureSummary(), 38u); - } - - return {}; -} - -void EditorWindow::ApplyHostCaptureRequests(const UIEditorShellInteractionResult& result) { - if (result.requestPointerCapture && GetCapture() != m_window.hwnd) { - SetCapture(m_window.hwnd); - } - if (result.releasePointerCapture && GetCapture() == m_window.hwnd) { - ReleaseCapture(); - } -} - -void EditorWindow::ApplyHostedContentCaptureRequests() { - if (m_composition.shellRuntime.WantsHostPointerCapture() && - GetCapture() != m_window.hwnd) { - SetCapture(m_window.hwnd); - } - - if (m_composition.shellRuntime.WantsHostPointerRelease() && - GetCapture() == m_window.hwnd && - !m_composition.shellRuntime.HasShellInteractiveCapture()) { - ReleaseCapture(); - } -} - -std::string EditorWindow::DescribeInputEvents( - const std::vector& events) const { - std::ostringstream stream = {}; - stream << "events=["; - for (std::size_t index = 0; index < events.size(); ++index) { - if (index > 0u) { - stream << " | "; - } - const UIInputEvent& event = events[index]; - stream << DescribeInputEventType(event) - << '@' - << static_cast(event.position.x) - << ',' - << static_cast(event.position.y); - } - stream << ']'; - return stream.str(); -} - } // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Platform/Win32/EditorWindowFrameSupport.cpp b/new_editor/app/Platform/Win32/EditorWindowFrameSupport.cpp new file mode 100644 index 00000000..27663cc6 --- /dev/null +++ b/new_editor/app/Platform/Win32/EditorWindowFrameSupport.cpp @@ -0,0 +1,71 @@ +#include "Platform/Win32/EditorWindow.h" +#include "Platform/Win32/EditorWindowInputSupport.h" +#include "Support/TextFormat.h" + +#include + +namespace XCEngine::UI::Editor::App { + +using namespace EditorWindowSupport; +using ::XCEngine::UI::Editor::Support::TruncateText; +using ::XCEngine::UI::UIInputEvent; + +std::string EditorWindow::BuildCaptureStatusText() const { + if (m_render.autoScreenshot.HasPendingCapture()) { + return "Shot pending..."; + } + + if (!m_render.autoScreenshot.GetLastCaptureError().empty()) { + return TruncateText(m_render.autoScreenshot.GetLastCaptureError(), 38u); + } + + if (!m_render.autoScreenshot.GetLastCaptureSummary().empty()) { + return TruncateText(m_render.autoScreenshot.GetLastCaptureSummary(), 38u); + } + + return {}; +} + +void EditorWindow::ApplyHostCaptureRequests(const UIEditorShellInteractionResult& result) { + if (result.requestPointerCapture && GetCapture() != m_window.hwnd) { + SetCapture(m_window.hwnd); + } + if (result.releasePointerCapture && GetCapture() == m_window.hwnd) { + ReleaseCapture(); + } +} + +void EditorWindow::ApplyHostedContentCaptureRequests() { + if (m_composition.shellRuntime.WantsHostPointerCapture() && + GetCapture() != m_window.hwnd) { + SetCapture(m_window.hwnd); + } + + if (m_composition.shellRuntime.WantsHostPointerRelease() && + GetCapture() == m_window.hwnd && + !m_composition.shellRuntime.HasShellInteractiveCapture()) { + ReleaseCapture(); + } +} + +std::string EditorWindow::DescribeInputEvents( + const std::vector& events) const { + std::ostringstream stream = {}; + stream << "events=["; + for (std::size_t index = 0; index < events.size(); ++index) { + if (index > 0u) { + stream << " | "; + } + + const UIInputEvent& event = events[index]; + stream << DescribeInputEventType(event) + << '@' + << static_cast(event.position.x) + << ',' + << static_cast(event.position.y); + } + stream << ']'; + return stream.str(); +} + +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Rendering/Native/NativeRendererTextureDecoding.cpp b/new_editor/app/Rendering/Native/NativeRendererTextureDecoding.cpp new file mode 100644 index 00000000..4c1ed5b8 --- /dev/null +++ b/new_editor/app/Rendering/Native/NativeRendererTextureDecoding.cpp @@ -0,0 +1,150 @@ +#include "NativeRendererSupport.h" + +#include + +namespace XCEngine::UI::Editor::Host { + +using namespace NativeRendererSupport; + +bool NativeRenderer::DecodeTextureFile( + const std::filesystem::path& path, + NativeTextureResource& outTexture, + std::string& outError) { + outError.clear(); + if (!EnsureWicFactory(outError)) { + return false; + } + + const std::wstring widePath = path.wstring(); + Microsoft::WRL::ComPtr decoder; + HRESULT hr = m_wicFactory->CreateDecoderFromFilename( + widePath.c_str(), + nullptr, + GENERIC_READ, + WICDecodeMetadataCacheOnLoad, + decoder.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !decoder) { + outError = HrToString("IWICImagingFactory::CreateDecoderFromFilename", hr); + return false; + } + + Microsoft::WRL::ComPtr frame; + hr = decoder->GetFrame(0u, frame.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !frame) { + outError = HrToString("IWICBitmapDecoder::GetFrame", hr); + return false; + } + + return DecodeTextureFrame(*frame.Get(), outTexture, outError); +} + +bool NativeRenderer::DecodeTextureMemory( + const std::uint8_t* data, + std::size_t size, + NativeTextureResource& outTexture, + std::string& outError) { + outError.clear(); + if (data == nullptr || size == 0u) { + outError = "DecodeTextureMemory rejected an empty image payload."; + return false; + } + + if (size > static_cast((std::numeric_limits::max)())) { + outError = "DecodeTextureMemory payload exceeds WIC stream limits."; + return false; + } + + if (!EnsureWicFactory(outError)) { + return false; + } + + Microsoft::WRL::ComPtr stream; + HRESULT hr = m_wicFactory->CreateStream(stream.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !stream) { + outError = HrToString("IWICImagingFactory::CreateStream", hr); + return false; + } + + hr = stream->InitializeFromMemory( + const_cast(reinterpret_cast(data)), + static_cast(size)); + if (FAILED(hr)) { + outError = HrToString("IWICStream::InitializeFromMemory", hr); + return false; + } + + Microsoft::WRL::ComPtr decoder; + hr = m_wicFactory->CreateDecoderFromStream( + stream.Get(), + nullptr, + WICDecodeMetadataCacheOnLoad, + decoder.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !decoder) { + outError = HrToString("IWICImagingFactory::CreateDecoderFromStream", hr); + return false; + } + + Microsoft::WRL::ComPtr frame; + hr = decoder->GetFrame(0u, frame.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !frame) { + outError = HrToString("IWICBitmapDecoder::GetFrame", hr); + return false; + } + + return DecodeTextureFrame(*frame.Get(), outTexture, outError); +} + +bool NativeRenderer::DecodeTextureFrame( + IWICBitmapSource& source, + NativeTextureResource& outTexture, + std::string& outError) { + outError.clear(); + + Microsoft::WRL::ComPtr converter; + HRESULT hr = m_wicFactory->CreateFormatConverter(converter.ReleaseAndGetAddressOf()); + if (FAILED(hr) || !converter) { + outError = HrToString("IWICImagingFactory::CreateFormatConverter", hr); + return false; + } + + hr = converter->Initialize( + &source, + GUID_WICPixelFormat32bppPBGRA, + WICBitmapDitherTypeNone, + nullptr, + 0.0f, + WICBitmapPaletteTypeCustom); + if (FAILED(hr)) { + outError = HrToString("IWICFormatConverter::Initialize", hr); + return false; + } + + UINT width = 0u; + UINT height = 0u; + hr = converter->GetSize(&width, &height); + if (FAILED(hr) || width == 0u || height == 0u) { + outError = HrToString("IWICBitmapSource::GetSize", hr); + return false; + } + + std::vector pixels( + static_cast(width) * static_cast(height) * 4u); + hr = converter->CopyPixels( + nullptr, + width * 4u, + static_cast(pixels.size()), + pixels.data()); + if (FAILED(hr)) { + outError = HrToString("IWICBitmapSource::CopyPixels", hr); + return false; + } + + outTexture.pixels = std::move(pixels); + outTexture.width = width; + outTexture.height = height; + outTexture.cachedBitmap.Reset(); + outTexture.cachedTarget = nullptr; + return true; +} + +} // namespace XCEngine::UI::Editor::Host diff --git a/new_editor/app/Rendering/Native/NativeRendererTextures.cpp b/new_editor/app/Rendering/Native/NativeRendererTextures.cpp index 422db24b..ab692d7b 100644 --- a/new_editor/app/Rendering/Native/NativeRendererTextures.cpp +++ b/new_editor/app/Rendering/Native/NativeRendererTextures.cpp @@ -1,7 +1,6 @@ #include "NativeRendererSupport.h" #include -#include #include namespace XCEngine::UI::Editor::Host { @@ -71,147 +70,6 @@ void NativeRenderer::ReleaseTexture(::XCEngine::UI::UITextureHandle& texture) { texture = {}; } -bool NativeRenderer::DecodeTextureFile( - const std::filesystem::path& path, - NativeTextureResource& outTexture, - std::string& outError) { - outError.clear(); - if (!EnsureWicFactory(outError)) { - return false; - } - - const std::wstring widePath = path.wstring(); - Microsoft::WRL::ComPtr decoder; - HRESULT hr = m_wicFactory->CreateDecoderFromFilename( - widePath.c_str(), - nullptr, - GENERIC_READ, - WICDecodeMetadataCacheOnLoad, - decoder.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !decoder) { - outError = HrToString("IWICImagingFactory::CreateDecoderFromFilename", hr); - return false; - } - - Microsoft::WRL::ComPtr frame; - hr = decoder->GetFrame(0u, frame.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !frame) { - outError = HrToString("IWICBitmapDecoder::GetFrame", hr); - return false; - } - - return DecodeTextureFrame(*frame.Get(), outTexture, outError); -} - -bool NativeRenderer::DecodeTextureMemory( - const std::uint8_t* data, - std::size_t size, - NativeTextureResource& outTexture, - std::string& outError) { - outError.clear(); - if (data == nullptr || size == 0u) { - outError = "DecodeTextureMemory rejected an empty image payload."; - return false; - } - - if (size > static_cast((std::numeric_limits::max)())) { - outError = "DecodeTextureMemory payload exceeds WIC stream limits."; - return false; - } - - if (!EnsureWicFactory(outError)) { - return false; - } - - Microsoft::WRL::ComPtr stream; - HRESULT hr = m_wicFactory->CreateStream(stream.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !stream) { - outError = HrToString("IWICImagingFactory::CreateStream", hr); - return false; - } - - hr = stream->InitializeFromMemory( - const_cast(reinterpret_cast(data)), - static_cast(size)); - if (FAILED(hr)) { - outError = HrToString("IWICStream::InitializeFromMemory", hr); - return false; - } - - Microsoft::WRL::ComPtr decoder; - hr = m_wicFactory->CreateDecoderFromStream( - stream.Get(), - nullptr, - WICDecodeMetadataCacheOnLoad, - decoder.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !decoder) { - outError = HrToString("IWICImagingFactory::CreateDecoderFromStream", hr); - return false; - } - - Microsoft::WRL::ComPtr frame; - hr = decoder->GetFrame(0u, frame.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !frame) { - outError = HrToString("IWICBitmapDecoder::GetFrame", hr); - return false; - } - - return DecodeTextureFrame(*frame.Get(), outTexture, outError); -} - -bool NativeRenderer::DecodeTextureFrame( - IWICBitmapSource& source, - NativeTextureResource& outTexture, - std::string& outError) { - outError.clear(); - - Microsoft::WRL::ComPtr converter; - HRESULT hr = m_wicFactory->CreateFormatConverter(converter.ReleaseAndGetAddressOf()); - if (FAILED(hr) || !converter) { - outError = HrToString("IWICImagingFactory::CreateFormatConverter", hr); - return false; - } - - hr = converter->Initialize( - &source, - GUID_WICPixelFormat32bppPBGRA, - WICBitmapDitherTypeNone, - nullptr, - 0.0f, - WICBitmapPaletteTypeCustom); - if (FAILED(hr)) { - outError = HrToString("IWICFormatConverter::Initialize", hr); - return false; - } - - UINT width = 0u; - UINT height = 0u; - hr = converter->GetSize(&width, &height); - if (FAILED(hr) || width == 0u || height == 0u) { - outError = HrToString("IWICBitmapSource::GetSize", hr); - return false; - } - - std::vector pixels( - static_cast(width) * static_cast(height) * 4u); - hr = converter->CopyPixels( - nullptr, - width * 4u, - static_cast(pixels.size()), - pixels.data()); - if (FAILED(hr)) { - outError = HrToString("IWICBitmapSource::CopyPixels", hr); - return false; - } - - outTexture.pixels = std::move(pixels); - outTexture.width = width; - outTexture.height = height; - outTexture.cachedBitmap.Reset(); - outTexture.cachedTarget = nullptr; - return true; -} - bool NativeRenderer::ResolveTextureBitmap( ID2D1RenderTarget& renderTarget, NativeTextureResource& texture,