okay this seems to fix opacity & cleartype in all cases

This commit is contained in:
Mike Griese 2021-10-20 11:50:50 -05:00
parent 70b9f8ce5f
commit 03711944f1
5 changed files with 33 additions and 21 deletions

View file

@ -278,7 +278,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// GH#5098: Inform the engine of the opacity of the default text background.
// GH#11315: Always do this, even if they don't have acrylic on.
_renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(_settings->Opacity()));
const auto ua = UseAcrylic();
_renderEngine->SetDefaultTextBackgroundOpacity(ua);
THROW_IF_FAILED(_renderEngine->Enable());
@ -464,6 +465,13 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_runtimeUseAcrylic = newOpacity < 1.0;
}
// if (_renderEngine)
// {
// auto lock = _terminal->LockForWriting();
// const auto ua = UseAcrylic();
// _renderEngine->SetDefaultTextBackgroundOpacity(ua);
// }
auto eventArgs = winrt::make_self<TransparencyChangedEventArgs>(newOpacity);
_TransparencyChangedHandlers(*this, *eventArgs);
}
@ -630,7 +638,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderEngine->SetForceFullRepaintRendering(_settings->ForceFullRepaintRendering());
_renderEngine->SetSoftwareRendering(_settings->SoftwareRendering());
// Inform the renderer of our opacity
_renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(Opacity()));
const auto ua = UseAcrylic();
_renderEngine->SetDefaultTextBackgroundOpacity(ua);
_updateAntiAliasingMode(_renderEngine.get());
@ -1310,14 +1319,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}
void ControlCore::SetBackgroundOpacity(const double opacity)
{
if (_renderEngine)
{
auto lock = _terminal->LockForWriting();
_renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(opacity));
}
}
// void ControlCore::SetBackgroundOpacity(const double opacity)
// {
// if (_renderEngine)
// {
// auto lock = _terminal->LockForWriting();
// _renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast<float>(opacity));
// }
// }
// Method Description:
// - Asynchronously close our connection. The Connection will likely wait

View file

@ -59,7 +59,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void UpdateSettings(const Control::IControlSettings& settings, const IControlAppearance& newAppearance);
void ApplyAppearance(const bool& focused);
// void UpdateAppearance(const Control::IControlAppearance& newAppearance);
Control::IControlSettings Settings()
Control::IControlSettings Settings()
{
auto l = std::unique_lock<til::ticket_lock>{ _settingsLock };
return *_settings;
@ -81,7 +81,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
uint16_t FontWeight() const noexcept;
til::color BackgroundColor() const;
void SetBackgroundOpacity(const double opacity);
// void SetBackgroundOpacity(const double opacity);
void SendInput(const winrt::hstring& wstr);
void PasteText(const winrt::hstring& hstr);

View file

@ -81,7 +81,7 @@ namespace Microsoft.Terminal.Control
void BlinkAttributeTick();
void UpdatePatternLocations();
void Search(String text, Boolean goForward, Boolean caseSensitive);
void SetBackgroundOpacity(Double opacity);
// void SetBackgroundOpacity(Double opacity);
Microsoft.Terminal.Core.Color BackgroundColor { get; };
Boolean HasSelection { get; };

View file

@ -88,7 +88,7 @@ DxEngine::DxEngine() :
_forceFullRepaintRendering{ false },
_softwareRendering{ false },
_antialiasingMode{ D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE },
_defaultTextBackgroundOpacity{ 1.0f },
_defaultBackgroundIsTransparent{ false },
_hwndTarget{ static_cast<HWND>(INVALID_HANDLE_VALUE) },
_sizeTarget{},
_dpi{ USER_DEFAULT_SCREEN_DPI },
@ -910,7 +910,7 @@ void DxEngine::_ReleaseDeviceResources() noexcept
// someone has chosen the slower ClearType antialiasing (versus the faster
// grayscale antialiasing)
const bool usingCleartype = _antialiasingMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
const bool usingTransparency = _defaultTextBackgroundOpacity != 1.0f;
const bool usingTransparency = _defaultBackgroundIsTransparent;
// Another way of naming "bgIsDefault" is "bgHasTransparency"
const auto bgIsDefault = (_backgroundColor.a == _defaultBackgroundColor.a) &&
(_backgroundColor.r == _defaultBackgroundColor.r) &&
@ -1938,8 +1938,10 @@ CATCH_RETURN()
// opacity bits unchanged. PaintBufferLine will later do some logic to
// determine if we should paint the text as grayscale or not.
const bool usingCleartype = _antialiasingMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
const bool usingTransparency = _defaultTextBackgroundOpacity != 1.0f;
const bool forceOpaqueBG = usingCleartype && !usingTransparency;
const bool usingTransparency = _defaultBackgroundIsTransparent;
const bool forceOpaqueBG = false; // usingCleartype && usingTransparency;
usingCleartype;
usingTransparency;
const auto [colorForeground, colorBackground] = pData->GetAttributeColors(textAttributes);
@ -2244,10 +2246,11 @@ CATCH_LOG()
// - opacity: the new opacity of our background, on [0.0f, 1.0f]
// Return Value:
// - <none>
void DxEngine::SetDefaultTextBackgroundOpacity(const float opacity) noexcept
void DxEngine::SetDefaultTextBackgroundOpacity(const bool useAcrylic) noexcept
try
{
_defaultTextBackgroundOpacity = opacity;
_defaultBackgroundIsTransparent = useAcrylic;
// _defaultTextBackgroundOpacity = opacity;
// Make sure we redraw all the cells, to update whether they're actually
// drawn with cleartype or not.

View file

@ -128,7 +128,7 @@ namespace Microsoft::Console::Render
void SetSelectionBackground(const COLORREF color, const float alpha = 0.5f) noexcept;
void SetAntialiasingMode(const D2D1_TEXT_ANTIALIAS_MODE antialiasingMode) noexcept;
void SetDefaultTextBackgroundOpacity(const float opacity) noexcept;
void SetDefaultTextBackgroundOpacity(const bool useAcrylic) noexcept;
void SetIntenseIsBold(const bool opacity) noexcept;
void UpdateHyperlinkHoveredId(const uint16_t hoveredId) noexcept;
@ -257,7 +257,7 @@ namespace Microsoft::Console::Render
D2D1_TEXT_ANTIALIAS_MODE _antialiasingMode;
float _defaultTextBackgroundOpacity;
bool _defaultBackgroundIsTransparent;
bool _intenseIsBold;
// DirectX constant buffers need to be a multiple of 16; align to pad the size.