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
* 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.util.Log;
/**
* @author Hannes Janetzek
*/
public class TextureObject {
private final static String TAG = TextureObject.class.getName();
@ -178,6 +181,10 @@ public class TextureObject {
TEXTURE_WIDTH, TEXTURE_HEIGHT,
Bitmap.Config.ARGB_8888);
if (TextureRenderer.debug)
Log.d(TAG, "alloc bitmap: " +
android.os.Debug.getNativeHeapAllocatedSize() / (1024 * 1024));
return bitmap;
}
return mBitmaps.remove(size - 1);

View File

@ -57,7 +57,6 @@ import android.graphics.Paint.Cap;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.os.SystemClock;
import android.util.Log;
public class TextOverlayExp extends BasicOverlay {
private final static String TAG = TextOverlayExp.class.getName();
@ -146,6 +145,12 @@ public class TextOverlayExp extends BasicOverlay {
Label it;
}
class ActiveTile{
MapTile tile;
int activeLabels;
Label labels;
}
//private static void setOBB(TextItem ti){
// if (ti.bbox == null)
// 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) {
}
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() {
if (mTmpLayer == null)
@ -343,14 +328,13 @@ public class TextOverlayExp extends BasicOverlay {
mRelabelCnt++;
for (Label lp = mPrevLabels; lp != null; ) {
//l.active = mRelabelCnt;
// transform screen coordinates to tile coordinates
float s = FastMath.pow(lp.tile.zoomLevel - pos.zoomLevel);
float sscale = pos.scale / s;
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);
lp = (Label) lp.next;
continue;
@ -379,7 +363,7 @@ public class TextOverlayExp extends BasicOverlay {
lp.y1 = (lp.y - height);
if (!wayIsVisible(lp)){
Log.d(TAG, "- visible " + lp);
//Log.d(TAG, "- visible " + lp);
TextItem.release(lp.item);
lp = (Label) lp.next;
continue;
@ -418,8 +402,8 @@ public class TextOverlayExp extends BasicOverlay {
overlaps = checkOverlap(tl, lp);
if (overlaps == 0) {
if (s != 1)
Log.d(TAG, s + "add prev label " + lp);
//if (s != 1)
//Log.d(TAG, s + "add prev label " + lp);
Label tmp = lp;
lp = (Label) lp.next;
@ -635,9 +619,31 @@ public class TextOverlayExp extends BasicOverlay {
mNextLayer = tl;
mDebugLayer = dbg;
}
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
public synchronized void update(MapPosition curPos, boolean positionChanged,
boolean tilesChanged) {
@ -647,7 +653,6 @@ public class TextOverlayExp extends BasicOverlay {
mTmpLayer = (TextLayer) layers.textureLayers;
// clear textures and text items from previous layer
layers.textureLayers = null;
layers.clear();
if (mDebugLayer != null) {