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

Reduce image stutter by using subsampling more often. #7516

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

greyson-signal
Copy link
Contributor

Fixes #7208.

On some phones, zooming in on large images (say, a 4k image) would be slow and stutter a lot. This is due to ZoomingImageView using a regular PhotoView instead of a SubsamplingScaleImageView. ZoomingImageView decides whether or not to use a SubsamplingScaleImageView depending on whether the image has a dimension larger than BitmapUtil.getMaxTextureSize().

However, while that method will determine the maximum size of an image that is possible to render, it doesn't necessarily mean it can be rendered efficiently. There is some size at which some phones will have to continually re-upload a bitmap to the GPU, as seen in this systrace taken from a Moto E.

moto-e-zoom-stutter

We could just use SubsamplingScaleImageView all the time (it has built-in logic to prevent tiling on smaller images), but given that it doesn't use Glide to load Bitmaps, we shouldn't be over-using it. As a result, I altered BitmapUtil.getMaxTextureSize() to have a cap of 2048, which from research and experimentation seems to be a good number (OpenGL operates in powers of 2 -- if 4096 is too big, 2048 is the next best bet).

Tested on the following devices. No scroll jank on images >= 2048x2048. No scroll jank on images < 2048x2048.

Example test image to induce jank:
signal-2018-03-13-104700

@greyson-signal greyson-signal merged commit 45520b7 into master Mar 13, 2018
@greyson-signal greyson-signal deleted the greyson/image-stutter branch March 13, 2018 18:30
@2-4601
Copy link
Contributor

2-4601 commented Mar 18, 2018

Tested f544b7d, can confirm it works on my device. Great fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants