Skip to content

Make the renderer optional #17442

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

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 16 additions & 16 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TextBuffer::TextBuffer(til::size screenBufferSize,
const TextAttribute defaultAttributes,
const UINT cursorSize,
const bool isActiveBuffer,
Microsoft::Console::Render::Renderer& renderer) :
Microsoft::Console::Render::Renderer* renderer) :
_renderer{ renderer },
_currentAttributes{ defaultAttributes },
// This way every TextBuffer will start with a ""unique"" _lastMutationId
Expand Down Expand Up @@ -888,9 +888,9 @@ void TextBuffer::IncrementCircularBuffer(const TextAttribute& fillAttributes)
{
// FirstRow is at any given point in time the array index in the circular buffer that corresponds
// to the logical position 0 in the window (cursor coordinates and all other coordinates).
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerFlush(true);
_renderer->TriggerFlush(true);
}

// Prune hyperlinks to delete obsolete references
Expand Down Expand Up @@ -1265,56 +1265,56 @@ bool TextBuffer::IsActiveBuffer() const noexcept
return _isActiveBuffer;
}

Microsoft::Console::Render::Renderer& TextBuffer::GetRenderer() noexcept
Microsoft::Console::Render::Renderer* TextBuffer::GetRenderer() noexcept
{
return _renderer;
}

void TextBuffer::NotifyPaintFrame() noexcept
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.NotifyPaintFrame();
_renderer->NotifyPaintFrame();
}
}

void TextBuffer::TriggerRedraw(const Viewport& viewport)
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerRedraw(viewport);
_renderer->TriggerRedraw(viewport);
}
}

void TextBuffer::TriggerRedrawAll()
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerRedrawAll();
_renderer->TriggerRedrawAll();
}
}

void TextBuffer::TriggerScroll()
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerScroll();
_renderer->TriggerScroll();
}
}

void TextBuffer::TriggerScroll(const til::point delta)
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerScroll(&delta);
_renderer->TriggerScroll(&delta);
}
}

void TextBuffer::TriggerNewTextNotification(const std::wstring_view newText)
{
if (_isActiveBuffer)
if (_isActiveBuffer && _renderer)
{
_renderer.TriggerNewTextNotification(newText);
_renderer->TriggerNewTextNotification(newText);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TextBuffer final
const TextAttribute defaultAttributes,
const UINT cursorSize,
const bool isActiveBuffer,
Microsoft::Console::Render::Renderer& renderer);
Microsoft::Console::Render::Renderer* renderer);

TextBuffer(const TextBuffer&) = delete;
TextBuffer(TextBuffer&&) = delete;
Expand Down Expand Up @@ -166,7 +166,7 @@ class TextBuffer final
void SetAsActiveBuffer(const bool isActiveBuffer) noexcept;
bool IsActiveBuffer() const noexcept;

Microsoft::Console::Render::Renderer& GetRenderer() noexcept;
Microsoft::Console::Render::Renderer* GetRenderer() noexcept;

void NotifyPaintFrame() noexcept;
void TriggerRedraw(const Microsoft::Console::Types::Viewport& viewport);
Expand Down Expand Up @@ -343,7 +343,7 @@ class TextBuffer final

static void _AppendRTFText(std::string& contentBuilder, const std::wstring_view& text);

Microsoft::Console::Render::Renderer& _renderer;
Microsoft::Console::Render::Renderer* _renderer = nullptr;

std::unordered_map<uint16_t, std::wstring> _hyperlinkMap;
std::unordered_map<std::wstring, uint16_t> _hyperlinkCustomIdMap;
Expand Down
4 changes: 2 additions & 2 deletions src/buffer/out/ut_textbuffer/ReflowTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ class ReflowTests
static DummyRenderer renderer;
static std::unique_ptr<TextBuffer> _textBufferFromTestBuffer(const TestBuffer& testBuffer)
{
auto buffer = std::make_unique<TextBuffer>(testBuffer.size, TextAttribute{ 0x7 }, 0, false, renderer);
auto buffer = std::make_unique<TextBuffer>(testBuffer.size, TextAttribute{ 0x7 }, 0, false, &renderer);

til::CoordType y = 0;
for (const auto& testRow : testBuffer.rows)
Expand All @@ -725,7 +725,7 @@ class ReflowTests

static std::unique_ptr<TextBuffer> _textBufferByReflowingTextBuffer(TextBuffer& originalBuffer, const til::size newSize)
{
auto buffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, renderer);
auto buffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, &renderer);
TextBuffer::Reflow(originalBuffer, *buffer);
return buffer;
}
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/out/ut_textbuffer/UTextAdapterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UTextAdapterTests
TEST_METHOD(Unicode)
{
DummyRenderer renderer;
TextBuffer buffer{ til::size{ 24, 1 }, TextAttribute{}, 0, false, renderer };
TextBuffer buffer{ til::size{ 24, 1 }, TextAttribute{}, 0, false, &renderer };

RowWriteState state{
.text = L"abc 𝒶𝒷𝒸 abc ネコちゃん",
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto lock = _terminal->LockForWriting();

auto& renderSettings = _terminal->GetRenderSettings();
renderSettings.ToggleBlinkRendition(*_renderer);
renderSettings.ToggleBlinkRendition(_renderer.get());
}

void ControlCore::BlinkCursor()
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ void Terminal::Create(til::size viewportSize, til::CoordType scrollbackLines, Re
Utils::ClampToShortMax(viewportSize.height + scrollbackLines, 1) };
const TextAttribute attr{};
const UINT cursorSize = 12;
_mainBuffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, true, renderer);
_mainBuffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, true, &renderer);

auto dispatch = std::make_unique<AdaptDispatch>(*this, renderer, _renderSettings, _terminalInput);
auto dispatch = std::make_unique<AdaptDispatch>(*this, &renderer, _renderSettings, _terminalInput);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
_stateMachine = std::make_unique<StateMachine>(std::move(engine));

Expand Down
5 changes: 2 additions & 3 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SCREEN_INFORMATION::~SCREEN_INFORMATION()
defaultAttributes,
uiCursorSize,
pScreen->IsActiveScreenBuffer(),
*ServiceLocator::LocateGlobals().pRender);
ServiceLocator::LocateGlobals().pRender);

const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
pScreen->_textBuffer->GetCursor().SetType(gci.GetCursorType());
Expand Down Expand Up @@ -253,10 +253,9 @@ void SCREEN_INFORMATION::s_RemoveScreenBuffer(_In_ SCREEN_INFORMATION* const pSc
{
auto& g = ServiceLocator::LocateGlobals();
auto& gci = g.getConsoleInformation();
auto& renderer = *g.pRender;
auto& renderSettings = gci.GetRenderSettings();
auto& terminalInput = gci.GetActiveInputBuffer()->GetTerminalInput();
auto adapter = std::make_unique<AdaptDispatch>(_api, renderer, renderSettings, terminalInput);
auto adapter = std::make_unique<AdaptDispatch>(_api, g.pRender, renderSettings, terminalInput);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(adapter));
// Note that at this point in the setup, we haven't determined if we're
// in VtIo mode or not yet. We'll set the OutputStateMachine's
Expand Down
36 changes: 18 additions & 18 deletions src/host/ut_host/TextBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ void TextBufferTests::ResizeTraditional()
const til::size smallSize = { 5, 5 };
const TextAttribute defaultAttr(0);

TextBuffer buffer(smallSize, defaultAttr, 12, false, _renderer);
TextBuffer buffer(smallSize, defaultAttr, 12, false, &_renderer);

Log::Comment(L"Fill buffer with some data and do assorted resize operations.");

Expand Down Expand Up @@ -1801,7 +1801,7 @@ void TextBufferTests::ResizeTraditionalRotationPreservesHighUnicode()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Get a position inside the buffer
const til::point pos{ 2, 1 };
Expand Down Expand Up @@ -1842,7 +1842,7 @@ void TextBufferTests::ScrollBufferRotationPreservesHighUnicode()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Get a position inside the buffer
const til::point pos{ 2, 1 };
Expand Down Expand Up @@ -1877,7 +1877,7 @@ void TextBufferTests::ResizeTraditionalHighUnicodeRowRemoval()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Get a position inside the buffer in the bottom row
const til::point pos{ 0, bufferSize.height - 1 };
Expand Down Expand Up @@ -1907,7 +1907,7 @@ void TextBufferTests::ResizeTraditionalHighUnicodeColumnRemoval()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Get a position inside the buffer in the last column (-2 as the inserted character is 2 columns wide).
const til::point pos{ bufferSize.width - 2, 0 };
Expand All @@ -1934,7 +1934,7 @@ void TextBufferTests::TestBurrito()
til::size bufferSize{ 80, 9001 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// This is the burrito emoji: 🌯
// It's encoded in UTF-16, as needed by the buffer.
Expand All @@ -1955,7 +1955,7 @@ void TextBufferTests::TestOverwriteChars()
til::size bufferSize{ 10, 3 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
TextBuffer buffer{ bufferSize, attr, cursorSize, false, _renderer };
TextBuffer buffer{ bufferSize, attr, cursorSize, false, &_renderer };
auto& row = buffer.GetMutableRowByOffset(0);

// scientist emoji U+1F9D1 U+200D U+1F52C
Expand Down Expand Up @@ -2011,7 +2011,7 @@ void TextBufferTests::TestReplace()
static constexpr til::size bufferSize{ 10, 3 };
static constexpr UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
TextBuffer buffer{ bufferSize, attr, cursorSize, false, _renderer };
TextBuffer buffer{ bufferSize, attr, cursorSize, false, &_renderer };

#define complex L"\U0001F41B"

Expand Down Expand Up @@ -2093,7 +2093,7 @@ void TextBufferTests::TestInsert()
static constexpr TextAttribute attr1{ 0x11111111, 0x00000000 };
static constexpr TextAttribute attr2{ 0x22222222, 0x00000000 };
static constexpr TextAttribute attr3{ 0x33333333, 0x00000000 };
TextBuffer buffer{ bufferSize, attr1, cursorSize, false, _renderer };
TextBuffer buffer{ bufferSize, attr1, cursorSize, false, &_renderer };

struct Test
{
Expand Down Expand Up @@ -2232,7 +2232,7 @@ void TextBufferTests::GetWordBoundaries()
til::size bufferSize{ 80, 9001 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Setup: Write lines of text to the buffer
const std::vector<std::wstring> text = { L"word other",
Expand Down Expand Up @@ -2448,7 +2448,7 @@ void TextBufferTests::MoveByWord()
til::size bufferSize{ 80, 9001 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Setup: Write lines of text to the buffer
const std::vector<std::wstring> text = { L"word other",
Expand Down Expand Up @@ -2555,7 +2555,7 @@ void TextBufferTests::GetGlyphBoundaries()
til::size bufferSize{ 10, 10 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// This is the burrito emoji: 🌯
// It's encoded in UTF-16, as needed by the buffer.
Expand Down Expand Up @@ -2591,7 +2591,7 @@ void TextBufferTests::GetTextRects()
til::size bufferSize{ 20, 50 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Setup: Write lines of text to the buffer
const std::vector<std::wstring> text = { L"0123456789",
Expand Down Expand Up @@ -2671,7 +2671,7 @@ void TextBufferTests::GetPlainText()
til::size bufferSize{ 10, 20 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Setup: Write lines of text to the buffer
const std::vector<std::wstring> bufferText = { L"12345",
Expand Down Expand Up @@ -2759,7 +2759,7 @@ void TextBufferTests::GetPlainText()
til::size bufferSize{ 5, 20 };
UINT cursorSize = 12;
TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

// Setup: Write lines of text to the buffer
const std::vector<std::wstring> bufferText = { L"1234567",
Expand Down Expand Up @@ -2888,7 +2888,7 @@ void TextBufferTests::HyperlinkTrim()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

static constexpr std::wstring_view url{ L"test.url" };
static constexpr std::wstring_view otherUrl{ L"other.url" };
Expand Down Expand Up @@ -2934,7 +2934,7 @@ void TextBufferTests::NoHyperlinkTrim()
const til::size bufferSize{ 80, 10 };
const UINT cursorSize = 12;
const TextAttribute attr{ 0x7f };
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);

static constexpr std::wstring_view url{ L"test.url" };
static constexpr std::wstring_view customId{ L"CustomId" };
Expand Down Expand Up @@ -3086,7 +3086,7 @@ void TextBufferTests::ReflowPromptRegions()

// After we resize, make sure to get the new textBuffers
til::size newSize{ oldSize.Width() + dx, oldSize.Height() };
auto newBuffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, _renderer);
auto newBuffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, &_renderer);
TextBuffer::Reflow(*tbi, *newBuffer);

Log::Comment(L"========== Checking the host buffer state (after) ==========");
Expand Down
2 changes: 1 addition & 1 deletion src/inc/test/CommonState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class CommonState
initialAttributes,
uiCursorSize,
true,
*g.pRender);
g.pRender);
if (textBuffer.get() == nullptr)
{
m_hrTextBufferInfo = E_OUTOFMEMORY;
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/base/RenderSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ COLORREF RenderSettings::GetAttributeUnderlineColor(const TextAttribute& attr) c
// renderer if there are blinking cells currently in view.
// Arguments:
// - renderer: the renderer that will be redrawn.
void RenderSettings::ToggleBlinkRendition(Renderer& renderer) noexcept
void RenderSettings::ToggleBlinkRendition(Renderer* renderer) noexcept
try
{
if (GetRenderMode(Mode::BlinkAllowed))
Expand All @@ -277,7 +277,10 @@ try
// We reset the _blinkIsInUse flag before redrawing, so we can
// get a fresh assessment of the current blink attribute usage.
_blinkIsInUse = false;
renderer.TriggerRedrawAll();
if (renderer)
{
renderer->TriggerRedrawAll();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/inc/RenderSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Microsoft::Console::Render
std::pair<COLORREF, COLORREF> GetAttributeColors(const TextAttribute& attr) const noexcept;
std::pair<COLORREF, COLORREF> GetAttributeColorsWithAlpha(const TextAttribute& attr) const noexcept;
COLORREF GetAttributeUnderlineColor(const TextAttribute& attr) const noexcept;
void ToggleBlinkRendition(class Renderer& renderer) noexcept;
void ToggleBlinkRendition(class Renderer* renderer) noexcept;

private:
til::enumset<Mode> _renderMode{ Mode::BlinkAllowed, Mode::IntenseIsBright };
Expand Down
Loading
Loading