Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Harden AndroidRendererFrontend::reduceMemoryUse #14622

Merged
merged 2 commits into from
May 10, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public boolean onGenericMotionEvent(@NonNull MotionEvent event) {
*/
@UiThread
public void onLowMemory() {
if (nativeMapView != null && !destroyed) {
if (nativeMapView != null && mapboxMap != null && !destroyed ) {
nativeMapView.onLowMemory();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, doub

@Override
public void onLowMemory() {
if (checkState("onLowMemory")) {
if (checkState("onLowMemory") || !mapRenderer.hasSurface()) {
return;
}
nativeOnLowMemory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.storage.FileSource;

import java.util.concurrent.atomic.AtomicBoolean;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

Expand All @@ -32,7 +34,7 @@ public abstract class MapRenderer implements MapRendererScheduler {
private long nativePtr = 0;
private double expectedRenderTime = 0;
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
protected boolean hasSurface;
protected AtomicBoolean hasSurface = new AtomicBoolean();

public MapRenderer(@NonNull Context context, String localIdeographFontFamily) {
float pixelRatio = context.getResources().getDisplayMetrics().density;
Expand Down Expand Up @@ -165,6 +167,6 @@ public void setMaximumFps(int maximumFps) {
* @return returns if renderer has a surface, false otherwise
*/
public boolean hasSurface() {
return hasSurface;
return hasSurface.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.opengl.GLSurfaceView;
import android.support.annotation.NonNull;
import android.view.SurfaceHolder;

import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.egl.EGLConfigChooser;

Expand Down Expand Up @@ -38,13 +39,13 @@ public GLSurfaceViewMapRenderer(Context context,
@Override
public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
hasSurface = true;
hasSurface.set(true);
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
super.surfaceDestroyed(holder);
hasSurface = false;
hasSurface.set(false);
nativeReset();
}
});
Expand Down Expand Up @@ -102,7 +103,7 @@ public void onDrawFrame(GL10 gl) {
*/
@Override
public void requestRender() {
if (!hasSurface) {
if (!hasSurface.get()) {
return;
}
glSurfaceView.requestRender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TextureViewMapRenderer(@NonNull Context context,
@Override
protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
hasSurface = true;
hasSurface.set(true);
}

/**
Expand All @@ -59,7 +59,7 @@ protected void onSurfaceChanged(GL10 gl, int width, int height) {
*/
@Override
protected void onSurfaceDestroyed() {
hasSurface = false;
hasSurface.set(false);
super.onSurfaceDestroyed();
}

Expand Down