This commit is contained in:
simon 2020-09-14 15:19:57 +03:00
parent b5a24dc23b
commit 419edcac29
4 changed files with 44 additions and 51 deletions

View file

@ -1,5 +1,6 @@
package net.osmand.plus.render; package net.osmand.plus.render;
import android.util.Log;
import net.osmand.core.android.MapRendererView; import net.osmand.core.android.MapRendererView;
import net.osmand.core.android.TileSourceProxyProvider; import net.osmand.core.android.TileSourceProxyProvider;
import net.osmand.core.jni.MapLayerConfiguration; import net.osmand.core.jni.MapLayerConfiguration;
@ -156,13 +157,19 @@ public class MapVectorLayer extends BaseMapLayer {
mapRenderer.setVisualZoomShift(zoomMagnifier - 1.0f); mapRenderer.setVisualZoomShift(zoomMagnifier - 1.0f);
} else { } else {
if (!view.isZooming()) { if (!view.isZooming()) {
if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings) && if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings) ||
!view.isScreenViewDetached()) { view.isScreenViewDetached()) {
// pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 *
// view.getHeight() / 2); // view.getHeight() / 2);
final RotatedTileBox copy = tilesRect.copy(); final RotatedTileBox copy = tilesRect.copy();
copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4); Log.d("SERVER: ","SERVER: interrupt in layer");
resourceManager.updateRendererMap(copy, null); if (view.isScreenViewDetached()){
resourceManager.getRenderer().loadMap(copy, resourceManager.getMapTileDownloader());
}
else {
copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4);
resourceManager.updateRendererMap(copy, null);
}
} }
} }
@ -175,7 +182,7 @@ public class MapVectorLayer extends BaseMapLayer {
private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) { private boolean drawRenderedMap(Canvas canvas, Bitmap bmp, RotatedTileBox bmpLoc, RotatedTileBox currentViewport) {
boolean shown = false; boolean shown = false;
if (bmp != null && bmpLoc != null) { if (bmp != null && bmpLoc != null) {
float rot = -bmpLoc.getRotate(); float rot = -bmpLoc.getRotate();
canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY()); canvas.rotate(rot, currentViewport.getCenterPixelX(), currentViewport.getCenterPixelY());
final RotatedTileBox calc = currentViewport.copy(); final RotatedTileBox calc = currentViewport.copy();

View file

@ -1040,7 +1040,7 @@ public class ResourceManager {
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings); return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
} }
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){ public synchronized void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){
renderer.interruptLoadingMap(); renderer.interruptLoadingMap();
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener)); asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
} }

View file

@ -1,16 +1,13 @@
package net.osmand.plus.server.endpoints; package net.osmand.plus.server.endpoints;
import android.graphics.*; import android.graphics.Bitmap;
import androidx.annotation.GuardedBy;
import fi.iki.elonen.NanoHTTPD; import fi.iki.elonen.NanoHTTPD;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.resources.AsyncLoadingThread;
import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.server.OsmAndHttpServer; import net.osmand.plus.server.OsmAndHttpServer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -36,7 +33,6 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
} }
@Override @Override
public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) { public NanoHTTPD.Response process(NanoHTTPD.IHTTPSession session, String url) {
// https://tile.osmand.net/hd/6/55/25.png // https://tile.osmand.net/hd/6/55/25.png
@ -56,7 +52,9 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
int y = Integer.parseInt(prms[3]); int y = Integer.parseInt(prms[3]);
MetaTileFileSystemCache.MetaTileCache res = cache.get(zoom, x, y); MetaTileFileSystemCache.MetaTileCache res = cache.get(zoom, x, y);
if (res == null) { if (res == null) {
lastRequestedZoom = zoom; synchronized (this) {
lastRequestedZoom = zoom;
}
res = requestMetatile(x, y, zoom); res = requestMetatile(x, y, zoom);
if (res == null) { if (res == null) {
return OsmAndHttpServer.ErrorResponses.response500; return OsmAndHttpServer.ErrorResponses.response500;
@ -93,42 +91,30 @@ public class TileEndpoint implements OsmAndHttpServer.ApiEndpoint {
mapActivity.getMapView().setCurrentViewport(res.bbox); mapActivity.getMapView().setCurrentViewport(res.bbox);
int timeout = 0; int timeout = 0;
try { try {
AsyncLoadingThread athread = resourceManager.getAsyncLoadingThread(); LOG.debug("SERVER: interrupt in request");
resourceManager.updateRendererMap(res.bbox, null); resourceManager.getRenderer().loadMap(res.bbox, resourceManager.getMapTileDownloader());
Thread.sleep(TIMEOUT_STEP); // to do line should be removed in future
OsmandMapLayer.DrawSettings drawSettings =
new OsmandMapLayer.DrawSettings(mapActivity.getMapView().getSettings().isLightContent(),
true);
mapActivity.getMapView().refreshMapInternal(drawSettings);
mapActivity.getMapView().refreshBaseMapInternal(res.bbox, drawSettings);
Thread.sleep(TIMEOUT_STEP); // to do line should be removed in future Thread.sleep(TIMEOUT_STEP); // to do line should be removed in future
// wait till all resources rendered and loaded
while (athread.areResourcesLoading() && timeout < TIMEOUT) {
if(lastRequestedZoom != zoom) {
return null;
}
Thread.sleep(TIMEOUT_STEP);
timeout += TIMEOUT_STEP;
}
mapActivity.getMapView().refreshMap();
// wait for image to be refreshed // wait for image to be refreshed
while(!resourceManager.getRenderingBufferImageThread().getLooper().getQueue().isIdle() && while (!resourceManager.getRenderingBufferImageThread().getLooper().getQueue().isIdle() &&
timeout < TIMEOUT) { timeout < TIMEOUT) {
Thread.sleep(TIMEOUT_STEP); Thread.sleep(TIMEOUT_STEP);
timeout += TIMEOUT_STEP; timeout += TIMEOUT_STEP;
} }
Bitmap rbmp = mapActivity.getMapView().getBufferBitmap(); Bitmap rbmp = mapActivity.getMapView().getBufferBitmap();
if (timeout >= TIMEOUT) {
return null;
// Canvas canvas = new Canvas(tempBmp);
// Paint paint = new Paint();
// paint.setColor(Color.RED);
// paint.setTextSize(12);
// paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
// canvas.drawText("TIMEOUT", tempBmp.getWidth() / 2, tempBmp.getHeight() / 2, paint);
// here we could return stub
}
res.bmp = rbmp.copy(rbmp.getConfig(), true); res.bmp = rbmp.copy(rbmp.getConfig(), true);
this.cache.put(res); this.cache.put(res);
LOG.debug("Render metatile: " + (System.currentTimeMillis() - tm)/1000.0f); LOG.debug("SERVER: metatile: " + (System.currentTimeMillis() - tm) / 1000.0f);
return res; return res;
} catch (InterruptedException e) { } catch (Exception e) {
LOG.error(e); LOG.error(e);
} }
LOG.debug("SERVER: metatile1: " + (System.currentTimeMillis() - tm) / 1000.0f);
return null; return null;
} }
} }

View file

@ -588,7 +588,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} }
} }
private void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) { public void refreshBaseMapInternal(RotatedTileBox tileBox, DrawSettings drawSettings) {
if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) { if (tileBox.getPixHeight() == 0 || tileBox.getPixWidth() == 0) {
return; return;
} }
@ -625,7 +625,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
additional.calculateFPS(start, end); additional.calculateFPS(start, end);
} }
private void refreshMapInternal(DrawSettings drawSettings) { public void refreshMapInternal(DrawSettings drawSettings) {
if (view == null) { if (view == null) {
return; return;
} }
@ -788,7 +788,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
canvas.drawCircle(x, y, 7 * dm.density, paintCenter); canvas.drawCircle(x, y, 7 * dm.density, paintCenter);
} }
private void refreshBufferImage(final DrawSettings drawSettings) { public void refreshBufferImage(final DrawSettings drawSettings) {
if (mapRenderer != null) { if (mapRenderer != null) {
return; return;
} }
@ -831,16 +831,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// this method could be called in non UI thread // this method could be called in non UI thread
public void refreshMap(final boolean updateVectorRendering) { public void refreshMap(final boolean updateVectorRendering) {
if ((view != null && view.isShown()) || isScreenViewDetached) { if ((view != null && view.isShown()) || isScreenViewDetached) {
boolean nightMode = application.getDaynightHelper().isNightMode(); // boolean nightMode = application.getDaynightHelper().isNightMode();
Boolean currentNightMode = this.nightMode; // Boolean currentNightMode = this.nightMode;
boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode; // boolean forceUpdateVectorDrawing = currentNightMode != null && currentNightMode != nightMode;
if (forceUpdateVectorDrawing) { // if (forceUpdateVectorDrawing) {
resetDefaultColor(); // resetDefaultColor();
} // }
this.nightMode = nightMode; // this.nightMode = nightMode;
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering || forceUpdateVectorDrawing); // DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering || forceUpdateVectorDrawing);
sendRefreshMapMsg(drawSettings, 20); // sendRefreshMapMsg(drawSettings, 20);
refreshBufferImage(drawSettings); // refreshBufferImage(drawSettings);
} }
} }
@ -880,7 +880,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
public void setCurrentViewport(RotatedTileBox viewport) { public void setCurrentViewport(RotatedTileBox viewport) {
currentViewport = viewport; currentViewport = viewport;
refreshMap(true); //refreshMap(true);
} }
public Bitmap getBufferBitmap() { public Bitmap getBufferBitmap() {