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

Port high resolution local SDFs #10298

Merged
merged 2 commits into from
Jan 25, 2021
Merged

Port high resolution local SDFs #10298

merged 2 commits into from
Jan 25, 2021

Conversation

ChrisLoer
Copy link
Contributor

@ChrisLoer ChrisLoer commented Jan 18, 2021

Launch Checklist

This PR brings gl-js to parity with gl-native by porting the 2x resolution local glyph generation. It includes:

  • 2x resolution local glyphs
  • Glyph metrics extraction via TextMetrics and support for local generation of non-ideographic glyphs using localFontFamily map option. (Previously in PR Add 'localFontFamily' option to support rendering of all glyphs. #10267: I've rolled it into this PR because both PRs depend on the same TinySDF changes and I've been testing them together).
  • Performance optimizations to offset the cost of doubling the SDF resolution: mainly (1) don't double-generate glyphs that share the same font and (2) trim whitespace from glyphs.

The visual improvement is noticeable on high DPI screens, and can also be seen easily in large labels:

Before
Screen Shot 2021-01-15 at 15 09 23
Screen Shot 2021-01-15 at 15 08 59

After
Screen Shot 2021-01-15 at 15 06 31
Screen Shot 2021-01-15 at 15 07 07

For default settings, these changes have negligible performance impact for maps without heavy CJK-use. For CJK maps, the main impact is at load time (generating SDFs for the first time), although there is a small ongoing hit from loading larger glyph atlases (SDF generation is also an ongoing cost once the map is loaded, but the rate of new glyph generation drops off pretty quickly once a set of common characters are loaded). One option we have for ameliorating the load time performance hit is to do SDF generation on the workers. However, if we can get away with it, I'd like to avoid that complexity. For performance testing, I used benchmap-js with a Japanese-language style that rendered three cities at z8, z12, and z16. The main results were:

Full load: 160ms/16% slower
Speed index: 96ms/19% slower
FPS: -6.3
Jank: indeterminate
Dropped frames: 7 greater

The 16% full-load slow down is similar to the performance hit we accepted on the "Tokyo All Local Glyphs" perf benchmark on the native side.

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes
  • tagged @mapbox/gl-native if this PR includes shader changes or needs a native port
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog:
<changelog>
- Add `localFontFamily` map option that enables local generation of all font glyphs
- Introduce high resolution local glyph generation for improved rendering quality of glyphs generated using `localIdeographFontFamily` or `localFontFamily` options
</changelog>

cc @mourner @zmiao @asheemmamoowala @alexshalamov @YoshiYazawa @tsuz @ansis

@ChrisLoer ChrisLoer requested review from mourner, ansis and zmiao January 18, 2021 02:21
@ChrisLoer ChrisLoer added feature 🍏 GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform labels Jan 18, 2021
@mourner mourner self-assigned this Jan 18, 2021
Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

This looks great! Added a few nits. Perhaps also worth adding some code comments around heuristics like baselineAdjustment.

src/render/glyph_atlas.js Show resolved Hide resolved
src/render/glyph_manager.js Show resolved Hide resolved
src/render/glyph_manager.js Outdated Show resolved Hide resolved
src/render/glyph_manager.js Outdated Show resolved Hide resolved
Don't double-generate for glyphs with different fontstack but same local font.
Align baselines for glyphs generated with different local fonts.
Update tests.
@ChrisLoer
Copy link
Contributor Author

Some belated testing with Arabic text turned up what look like some alignment issues:

Server side glyphs
Screen Shot 2021-01-25 at 17 25 18

Locally generated glyphs
Screen Shot 2021-01-25 at 17 25 23

The locally generated text is legible, but there are some improperly overlapping glyphs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🍏 GL native → GL JS For feature parity with Mapbox Maps SDK on a native platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants