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

Move the common render settings into a shared class #12127

Merged
16 commits merged into from
Jan 13, 2022
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
35 changes: 0 additions & 35 deletions src/buffer/out/TextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,41 +124,6 @@ bool TextAttribute::IsLegacy() const noexcept
return _foreground.IsLegacy() && _background.IsLegacy();
}

// Routine Description:
// - Calculates rgb colors based off of current color table and active modification attributes.
// Arguments:
// - colorTable: the current color table rgb values.
// - defaultFgIndex: the color table index of the default foreground color.
// - defaultBgIndex: the color table index of the default background color.
// - reverseScreenMode: true if the screen mode is reversed.
// - blinkingIsFaint: true if blinking should be interpreted as faint. (defaults to false)
// - boldIsBright: true if "bold" should be interpreted as bright. (defaults to true)
// Return Value:
// - the foreground and background colors that should be displayed.
std::pair<COLORREF, COLORREF> TextAttribute::CalculateRgbColors(const std::array<COLORREF, TextColor::TABLE_SIZE>& colorTable,
const size_t defaultFgIndex,
const size_t defaultBgIndex,
const bool reverseScreenMode,
const bool blinkingIsFaint,
const bool boldIsBright) const noexcept
{
auto fg = _foreground.GetColor(colorTable, defaultFgIndex, boldIsBright && IsBold());
auto bg = _background.GetColor(colorTable, defaultBgIndex);
if (IsFaint() || (IsBlinking() && blinkingIsFaint))
{
fg = (fg >> 1) & 0x7F7F7F; // Divide foreground color components by two.
}
if (IsReverseVideo() ^ reverseScreenMode)
{
std::swap(fg, bg);
}
if (IsInvisible())
{
fg = bg;
}
return { fg, bg };
}

// Method description:
// - Tells us whether the text is a hyperlink or not
// Return value:
Expand Down
7 changes: 0 additions & 7 deletions src/buffer/out/TextAttribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class TextAttribute final
static TextAttribute StripErroneousVT16VersionsOfLegacyDefaults(const TextAttribute& attribute) noexcept;
WORD GetLegacyAttributes() const noexcept;

std::pair<COLORREF, COLORREF> CalculateRgbColors(const std::array<COLORREF, TextColor::TABLE_SIZE>& colorTable,
const size_t defaultFgIndex,
const size_t defaultBgIndex,
const bool reverseScreenMode = false,
const bool blinkingIsFaint = false,
const bool boldIsBright = true) const noexcept;

bool IsLeadingByte() const noexcept;
bool IsTrailingByte() const noexcept;
bool IsTopHorizontalDisplayed() const noexcept;
Expand Down
7 changes: 7 additions & 0 deletions src/buffer/out/TextColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ enum class ColorType : BYTE
IsRgb = 0x3
};

enum class ColorAlias : size_t
{
DefaultForeground,
DefaultBackground,
ENUM_COUNT // must be the last element in the enum class
};

struct TextColor
{
public:
Expand Down
136 changes: 70 additions & 66 deletions src/buffer/out/ut_textbuffer/TextAttributeTests.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/buffer/out/ut_textbuffer/TextBuffer.Unit.Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\renderer\base\lib\base.vcxproj">
<Project>{af0a096a-8b3a-4949-81ef-7df8f0fee91f}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\types\lib\types.vcxproj">
<Project>{18d09a24-8240-42d6-8cb6-236eee820263}</Project>
</ProjectReference>
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/PublicTerminalCore/HwndTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ HRESULT HwndTerminal::Initialize()
_terminal = std::make_unique<::Microsoft::Terminal::Core::Terminal>();
auto renderThread = std::make_unique<::Microsoft::Console::Render::RenderThread>();
auto* const localPointerToThread = renderThread.get();
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(_terminal.get(), nullptr, 0, std::move(renderThread));
const auto& renderSettings = _terminal->GetRenderSettings();
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(renderSettings, _terminal.get(), nullptr, 0, std::move(renderThread));
RETURN_HR_IF_NULL(E_POINTER, localPointerToThread);
RETURN_IF_FAILED(localPointerToThread->Initialize(_renderer.get()));

Expand Down
11 changes: 5 additions & 6 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto* const localPointerToThread = renderThread.get();

// Now create the renderer and initialize the render thread.
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(_terminal.get(), nullptr, 0, std::move(renderThread));
const auto& renderSettings = _terminal->GetRenderSettings();
_renderer = std::make_unique<::Microsoft::Console::Render::Renderer>(renderSettings, _terminal.get(), nullptr, 0, std::move(renderThread));

_renderer->SetRendererEnteredErrorStateCallback([weakThis = get_weak()]() {
if (auto strongThis{ weakThis.get() })
Expand Down Expand Up @@ -281,7 +282,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderEngine->SetPixelShaderPath(_settings->PixelShaderPath());
_renderEngine->SetForceFullRepaintRendering(_settings->ForceFullRepaintRendering());
_renderEngine->SetSoftwareRendering(_settings->SoftwareRendering());
_renderEngine->SetIntenseIsBold(_settings->IntenseIsBold());

_updateAntiAliasingMode();

Expand Down Expand Up @@ -677,7 +677,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_renderEngine->SetSelectionBackground(til::color{ newAppearance->SelectionBackground() });
_renderEngine->SetRetroTerminalEffect(newAppearance->RetroTerminalEffect());
_renderEngine->SetPixelShaderPath(newAppearance->PixelShaderPath());
_renderEngine->SetIntenseIsBold(_settings->IntenseIsBold());
_renderer->TriggerRedrawAll();
}
}
Expand Down Expand Up @@ -1112,7 +1111,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

til::color ControlCore::BackgroundColor() const
{
return _terminal->GetColorTableEntry(TextColor::DEFAULT_BACKGROUND);
return _terminal->GetRenderSettings().GetColorAlias(ColorAlias::DefaultBackground);
}

// Method Description:
Expand Down Expand Up @@ -1398,8 +1397,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
auto lock = _terminal->LockForWriting();

auto& renderTarget = *_renderer;
auto& blinkingState = _terminal->GetBlinkingState();
blinkingState.ToggleBlinkingRendition(renderTarget);
auto& renderSettings = _terminal->GetRenderSettings();
renderSettings.ToggleBlinkRendition(renderTarget);
}

void ControlCore::BlinkCursor()
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalControl/IControlAppearance.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace Microsoft.Terminal.Control
Windows.UI.Xaml.Media.Stretch BackgroundImageStretchMode { get; };
Windows.UI.Xaml.HorizontalAlignment BackgroundImageHorizontalAlignment { get; };
Windows.UI.Xaml.VerticalAlignment BackgroundImageVerticalAlignment { get; };
Boolean IntenseIsBold { get; };
// IntenseIsBright is in Core Appearance
// IntenseIsBold and IntenseIsBright are in Core Appearance
Double Opacity { get; };

// Experimental settings
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/ICoreAppearance.idl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ namespace Microsoft.Terminal.Core
Microsoft.Terminal.Core.Color CursorColor;
CursorStyle CursorShape;
UInt32 CursorHeight;
Boolean IntenseIsBold;
Boolean IntenseIsBright;
Boolean AdjustIndistinguishableColors;
};
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalCore/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../terminal/adapter/DispatchTypes.hpp"
#include "../../terminal/input/terminalInput.hpp"
#include "../../buffer/out/TextAttribute.hpp"
#include "../../renderer/inc/RenderSettings.hpp"
#include "../../types/inc/Viewport.hpp"

namespace Microsoft::Terminal::Core
Expand Down Expand Up @@ -42,12 +43,13 @@ namespace Microsoft::Terminal::Core

virtual COLORREF GetColorTableEntry(const size_t tableIndex) const noexcept = 0;
virtual bool SetColorTableEntry(const size_t tableIndex, const COLORREF color) noexcept = 0;
virtual void SetColorAliasIndex(const ColorAlias alias, const size_t tableIndex) noexcept = 0;

virtual bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept = 0;

virtual bool SetInputMode(const ::Microsoft::Console::VirtualTerminal::TerminalInput::Mode mode, const bool enabled) noexcept = 0;
virtual bool SetRenderMode(const ::Microsoft::Console::Render::RenderSettings::Mode mode, const bool enabled) noexcept = 0;

virtual bool SetScreenMode(const bool reverseMode) noexcept = 0;
virtual bool EnableXtermBracketedPasteMode(const bool enabled) noexcept = 0;
virtual bool IsXtermBracketedPasteModeEnabled() const = 0;

Expand Down
139 changes: 54 additions & 85 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ static std::wstring _KeyEventsToText(std::deque<std::unique_ptr<IInputEvent>>& i
Terminal::Terminal() :
_mutableViewport{ Viewport::Empty() },
_title{},
_colorTable{},
_screenReversed{ false },
_pfnWriteInput{ nullptr },
_scrollOffset{ 0 },
_snapOnInput{ true },
Expand All @@ -49,9 +47,7 @@ Terminal::Terminal() :
_selection{ std::nullopt },
_taskbarState{ 0 },
_taskbarProgress{ 0 },
_trimBlockSelection{ false },
_intenseIsBright{ true },
_adjustIndistinguishableColors{ true }
_trimBlockSelection{ false }
{
auto dispatch = std::make_unique<TerminalDispatch>(*this);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
Expand All @@ -77,11 +73,8 @@ Terminal::Terminal() :

_terminalInput = std::make_unique<TerminalInput>(passAlongInput);

_InitializeColorTable();

_colorTable.at(TextColor::DEFAULT_FOREGROUND) = RGB(255, 255, 255);
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = RGB(0, 0, 0);
_colorTable.at(TextColor::CURSOR_COLOR) = INVALID_COLOR;
_renderSettings.SetColorAlias(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND, RGB(255, 255, 255));
_renderSettings.SetColorAlias(ColorAlias::DefaultBackground, TextColor::DEFAULT_BACKGROUND, RGB(0, 0, 0));
}

void Terminal::Create(COORD viewportSize, SHORT scrollbackLines, IRenderTarget& renderTarget)
Expand Down Expand Up @@ -179,29 +172,22 @@ void Terminal::UpdateSettings(ICoreSettings settings)
// - appearance: an ICoreAppearance with new settings values for us to use.
void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
{
_intenseIsBright = appearance.IntenseIsBright();
_adjustIndistinguishableColors = appearance.AdjustIndistinguishableColors();
_renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBold, appearance.IntenseIsBold());
_renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBright, appearance.IntenseIsBright());
_renderSettings.SetRenderMode(RenderSettings::Mode::DistinguishableColors, appearance.AdjustIndistinguishableColors());

// Set the default background as transparent to prevent the
// DX layer from overwriting the background image or acrylic effect
const til::color newBackgroundColor{ appearance.DefaultBackground() };
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = newBackgroundColor;
_renderSettings.SetColorAlias(ColorAlias::DefaultBackground, TextColor::DEFAULT_BACKGROUND, newBackgroundColor);
const til::color newForegroundColor{ appearance.DefaultForeground() };
_colorTable.at(TextColor::DEFAULT_FOREGROUND) = newForegroundColor;
_renderSettings.SetColorAlias(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND, newForegroundColor);
const til::color newCursorColor{ appearance.CursorColor() };
_colorTable.at(TextColor::CURSOR_COLOR) = newCursorColor;

_intenseIsBright = appearance.IntenseIsBright();
_adjustIndistinguishableColors = appearance.AdjustIndistinguishableColors();
_renderSettings.SetColorTableEntry(TextColor::CURSOR_COLOR, newCursorColor);

for (int i = 0; i < 16; i++)
{
_colorTable.at(i) = til::color{ appearance.GetColorTableEntry(i) };
}
if (_adjustIndistinguishableColors)
{
_MakeAdjustedColorArray();
_renderSettings.SetColorTableEntry(i, til::color{ appearance.GetColorTableEntry(i) });
}
_renderSettings.MakeAdjustedColorArray();

CursorType cursorShape = CursorType::VerticalBar;
switch (appearance.CursorShape())
Expand Down Expand Up @@ -1219,15 +1205,6 @@ void Microsoft::Terminal::Core::Terminal::TaskbarProgressChangedCallback(std::fu
_pfnTaskbarProgressChanged.swap(pfn);
}

void Terminal::_InitializeColorTable()
try
{
const gsl::span<COLORREF> tableView = { _colorTable.data(), _colorTable.size() };
// First set up the basic 256 colors
Utils::InitializeColorTable(tableView);
}
CATCH_LOG()

// Method Description:
// - Sets the cursor to be currently on. On/Off is tracked independently of
// cursor visibility (hidden/visible). On/off is controlled by the cursor
Expand Down Expand Up @@ -1280,11 +1257,6 @@ const std::optional<til::color> Terminal::GetTabColor() const noexcept
return _startingTabColor.has_value() ? _startingTabColor : _tabColor;
}

BlinkingState& Terminal::GetBlinkingState() const noexcept
{
return _blinkingState;
}

// Method Description:
// - Gets the internal taskbar state value
// Return Value:
Expand All @@ -1307,57 +1279,54 @@ Scheme Terminal::GetColorScheme() const noexcept
{
Scheme s;

s.Foreground = til::color{ _colorTable.at(TextColor::DEFAULT_FOREGROUND) };
s.Background = til::color{ _colorTable.at(TextColor::DEFAULT_BACKGROUND) };
s.Foreground = til::color{ _renderSettings.GetColorAlias(ColorAlias::DefaultForeground) };
s.Background = til::color{ _renderSettings.GetColorAlias(ColorAlias::DefaultBackground) };

// SelectionBackground is stored in the ControlAppearance
s.CursorColor = til::color{ _colorTable.at(TextColor::CURSOR_COLOR) };

s.Black = til::color{ _colorTable[0] };
s.Red = til::color{ _colorTable[1] };
s.Green = til::color{ _colorTable[2] };
s.Yellow = til::color{ _colorTable[3] };
s.Blue = til::color{ _colorTable[4] };
s.Purple = til::color{ _colorTable[5] };
s.Cyan = til::color{ _colorTable[6] };
s.White = til::color{ _colorTable[7] };
s.BrightBlack = til::color{ _colorTable[8] };
s.BrightRed = til::color{ _colorTable[9] };
s.BrightGreen = til::color{ _colorTable[10] };
s.BrightYellow = til::color{ _colorTable[11] };
s.BrightBlue = til::color{ _colorTable[12] };
s.BrightPurple = til::color{ _colorTable[13] };
s.BrightCyan = til::color{ _colorTable[14] };
s.BrightWhite = til::color{ _colorTable[15] };
s.CursorColor = til::color{ _renderSettings.GetColorTableEntry(TextColor::CURSOR_COLOR) };

s.Black = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_BLACK) };
s.Red = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_RED) };
s.Green = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_GREEN) };
s.Yellow = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_YELLOW) };
s.Blue = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_BLUE) };
s.Purple = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_MAGENTA) };
s.Cyan = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_CYAN) };
s.White = til::color{ _renderSettings.GetColorTableEntry(TextColor::DARK_WHITE) };
s.BrightBlack = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_BLACK) };
s.BrightRed = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_RED) };
s.BrightGreen = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_GREEN) };
s.BrightYellow = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_YELLOW) };
s.BrightBlue = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_BLUE) };
s.BrightPurple = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_MAGENTA) };
s.BrightCyan = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_CYAN) };
s.BrightWhite = til::color{ _renderSettings.GetColorTableEntry(TextColor::BRIGHT_WHITE) };
lhecker marked this conversation as resolved.
Show resolved Hide resolved
return s;
}

void Terminal::ApplyScheme(const Scheme& colorScheme)
{
_colorTable.at(TextColor::DEFAULT_FOREGROUND) = til::color{ colorScheme.Foreground };
_colorTable.at(TextColor::DEFAULT_BACKGROUND) = til::color{ colorScheme.Background };

_colorTable[0] = til::color{ colorScheme.Black };
_colorTable[1] = til::color{ colorScheme.Red };
_colorTable[2] = til::color{ colorScheme.Green };
_colorTable[3] = til::color{ colorScheme.Yellow };
_colorTable[4] = til::color{ colorScheme.Blue };
_colorTable[5] = til::color{ colorScheme.Purple };
_colorTable[6] = til::color{ colorScheme.Cyan };
_colorTable[7] = til::color{ colorScheme.White };
_colorTable[8] = til::color{ colorScheme.BrightBlack };
_colorTable[9] = til::color{ colorScheme.BrightRed };
_colorTable[10] = til::color{ colorScheme.BrightGreen };
_colorTable[11] = til::color{ colorScheme.BrightYellow };
_colorTable[12] = til::color{ colorScheme.BrightBlue };
_colorTable[13] = til::color{ colorScheme.BrightPurple };
_colorTable[14] = til::color{ colorScheme.BrightCyan };
_colorTable[15] = til::color{ colorScheme.BrightWhite };

_colorTable.at(TextColor::CURSOR_COLOR) = til::color{ colorScheme.CursorColor };

if (_adjustIndistinguishableColors)
{
_MakeAdjustedColorArray();
}
_renderSettings.SetColorAlias(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND, til::color{ colorScheme.Foreground });
_renderSettings.SetColorAlias(ColorAlias::DefaultBackground, TextColor::DEFAULT_BACKGROUND, til::color{ colorScheme.Background });

_renderSettings.SetColorTableEntry(TextColor::DARK_BLACK, til::color{ colorScheme.Black });
_renderSettings.SetColorTableEntry(TextColor::DARK_RED, til::color{ colorScheme.Red });
_renderSettings.SetColorTableEntry(TextColor::DARK_GREEN, til::color{ colorScheme.Green });
_renderSettings.SetColorTableEntry(TextColor::DARK_YELLOW, til::color{ colorScheme.Yellow });
_renderSettings.SetColorTableEntry(TextColor::DARK_BLUE, til::color{ colorScheme.Blue });
_renderSettings.SetColorTableEntry(TextColor::DARK_MAGENTA, til::color{ colorScheme.Purple });
_renderSettings.SetColorTableEntry(TextColor::DARK_CYAN, til::color{ colorScheme.Cyan });
_renderSettings.SetColorTableEntry(TextColor::DARK_WHITE, til::color{ colorScheme.White });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_BLACK, til::color{ colorScheme.BrightBlack });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_RED, til::color{ colorScheme.BrightRed });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_GREEN, til::color{ colorScheme.BrightGreen });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_YELLOW, til::color{ colorScheme.BrightYellow });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_BLUE, til::color{ colorScheme.BrightBlue });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_MAGENTA, til::color{ colorScheme.BrightPurple });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_CYAN, til::color{ colorScheme.BrightCyan });
_renderSettings.SetColorTableEntry(TextColor::BRIGHT_WHITE, til::color{ colorScheme.BrightWhite });

_renderSettings.SetColorTableEntry(TextColor::CURSOR_COLOR, til::color{ colorScheme.CursorColor });

_renderSettings.MakeAdjustedColorArray();
}
Loading