Skip to content

Commit e6bbc30

Browse files
committed
Revert "Merge pull request #18 from Sufaev/fix/invalid-resource-cache-capacity"
This reverts commit ff92b7d, reversing changes made to 6836432. # Conflicts: # worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java # worldwind/src/main/java/gov/nasa/worldwind/render/RenderResourceCache.java
1 parent cce45bf commit e6bbc30

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

worldwind/src/main/java/gov/nasa/worldwind/WorldWindow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ protected void init(EGLConfigChooser configChooser) {
183183
this.camera.position.set(initLocation.latitude, initLocation.longitude, initAltitude);
184184

185185
// Initialize the WorldWindow's render resource cache.
186-
int cacheCapacity = RenderResourceCache.recommendedCapacity();
187-
this.renderResourceCache = new RenderResourceCache(getContext(), cacheCapacity);
186+
int cacheCapacity = RenderResourceCache.recommendedCapacity(this.getContext());
187+
this.renderResourceCache = new RenderResourceCache(this.getContext(), cacheCapacity);
188188

189189
// Set up to render on demand to an OpenGL ES 2.x context
190190
// TODO Investigate and use the EGL chooser submitted by jgiovino

worldwind/src/main/java/gov/nasa/worldwind/render/RenderResourceCache.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package gov.nasa.worldwind.render;
77

8+
import android.app.ActivityManager;
89
import android.content.Context;
910
import android.graphics.Bitmap;
1011
import android.opengl.GLES20;
@@ -65,8 +66,27 @@ protected void init(Context context) {
6566
this.getCapacity() / 1024.0, this.imageRetrieverCache.getCapacity() / 1024.0));
6667
}
6768

68-
public static int recommendedCapacity() {
69-
return (int) (Runtime.getRuntime().maxMemory() * 0.75); // Use maximum 75% of available application heap
69+
public static int recommendedCapacity(Context context) {
70+
ActivityManager am = (context != null) ? (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE) : null;
71+
if (am != null) {
72+
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
73+
am.getMemoryInfo(mi);
74+
if (mi.totalMem >= 1024 * 1024 * 4096L) { // use 768 MB on machines with 4048 MB or more
75+
return 1024 * 1024 * 768;
76+
} else if (mi.totalMem >= 1024 * 1024 * 2048L) { // use 384 MB on machines with 2048 MB or more
77+
return 1024 * 1024 * 384;
78+
} else if (mi.totalMem >= 1024 * 1024 * 1536) { // use 256 MB on machines with 1536 MB or more
79+
return 1024 * 1024 * 256;
80+
} else if (mi.totalMem >= 1024 * 1024 * 1024) { // use 192 MB on machines with 1024 MB or more
81+
return 1024 * 1024 * 192;
82+
} else if (mi.totalMem >= 1024 * 1024 * 512) { // use 96 MB on machines with 512 MB or more
83+
return 1024 * 1024 * 96;
84+
} else { // use 64 MB on machines with less than 512 MB
85+
return 1024 * 1024 * 64;
86+
}
87+
} else { // use 64 MB by default
88+
return 1024 * 1024 * 64;
89+
}
7090
}
7191

7292
public void clear() { // TODO rename as contextLost to clarify this method's purpose for RenderResourceCache

0 commit comments

Comments
 (0)