From c113b65d9b15028281f6383909a73dba6af55bfc Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 20 Apr 2021 12:16:31 -0500 Subject: [PATCH] Revert "Use DComp surface handle for Swap Chain management." This reverts commit 30b833547928d6dcbf88d49df0dbd5b3f6a7c879. --- src/cascadia/TerminalControl/ControlCore.cpp | 4 ++-- src/cascadia/TerminalControl/ControlCore.h | 2 +- src/cascadia/TerminalControl/TermControl.cpp | 12 +++++----- src/cascadia/TerminalControl/TermControl.h | 3 ++- src/common.build.post.props | 2 +- src/renderer/dx/DxRenderer.cpp | 23 ++++++-------------- src/renderer/dx/DxRenderer.hpp | 3 +-- src/renderer/dx/precomp.h | 2 -- 8 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index de9926320e..ac88139c24 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1192,9 +1192,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation } } - HANDLE ControlCore::GetSwapChainHandle() const + IDXGISwapChain1* ControlCore::GetSwapChain() const { - return _renderEngine->GetSwapChainHandle(); + return _renderEngine->GetSwapChain().Get(); } void ControlCore::_rendererWarning(const HRESULT hr) diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index ac124412fe..29ce4a532c 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -49,7 +49,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void UpdateAppearance(IControlAppearance newAppearance); void SizeChanged(const double width, const double height); void ScaleChanged(const double scaleX, const double scaleY); - HANDLE GetSwapChainHandle() const; + IDXGISwapChain1* GetSwapChain() const; void AdjustFontSize(int fontSizeDelta); void ResetFontSize(); diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 000bf3958e..51486718c5 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -572,14 +572,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation // This event is only registered during terminal initialization, // so we don't need to check _initializedTerminal. // We also don't lock for things that come back from the renderer. - auto chainHandle = _core->GetSwapChainHandle(); + auto chain = _core->GetSwapChain(); auto weakThis{ get_weak() }; co_await winrt::resume_foreground(Dispatcher()); if (auto control{ weakThis.get() }) { - _AttachDxgiSwapChainToXaml(chainHandle); + _AttachDxgiSwapChainToXaml(chain); } } @@ -625,10 +625,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation } } - void TermControl::_AttachDxgiSwapChainToXaml(HANDLE swapChainHandle) + void TermControl::_AttachDxgiSwapChainToXaml(IDXGISwapChain1* swapChain) { - auto nativePanel = SwapChainPanel().as(); - nativePanel->SetSwapChainHandle(swapChainHandle); + auto nativePanel = SwapChainPanel().as(); + nativePanel->SetSwapChain(swapChain); } bool TermControl::_InitializeTerminal() @@ -667,7 +667,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } _interactivity->Initialize(); - _AttachDxgiSwapChainToXaml(_core->GetSwapChainHandle()); + _AttachDxgiSwapChainToXaml(_core->GetSwapChain()); // Tell the DX Engine to notify us when the swap chain changes. We do // this after we initially set the swapchain so as to avoid unnecessary diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index a4ebffc924..1fcb48ee1f 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -66,8 +66,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation void ToggleShaderEffects(); winrt::fire_and_forget RenderEngineSwapChainChanged(const IInspectable& sender, const IInspectable& args); - void _AttachDxgiSwapChainToXaml(HANDLE swapChainHandle); + void _AttachDxgiSwapChainToXaml(IDXGISwapChain1* swapChain); winrt::fire_and_forget _RendererEnteredErrorState(const IInspectable& sender, const IInspectable& args); + void _RenderRetryButton_Click(IInspectable const& button, IInspectable const& args); winrt::fire_and_forget _RendererWarning(const IInspectable& sender, const Control::RendererWarningArgs& args); diff --git a/src/common.build.post.props b/src/common.build.post.props index c3b0d52121..e3e563b900 100644 --- a/src/common.build.post.props +++ b/src/common.build.post.props @@ -13,7 +13,7 @@ ProgramDatabase - onecoreuap_apiset.lib;d3dcompiler.lib;dwmapi.lib;uxtheme.lib;shlwapi.lib;ntdll.lib;dcomp.lib;%(AdditionalDependencies) + onecoreuap_apiset.lib;d3dcompiler.lib;dwmapi.lib;uxtheme.lib;shlwapi.lib;ntdll.lib;%(AdditionalDependencies) diff --git a/src/renderer/dx/DxRenderer.cpp b/src/renderer/dx/DxRenderer.cpp index 77709d932f..1763f3c5b5 100644 --- a/src/renderer/dx/DxRenderer.cpp +++ b/src/renderer/dx/DxRenderer.cpp @@ -79,7 +79,6 @@ DxEngine::DxEngine() : _backgroundColor{ 0 }, _selectionBackground{}, _haveDeviceResources{ false }, - _swapChainHandle{ INVALID_HANDLE_VALUE }, _swapChainDesc{ 0 }, _swapChainFrameLatencyWaitableObject{ INVALID_HANDLE_VALUE }, _recreateDeviceRequested{ false }, @@ -619,13 +618,6 @@ try } case SwapChainMode::ForComposition: { - if (!_swapChainHandle) - { - RETURN_IF_FAILED(DCompositionCreateSurfaceHandle(GENERIC_ALL, nullptr, &_swapChainHandle)); - } - - RETURN_IF_FAILED(_dxgiFactory2.As(&_dxgiFactoryMedia)); - // Use the given target size for compositions. _swapChainDesc.Width = _displaySizePixels.width(); _swapChainDesc.Height = _displaySizePixels.height(); @@ -635,11 +627,10 @@ try // It's 100% required to use scaling mode stretch for composition. There is no other choice. _swapChainDesc.Scaling = DXGI_SCALING_STRETCH; - RETURN_IF_FAILED(_dxgiFactoryMedia->CreateSwapChainForCompositionSurfaceHandle(_d3dDevice.Get(), - _swapChainHandle.get(), - &_swapChainDesc, - nullptr, - &_dxgiSwapChain)); + RETURN_IF_FAILED(_dxgiFactory2->CreateSwapChainForComposition(_d3dDevice.Get(), + &_swapChainDesc, + nullptr, + &_dxgiSwapChain)); break; } default: @@ -1012,14 +1003,14 @@ try } CATCH_LOG() -HANDLE DxEngine::GetSwapChainHandle() +Microsoft::WRL::ComPtr DxEngine::GetSwapChain() { - if (!_swapChainHandle) + if (_dxgiSwapChain.Get() == nullptr) { THROW_IF_FAILED(_CreateDeviceResources(true)); } - return _swapChainHandle.get(); + return _dxgiSwapChain; } void DxEngine::_InvalidateRectangle(const til::rectangle& rc) diff --git a/src/renderer/dx/DxRenderer.hpp b/src/renderer/dx/DxRenderer.hpp index f4ae176c7e..7de6832146 100644 --- a/src/renderer/dx/DxRenderer.hpp +++ b/src/renderer/dx/DxRenderer.hpp @@ -70,7 +70,7 @@ namespace Microsoft::Console::Render void SetSoftwareRendering(bool enable) noexcept; - HANDLE GetSwapChainHandle(); + ::Microsoft::WRL::ComPtr GetSwapChain(); // IRenderEngine Members [[nodiscard]] HRESULT Invalidate(const SMALL_RECT* const psrRegion) noexcept override; @@ -212,7 +212,6 @@ namespace Microsoft::Console::Render ::Microsoft::WRL::ComPtr _d2dBrushBackground; ::Microsoft::WRL::ComPtr _dxgiFactory2; - ::Microsoft::WRL::ComPtr _dxgiFactoryMedia; ::Microsoft::WRL::ComPtr _dxgiDevice; ::Microsoft::WRL::ComPtr _dxgiSurface; diff --git a/src/renderer/dx/precomp.h b/src/renderer/dx/precomp.h index d3d51af5f5..5715fd8fed 100644 --- a/src/renderer/dx/precomp.h +++ b/src/renderer/dx/precomp.h @@ -21,8 +21,6 @@ #include #include -#include - #include #include #include