Skip to content

minimap - allow variable scaling - #82265

Merged
Connor Peet (connor4312) merged 10 commits into
masterfrom
feat/minimap-variable-scaling
Oct 14, 2019
Merged

Connor Peet (connor4312) merged 10 commits into
masterfrom
feat/minimap-variable-scaling

Conversation

@connor4312

Copy link
Copy Markdown
Member

This PR allows the minimap to be scaled to several constant values. Most of the
work in this PR is adjusting the the font renderer to render character at
variable sizes. It turns out most generic image scaling algorithms are not
built to scale down to one or two pixels (the default minimap font size has
1px by 2px characters), so some work was needed to make this possible and look
good.

Generating fonts at runtime does incur a small performance penalty, taking
about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font
the first time we render a minimap. If we want to avoid this, we could consider
shipping pre-rendered font for the first few scale settings.

Draw speed is comparable to the previous version, the profiler reported in
the range of 8-11ms to render my test file in both the previous and new code.

I've tested this on my high DPI Macbook display and it appears to work well
there too.

Talking to Alex, something we may need to look into is matching the user font
and render settings. Previously, and continuing in this PR, we use the default
monospace font on the system with a restricted set of character codes.
Previously the sidebar's font was too small to be visible, but now its content
can be seen under large settings. We may need to look and reworking how this
data is rendered. Perhaps we generate the characters we need on the fly into
their own buffers? Open to ideas.

Kapture 2019-10-10 at 9 55 16

Fixes #21773

This PR allows the minimap to be scaled to several constant values. Most of the
work in this PR is adjusting the the font renderer to render character at
variable sizes. It turns out most generic image scaling algorithms are not
built to scale down to one or two pixels (the default minimap font size has
1px by 2px characters), so some work was needed to make this possible and look
good.

Generating fonts at runtime does incur a small performance penalty, taking
about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font
the first time we render a minimap. If we want to avoid this, we could consider
shipping pre-rendered font for the first few scale settings.

At this moment this only supports scaling to a constant integer--effectively,
scaling the character width, since we start at 1x2px. More granular scaling
would be interesting, but will come at a runtime cost as we'll need to do
linear interpolation for each character we draw at a non-integral coordinate.

Draw speed is comparable to the previous version, the profiler reported in
the range of 8-11ms to render my test file in both the previous and new code.

I've tested this on my high DPI Macbook display and it appears to work well
there too.

Talking to Alex, something we may need to look into is matching the user font
and render settings. Previously, and continuing in this PR, we use the default
monospace font on the system with a restricted set of character codes.
Previously the sidebar's font was too small to be visible, but now its content
can be seen under large settings. We may need to look and reworking how this
data is rendered. Perhaps we generate the characters we need on the fly into
their own buffers? Open to ideas.

Fixes #21773
@connor4312
Connor Peet (connor4312) force-pushed the feat/minimap-variable-scaling branch from 551bd19 to 928d48b Compare October 10, 2019 17:00
renderMinimapCharRenderer(minimapCharRenderer1x, 400, 1);
renderMinimapCharRenderer(minimapCharRenderer2x, 500, 2);
renderMinimapCharRenderer(minimapCharRenderer4x, 600, 4);
renderMinimapCharRenderer(minimapCharRenderer6x, 750, 8);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generating fonts at runtime does incur a small performance penalty, taking
about 0.6m at 1x scale and 0.9ms at 4x scale on my machine to create the font
the first time we render a minimap.

Shouldn't we only be rendering the scale we need and reacting when the scale setting or device pixel ratio changes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, this can vary wildly based on hardware and Chromium version based on my experience.

@connor4312 Connor Peet (connor4312) Oct 10, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we only be rendering the scale we need and reacting when the scale setting or device pixel ratio changes?

This is what we do! This file is a 'demo' page, previously used to generate the hardcoded image maps, and I put several more scales here now to assist with development. In the editor, the minimap calls MinimapCharRendererFactory.create(scale) when it resolves its rendering settings. The factory caches a singleton of the char renderer, so that it only creates one as needed (instead of rerendering the font for every minimap instance)

ctx.fillStyle = '#ffffff';
ctx.font = `bold ${Constants.SAMPLED_CHAR_HEIGHT}px monospace`;
ctx.textBaseline = 'middle';
for (let chCode = Constants.START_CH_CODE; chCode <= Constants.END_CH_CODE; chCode++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't handle unicode or wide characters. Kind of feels like this is just leading to re-implementing xterm.js' texture atlas?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this is something alexandrudima mentioned. Maybe the texture atlas in xterm could be popped into its own module that vscode can provide to and share between the minimap and xterm instances?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related existing issue that a user noticed on their high DPI display (where we used the 2x4px font) #64477

@alexdima Alexandru Dima (alexdima) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Really well done! I love the new down-sampling, the results are so much better!!:

So this PR fixes also #20929

Before After
image image

I am not super concerned with non-ASCII letters for this PR... since this is a minimap after all, and we can be imperfect in the name of speed... It's also an existing issue, so it is not introduced by this PR...

Some ideas to tackle letters outside the ASCII range:

  • cheap way would be to render the famous unicode box for missing glyphs or switch to block rendering for lines which contain characters outside of the ASCII range.
  • (more expensive) we could render them as space in the minimap imagedata and then have a post-process step on the <canvas> where we invoke the canvas renderText on top of the places we skipped.
  • otherwise, perhaps an atlas of shapes, but that gets difficult very quickly (as Daniel Imms (@Tyriar) would know from xterm)

And a final idea:

  • maybe it wouldn't be so bad to generate the minimap font based on the current configured font... Since with the scale: 8 we can really see it in detail. LMK if you need help figuring it out, the font info is also available as an editor option...

@connor4312

Connor Peet (connor4312) commented Oct 11, 2019 •

Copy link
Copy Markdown
Member Author

maybe it wouldn't be so bad to generate the minimap font based on the current configured font... Since with the scale: 8 we can really see it in detail. LMK if you need help figuring it out, the font info is also available as an editor option...

Good idea! Previously this wasn't possible but now that we're rendering at runtime it's pretty easy 🙂 In my next commit

cheap way would be to render the famous unicode box for missing glyphs or switch to block rendering for lines which contain characters outside of the ASCII range.

This was straightfoward, so I've implemented this. The question box is, somewhat ironically, itself a double-width character, but it's legible at resolutions that text is, and it gets the message across and won't look out of place on most practical minimap scales.

image

Thinking on it more overnight I'm inclined to agree with Alex regarding support for higher unicode characters. Unlike the terminal, where fonts need to be correct and beautifully rendered, the minimap is used to overview the shape of the code, and legibility is not a concern. As a user I'd put more weight on the minimap being lightweight and not impacting editor performance; the existing routines that we have that I've expanded on here are very fast, and increasing their correctness would likely involve a performance and complexity tradeoff.

@connor4312
Connor Peet (connor4312) force-pushed the feat/minimap-variable-scaling branch from f8fe96f to b48b016 Compare October 11, 2019 16:51

@Tyriar Daniel Imms (Tyriar) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question mark icon would be far better than what there was previously where is was just random ascii characters imo. The main concern around that is that you might get an increased number of reports about this as more users would be able to make out the differences.

@connor4312

Copy link
Copy Markdown
Member Author

We could limit the maximum minimap scale to be just below where text could be legible to avoid that.

@connor4312

Copy link
Copy Markdown
Member Author

This is now the max minimap scale. Note that on high DPI screens it will actually be doubled--though the physical size should stay approximately the same.

image

@qwertie

David Piepgrass (qwertie) commented Jan 7, 2020 •

Copy link
Copy Markdown

Can we select a different font for the minimap than is used in the main text area?

Back in the day, I made a font called 2Small designed for legibility at extremely small sizes - each character being 5 pixels high. I'd like to try using it in the minimap but it's unsuitable in the main window. With ClearType, a horizontally condensed version of this font should remain legible in the minimap...

@connor4312

Copy link
Copy Markdown
Member Author

Please open a new issue for that feature request!

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minimap: add scale (font size) option

5 participants