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

FINALLY fix blurry canvas/webgl renderer issues due to device pixel rounding errors 🎉 #3926

Merged
merged 7 commits into from
Jul 28, 2022

Conversation

Tyriar
Copy link
Member

@Tyriar Tyriar commented Jul 24, 2022

Fixes #2662
Part of microsoft/vscode#85154

Below tested on Edge 105 (dev) on Windows 11 (set at 100% scale) with the webgl renderer. The same fix applies also to the canvas renderer.

Zoom 50%

image

Zoom 67%

image

Zoom 75%

image

Zoom 80%

image

Zoom 90%

image

Zoom 100%

image

Zoom 110%

image

Zoom 125%

image

Zoom 150%

image

Zoom 175%

image

This uses the ResizeObserver devicePixelContentBoxSize API in order to
fetch the exact device pixel dimensions from the browser. The old
possibly blurry behavior is used as a fallback if that API is not
available.

Part of xtermjs#2662
Part of microsoft/vscode#85154
Required for devicePixelContentBoxSize ResizeObserver API
@Tyriar Tyriar added this to the 4.20.0 milestone Jul 24, 2022
@Tyriar Tyriar self-assigned this Jul 24, 2022
@carlfriedrich
Copy link

carlfriedrich commented Jul 26, 2022

Hey @Tyriar, thanks for taking care of this! I just checked out your branch to test this on my machine. Is this fix automatically applied when I run yarn on this branch or do I have to modify any settings?

My first test unfortunately did not show any improvement compared to master, still having non-consistent character rendering throughout the line (sharp on the left and right edges, blurry in the middle):

grafik

Checking the canvas element's properties in the DOM:

grafik

It shows that the zoom factor is still not exact:

width / css-width = 968 / 774 = 1,2506459948320413436692506459948

Should be 1.25, since that's my display zoom factor.

@Tyriar
Copy link
Member Author

Tyriar commented Jul 26, 2022

@carlfriedrich the zoom factor shouldn't matter if it's not perfect with this method as we're querying the browser for the exact device pixel dimensions of the canvas. You may be using a browser that doesn't support the API in which case we fallback to the original possibly blurry method?

@carlfriedrich
Copy link

@Tyriar Hmm, not sure if I understand that correctly. What browser would you recommend?
I am using latest Firefox (102.0.1). Tested also in Edge (103.0.1264.71), behaviour is the same.

@Tyriar
Copy link
Member Author

Tyriar commented Jul 26, 2022

You also need to run yarn and restart the build or your won't get a successful compile

@carlfriedrich
Copy link

This is what I'm doing and the output:

grafik

Am I missing something?

@Tyriar
Copy link
Member Author

Tyriar commented Jul 26, 2022

@carlfriedrich make sure you run yarn watch as well, that will show you the compilation results. Start only launches the demo server

@carlfriedrich
Copy link

Okay thanks, then it shows errors:

grafik

@Tyriar
Copy link
Member Author

Tyriar commented Jul 26, 2022

@carlfriedrich to fix that you'll need to run yarn to install the newer version of typescript then restart it

@carlfriedrich
Copy link

@Tyriar Ah yep, I already recognized that myself. Now yarn watch doesn't show any more errors, and I indeed see a difference in Edge!

master branch:
grafik

rounding branch:
grafik

So the font is indeed crisp, thumbs up! 👍

In my Firefox, however, the rendering is the same as before. Does that mean that Firefox does not support the new API? Wouldn't be a problem, since VS Code will be the place where it is supposed to work, just curious.

@Tyriar
Copy link
Member Author

Tyriar commented Jul 26, 2022

Great! I didn't check Firefox, but yes vscode is based on electron which uses chromium underneath. I didn't check whether the current version of vscodes electron will have it yet, if not it will get fixed in vscode eventually after an electron update.

@Tyriar Tyriar modified the milestones: 4.20.0, 5.0.0 Jul 28, 2022
@Tyriar Tyriar merged commit 04b513c into xtermjs:master Jul 28, 2022
@Tyriar Tyriar deleted the rounding branch July 28, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Renderer is blurry when window zoom level is changed
2 participants