Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable hot reload of renderer settings that aren't already hot reload capable #6551

Merged
4 commits merged into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,32 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// Update our control settings
_ApplyUISettings();

// Update DxEngine's SelectionBackground
_renderEngine->SetSelectionBackground(_settings.SelectionBackground());

// Update the terminal core with its new Core settings
_terminal->UpdateSettings(_settings);

auto lock = _terminal->LockForWriting();

// Update DxEngine settings under the lock
_renderEngine->SetSelectionBackground(_settings.SelectionBackground());

_renderEngine->SetRetroTerminalEffects(_settings.RetroTerminalEffect());
_renderEngine->SetForceFullRepaintRendering(_settings.ForceFullRepaintRendering());
_renderEngine->SetSoftwareRendering(_settings.SoftwareRendering());

switch (_settings.AntialiasingMode())
{
case TextAntialiasingMode::Cleartype:
_renderEngine->SetAntialiasingMode(D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE);
break;
case TextAntialiasingMode::Aliased:
_renderEngine->SetAntialiasingMode(D2D1_TEXT_ANTIALIAS_MODE_ALIASED);
break;
case TextAntialiasingMode::Grayscale:
default:
_renderEngine->SetAntialiasingMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
break;
}

// Refresh our font with the renderer
const auto actualFontOldSize = _actualFont.GetSize();
_UpdateFont();
Expand Down Expand Up @@ -611,13 +629,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation

_terminal->CreateFromSettings(_settings, renderTarget);

// TODO:GH#3927 - Make it possible to hot-reload these settings. Right
// here, the setting will only be used when the Terminal is initialized.
dxEngine->SetRetroTerminalEffects(_settings.RetroTerminalEffect());
dxEngine->SetForceFullRepaintRendering(_settings.ForceFullRepaintRendering());
dxEngine->SetSoftwareRendering(_settings.SoftwareRendering());

// TODO:GH#3927 - hot-reload this one too
// Update DxEngine's AntialiasingMode
switch (_settings.AntialiasingMode())
{
Expand Down
44 changes: 39 additions & 5 deletions src/renderer/dx/DxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ DxEngine::DxEngine() :
_boxDrawingEffect{},
_haveDeviceResources{ false },
_swapChainFrameLatencyWaitableObject{ INVALID_HANDLE_VALUE },
_recreateDeviceRequested{ false },
_retroTerminalEffects{ false },
_forceFullRepaintRendering{ false },
_softwareRendering{ false },
Expand Down Expand Up @@ -621,6 +622,9 @@ void DxEngine::_ReleaseDeviceResources() noexcept
try
{
_haveDeviceResources = false;

_pixelShaderSettingsBuffer.Reset();

_d2dBrushForeground.Reset();
_d2dBrushBackground.Reset();

Expand Down Expand Up @@ -703,19 +707,39 @@ void DxEngine::SetCallback(std::function<void()> pfn)
}

void DxEngine::SetRetroTerminalEffects(bool enable) noexcept
try
{
_retroTerminalEffects = enable;
if (_retroTerminalEffects != enable)
{
_retroTerminalEffects = enable;
_recreateDeviceRequested = true;
LOG_IF_FAILED(InvalidateAll());
}
}
CATCH_LOG()

void DxEngine::SetForceFullRepaintRendering(bool enable) noexcept
try
{
_forceFullRepaintRendering = enable;
if (_forceFullRepaintRendering != enable)
{
_forceFullRepaintRendering = enable;
LOG_IF_FAILED(InvalidateAll());
}
}
CATCH_LOG()

void DxEngine::SetSoftwareRendering(bool enable) noexcept
try
{
_softwareRendering = enable;
if (_softwareRendering != enable)
{
_softwareRendering = enable;
_recreateDeviceRequested = true;
LOG_IF_FAILED(InvalidateAll());
}
}
CATCH_LOG()

Microsoft::WRL::ComPtr<IDXGISwapChain1> DxEngine::GetSwapChain()
{
Expand Down Expand Up @@ -965,9 +989,13 @@ try
if (_isEnabled)
{
const auto clientSize = _GetClientSize();
if (!_haveDeviceResources)

// If we don't have device resources or if someone has requested that we
// recreate the device... then make new resources. (Create will dump the old ones.)
if (!_haveDeviceResources || _recreateDeviceRequested)
{
RETURN_IF_FAILED(_CreateDeviceResources(true));
_recreateDeviceRequested = false;
}
else if (_displaySizePixels != clientSize || _prevScale != _scale)
{
Expand Down Expand Up @@ -2172,9 +2200,15 @@ void DxEngine::SetSelectionBackground(const COLORREF color) noexcept
// Return Value:
// - N/A
void DxEngine::SetAntialiasingMode(const D2D1_TEXT_ANTIALIAS_MODE antialiasingMode) noexcept
try
{
_antialiasingMode = antialiasingMode;
if (_antialiasingMode != antialiasingMode)
{
_antialiasingMode = antialiasingMode;
LOG_IF_FAILED(InvalidateAll());
}
}
CATCH_LOG()

// Method Description:
// - Update our tracker of the opacity of our background. We can only
Expand Down
1 change: 1 addition & 0 deletions src/renderer/dx/DxRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace Microsoft::Console::Render
::Microsoft::WRL::ComPtr<ID2D1StrokeStyle> _strokeStyle;

// Device-Dependent Resources
bool _recreateDeviceRequested;
bool _haveDeviceResources;
::Microsoft::WRL::ComPtr<ID3D11Device> _d3dDevice;
::Microsoft::WRL::ComPtr<ID3D11DeviceContext> _d3dDeviceContext;
Expand Down