Extremely slow nSyncAndDrawFrame when drawing large bitmaps

I want to optimize parallax scrolling with several large bitmaps. On my Nexus 5, everything looks smooth, and the Traceview dump looks like this:

Smooth scrolling on the Nexus 5

The doFrame () method uses ~ 18 ms to complete.

However, when using my Nexus 7 or Android 6 emulator (Genymotion), the Traceview dump looks like this:

Very slow rendering on Nexus 7

The nSyncAndDrawFrame method now takes ~ 300 ms when starting the same application.

The interesting part of the code is in the onDraw () of the parallax view:

for (int i = 0; i < parallaxConfigManager.getNumberOfLayers(); i++) { Bitmap layer = parallaxConfigManager.getLayer(i); float dx = (offset * parallaxConfigManager.getScrollSpeedFactorForLayer(i) * imageScaleFactor); int offset = Math.round(-parallaxConfigManager.getBoardOffset(i) + dx); srcRect.offsetTo(offset, 0); int realWidth = getRealWidth(srcRect, layer.getWidth()); float scaleFactor = destRect.width() / (float) srcRect.width(); if (realWidth < srcRect.width()) { destRect.left = (int) (scaleFactor * Math.max(0, -srcRect.left)); destRect.right = destRect.left + (int) (scaleFactor * realWidth); } destRect.bottom = Math.min(screenHeight, (int) (scaleFactor * layer.getHeight())); canvas.drawBitmap(layer, srcRect, destRect, paint); destRect.left = 0; destRect.right = screenWidth; } 

However, this code is fast enough. The slower part is in android nSyncAndDrawFrame () androids.

What could be the problem? Is there a way to get deeper into this problem? Right now this method is a black box because I do not see my own call stack.

+7
android bitmap parallax
source share
1 answer

I stumbled upon this question, having encountered similar behavior with a large image (1920x933) in CollapsingToolbarLayout . The profiler showed that calls to android.view.ThreadedRenderer.nSyncAndDrawFrame() are time consuming.

Although reducing the resolution of the image (for example, to 1280x622) will fix the problem, there is a way to avoid the problem altogether.

Move the image to the drawable-nodpi , which means that the image is resolution independent. The rendering indent should disappear.

0
source share

All Articles