Skip to content

Commit bd116e3

Browse files
authored
Make the renderer optional (#17442)
If `VtEngine` gets removed from conhost, we need to be able to run without any renderer present whatsoever. To make this possible, I've turned all `Renderer&` into `Renderer*`. Part of #14000
1 parent e0686fa commit bd116e3

File tree

16 files changed

+111
-89
lines changed

16 files changed

+111
-89
lines changed

src/buffer/out/textBuffer.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TextBuffer::TextBuffer(til::size screenBufferSize,
4848
const TextAttribute defaultAttributes,
4949
const UINT cursorSize,
5050
const bool isActiveBuffer,
51-
Microsoft::Console::Render::Renderer& renderer) :
51+
Microsoft::Console::Render::Renderer* renderer) :
5252
_renderer{ renderer },
5353
_currentAttributes{ defaultAttributes },
5454
// This way every TextBuffer will start with a ""unique"" _lastMutationId
@@ -718,9 +718,9 @@ void TextBuffer::IncrementCircularBuffer(const TextAttribute& fillAttributes)
718718
{
719719
// FirstRow is at any given point in time the array index in the circular buffer that corresponds
720720
// to the logical position 0 in the window (cursor coordinates and all other coordinates).
721-
if (_isActiveBuffer)
721+
if (_isActiveBuffer && _renderer)
722722
{
723-
_renderer.TriggerFlush(true);
723+
_renderer->TriggerFlush(true);
724724
}
725725

726726
// Prune hyperlinks to delete obsolete references
@@ -1063,56 +1063,56 @@ bool TextBuffer::IsActiveBuffer() const noexcept
10631063
return _isActiveBuffer;
10641064
}
10651065

1066-
Microsoft::Console::Render::Renderer& TextBuffer::GetRenderer() noexcept
1066+
Microsoft::Console::Render::Renderer* TextBuffer::GetRenderer() noexcept
10671067
{
10681068
return _renderer;
10691069
}
10701070

10711071
void TextBuffer::NotifyPaintFrame() noexcept
10721072
{
1073-
if (_isActiveBuffer)
1073+
if (_isActiveBuffer && _renderer)
10741074
{
1075-
_renderer.NotifyPaintFrame();
1075+
_renderer->NotifyPaintFrame();
10761076
}
10771077
}
10781078

10791079
void TextBuffer::TriggerRedraw(const Viewport& viewport)
10801080
{
1081-
if (_isActiveBuffer)
1081+
if (_isActiveBuffer && _renderer)
10821082
{
1083-
_renderer.TriggerRedraw(viewport);
1083+
_renderer->TriggerRedraw(viewport);
10841084
}
10851085
}
10861086

10871087
void TextBuffer::TriggerRedrawAll()
10881088
{
1089-
if (_isActiveBuffer)
1089+
if (_isActiveBuffer && _renderer)
10901090
{
1091-
_renderer.TriggerRedrawAll();
1091+
_renderer->TriggerRedrawAll();
10921092
}
10931093
}
10941094

10951095
void TextBuffer::TriggerScroll()
10961096
{
1097-
if (_isActiveBuffer)
1097+
if (_isActiveBuffer && _renderer)
10981098
{
1099-
_renderer.TriggerScroll();
1099+
_renderer->TriggerScroll();
11001100
}
11011101
}
11021102

11031103
void TextBuffer::TriggerScroll(const til::point delta)
11041104
{
1105-
if (_isActiveBuffer)
1105+
if (_isActiveBuffer && _renderer)
11061106
{
1107-
_renderer.TriggerScroll(&delta);
1107+
_renderer->TriggerScroll(&delta);
11081108
}
11091109
}
11101110

11111111
void TextBuffer::TriggerNewTextNotification(const std::wstring_view newText)
11121112
{
1113-
if (_isActiveBuffer)
1113+
if (_isActiveBuffer && _renderer)
11141114
{
1115-
_renderer.TriggerNewTextNotification(newText);
1115+
_renderer->TriggerNewTextNotification(newText);
11161116
}
11171117
}
11181118

src/buffer/out/textBuffer.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TextBuffer final
7272
const TextAttribute defaultAttributes,
7373
const UINT cursorSize,
7474
const bool isActiveBuffer,
75-
Microsoft::Console::Render::Renderer& renderer);
75+
Microsoft::Console::Render::Renderer* renderer);
7676

7777
TextBuffer(const TextBuffer&) = delete;
7878
TextBuffer(TextBuffer&&) = delete;
@@ -161,7 +161,7 @@ class TextBuffer final
161161
void SetAsActiveBuffer(const bool isActiveBuffer) noexcept;
162162
bool IsActiveBuffer() const noexcept;
163163

164-
Microsoft::Console::Render::Renderer& GetRenderer() noexcept;
164+
Microsoft::Console::Render::Renderer* GetRenderer() noexcept;
165165

166166
void NotifyPaintFrame() noexcept;
167167
void TriggerRedraw(const Microsoft::Console::Types::Viewport& viewport);
@@ -333,7 +333,7 @@ class TextBuffer final
333333

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

336-
Microsoft::Console::Render::Renderer& _renderer;
336+
Microsoft::Console::Render::Renderer* _renderer = nullptr;
337337

338338
std::unordered_map<uint16_t, std::wstring> _hyperlinkMap;
339339
std::unordered_map<std::wstring, uint16_t> _hyperlinkCustomIdMap;

src/buffer/out/ut_textbuffer/ReflowTests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class ReflowTests
699699
static DummyRenderer renderer;
700700
static std::unique_ptr<TextBuffer> _textBufferFromTestBuffer(const TestBuffer& testBuffer)
701701
{
702-
auto buffer = std::make_unique<TextBuffer>(testBuffer.size, TextAttribute{ 0x7 }, 0, false, renderer);
702+
auto buffer = std::make_unique<TextBuffer>(testBuffer.size, TextAttribute{ 0x7 }, 0, false, &renderer);
703703

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

726726
static std::unique_ptr<TextBuffer> _textBufferByReflowingTextBuffer(TextBuffer& originalBuffer, const til::size newSize)
727727
{
728-
auto buffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, renderer);
728+
auto buffer = std::make_unique<TextBuffer>(newSize, TextAttribute{ 0x7 }, 0, false, &renderer);
729729
TextBuffer::Reflow(originalBuffer, *buffer);
730730
return buffer;
731731
}

src/buffer/out/ut_textbuffer/UTextAdapterTests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class UTextAdapterTests
3737
TEST_METHOD(Unicode)
3838
{
3939
DummyRenderer renderer;
40-
TextBuffer buffer{ til::size{ 24, 1 }, TextAttribute{}, 0, false, renderer };
40+
TextBuffer buffer{ til::size{ 24, 1 }, TextAttribute{}, 0, false, &renderer };
4141

4242
RowWriteState state{
4343
.text = L"abc 𝒶𝒷𝒸 abc ネコちゃん",

src/cascadia/TerminalControl/ControlCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
18941894
const auto lock = _terminal->LockForWriting();
18951895

18961896
auto& renderSettings = _terminal->GetRenderSettings();
1897-
renderSettings.ToggleBlinkRendition(*_renderer);
1897+
renderSettings.ToggleBlinkRendition(_renderer.get());
18981898
}
18991899

19001900
void ControlCore::BlinkCursor()

src/cascadia/TerminalCore/Terminal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ void Terminal::Create(til::size viewportSize, til::CoordType scrollbackLines, Re
4747
Utils::ClampToShortMax(viewportSize.height + scrollbackLines, 1) };
4848
const TextAttribute attr{};
4949
const UINT cursorSize = 12;
50-
_mainBuffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, true, renderer);
50+
_mainBuffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, true, &renderer);
5151

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

src/host/screenInfo.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SCREEN_INFORMATION::~SCREEN_INFORMATION()
117117
defaultAttributes,
118118
uiCursorSize,
119119
pScreen->IsActiveScreenBuffer(),
120-
*ServiceLocator::LocateGlobals().pRender);
120+
ServiceLocator::LocateGlobals().pRender);
121121

122122
const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
123123
pScreen->_textBuffer->GetCursor().SetType(gci.GetCursorType());
@@ -253,10 +253,9 @@ void SCREEN_INFORMATION::s_RemoveScreenBuffer(_In_ SCREEN_INFORMATION* const pSc
253253
{
254254
auto& g = ServiceLocator::LocateGlobals();
255255
auto& gci = g.getConsoleInformation();
256-
auto& renderer = *g.pRender;
257256
auto& renderSettings = gci.GetRenderSettings();
258257
auto& terminalInput = gci.GetActiveInputBuffer()->GetTerminalInput();
259-
auto adapter = std::make_unique<AdaptDispatch>(_api, renderer, renderSettings, terminalInput);
258+
auto adapter = std::make_unique<AdaptDispatch>(_api, g.pRender, renderSettings, terminalInput);
260259
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(adapter));
261260
// Note that at this point in the setup, we haven't determined if we're
262261
// in VtIo mode or not yet. We'll set the OutputStateMachine's

src/host/ut_host/TextBufferTests.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ void TextBufferTests::ResizeTraditional()
15421542
const til::size smallSize = { 5, 5 };
15431543
const TextAttribute defaultAttr(0);
15441544

1545-
TextBuffer buffer(smallSize, defaultAttr, 12, false, _renderer);
1545+
TextBuffer buffer(smallSize, defaultAttr, 12, false, &_renderer);
15461546

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

@@ -1638,7 +1638,7 @@ void TextBufferTests::ResizeTraditionalRotationPreservesHighUnicode()
16381638
const til::size bufferSize{ 80, 10 };
16391639
const UINT cursorSize = 12;
16401640
const TextAttribute attr{ 0x7f };
1641-
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
1641+
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);
16421642

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

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

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

17491749
// Get a position inside the buffer in the last column (-2 as the inserted character is 2 columns wide).
17501750
const til::point pos{ bufferSize.width - 2, 0 };
@@ -1771,7 +1771,7 @@ void TextBufferTests::TestOverwriteChars()
17711771
til::size bufferSize{ 10, 3 };
17721772
UINT cursorSize = 12;
17731773
TextAttribute attr{ 0x7f };
1774-
TextBuffer buffer{ bufferSize, attr, cursorSize, false, _renderer };
1774+
TextBuffer buffer{ bufferSize, attr, cursorSize, false, &_renderer };
17751775
auto& row = buffer.GetMutableRowByOffset(0);
17761776

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

18321832
#define complex L"\U0001F41B"
18331833

@@ -1909,7 +1909,7 @@ void TextBufferTests::TestInsert()
19091909
static constexpr TextAttribute attr1{ 0x11111111, 0x00000000 };
19101910
static constexpr TextAttribute attr2{ 0x22222222, 0x00000000 };
19111911
static constexpr TextAttribute attr3{ 0x33333333, 0x00000000 };
1912-
TextBuffer buffer{ bufferSize, attr1, cursorSize, false, _renderer };
1912+
TextBuffer buffer{ bufferSize, attr1, cursorSize, false, &_renderer };
19131913

19141914
struct Test
19151915
{
@@ -2048,7 +2048,7 @@ void TextBufferTests::GetWordBoundaries()
20482048
til::size bufferSize{ 80, 9001 };
20492049
UINT cursorSize = 12;
20502050
TextAttribute attr{ 0x7f };
2051-
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, _renderer);
2051+
auto _buffer = std::make_unique<TextBuffer>(bufferSize, attr, cursorSize, false, &_renderer);
20522052

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

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

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

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

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

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

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

27552755
static constexpr std::wstring_view url{ L"test.url" };
27562756
static constexpr std::wstring_view customId{ L"CustomId" };
@@ -2902,7 +2902,7 @@ void TextBufferTests::ReflowPromptRegions()
29022902

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

29082908
Log::Comment(L"========== Checking the host buffer state (after) ==========");

src/inc/test/CommonState.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class CommonState
188188
initialAttributes,
189189
uiCursorSize,
190190
true,
191-
*g.pRender);
191+
g.pRender);
192192
if (textBuffer.get() == nullptr)
193193
{
194194
m_hrTextBufferInfo = E_OUTOFMEMORY;

src/renderer/base/RenderSettings.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ COLORREF RenderSettings::GetAttributeUnderlineColor(const TextAttribute& attr) c
259259
// renderer if there are blinking cells currently in view.
260260
// Arguments:
261261
// - renderer: the renderer that will be redrawn.
262-
void RenderSettings::ToggleBlinkRendition(Renderer& renderer) noexcept
262+
void RenderSettings::ToggleBlinkRendition(Renderer* renderer) noexcept
263263
try
264264
{
265265
if (GetRenderMode(Mode::BlinkAllowed))
@@ -277,7 +277,10 @@ try
277277
// We reset the _blinkIsInUse flag before redrawing, so we can
278278
// get a fresh assessment of the current blink attribute usage.
279279
_blinkIsInUse = false;
280-
renderer.TriggerRedrawAll();
280+
if (renderer)
281+
{
282+
renderer->TriggerRedrawAll();
283+
}
281284
}
282285
}
283286
}

src/renderer/inc/RenderSettings.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Microsoft::Console::Render
4242
std::pair<COLORREF, COLORREF> GetAttributeColors(const TextAttribute& attr) const noexcept;
4343
std::pair<COLORREF, COLORREF> GetAttributeColorsWithAlpha(const TextAttribute& attr) const noexcept;
4444
COLORREF GetAttributeUnderlineColor(const TextAttribute& attr) const noexcept;
45-
void ToggleBlinkRendition(class Renderer& renderer) noexcept;
45+
void ToggleBlinkRendition(class Renderer* renderer) noexcept;
4646

4747
private:
4848
til::enumset<Mode> _renderMode{ Mode::BlinkAllowed, Mode::IntenseIsBright };

src/terminal/adapter/PageManager.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void Page::MoveViewportDown() noexcept
9999
_viewport.bottom++;
100100
}
101101

102-
PageManager::PageManager(ITerminalApi& api, Renderer& renderer) noexcept :
102+
PageManager::PageManager(ITerminalApi& api, Renderer* renderer) noexcept :
103103
_api{ api },
104104
_renderer{ renderer }
105105
{
@@ -220,9 +220,9 @@ void PageManager::MoveTo(const til::CoordType pageNumber, const bool makeVisible
220220
}
221221

222222
_activePageNumber = newPageNumber;
223-
if (redrawRequired)
223+
if (redrawRequired && _renderer)
224224
{
225-
_renderer.TriggerRedrawAll();
225+
_renderer->TriggerRedrawAll();
226226
}
227227
}
228228

0 commit comments

Comments
 (0)