Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Android Auto start-up #21410

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions OsmAnd/src/net/osmand/core/android/MapRendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,29 @@ public MapRendererContext(OsmandApplication app, float density) {
*
* @param mapRendererView Reference to MapRendererView
*/
public void setMapRendererView(@Nullable MapRendererView mapRendererView) {
boolean update = (this.mapRendererView != mapRendererView);
if (update && this.mapRendererView != null)
this.mapRendererView.stopRenderer();
this.mapRendererView = mapRendererView;
if (!update) {
public synchronized void setMapRendererView(@Nullable MapRendererView mapRendererView) {
if (this.mapRendererView == mapRendererView) {
return;
}
this.mapRendererView = mapRendererView;
if (mapRendererView != null) {
applyCurrentContextToView();
}
}

public synchronized void suspendMapRendererView(@Nullable MapRendererView mapRendererView) {
if (this.mapRendererView != null && (mapRendererView == null || this.mapRendererView == mapRendererView)) {
this.mapRendererView.handleOnPause();
}
}

public synchronized void releaseMapRendererView(@Nullable MapRendererView mapRendererView) {
if (this.mapRendererView != null && (mapRendererView == null || this.mapRendererView == mapRendererView)) {
this.mapRendererView.stopRenderer();
this.mapRendererView = null;
}
}

@Nullable
public MapRendererView getMapRendererView() {
return mapRendererView;
Expand Down Expand Up @@ -391,11 +401,9 @@ public void recreateHeightmapProvider() {
heightmapsActive = false;
}
}
public void resetHeightmapProvider() {
MapRendererView mapRendererView = this.mapRendererView;
if (mapRendererView != null) {
mapRendererView.resetElevationDataProvider();
}

public void presetMapRendererOptions(@NonNull MapRendererView mapRendererView) {
mapRendererView.setupOptions.setMaxNumberOfRasterMapLayersInBatch(1);
}

private void updateObfMapRasterLayerProvider(@NonNull MapPrimitivesProvider mapPrimitivesProvider,
Expand Down Expand Up @@ -433,8 +441,6 @@ private void applyCurrentContextToView() {
if (mapRendererView == null) {
return;
}
mapRendererView.setMapRendererSetupOptionsConfigurator(
mapRendererSetupOptions -> mapRendererSetupOptions.setMaxNumberOfRasterMapLayersInBatch(1));
if (mapRendererView instanceof AtlasMapRendererView) {
cachedReferenceTileSize = getReferenceTileSize();
((AtlasMapRendererView) mapRendererView).setReferenceTileSizeOnScreenInPixels(cachedReferenceTileSize);
Expand Down
4 changes: 4 additions & 0 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,10 @@ private void cancelSplashScreenTimer() {
}
}

public boolean isActivityStopped() {
return stopped;
}

public boolean isActivityDestroyed() {
return mIsDestroyed;
}
Expand Down
49 changes: 26 additions & 23 deletions OsmAnd/src/net/osmand/plus/auto/SurfaceRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.osmand.plus.auto;

import static net.osmand.plus.views.OsmandMapTileView.DEFAULT_ELEVATION_ANGLE;
import static net.osmand.plus.views.MapViewWithLayers.SYMBOLS_UPDATE_INTERVAL;

import android.graphics.Canvas;
import android.graphics.Color;
Expand Down Expand Up @@ -32,6 +33,7 @@
import net.osmand.plus.AppInitializer;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.auto.views.CarSurfaceView;
import net.osmand.plus.helpers.MapDisplayPositionManager;
import net.osmand.plus.plugins.PluginsHelper;
Expand Down Expand Up @@ -331,39 +333,41 @@ public void onFinish(@NonNull AppInitializer init) {
setupOffscreenRenderer();
}

public void setupOffscreenRenderer() {
public synchronized void setupOffscreenRenderer() {
Log.i(TAG, "setupOffscreenRenderer");
if (getApp().useOpenGlRenderer()) {
if (surface != null && surface.isValid()) {
if (offscreenMapRendererView != null) {
MapRendererContext mapRendererContext = NativeCoreContext.getMapRendererContext();
if (mapRendererContext != null) {
if (mapRendererContext.getMapRendererView() == offscreenMapRendererView)
return;
if (mapRendererContext != null && mapRendererContext.getMapRendererView() != offscreenMapRendererView) {
offscreenMapRendererView = null;
}
}
if (offscreenMapRendererView == null) {
MapRendererView mapRendererView = null;
MapRendererContext mapRendererContext = NativeCoreContext.getMapRendererContext();
if (mapRendererContext != null) {
if (mapView != null && mapView.getMapRenderer() != null)
mapView.setMapRenderer(null);
MapRendererView mapRendererView = null;
if (mapView != null && mapView.getMapRenderer() != null) {
mapView.detachMapRenderer();
}
if (mapRendererContext.getMapRendererView() != null) {
mapRendererView = mapRendererContext.getMapRendererView();
mapRendererContext.setMapRendererView(null);
mapRendererView = mapRendererContext.getMapRendererView();
mapRendererContext.setMapRendererView(null);
}
offscreenMapRendererView = new AtlasMapRendererView(carContext);
offscreenMapRendererView.setupRenderer(carContext, getWidth(), getHeight(), mapRendererView);
offscreenMapRendererView.setMinZoomLevel(ZoomLevel.swigToEnum(mapView.getMinZoom()));
offscreenMapRendererView.setMaxZoomLevel(ZoomLevel.swigToEnum(mapView.getMaxZoom()));
offscreenMapRendererView.setAzimuth(0);
mapView.setMinAllowedElevationAngle(MIN_ALLOWED_ELEVATION_ANGLE_AA);
float elevationAngle = mapView.normalizeElevationAngle(getApp().getSettings().getLastKnownMapElevation());
NativeCoreContext.setMapRendererContext(getApp(), surfaceView.getDensity());
mapRendererContext = NativeCoreContext.getMapRendererContext();
if (mapRendererContext != null) {
offscreenMapRendererView = new AtlasMapRendererView(carContext);
mapRendererContext.presetMapRendererOptions(offscreenMapRendererView);
offscreenMapRendererView.setupRenderer(carContext, getWidth(), getHeight(), mapRendererView);
offscreenMapRendererView.setMinZoomLevel(ZoomLevel.swigToEnum(mapView.getMinZoom()));
offscreenMapRendererView.setMaxZoomLevel(ZoomLevel.swigToEnum(mapView.getMaxZoom()));
offscreenMapRendererView.setAzimuth(0);
offscreenMapRendererView.setSymbolsUpdateInterval(SYMBOLS_UPDATE_INTERVAL);
offscreenMapRendererView.enableBatterySavingMode();
mapRendererContext.setMapRendererView(offscreenMapRendererView);
mapView.setMinAllowedElevationAngle(MIN_ALLOWED_ELEVATION_ANGLE_AA);
float elevationAngle = mapView.normalizeElevationAngle(getApp().getSettings().getLastKnownMapElevation());
mapView.setMapRenderer(offscreenMapRendererView);
mapView.setElevationAngle(elevationAngle);
mapView.addElevationListener(this);
Expand All @@ -372,28 +376,27 @@ public void setupOffscreenRenderer() {
offscreenMapRendererView.addListener(this);
mapView.getAnimatedDraggingThread().toggleAnimations();
}
offscreenMapRendererView.enableBatterySavingMode();
}
}
}
}
}

public void stopOffscreenRenderer() {
public synchronized void stopOffscreenRenderer() {
Log.i(TAG, "stopOffscreenRenderer");
if (offscreenMapRendererView != null) {
AtlasMapRendererView offscreenMapRendererView = this.offscreenMapRendererView;
this.offscreenMapRendererView = null;
if (mapView != null) {
mapView.removeElevationListener(this);
mapView.getAnimatedDraggingThread().toggleAnimations();
if (mapView.getMapRenderer() == offscreenMapRendererView) {
mapView.setMapRenderer(null);
mapView.detachMapRenderer();
}
}
MapRendererContext mapRendererContext = NativeCoreContext.getMapRendererContext();
if (mapRendererContext != null && mapRendererContext.getMapRendererView() == offscreenMapRendererView)
offscreenMapRendererView.stopRenderer();
if (mapRendererContext != null) {
mapRendererContext.suspendMapRendererView(offscreenMapRendererView);
}
offscreenMapRendererView = null;
}
}

Expand Down
7 changes: 4 additions & 3 deletions OsmAnd/src/net/osmand/plus/views/MapViewWithLayers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class MapViewWithLayers extends FrameLayout {

private static final int SYMBOLS_UPDATE_INTERVAL = 2000;
public static final int SYMBOLS_UPDATE_INTERVAL = 2000;

private final OsmandApplication app;
private final OsmandSettings settings;
Expand Down Expand Up @@ -96,8 +96,8 @@ public void setupRenderingView() {

private void resetMapRendererView() {
MapRendererContext mapRendererContext = NativeCoreContext.getMapRendererContext();
if (mapRendererContext != null && atlasMapRendererView != null && mapRendererContext.getMapRendererView() == atlasMapRendererView)
mapRendererContext.setMapRendererView(null);
if (mapRendererContext != null && atlasMapRendererView != null)
mapRendererContext.releaseMapRendererView(atlasMapRendererView);
}

private void setupAtlasMapRendererView() {
Expand All @@ -124,6 +124,7 @@ private void setupAtlasMapRendererView() {
} else {
atlasMapRendererView.handleOnCreate(null);
}
mapRendererContext.presetMapRendererOptions(atlasMapRendererView);
atlasMapRendererView.setupRenderer(getContext(), 0, 0, mapRendererView);
atlasMapRendererView.setMinZoomLevel(ZoomLevel.swigToEnum(mapView.getMinZoom()));
atlasMapRendererView.setMaxZoomLevel(ZoomLevel.swigToEnum(mapView.getMaxZoom()));
Expand Down
8 changes: 8 additions & 0 deletions OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,14 @@ public void setMapRenderer(@Nullable MapRendererView mapRenderer) {
}
}

public void detachMapRenderer() {
if (mapRenderer != null) {
mapRenderer.removeAllSymbolsProviders();
mapRenderer.resetElevationDataProvider();
mapRenderer = null;
}
}

@Nullable
public MapRendererView getMapRenderer() {
return mapRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.osmand.core.android.CoreResourcesFromAndroidAssets;
import net.osmand.core.android.MapRendererContext;
import net.osmand.core.android.MapRendererContext.ProviderType;
import net.osmand.core.android.MapRendererView;
import net.osmand.core.android.NativeCore;
import net.osmand.core.jni.Logger;
import net.osmand.core.jni.MapStylesCollection;
Expand Down Expand Up @@ -110,9 +111,9 @@ public static MapRendererContext getMapRendererContext() {

public static void setMapRendererContext(@NonNull OsmandApplication app, float density) {
if (mapRendererContext != null) {
if (mapRendererContext.getDensity() == density)
if (mapRendererContext.getDensity() == density) {
return;
mapRendererContext.setMapRendererView(null);
}
}
mapRendererContext = new MapRendererContext(app, density);
mapRendererContext.setupObfMap(new MapStylesCollection(), obfsCollectionsByProviderType);
Expand Down
Loading