Skip to content

Commit

Permalink
AtlasEngine: Redraw immediately on opacity changes (#12226)
Browse files Browse the repository at this point in the history
Since `AtlasEngine` prefers drawing without alpha for performance reasons,
calls to `EnableTransparentBackground` require a draw cycle.
This PR makes `Renderer::_NotifyPaintFrame` public and calls it.

Related to #9999.

## PR Checklist
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed

* Open Windows Terminal command palette
* Choose "Set background opacity..."
* Cycling through the items without selecting one
  changes background opacity immediately ✅
  • Loading branch information
lhecker authored Jan 25, 2022
1 parent 57b93d2 commit f210784
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (_renderEngine)
{
_renderEngine->EnableTransparentBackground(_isBackgroundTransparent());
_renderer->NotifyPaintFrame();
}

auto eventArgs = winrt::make_self<TransparencyChangedEventArgs>(newOpacity);
Expand Down
22 changes: 11 additions & 11 deletions src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ try
// at the next opportunity.
if (pEngine->RequiresContinuousRedraw())
{
_NotifyPaintFrame();
NotifyPaintFrame();
}
});

Expand Down Expand Up @@ -183,7 +183,7 @@ try
}
CATCH_RETURN()

void Renderer::_NotifyPaintFrame()
void Renderer::NotifyPaintFrame() noexcept
{
// If we're running in the unittests, we might not have a render thread.
if (_pThread)
Expand All @@ -206,7 +206,7 @@ void Renderer::TriggerSystemRedraw(const RECT* const prcDirtyClient)
LOG_IF_FAILED(pEngine->InvalidateSystem(prcDirtyClient));
}

_NotifyPaintFrame();
NotifyPaintFrame();
}

// Routine Description:
Expand Down Expand Up @@ -240,7 +240,7 @@ void Renderer::TriggerRedraw(const Viewport& region)
LOG_IF_FAILED(pEngine->Invalidate(&srUpdateRegion));
}

_NotifyPaintFrame();
NotifyPaintFrame();
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ void Renderer::TriggerRedrawCursor(const COORD* const pcoord)
LOG_IF_FAILED(pEngine->InvalidateCursor(&updateRect));
}

_NotifyPaintFrame();
NotifyPaintFrame();
}
}
}
Expand All @@ -311,7 +311,7 @@ void Renderer::TriggerRedrawAll()
LOG_IF_FAILED(pEngine->InvalidateAll());
}

_NotifyPaintFrame();
NotifyPaintFrame();
}

// Method Description:
Expand Down Expand Up @@ -377,7 +377,7 @@ void Renderer::TriggerSelection()

_previousSelection = std::move(rects);

_NotifyPaintFrame();
NotifyPaintFrame();
}
CATCH_LOG();
}
Expand Down Expand Up @@ -425,7 +425,7 @@ void Renderer::TriggerScroll()
{
if (_CheckViewportAndScroll())
{
_NotifyPaintFrame();
NotifyPaintFrame();
}
}

Expand All @@ -447,7 +447,7 @@ void Renderer::TriggerScroll(const COORD* const pcoordDelta)

_ScrollPreviousSelection(til::point{ *pcoordDelta });

_NotifyPaintFrame();
NotifyPaintFrame();
}

// Routine Description:
Expand Down Expand Up @@ -490,7 +490,7 @@ void Renderer::TriggerTitleChange()
{
LOG_IF_FAILED(pEngine->InvalidateTitle(newTitle));
}
_NotifyPaintFrame();
NotifyPaintFrame();
}

// Routine Description:
Expand Down Expand Up @@ -521,7 +521,7 @@ void Renderer::TriggerFontChange(const int iDpi, const FontInfoDesired& FontInfo
LOG_IF_FAILED(pEngine->UpdateFont(FontInfoDesired, FontInfo));
}

_NotifyPaintFrame();
NotifyPaintFrame();
}

// Routine Description:
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/base/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Microsoft::Console::Render

[[nodiscard]] HRESULT PaintFrame();

void NotifyPaintFrame() noexcept;
void TriggerSystemRedraw(const RECT* const prcDirtyClient);
void TriggerRedraw(const Microsoft::Console::Types::Viewport& region) override;
void TriggerRedraw(const COORD* const pcoord) override;
Expand Down Expand Up @@ -82,7 +83,6 @@ namespace Microsoft::Console::Render
static IRenderEngine::GridLineSet s_GetGridlines(const TextAttribute& textAttribute) noexcept;
static bool s_IsSoftFontChar(const std::wstring_view& v, const size_t firstSoftFontChar, const size_t lastSoftFontChar);

void _NotifyPaintFrame();
[[nodiscard]] HRESULT _PaintFrameForEngine(_In_ IRenderEngine* const pEngine) noexcept;
bool _CheckViewportAndScroll();
[[nodiscard]] HRESULT _PaintBackground(_In_ IRenderEngine* const pEngine);
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/base/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ DWORD WINAPI RenderThread::_ThreadProc()
return S_OK;
}

void RenderThread::NotifyPaint()
void RenderThread::NotifyPaint() noexcept
{
if (_fWaiting.load(std::memory_order_acquire))
{
Expand All @@ -231,17 +231,17 @@ void RenderThread::NotifyPaint()
}
}

void RenderThread::EnablePainting()
void RenderThread::EnablePainting() noexcept
{
SetEvent(_hPaintEnabledEvent);
}

void RenderThread::DisablePainting()
void RenderThread::DisablePainting() noexcept
{
ResetEvent(_hPaintEnabledEvent);
}

void RenderThread::WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs)
void RenderThread::WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) noexcept
{
// When rendering takes place via DirectX, and a console application
// currently owns the screen, and a new console application is launched (or
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/base/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ namespace Microsoft::Console::Render

[[nodiscard]] HRESULT Initialize(Renderer* const pRendererParent) noexcept;

void NotifyPaint();

void EnablePainting();
void DisablePainting();
void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs);
void NotifyPaint() noexcept;
void EnablePainting() noexcept;
void DisablePainting() noexcept;
void WaitForPaintCompletionAndDisable(const DWORD dwTimeoutMs) noexcept;

private:
static DWORD WINAPI s_ThreadProc(_In_ LPVOID lpParameter);
Expand Down

0 comments on commit f210784

Please sign in to comment.