Skip to content

Don't multiply SVG size by device pixel ratio #84

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

Merged
merged 1 commit into from
Oct 31, 2019

Conversation

adroitwhiz
Copy link
Contributor

@adroitwhiz adroitwhiz commented Apr 21, 2019

Proposed Changes

This changes SvgRenderer so that, when told to draw an SVG at a certain scale, it doesn't multiply the scale by the device pixel ratio.

Reason for Changes

The WebGLRenderer already handles all the device pixel ratio stuff [EDIT: here], and passes the SvgRenderer the proper scale for the device. By enlarging the SVGs here as well, the SvgRenderer makes them too high-resolution. If on a device with pixel ratio 2, for instance, rendered SVGs will be 4 times as large in each dimension instead of 2, and on a device with pixel ratio 3, they will be 9 times as large instead of 3.

This causes jaggies from downscaling, reduces graphics performance, and wastes VRAM.

@adroitwhiz
Copy link
Contributor Author

@cwillisf I ran a quick benchmark on this animation, and this change reduces RAM usage on pixel-ratio 2 devices (e.g. mobile devices) by around 40%:
image

@adroitwhiz
Copy link
Contributor Author

@thisandagain Any update on this? This would save a substantial amount of RAM on mobile devices (see above), especially once scratchfoundation/scratch-render#431 is merged.

@fsih fsih assigned fsih and unassigned cwillisf Oct 30, 2019
Copy link
Contributor

@fsih fsih 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, thanks!

It looks like with this change, calls to _draw caused by setSVG in scratch-render no longer take into account device pixel density. However, I think that those calls are unnecessary, since they are immediately overwritten by a call to _draw started by _step in vm. So I've opened scratchfoundation/scratch-render#518

@fsih fsih merged commit 3ce77f6 into scratchfoundation:develop Oct 31, 2019
fsih added a commit to scratchfoundation/scratch-paint that referenced this pull request Nov 1, 2019
….0-prerelease.20191031221353

Update scratch-svg-renderer to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84
fsih added a commit to scratchfoundation/scratch-render that referenced this pull request Nov 1, 2019
….0-prerelease.20191031221353

Update scratch-svg-renderer to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84
fsih added a commit to scratchfoundation/scratch-gui that referenced this pull request Nov 1, 2019
…2.0-prerelease.20191031221353

Update scratch-svg-renderer to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84
fsih added a commit to scratchfoundation/scratch-gui that referenced this pull request Nov 2, 2019
…release.20191101193358

Update scratch-paint to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84 via paint
fsih added a commit to scratchfoundation/scratch-gui that referenced this pull request Nov 2, 2019
…erelease.20191101193213

Update scratch-render to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84 via render
paulkaplan pushed a commit to paulkaplan/scratch-labs-test that referenced this pull request Sep 18, 2020
….0-prerelease.20191031221353

Update scratch-svg-renderer to the latest version 🚀
brings in scratchfoundation/scratch-svg-renderer#84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants