This commit is contained in:
Dustin Howett 2021-11-22 12:51:16 -08:00
parent f5f09a6869
commit a7a0d2a6c2
2 changed files with 17 additions and 21 deletions

View file

@ -137,12 +137,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// functions. // functions.
try try
{ {
_dispatcher = winrt::Windows::System::DispatcherQueue::GetForCurrentThread(); //_dispatcher = winrt::Windows::System::DispatcherQueue::GetForCurrentThread();
if (!_dispatcher) //if (!_dispatcher)
{ //{
auto controller{ winrt::Windows::System::DispatcherQueueController::CreateOnDedicatedThread() }; //auto controller{ winrt::Windows::System::DispatcherQueueController::CreateOnDedicatedThread() };
_dispatcher = controller.DispatcherQueue(); //_dispatcher = controller.DispatcherQueue();
} //}
// A few different events should be throttled, so they don't fire absolutely all the time: // A few different events should be throttled, so they don't fire absolutely all the time:
// * _tsfTryRedrawCanvas: When the cursor position moves, we need to // * _tsfTryRedrawCanvas: When the cursor position moves, we need to
@ -157,8 +157,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// need to hop across the process boundary every time text is output. // need to hop across the process boundary every time text is output.
// We can throttle this to once every 8ms, which will get us out of // We can throttle this to once every 8ms, which will get us out of
// the way of the main output & rendering threads. // the way of the main output & rendering threads.
_tsfTryRedrawCanvas = std::make_shared<ThrottledFuncTrailing<>>( _tsfTryRedrawCanvas = std::make_unique<til::throttled_func_trailing<>>(
_dispatcher,
TsfRedrawInterval, TsfRedrawInterval,
[weakThis = get_weak()]() { [weakThis = get_weak()]() {
if (auto core{ weakThis.get() }; !core->_IsClosing()) if (auto core{ weakThis.get() }; !core->_IsClosing())
@ -167,8 +166,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
} }
}); });
_updatePatternLocations = std::make_shared<ThrottledFuncTrailing<>>( _updatePatternLocations = std::make_unique<til::throttled_func_trailing<>>(
_dispatcher,
UpdatePatternLocationsInterval, UpdatePatternLocationsInterval,
[weakThis = get_weak()]() { [weakThis = get_weak()]() {
if (auto core{ weakThis.get() }; !core->_IsClosing()) if (auto core{ weakThis.get() }; !core->_IsClosing())
@ -177,8 +175,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
} }
}); });
_updateScrollBar = std::make_shared<ThrottledFuncTrailing<Control::ScrollPositionChangedArgs>>( _updateScrollBar = std::make_unique<til::throttled_func_trailing<Control::ScrollPositionChangedArgs>>(
_dispatcher,
ScrollBarUpdateInterval, ScrollBarUpdateInterval,
[weakThis = get_weak()](const auto& update) { [weakThis = get_weak()](const auto& update) {
if (auto core{ weakThis.get() }; !core->_IsClosing()) if (auto core{ weakThis.get() }; !core->_IsClosing())
@ -436,7 +433,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_terminal->UserScrollViewport(viewTop); _terminal->UserScrollViewport(viewTop);
if (_updatePatternLocations) if (_updatePatternLocations)
_updatePatternLocations->Run(); _updatePatternLocations->operator()();
} }
void ControlCore::AdjustOpacity(const double adjustment) void ControlCore::AdjustOpacity(const double adjustment)
@ -1213,7 +1210,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (!_inUnitTests) if (!_inUnitTests)
{ {
if (_updateScrollBar) if (_updateScrollBar)
_updateScrollBar->Run(update); _updateScrollBar->operator()(update);
} }
else else
{ {
@ -1222,7 +1219,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Additionally, start the throttled update of where our links are. // Additionally, start the throttled update of where our links are.
if (_updatePatternLocations) if (_updatePatternLocations)
_updatePatternLocations->Run(); _updatePatternLocations->operator()();
} }
void ControlCore::_terminalCursorPositionChanged() void ControlCore::_terminalCursorPositionChanged()
@ -1230,7 +1227,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// When the buffer's cursor moves, start the throttled func to // When the buffer's cursor moves, start the throttled func to
// eventually dispatch a CursorPositionChanged event. // eventually dispatch a CursorPositionChanged event.
if (_tsfTryRedrawCanvas) if (_tsfTryRedrawCanvas)
_tsfTryRedrawCanvas->Run(); _tsfTryRedrawCanvas->operator()();
} }
void ControlCore::_terminalTaskbarProgressChanged() void ControlCore::_terminalTaskbarProgressChanged()
@ -1521,7 +1518,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Start the throttled update of where our hyperlinks are. // Start the throttled update of where our hyperlinks are.
if (_updatePatternLocations) if (_updatePatternLocations)
_updatePatternLocations->Run(); _updatePatternLocations->operator()();
} }
// Method Description: // Method Description:

View file

@ -214,10 +214,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
double _panelHeight{ 0 }; double _panelHeight{ 0 };
double _compositionScale{ 0 }; double _compositionScale{ 0 };
winrt::Windows::System::DispatcherQueue _dispatcher{ nullptr }; std::unique_ptr<til::throttled_func_trailing<>> _tsfTryRedrawCanvas;
std::shared_ptr<ThrottledFuncTrailing<>> _tsfTryRedrawCanvas; std::unique_ptr<til::throttled_func_trailing<>> _updatePatternLocations;
std::shared_ptr<ThrottledFuncTrailing<>> _updatePatternLocations; std::unique_ptr<til::throttled_func_trailing<Control::ScrollPositionChangedArgs>> _updateScrollBar;
std::shared_ptr<ThrottledFuncTrailing<Control::ScrollPositionChangedArgs>> _updateScrollBar;
winrt::fire_and_forget _asyncCloseConnection(); winrt::fire_and_forget _asyncCloseConnection();