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

Introduce RenderClusterIterator #3458

Closed
Closed
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
2 changes: 1 addition & 1 deletion src/buffer/out/textBufferCellIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace Microsoft::Console::Types;
// Routine Description:
// - Creates a new read-only iterator to seek through cell data stored within a screen buffer
// Arguments:
// - buffer - Text buffer to seek throught
// - buffer - Text buffer to seek through
// - pos - Starting position to retrieve text data from (within screen buffer bounds)
TextBufferCellIterator::TextBufferCellIterator(const TextBuffer& buffer, COORD pos) :
TextBufferCellIterator(buffer, pos, buffer.GetSize())
Expand Down
89 changes: 54 additions & 35 deletions src/host/ut_host/VtRendererTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// Licensed under the MIT license.

#include "precomp.h"
#include <wextestclass.h>
#include <WexTestClass.h>
#include "CommonState.hpp"

#include "../../inc/consoletaeftemplates.hpp"
#include "../../types/inc/Viewport.hpp"

#include "../../interactivity/base/ServiceLocator.cpp"
#include "../../renderer/inc/DummyRenderTarget.hpp"
#include "../../renderer/vt/Xterm256Engine.hpp"
#include "../../renderer/vt/XtermEngine.hpp"
#include "../../renderer/vt/WinTelnetEngine.hpp"
Expand Down Expand Up @@ -59,6 +63,8 @@ class Microsoft::Console::Render::VtRendererTest
{
TEST_CLASS(VtRendererTest);

CommonState* m_state;

TEST_CLASS_SETUP(ClassSetup)
{
// clang-format off
Expand All @@ -79,11 +85,21 @@ class Microsoft::Console::Render::VtRendererTest
g_ColorTable[14] = RGB(249, 241, 165); // Bright Yellow
g_ColorTable[15] = RGB(242, 242, 242); // White
// clang-format on
m_state = new CommonState();

m_state->PrepareGlobalFont();
m_state->PrepareGlobalScreenBuffer();

return true;
}

TEST_CLASS_CLEANUP(ClassCleanup)
{
m_state->CleanupGlobalScreenBuffer();
m_state->CleanupGlobalFont();

delete m_state;

return true;
}

Expand Down Expand Up @@ -125,6 +141,7 @@ class Microsoft::Console::Render::VtRendererTest
bool WriteCallback(const char* const pch, size_t const cch);
void TestPaint(VtEngine& engine, std::function<void()> pfn);
Viewport SetUpViewport();
TextBuffer& GetTbi();

void VerifyExpectedInputsDrained();
};
Expand All @@ -139,6 +156,12 @@ Viewport VtRendererTest::SetUpViewport()
return Viewport::FromInclusive(view);
}

TextBuffer& VtRendererTest::GetTbi()
{
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
return gci.GetActiveOutputBuffer().GetTextBuffer();
}

void VtRendererTest::VerifyExpectedInputsDrained()
{
if (!qExpectedInput.empty())
Expand Down Expand Up @@ -596,15 +619,14 @@ void VtRendererTest::Xterm256TestCursor()
qExpectedInput.push_back("asdfghjkl");

const wchar_t* const line = L"asdfghjkl";
const unsigned char rgWidths[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };

std::vector<Cluster> clusters;
for (size_t i = 0; i < wcslen(line); i++)
{
clusters.emplace_back(std::wstring_view{ &line[i], 1 }, static_cast<size_t>(rgWidths[i]));
}
TextBuffer& tbi = GetTbi();
const TextAttribute attr{};
tbi.WriteLine(OutputCellIterator(line, attr), { 0, 0 });
TextBufferCellIterator cellIt(tbi, { 0, 0 });
RenderClusterIterator clusterIt(cellIt);

VERIFY_SUCCEEDED(engine->PaintBufferLine({ clusters.data(), clusters.size() }, { 1, 1 }, false));
VERIFY_SUCCEEDED(engine->PaintBufferLine(clusterIt, { 1, 1 }, false));

qExpectedInput.push_back(EMPTY_CALLBACK_SENTINEL);
VERIFY_SUCCEEDED(engine->_MoveCursor({ 10, 1 }));
Expand Down Expand Up @@ -1012,15 +1034,14 @@ void VtRendererTest::XtermTestCursor()
qExpectedInput.push_back("asdfghjkl");

const wchar_t* const line = L"asdfghjkl";
const unsigned char rgWidths[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };

std::vector<Cluster> clusters;
for (size_t i = 0; i < wcslen(line); i++)
{
clusters.emplace_back(std::wstring_view{ &line[i], 1 }, static_cast<size_t>(rgWidths[i]));
}
TextBuffer& tbi = GetTbi();
const TextAttribute attr{};
tbi.WriteLine(OutputCellIterator(line, attr), { 0, 0 });
TextBufferCellIterator cellIt(tbi, { 0, 0 });
RenderClusterIterator clusterIt(cellIt);

VERIFY_SUCCEEDED(engine->PaintBufferLine({ clusters.data(), clusters.size() }, { 1, 1 }, false));
VERIFY_SUCCEEDED(engine->PaintBufferLine(clusterIt, { 1, 1 }, false));

qExpectedInput.push_back(EMPTY_CALLBACK_SENTINEL);
VERIFY_SUCCEEDED(engine->_MoveCursor({ 10, 1 }));
Expand Down Expand Up @@ -1242,15 +1263,14 @@ void VtRendererTest::WinTelnetTestCursor()
qExpectedInput.push_back("asdfghjkl");

const wchar_t* const line = L"asdfghjkl";
const unsigned char rgWidths[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };

std::vector<Cluster> clusters;
for (size_t i = 0; i < wcslen(line); i++)
{
clusters.emplace_back(std::wstring_view{ &line[i], 1 }, static_cast<size_t>(rgWidths[i]));
}
TextBuffer& tbi = GetTbi();
const TextAttribute attr{};
tbi.WriteLine(OutputCellIterator(line, attr), { 0, 0 });
TextBufferCellIterator cellIt(tbi, { 0, 0 });
RenderClusterIterator clusterIt(cellIt);

VERIFY_SUCCEEDED(engine->PaintBufferLine({ clusters.data(), clusters.size() }, { 1, 1 }, false));
VERIFY_SUCCEEDED(engine->PaintBufferLine(clusterIt, { 1, 1 }, false));

qExpectedInput.push_back(EMPTY_CALLBACK_SENTINEL);
VERIFY_SUCCEEDED(engine->_MoveCursor({ 10, 1 }));
Expand Down Expand Up @@ -1302,21 +1322,20 @@ void VtRendererTest::TestWrapping()

const wchar_t* const line1 = L"asdfghjkl";
const wchar_t* const line2 = L"zxcvbnm,.";
const unsigned char rgWidths[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };

std::vector<Cluster> clusters1;
for (size_t i = 0; i < wcslen(line1); i++)
{
clusters1.emplace_back(std::wstring_view{ &line1[i], 1 }, static_cast<size_t>(rgWidths[i]));
}
std::vector<Cluster> clusters2;
for (size_t i = 0; i < wcslen(line2); i++)
{
clusters2.emplace_back(std::wstring_view{ &line2[i], 1 }, static_cast<size_t>(rgWidths[i]));
}
const TextAttribute attr{};

TextBuffer& tbi = GetTbi();

tbi.WriteLine(OutputCellIterator(line1, attr), { 0, 0 });
TextBufferCellIterator cellIt1(tbi, { 0, 0 });
RenderClusterIterator clusterIt1(cellIt1);
VERIFY_SUCCEEDED(engine->PaintBufferLine(clusterIt1, { 0, 0 }, false));

VERIFY_SUCCEEDED(engine->PaintBufferLine({ clusters1.data(), clusters1.size() }, { 0, 0 }, false));
VERIFY_SUCCEEDED(engine->PaintBufferLine({ clusters2.data(), clusters2.size() }, { 0, 1 }, false));
tbi.WriteLine(OutputCellIterator(line2, attr), { 0, 0 });
TextBufferCellIterator cellIt2(tbi, { 0, 0 });
RenderClusterIterator clusterIt2(cellIt2);
VERIFY_SUCCEEDED(engine->PaintBufferLine(clusterIt2, { 0, 1 }, false));
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/base/Cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const wchar_t Cluster::GetTextAsSingle() const noexcept
// - <none>
// Return Value:
// - String view of wchar_ts.
const std::wstring_view& Cluster::GetText() const noexcept
std::wstring_view& Cluster::GetText() noexcept
{
return _text;
}
Expand All @@ -55,7 +55,7 @@ const std::wstring_view& Cluster::GetText() const noexcept
// - <none>
// Return Value:
// - Number of columns to use when drawing (not a pixel count).
const size_t Cluster::GetColumns() const noexcept
size_t Cluster::GetColumns() const noexcept
{
return _columns;
}
Loading