fix: release textures

This commit is contained in:
Hannes Janetzek 2013-02-20 00:43:41 +01:00
parent 34bffcc15f
commit 1af037d783
2 changed files with 41 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012 Hannes Janetzek * Copyright 2012, 2013 Hannes Janetzek
* *
* This program is free software: you can redistribute it and/or modify it under the * This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software * terms of the GNU Lesser General Public License as published by the Free Software
@ -22,6 +22,9 @@ import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import android.util.Log; import android.util.Log;
/**
* @author Hannes Janetzek
*/
public class TextureObject { public class TextureObject {
private final static String TAG = TextureObject.class.getName(); private final static String TAG = TextureObject.class.getName();
@ -178,6 +181,10 @@ public class TextureObject {
TEXTURE_WIDTH, TEXTURE_HEIGHT, TEXTURE_WIDTH, TEXTURE_HEIGHT,
Bitmap.Config.ARGB_8888); Bitmap.Config.ARGB_8888);
if (TextureRenderer.debug)
Log.d(TAG, "alloc bitmap: " +
android.os.Debug.getNativeHeapAllocatedSize() / (1024 * 1024));
return bitmap; return bitmap;
} }
return mBitmaps.remove(size - 1); return mBitmaps.remove(size - 1);

View File

@ -57,7 +57,6 @@ import android.graphics.Paint.Cap;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.Matrix; import android.opengl.Matrix;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
public class TextOverlayExp extends BasicOverlay { public class TextOverlayExp extends BasicOverlay {
private final static String TAG = TextOverlayExp.class.getName(); private final static String TAG = TextOverlayExp.class.getName();
@ -146,6 +145,12 @@ public class TextOverlayExp extends BasicOverlay {
Label it; Label it;
} }
class ActiveTile{
MapTile tile;
int activeLabels;
Label labels;
}
//private static void setOBB(TextItem ti){ //private static void setOBB(TextItem ti){
// if (ti.bbox == null) // if (ti.bbox == null)
// ti.bbox = new OBB2D(ti.x, ti.y, ti.x1, ti.y1, ti.width + 10, // ti.bbox = new OBB2D(ti.x, ti.y, ti.x1, ti.y1, ti.width + 10,
@ -269,27 +274,7 @@ public class TextOverlayExp extends BasicOverlay {
void addTile(MapTile t) { void addTile(MapTile t) {
} }
private static void addDebugLayers(Layers dbg){
dbg.clear();
LineLayer ll = (LineLayer) dbg.getLayer(0, Layer.LINE);
ll.line = new Line((Color.BLUE & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(3, Layer.LINE);
ll.line = new Line((Color.YELLOW & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(1, Layer.LINE);
ll.line = new Line((Color.RED & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(2, Layer.LINE);
ll.line = new Line((Color.GREEN & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(4, Layer.LINE);
ll.line = new Line((Color.CYAN & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(5, Layer.LINE);
ll.line = new Line((Color.MAGENTA & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
}
boolean updateLabels() { boolean updateLabels() {
if (mTmpLayer == null) if (mTmpLayer == null)
@ -343,14 +328,13 @@ public class TextOverlayExp extends BasicOverlay {
mRelabelCnt++; mRelabelCnt++;
for (Label lp = mPrevLabels; lp != null; ) { for (Label lp = mPrevLabels; lp != null; ) {
//l.active = mRelabelCnt;
// transform screen coordinates to tile coordinates // transform screen coordinates to tile coordinates
float s = FastMath.pow(lp.tile.zoomLevel - pos.zoomLevel); float s = FastMath.pow(lp.tile.zoomLevel - pos.zoomLevel);
float sscale = pos.scale / s; float sscale = pos.scale / s;
if (lp.width > lp.length * sscale){ if (lp.width > lp.length * sscale){
Log.d(TAG, "- scale " + lp + " " + s + " " + sscale + " " + lp.length + " " + lp.width); //Log.d(TAG, "- scale " + lp + " " + s + " " + sscale + " " + lp.length + " " + lp.width);
TextItem.release(lp.item); TextItem.release(lp.item);
lp = (Label) lp.next; lp = (Label) lp.next;
continue; continue;
@ -379,7 +363,7 @@ public class TextOverlayExp extends BasicOverlay {
lp.y1 = (lp.y - height); lp.y1 = (lp.y - height);
if (!wayIsVisible(lp)){ if (!wayIsVisible(lp)){
Log.d(TAG, "- visible " + lp); //Log.d(TAG, "- visible " + lp);
TextItem.release(lp.item); TextItem.release(lp.item);
lp = (Label) lp.next; lp = (Label) lp.next;
continue; continue;
@ -418,8 +402,8 @@ public class TextOverlayExp extends BasicOverlay {
overlaps = checkOverlap(tl, lp); overlaps = checkOverlap(tl, lp);
if (overlaps == 0) { if (overlaps == 0) {
if (s != 1) //if (s != 1)
Log.d(TAG, s + "add prev label " + lp); //Log.d(TAG, s + "add prev label " + lp);
Label tmp = lp; Label tmp = lp;
lp = (Label) lp.next; lp = (Label) lp.next;
@ -635,9 +619,31 @@ public class TextOverlayExp extends BasicOverlay {
mNextLayer = tl; mNextLayer = tl;
mDebugLayer = dbg; mDebugLayer = dbg;
} }
return true; return true;
} }
private static void addDebugLayers(Layers dbg){
dbg.clear();
LineLayer ll = (LineLayer) dbg.getLayer(0, Layer.LINE);
ll.line = new Line((Color.BLUE & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(3, Layer.LINE);
ll.line = new Line((Color.YELLOW & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(1, Layer.LINE);
ll.line = new Line((Color.RED & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(2, Layer.LINE);
ll.line = new Line((Color.GREEN & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(4, Layer.LINE);
ll.line = new Line((Color.CYAN & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
ll = (LineLayer) dbg.getLayer(5, Layer.LINE);
ll.line = new Line((Color.MAGENTA & 0xaaffffff), 1, Cap.BUTT);
ll.width = 2;
}
@Override @Override
public synchronized void update(MapPosition curPos, boolean positionChanged, public synchronized void update(MapPosition curPos, boolean positionChanged,
boolean tilesChanged) { boolean tilesChanged) {
@ -647,7 +653,6 @@ public class TextOverlayExp extends BasicOverlay {
mTmpLayer = (TextLayer) layers.textureLayers; mTmpLayer = (TextLayer) layers.textureLayers;
// clear textures and text items from previous layer // clear textures and text items from previous layer
layers.textureLayers = null;
layers.clear(); layers.clear();
if (mDebugLayer != null) { if (mDebugLayer != null) {