Add double buffer for images

This commit is contained in:
Victor Shcherb 2012-08-13 00:04:16 +02:00
parent fb3bd38400
commit 0a4e0ae3b8
10 changed files with 65 additions and 71 deletions

View file

@ -89,11 +89,6 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.rim.ajde.internal.verifier</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
@ -102,7 +97,6 @@
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>net.rim.ajde.BlackBerryAndroidNature</nature>
</natures>
<linkedResources>
<link>

View file

@ -10,7 +10,7 @@ public class RotatedTileBox {
private float tileWidth;
private float tileHeight;
private float rotate;
private int zoom;
private float zoom;
private float rotateCos;
private float rotateSin;
@ -28,7 +28,7 @@ public class RotatedTileBox {
rotateSin = FloatMath.sin(rad);
}
public void set(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) {
public void set(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, float zoom) {
this.leftTileX = leftTileX;
if(rotate < 0){
rotate += 360;
@ -51,9 +51,13 @@ public class RotatedTileBox {
return rotateSin;
}
public int getZoom() {
public float getZoom() {
return zoom;
}
public int getIntZoom() {
return Math.round(zoom);
}
public float getRotate() {
return rotate;
@ -77,7 +81,7 @@ public class RotatedTileBox {
public boolean containsTileBox(RotatedTileBox box) {
PointF temp = new PointF();
if(box.getZoom() != zoom){
if(box.zoom != zoom){
throw new UnsupportedOperationException();
}
box.calcPointTile(0, 0, temp);
@ -105,7 +109,7 @@ public class RotatedTileBox {
float tx3 = calcPointTileX(0, tileHeight);
float minTileX = Math.min(Math.min(leftTileX, tx), Math.min(tx2, tx3)) ;
float maxTileX = Math.max(Math.max(leftTileX, tx), Math.max(tx2, tx3)) ;
int max = 1 << zoom;
int max = (int) MapUtils.getPowZoom(zoom);
if(minTileX < 0){
minTileX = 0;
}

View file

@ -458,6 +458,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
}
public void changeZoom(float newZoom){
newZoom = Math.round(newZoom * OsmandMapTileView.ZOOM_DELTA) * OsmandMapTileView.ZOOM_DELTA_1;
boolean changeLocation = settings.AUTO_ZOOM_MAP.get();
mapView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation);
if (getMyApplication().accessibilityEnabled())
@ -703,7 +704,9 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
Sensor s = sensorMgr.getDefaultSensor(Sensor.TYPE_ORIENTATION);
if (s != null) {
sensorMgr.registerListener(this, s, SensorManager.SENSOR_DELAY_UI);
if(!sensorMgr.registerListener(this, s, SensorManager.SENSOR_DELAY_NORMAL)) {
Log.e(LogUtil.TAG, "Sensor could not be enabled");
}
}
sensorRegistered = true;
}
@ -881,22 +884,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
}
public float defineZoomFromSpeed(float speed) {
// Hardy's old implementation: correct for roughly constant "look ahead" distance on different screens using screen size correction, see Issue 914
// less than 23: show zoom 17
// int screenSizeCorrection = (int)Math.round(Math.log(((float)getMapView().getHeight())/320.0f) / Math.log(2.0f));
// if(speed < 23f/3.6){
// return 17 + screenSizeCorrection;
// } else if(speed < 43f/3.6){
// return 16 + screenSizeCorrection;
// } else if(speed < 63f/3.6){
// return 15 + screenSizeCorrection;
// } else if(speed < 83f/3.6){
// return 14 + screenSizeCorrection;
// }
// return 13 + screenSizeCorrection;
// new implementation
// TODO Hardy: verify look ahead distance, there still seems bug in calculation
if (speed < 7f / 3.6) {
return 0;
}

View file

@ -528,10 +528,10 @@ public class MapRenderRepositories {
boolean loaded;
if(nativeLib != null) {
cObjects = new LinkedList<BinaryMapDataObject>();
loaded = loadVectorDataNative(dataBox, requestedBox.getZoom(), renderingReq, nativeLib);
loaded = loadVectorDataNative(dataBox, requestedBox.getIntZoom(), renderingReq, nativeLib);
} else {
cNativeObjects = null;
loaded = loadVectorData(dataBox, requestedBox.getZoom(), renderingReq);
loaded = loadVectorData(dataBox, requestedBox.getIntZoom(), renderingReq);
}
if (!loaded || checkWhetherInterrupted()) {
@ -542,19 +542,19 @@ public class MapRenderRepositories {
currentRenderingContext = new OsmandRenderer.RenderingContext(context);
renderingReq.clearState();
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getIntZoom());
if(renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) {
currentRenderingContext.defaultColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_COLOR_VALUE);
}
renderingReq.clearState();
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getZoom());
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, requestedBox.getIntZoom());
if(renderingReq.searchRenderingAttribute(RenderingRuleStorageProperties.A_SHADOW_RENDERING)) {
currentRenderingContext.shadowRenderingMode = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE);
currentRenderingContext.shadowRenderingColor = renderingReq.getIntPropertyValue(renderingReq.ALL.R_SHADOW_COLOR);
}
currentRenderingContext.leftX = (float) requestedBox.getLeftTileX();
currentRenderingContext.topY = (float) requestedBox.getTopTileY();
currentRenderingContext.zoom = requestedBox.getZoom();
currentRenderingContext.leftX = requestedBox.getLeftTileX();
currentRenderingContext.topY = requestedBox.getTopTileY() ;
currentRenderingContext.zoom = requestedBox.getIntZoom();
currentRenderingContext.rotate = requestedBox.getRotate();
currentRenderingContext.width = (int) (requestedBox.getTileWidth() * OsmandRenderer.TILE_SIZE);
currentRenderingContext.height = (int) (requestedBox.getTileHeight() * OsmandRenderer.TILE_SIZE);
@ -562,6 +562,8 @@ public class MapRenderRepositories {
currentRenderingContext.useEnglishNames = prefs.USE_ENGLISH_NAMES.get();
currentRenderingContext.setDensityValue(prefs.USE_HIGH_RES_MAPS.get(),
prefs.MAP_TEXT_SIZE.get(), renderer.getDensity());
// init rendering context
currentRenderingContext.tileDivisor = (float) MapUtils.getPowZoom(31 - requestedBox.getZoom());
if (checkWhetherInterrupted()) {
return;
}
@ -573,19 +575,25 @@ public class MapRenderRepositories {
if (rr != null) {
transparent = renderingReq.getIntPropertyValue(rr) > 0;
}
// if(transparent) {
// bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, Config.ARGB_8888);
// } else {
bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, Config.RGB_565);
// }
// 1. generate image step by step
Bitmap reuse = prevBmp;
this.prevBmp = this.bmp;
this.prevBmpLocation = this.bmpLocation;
if (reuse != null && reuse.getWidth() == currentRenderingContext.width && reuse.getHeight() == currentRenderingContext.height) {
bmp = reuse;
bmp.eraseColor(currentRenderingContext.defaultColor);
} else {
if(reuse != null){
log.error(String.format("Create new image ? %d != %d (w) %d != %d (h) ", currentRenderingContext.width, reuse.getWidth(), currentRenderingContext.height, reuse.getHeight()));
}
bmp = Bitmap.createBitmap(currentRenderingContext.width, currentRenderingContext.height, Config.RGB_565);
}
this.bmp = bmp;
this.bmpLocation = tileRect;
if(nativeLib != null) {
renderer.generateNewBitmapNative(currentRenderingContext, nativeLib, cNativeObjects, bmp, renderingReq, notifyList);
} else {
@ -601,8 +609,11 @@ public class MapRenderRepositories {
// revert if it was interrupted
// (be smart a bit do not revert if road already drawn)
if(currentRenderingContext.lastRenderedKey < 35) {
reuse = this.bmp;
this.bmp = this.prevBmp;
this.bmpLocation = this.prevBmpLocation;
this.prevBmp = reuse;
this.prevBmpLocation = null;
}
currentRenderingContext = null;
return;
@ -610,7 +621,8 @@ public class MapRenderRepositories {
currentRenderingContext = null;
// 2. replace whole image
this.prevBmp = null;
// keep cache
// this.prevBmp = null;
this.prevBmpLocation = null;
if (prefs.DEBUG_RENDERING_INFO.get()) {
String timeInfo = "Searching: " + searchTime + " ms"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
@ -660,15 +672,16 @@ public class MapRenderRepositories {
}
public Bitmap getPrevBitmap() {
return prevBmp;
return prevBmpLocation == null ? null : prevBmp ;
}
public synchronized void clearCache() {
cObjects = new ArrayList<BinaryMapDataObject>();
cObjectsBox = new RectF();
prevBmp = null;
requestedBox = prevBmpLocation = null;
// Do not clear main bitmap to not cause a screen refresh
// prevBmp = null;
// bmp = null;
// bmpLocation = null;
}

View file

@ -49,13 +49,11 @@ public class MapVectorLayer extends BaseMapLayer {
}
private void updateRotatedTileBox(){
// float ts = view.getTileSize();
int zm = Math.round(view.getFloatZoom());
float xL = view.calcDiffTileX(pixRect.left - view.getCenterPointX(), pixRect.top - view.getCenterPointY()) + view.getXTile();
float yT = view.calcDiffTileY(pixRect.left - view.getCenterPointX(), pixRect.top - view.getCenterPointY()) + view.getYTile();
float mult = (float) Math.pow(2, zm - view.getZoom());
float ts = (float) (view.getSourceTileSize() * Math.pow(2, view.getFloatZoom() - (int) zm));
rotatedTileBox.set(xL * mult, yT * mult, ((float) pixRect.width()) / ts , ((float) pixRect.height()) / ts, view.getRotate(), zm);
float mult = (float) Math.pow(2, view.getFloatZoom() - view.getZoom());
float xL = (view.calcDiffTileX(pixRect.left - view.getCenterPointX(), pixRect.top - view.getCenterPointY()) + view.getXTile());
float yT = (view.calcDiffTileY(pixRect.left - view.getCenterPointX(), pixRect.top - view.getCenterPointY()) + view.getYTile()) ;
float ts = view.getSourceTileSize();
rotatedTileBox.set(xL * mult, yT * mult, ((float) pixRect.width()) / ts , ((float) pixRect.height()) / ts, view.getRotate(), view.getFloatZoom());
}
public boolean isVectorDataVisible() {
@ -118,21 +116,23 @@ public class MapVectorLayer extends BaseMapLayer {
if (bmp != null && bmpLoc != null) {
float rot = bmpLoc.getRotate();
float mult = (float) MapUtils.getPowZoom(view.getZoom() - bmpLoc.getZoom());
float fmult = (float) MapUtils.getPowZoom(view.getFloatZoom() - bmpLoc.getZoom());
float tx = view.getXTile();
float ty = view.getYTile();
float dleftX1 = (bmpLoc.getLeftTileX() * mult - tx) ;
float dtopY1 = (bmpLoc.getTopTileY() * mult - ty);
float tx = view.getXTile() / mult;
float ty = view.getYTile() / mult;
float dleftX1 = bmpLoc.getLeftTileX() - tx;
float dtopY1 = bmpLoc.getTopTileY() - ty;
float ts = view.getSourceTileSize() * fmult;
float cos = bmpLoc.getRotateCos();
float sin = bmpLoc.getRotateSin();
float x1 = MapUtils.calcDiffPixelX(sin, cos, dleftX1, dtopY1, view.getTileSize()) + view.getCenterPointX();
float y1 = MapUtils.calcDiffPixelY(sin, cos, dleftX1, dtopY1, view.getTileSize()) + view.getCenterPointY();
float x1 = MapUtils.calcDiffPixelX(sin, cos, dleftX1, dtopY1, ts) + view.getCenterPointX();
float y1 = MapUtils.calcDiffPixelY(sin, cos, dleftX1, dtopY1, ts) + view.getCenterPointY();
canvas.rotate(-rot, view.getCenterPointX(), view.getCenterPointY());
destImage.set(x1, y1, x1 + bmpLoc.getTileWidth() * mult * view.getTileSize(), y1 + bmpLoc.getTileHeight() * mult
* view.getTileSize());
destImage.set(x1, y1, x1 + bmpLoc.getTileWidth() * ts, y1 +
bmpLoc.getTileHeight() * ts);
if(!bmp.isRecycled()){
canvas.drawBitmap(bmp, null, destImage, paintImg);
shown = true;

View file

@ -160,8 +160,6 @@ public class OsmandRenderer {
Bitmap bmp, RenderingRuleSearchRequest render, final List<IMapDownloaderCallback> notifyList) {
long now = System.currentTimeMillis();
if (rc.width > 0 && rc.height > 0 && searchResultHandler != null) {
// init rendering context
rc.tileDivisor = (int) (1 << (31 - rc.zoom));
rc.cosRotateTileSize = FloatMath.cos((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
try {
@ -201,8 +199,6 @@ public class OsmandRenderer {
cv.drawColor(rc.defaultColor);
}
if (objects != null && !objects.isEmpty() && rc.width > 0 && rc.height > 0) {
// init rendering context
rc.tileDivisor = (int) (1 << (31 - rc.zoom));
rc.cosRotateTileSize = FloatMath.cos((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;

View file

@ -488,7 +488,7 @@ public class RoutingHelper {
public String formatStreetName(String name, String ref) {
if(name != null && name.length() > 0){
if(ref != null && ref.length() > 0) {
name += "(" + ref +")";
name = ref + " " + name;
}
return name;
} else {

View file

@ -303,11 +303,11 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void onClick(View v) {
if (view.isZooming()) {
activity.changeZoom(view.getZoom() + 2 );
// activity.changeZoom(view.getFloatZoom() + 2 * OsmandMapTileView.ZOOM_DELTA_1 );
// activity.changeZoom(view.getZoom() + 2 );
activity.changeZoom(view.getFloatZoom() + 2 * OsmandMapTileView.ZOOM_DELTA_1 );
} else {
activity.changeZoom(view.getZoom() + 1 );
// activity.changeZoom(view.getFloatZoom() + 1 * OsmandMapTileView.ZOOM_DELTA_1 );
// activity.changeZoom(view.getZoom() + 1 );
activity.changeZoom(view.getFloatZoom() + 1 * OsmandMapTileView.ZOOM_DELTA_1 );
}
}
@ -316,8 +316,8 @@ public class MapControlsLayer extends OsmandMapLayer {
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.changeZoom(view.getZoom() - 1 );
// activity.changeZoom(view.getFloatZoom() - 1 * OsmandMapTileView.ZOOM_DELTA_1 );
// activity.changeZoom(view.getZoom() - 1 );
activity.changeZoom(view.getFloatZoom() - 1 * OsmandMapTileView.ZOOM_DELTA_1 );
}
});
}

View file

@ -617,7 +617,7 @@ public class MapInfoLayer extends OsmandMapLayer {
if (!text.equals(getText().toString())) {
TextPaint pp = new TextPaint(getPaint());
if (!text.equals("")) {
pp.setTextSize(25 * scaleCoefficient);
pp.setTextSize(20 * scaleCoefficient);
float ts = pp.measureText(text);
int wth = getWidth();
while (ts > wth && pp.getTextSize() > (14 * scaleCoefficient)) {

View file

@ -103,7 +103,7 @@ public class NextTurnInfoControl extends MapInfoControl {
canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
if (exitOut != null && !horisontalMini) {
if (exitOut != null && !horisontalMini && !makeUturnWhenPossible) {
drawShadowText(canvas, exitOut, width / 2 - 7 * scaleCoefficient,
height / 2 + textPaint.getTextSize() / 2 - 3 * scaleCoefficient, textPaint);
}