Implement buffer image to increase FPS

This commit is contained in:
vshcherb 2013-10-16 20:37:03 +02:00
parent 0bae5ded80
commit 82a751545c
2 changed files with 18 additions and 11 deletions

View file

@ -61,6 +61,7 @@ import android.content.res.AssetManager;
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.HandlerThread;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import net.osmand.map.OsmandRegions;
@ -126,6 +127,7 @@ public class ResourceManager {
protected final MapTileDownloader tileDownloader;
public final AsyncLoadingThread asyncLoadingThread = new AsyncLoadingThread(this);
private HandlerThread renderingBufferImageThread;
protected boolean internetIsNotAccessible = false;
@ -133,6 +135,8 @@ public class ResourceManager {
this.context = context;
this.renderer = new MapRenderRepositories(context);
asyncLoadingThread.start();
renderingBufferImageThread = new HandlerThread("RenderingBaseImage");
renderingBufferImageThread.start();
tileDownloader = MapTileDownloader.getInstance(Version.getFullVersion(context));
@ -151,6 +155,10 @@ public class ResourceManager {
public MapTileDownloader getMapTileDownloader() {
return tileDownloader;
}
public HandlerThread getRenderingBufferImageThread() {
return renderingBufferImageThread;
}
public void resetStoreDirectory() {

View file

@ -36,7 +36,6 @@ import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
@ -199,9 +198,8 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
handler = new Handler();
HandlerThread ht = new HandlerThread("RenderingBaseImage");
ht.start();
baseHandler = new Handler(ht.getLooper());
baseHandler = new Handler(application.getResourceManager().getRenderingBufferImageThread().getLooper());
getHolder().addCallback(this);
animatedDraggingThread = new AnimateDraggingMapThread(this);
gestureDetector = new GestureDetector(getContext(), new MapExplorer(this, new MapTileViewOnGestureListener()));
@ -411,7 +409,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if(tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0){
return;
}
baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
if(bufferBitmapTmp == null || tileBox.getPixHeight() != bufferBitmapTmp.getHeight()
|| tileBox.getPixWidth() != bufferBitmapTmp.getWidth()) {
bufferBitmapTmp = Bitmap.createBitmap(tileBox.getPixWidth(), tileBox.getPixHeight(), Config.RGB_565);
@ -452,7 +449,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
Canvas canvas = holder.lockCanvas();
if (canvas != null) {
try {
final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.8f : 0.5f;
final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.8f : 0.5f;
final int cy = (int) (ratioy * getHeight());
if(currentViewport.getPixWidth() != getWidth() || currentViewport.getPixHeight() != getHeight() ||
currentViewport.getCenterPixelY() != cy) {
@ -534,7 +531,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private void refreshBufferImage(final DrawSettings drawSettings) {
if (!baseHandler.hasMessages(BASE_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) {
Message msg = Message.obtain(handler, new Runnable() {
Message msg = Message.obtain(baseHandler, new Runnable() {
@Override
public void run() {
baseHandler.removeMessages(BASE_REFRESH_MESSAGE);
@ -555,10 +552,12 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// this method could be called in non UI thread
public void refreshMap(final boolean updateVectorRendering) {
boolean nightMode = application.getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering);
sendRefreshMapMsg(drawSettings, 20);
refreshBufferImage(drawSettings);
if (isShown()) {
boolean nightMode = application.getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering);
sendRefreshMapMsg(drawSettings, 20);
refreshBufferImage(drawSettings);
}
}
private void sendRefreshMapMsg(final DrawSettings drawSettings, int delay) {