terminal/src/renderer/inc
Leon Liang fe3f528827
Show a double width cursor for double width characters (#5319)
# Summary of the Pull Request
This PR will allow the cursor to be double width when on top of a double width character. This required changing `IsCursorDoubleWidth` to check whether the glyph the cursor's on top of is double width. This code is exactly the same as the original PR that addressed this issue in #2932. That one got reverted at some point due to the crashes related to it, but due to a combination of Terminal having come further since that PR and other changes to address use-after-frees, some of the crashes may/may not be relevant now. The ones that seemed to be relevant/repro-able, I attempt to address in this PR.

The `IsCursorDoubleWidth` check would fail during the `TextBuffer::Reflow` call inside of `Terminal::UserResize` occasionally, particularly when `newCursor.EndDeferDrawing()` is called. This is because when we tell the newCursor to `EndDefer`, the renderer will attempt to redraw the cursor. As part of this redraw, it'll ask if `IsCursorDoubleWidth`, and if the renderer managed to ask this before `UserResize` swapped out the old buffer with the new one from `Reflow`, the renderer will be asking the old buffer if its out-of-bounds cursor is double width. This was pretty easily repro'd using `cmatrix -u0` and resizing the window like a madman.

As a solution, I've moved the Start/End DeferDrawing calls out of `Reflow` and into `UserResize`. This way, I can "clamp" the portion of the code where the newBuffer is getting created and reflowed and swapped into the Terminal buffer, and only allow the renderer to draw once the swap is done. This also means that ConHost's `ResizeWithReflow` needed to change slightly.

In addition, I've added a WriteLock to `SetCursorOn`. It was mentioned as a fix for a crash in #2965 (although I can't repro), and I also figured it would be good to try to emulate where ConHost locks with regards to Cursor operations, and this seemed to be one that we were missing.

## PR Checklist
* [x] Closes #2713
* [x] CLA signed
* [x] Tests added/passed

## Validation Steps Performed
Manual validation that the cursor is indeed chonky, added a test case to check that we are correctly saying that the cursor is double width (not too sure if I put it in the right place). Also open to other test case ideas and thoughts on what else I should be careful for since I am quite nervous about what other crashes might occur.
2020-04-15 19:23:06 +00:00
..
Cluster.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
DummyRenderTarget.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
FontInfo.hpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
FontInfoBase.hpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
FontInfoDesired.hpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
IFontDefaultList.hpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
IRenderData.hpp Show a double width cursor for double width characters (#5319) 2020-04-15 19:23:06 +00:00
IRenderEngine.hpp Move ConPTY to use til::bitmap (#5024) 2020-03-23 15:57:54 +00:00
IRenderer.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
IRenderTarget.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
IRenderThread.hpp Add support for renderer backoff, don't FAIL_FAST on 3x failures, add UI (#5353) 2020-04-14 20:11:47 +00:00
RenderEngineBase.hpp Suppress last two errors (C26455 default constructor throw in DxEngine because it's due for refactoring soon anyway & C26444 custom construction/destruction on OutputCellIterator because I can't see what's going on and it needs more investigation and shouldn't hold this up). Also run codeformat. 2019-09-03 16:18:19 -07:00