forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBgfxEngine.cpp
252 lines (207 loc) · 7.76 KB
/
BgfxEngine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "BgfxEngine.hpp"
#include "ConIoSrvComm.hpp"
#include "../inc/ServiceLocator.hpp"
#pragma hdrstop
//
// Default non-bright white.
//
#define DEFAULT_COLOR_ATTRIBUTE (0xC)
using namespace Microsoft::Console::Render;
using namespace Microsoft::Console::Interactivity;
using namespace Microsoft::Console::Interactivity::OneCore;
BgfxEngine::BgfxEngine(PVOID SharedViewBase, LONG DisplayHeight, LONG DisplayWidth, LONG FontWidth, LONG FontHeight) noexcept :
RenderEngineBase(),
_sharedViewBase(static_cast<std::byte*>(SharedViewBase)),
_displayHeight(gsl::narrow_cast<SIZE_T>(DisplayHeight)),
_displayWidth(gsl::narrow_cast<SIZE_T>(DisplayWidth)),
_currentLegacyColorAttribute(DEFAULT_COLOR_ATTRIBUTE)
{
_runLength = sizeof(CD_IO_CHARACTER) * DisplayWidth;
_fontSize.width = FontWidth > SHORT_MAX ? SHORT_MAX : gsl::narrow_cast<til::CoordType>(FontWidth);
_fontSize.height = FontHeight > SHORT_MAX ? SHORT_MAX : gsl::narrow_cast<til::CoordType>(FontHeight);
}
[[nodiscard]] HRESULT BgfxEngine::Invalidate(const til::rect* /*psrRegion*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::InvalidateCursor(const til::rect* /*psrRegion*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::InvalidateSystem(const til::rect* /*prcDirtyClient*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::InvalidateSelection(const std::vector<til::rect>& /*rectangles*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::InvalidateScroll(const til::point* /*pcoordDelta*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::InvalidateAll() noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::PrepareForTeardown(_Out_ bool* const pForcePaint) noexcept
{
*pForcePaint = false;
return S_FALSE;
}
[[nodiscard]] HRESULT BgfxEngine::StartPaint() noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::EndPaint() noexcept
try
{
const auto Status = ConIoSrvComm::GetConIoSrvComm()->RequestUpdateDisplay(0);
if (SUCCEEDED_NTSTATUS(Status))
{
for (SIZE_T i = 0; i < _displayHeight; i++)
{
const auto OldRunBase = _sharedViewBase + (i * 2 * _runLength);
const auto NewRunBase = OldRunBase + _runLength;
memcpy_s(OldRunBase, _runLength, NewRunBase, _runLength);
}
}
return HRESULT_FROM_NT(Status);
}
CATCH_RETURN()
// Routine Description:
// - Used to perform longer running presentation steps outside the lock so the other threads can continue.
// - Not currently used by BgfxEngine.
// Arguments:
// - <none>
// Return Value:
// - S_FALSE since we do nothing.
[[nodiscard]] HRESULT BgfxEngine::Present() noexcept
{
return S_FALSE;
}
[[nodiscard]] HRESULT BgfxEngine::ScrollFrame() noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::PaintBackground() noexcept
{
for (SIZE_T i = 0; i < _displayHeight; i++)
{
const auto NewRun = reinterpret_cast<PCD_IO_CHARACTER>(_sharedViewBase + (i * 2 * _runLength) + _runLength);
for (SIZE_T j = 0; j < _displayWidth; j++)
{
NewRun[j].Character = L' ';
NewRun[j].Attribute = 0;
}
}
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::PaintBufferLine(const std::span<const Cluster> clusters,
const til::point coord,
const bool /*trimLeft*/,
const bool /*lineWrapped*/) noexcept
{
try
{
const auto y = gsl::narrow_cast<SIZE_T>(coord.y);
const auto NewRun = reinterpret_cast<PCD_IO_CHARACTER>(_sharedViewBase + (y * 2 * _runLength) + _runLength);
for (SIZE_T i = 0; i < clusters.size() && i < _displayWidth; i++)
{
NewRun[coord.x + i].Character = til::at(clusters, i).GetTextAsSingle();
NewRun[coord.x + i].Attribute = _currentLegacyColorAttribute;
}
return S_OK;
}
CATCH_RETURN()
}
[[nodiscard]] HRESULT BgfxEngine::PaintBufferGridLines(const GridLineSet /*lines*/,
const COLORREF /*gridlineColor*/,
const COLORREF /*underlineColor*/,
const size_t /*cchLine*/,
const til::point /*coordTarget*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::PaintSelection(const til::rect& /*rect*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::PaintCursor(const CursorOptions& options) noexcept
try
{
// TODO: MSFT: 11448021 - Modify BGFX to support rendering full-width
// characters and a full-width cursor.
CD_IO_CURSOR_INFORMATION CursorInfo;
CursorInfo.Row = gsl::narrow<USHORT>(options.coordCursor.y);
CursorInfo.Column = gsl::narrow<USHORT>(options.coordCursor.x);
CursorInfo.Height = options.ulCursorHeightPercent;
CursorInfo.IsVisible = TRUE;
const auto Status = ConIoSrvComm::GetConIoSrvComm()->RequestSetCursor(&CursorInfo);
return HRESULT_FROM_NT(Status);
}
CATCH_RETURN()
[[nodiscard]] HRESULT BgfxEngine::UpdateDrawingBrushes(const TextAttribute& textAttributes,
const RenderSettings& /*renderSettings*/,
const gsl::not_null<IRenderData*> /*pData*/,
const bool /*usingSoftFont*/,
const bool /*isSettingDefaultBrushes*/) noexcept
{
_currentLegacyColorAttribute = textAttributes.GetLegacyAttributes();
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::UpdateFont(const FontInfoDesired& /*pfiFontInfoDesired*/, FontInfo& /*pfiFontInfo*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::UpdateDpi(const int /*iDpi*/) noexcept
{
return S_OK;
}
// Method Description:
// - This method will update our internal reference for how big the viewport is.
// Does nothing for BGFX.
// Arguments:
// - srNewViewport - The bounds of the new viewport.
// Return Value:
// - HRESULT S_OK
[[nodiscard]] HRESULT BgfxEngine::UpdateViewport(const til::inclusive_rect& /*srNewViewport*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::GetProposedFont(const FontInfoDesired& /*pfiFontInfoDesired*/, FontInfo& /*pfiFontInfo*/, const int /*iDpi*/) noexcept
{
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::GetDirtyArea(std::span<const til::rect>& area) noexcept
{
_dirtyArea.bottom = gsl::narrow_cast<til::CoordType>(std::max(static_cast<SIZE_T>(0), _displayHeight));
_dirtyArea.right = gsl::narrow_cast<til::CoordType>(std::max(static_cast<SIZE_T>(0), _displayWidth));
area = { &_dirtyArea,
1 };
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::GetFontSize(_Out_ til::size* pFontSize) noexcept
{
*pFontSize = _fontSize;
return S_OK;
}
[[nodiscard]] HRESULT BgfxEngine::IsGlyphWideByFont(const std::wstring_view /*glyph*/, _Out_ bool* const pResult) noexcept
{
*pResult = false;
return S_OK;
}
// Method Description:
// - Updates the window's title string.
// Does nothing for BGFX.
// Arguments:
// - newTitle: the new string to use for the title of the window
// Return Value:
// - S_OK
[[nodiscard]] HRESULT BgfxEngine::_DoUpdateTitle(_In_ const std::wstring_view /*newTitle*/) noexcept
{
return S_OK;
}