Reduce image stutter by using subsampling more often. #7516
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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: