diff --git a/src/host/getset.cpp b/src/host/getset.cpp index 3606bd093b7..29aa8ca79a9 100644 --- a/src/host/getset.cpp +++ b/src/host/getset.cpp @@ -1651,7 +1651,7 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo, // - pwAttributes - Pointer to space that will receive color attributes data // Return Value: // - STATUS_SUCCESS if we succeeded or STATUS_INVALID_PARAMETER for bad params (nullptr). -[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, _Out_ WORD* const pwAttributes) +[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(_In_ const SCREEN_INFORMATION& screenInfo, _Out_ WORD* const pwAttributes) { NTSTATUS Status = STATUS_SUCCESS; @@ -1668,6 +1668,12 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo, return Status; } +void DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, TextAttribute& attributes) +{ + attributes = screenInfo.GetActiveBuffer().GetAttributes(); +} + + // Routine Description: // - A private API call for forcing the renderer to repaint the screen. If the // input screen buffer is not the active one, then just do nothing. We only diff --git a/src/host/getset.h b/src/host/getset.h index 129bb8cd123..9115505501e 100644 --- a/src/host/getset.h +++ b/src/host/getset.h @@ -16,6 +16,7 @@ Revision History: #pragma once #include "../inc/conattrs.hpp" +#include "../buffer/out/TextAttribute.hpp" class SCREEN_INFORMATION; void DoSrvPrivateSetLegacyAttributes(SCREEN_INFORMATION& screenInfo, @@ -67,8 +68,9 @@ void DoSrvSetCursorStyle(SCREEN_INFORMATION& screenInfo, void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo, const COLORREF cursorColor); -[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferAttributes(const SCREEN_INFORMATION& screenInfo, - _Out_ WORD* const pwAttributes); +[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(const SCREEN_INFORMATION& screenInfo, + _Out_ WORD* const pwAttributes); +void DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, TextAttribute& attributes); void DoSrvPrivateRefreshWindow(const SCREEN_INFORMATION& screenInfo); diff --git a/src/host/outputStream.cpp b/src/host/outputStream.cpp index 9f1211ce9d9..21498b09370 100644 --- a/src/host/outputStream.cpp +++ b/src/host/outputStream.cpp @@ -629,9 +629,21 @@ BOOL ConhostInternalGetSet::SetCursorStyle(const CursorType cursorType) // - pwAttributes - Pointer to space to receive color attributes data // Return Value: // - TRUE if successful. FALSE otherwise. -BOOL ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) +BOOL ConhostInternalGetSet::PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) { - return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), pwAttributes)); + return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(_io.GetActiveOutputBuffer(), pwAttributes)); +} + +// Routine Description: +// - Retrieves the default color attributes information for the active screen buffer. +// - This function is used to optimize SGR calls in lieu of calling GetConsoleScreenBufferInfoEx. +// Arguments: +// - pAttributes - Pointer to space to receive color attributes data +// Return Value: +// - TRUE if successful. FALSE otherwise. +void ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) +{ + DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), attributes); } // Routine Description: diff --git a/src/host/outputStream.hpp b/src/host/outputStream.hpp index cc626e054ad..64013048031 100644 --- a/src/host/outputStream.hpp +++ b/src/host/outputStream.hpp @@ -132,7 +132,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal:: BOOL PrivateEnableAlternateScroll(const bool fEnabled) override; BOOL PrivateEraseAll() override; - BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) override; + BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) override; + void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) override; BOOL PrivatePrependConsoleInput(_Inout_ std::deque>& events, _Out_ size_t& eventsWritten) override; diff --git a/src/terminal/adapter/adaptDispatchGraphics.cpp b/src/terminal/adapter/adaptDispatchGraphics.cpp index f676e08adac..680bca51a0d 100644 --- a/src/terminal/adapter/adaptDispatchGraphics.cpp +++ b/src/terminal/adapter/adaptDispatchGraphics.cpp @@ -400,7 +400,7 @@ bool AdaptDispatch::SetGraphicsRendition(_In_reads_(cOptions) const DispatchType // because it has to fill the Largest Window Size by asking the OS and wastes time memcpying colors and other data // we do not need to resolve this Set Graphics Rendition request. WORD attr; - bool fSuccess = !!_conApi->PrivateGetConsoleScreenBufferAttributes(&attr); + bool fSuccess = !!_conApi->PrivateGetConsoleScreenBufferLegacyAttributes(&attr); if (fSuccess) { diff --git a/src/terminal/adapter/conGetSet.hpp b/src/terminal/adapter/conGetSet.hpp index 37b85596cab..21905086f3b 100644 --- a/src/terminal/adapter/conGetSet.hpp +++ b/src/terminal/adapter/conGetSet.hpp @@ -17,6 +17,7 @@ Author(s): #include "..\..\types\inc\IInputEvent.hpp" #include "..\..\inc\conattrs.hpp" +#include "..\..\buffer\out\TextAttribute.hpp" #include #include @@ -87,7 +88,8 @@ namespace Microsoft::Console::VirtualTerminal virtual BOOL PrivateEraseAll() = 0; virtual BOOL SetCursorStyle(const CursorType cursorType) = 0; virtual BOOL SetCursorColor(const COLORREF cursorColor) = 0; - virtual BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) = 0; + virtual BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) = 0; + virtual void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) = 0; virtual BOOL PrivatePrependConsoleInput(_Inout_ std::deque>& events, _Out_ size_t& eventsWritten) = 0; virtual BOOL PrivateWriteConsoleControlInput(_In_ KeyEvent key) = 0; diff --git a/src/terminal/adapter/ut_adapter/adapterTest.cpp b/src/terminal/adapter/ut_adapter/adapterTest.cpp index 7b079f2487d..2be5e319b70 100644 --- a/src/terminal/adapter/ut_adapter/adapterTest.cpp +++ b/src/terminal/adapter/ut_adapter/adapterTest.cpp @@ -689,16 +689,24 @@ class TestGetSet final : public ConGetSet return _fSetCursorColorResult; } - BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) override + BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) override { - Log::Comment(L"PrivateGetConsoleScreenBufferAttributes MOCK returning data..."); + Log::Comment(L"PrivateGetConsoleScreenBufferLegacyAttributes MOCK returning data..."); - if (pwAttributes != nullptr && _fPrivateGetConsoleScreenBufferAttributesResult) + if (pwAttributes != nullptr && _fPrivateGetConsoleScreenBufferLegacyAttributesResult) { *pwAttributes = _wAttribute; } - return _fPrivateGetConsoleScreenBufferAttributesResult; + return _fPrivateGetConsoleScreenBufferLegacyAttributesResult; + } + + void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) override + { + Log::Comment(L"PrivateGetConsoleScreenBufferAttributes MOCK returning data..."); + + // TODO + attributes = TextAttribute(); } BOOL PrivateRefreshWindow() override @@ -871,7 +879,7 @@ class TestGetSet final : public ConGetSet _fPrivateWriteConsoleControlInputResult = TRUE; _fScrollConsoleScreenBufferWResult = TRUE; _fSetConsoleWindowInfoResult = TRUE; - _fPrivateGetConsoleScreenBufferAttributesResult = TRUE; + _fPrivateGetConsoleScreenBufferLegacyAttributesResult = TRUE; _fMoveToBottomResult = true; _PrepCharsBuffer(wch, wAttr); @@ -1394,7 +1402,7 @@ class TestGetSet final : public ConGetSet BOOL _fSetConsoleXtermTextAttributeResult = false; BOOL _fSetConsoleRGBTextAttributeResult = false; BOOL _fPrivateSetLegacyAttributesResult = false; - BOOL _fPrivateGetConsoleScreenBufferAttributesResult = false; + BOOL _fPrivateGetConsoleScreenBufferLegacyAttributesResult = false; BOOL _fSetCursorStyleResult = false; CursorType _ExpectedCursorStyle; BOOL _fSetCursorColorResult = false; @@ -2505,7 +2513,7 @@ class AdapterTest Log::Comment(L"Test 2: Gracefully fail when getting buffer information fails."); _testGetSet->PrepData(); - _testGetSet->_fPrivateGetConsoleScreenBufferAttributesResult = FALSE; + _testGetSet->_fPrivateGetConsoleScreenBufferLegacyAttributesResult = FALSE; VERIFY_IS_FALSE(_pDispatch->SetGraphicsRendition(rgOptions, cOptions));