start BitmapTileLayer pool
This commit is contained in:
parent
879e0ccb81
commit
2e56e3facc
@ -25,12 +25,13 @@ import android.opengl.GLUtils;
|
||||
|
||||
public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
final Bitmap mBitmap;
|
||||
|
||||
public AndroidBitmap(InputStream inputStream) {
|
||||
mBitmap = BitmapFactory.decodeStream(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(){
|
||||
public boolean isValid() {
|
||||
return mBitmap != null;
|
||||
}
|
||||
|
||||
@ -86,6 +87,9 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
|
||||
|
||||
@Override
|
||||
public void recycle() {
|
||||
if (mBitmap == null)
|
||||
return;
|
||||
|
||||
mBitmap.recycle();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.layers.tile.VectorTileRenderer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.elements.TextureItem.TexturePool;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
@ -102,4 +103,40 @@ public class BitmapTileLayer extends TileLayer {
|
||||
protected TileLoader createLoader() {
|
||||
return new BitmapTileLoader(this, mTileSource);
|
||||
}
|
||||
|
||||
final static int TEXTURE_HEIGHT = 256;
|
||||
final static int TEXTURE_WIDTH = 256;
|
||||
final static int POOL_FILL = 40;
|
||||
|
||||
/** pool shared by TextLayers */
|
||||
final static TexturePool pool = new TexturePool(POOL_FILL,
|
||||
TEXTURE_WIDTH,
|
||||
TEXTURE_HEIGHT) {
|
||||
|
||||
// int sum = 0;
|
||||
//
|
||||
// public TextureItem release(TextureItem item) {
|
||||
// log.debug(getFill() + " " + sum + " release tex " + item.id);
|
||||
// return super.release(item);
|
||||
// };
|
||||
//
|
||||
// public synchronized TextureItem get() {
|
||||
// log.debug(getFill() + " " + sum + " get tex ");
|
||||
//
|
||||
// return super.get();
|
||||
// };
|
||||
//
|
||||
// protected TextureItem createItem() {
|
||||
// log.debug(getFill() + " " + (sum++) + " create tex ");
|
||||
//
|
||||
// return super.createItem();
|
||||
// };
|
||||
//
|
||||
// protected void freeItem(TextureItem t) {
|
||||
// log.debug(getFill() + " " + (sum--) + " free tex ");
|
||||
// super.freeItem(t);
|
||||
//
|
||||
// };
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ public class BitmapTileLoader extends TileLoader {
|
||||
throw new CancellationException();
|
||||
|
||||
BitmapLayer l = new BitmapLayer(false);
|
||||
l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE);
|
||||
l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE, BitmapTileLayer.pool);
|
||||
|
||||
ElementLayers layers = new ElementLayers();
|
||||
layers.setTextureLayers(l);
|
||||
mTile.data = layers;
|
||||
|
@ -24,6 +24,7 @@ import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLUtils;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.elements.TextureItem.TexturePool;
|
||||
|
||||
/**
|
||||
* Renderer for a single bitmap, width and height must be power of 2.
|
||||
@ -54,13 +55,25 @@ public class BitmapLayer extends TextureLayer {
|
||||
/**
|
||||
* w/h sets also target dimension to render the bitmap.
|
||||
*/
|
||||
|
||||
public void setBitmap(Bitmap bitmap, int w, int h) {
|
||||
setBitmap(bitmap, w, h, null);
|
||||
}
|
||||
|
||||
public void setBitmap(Bitmap bitmap, int w, int h, TexturePool pool) {
|
||||
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
|
||||
mBitmap = bitmap;
|
||||
if (textures == null)
|
||||
textures = new TextureItem(mBitmap);
|
||||
if (textures == null) {
|
||||
if (pool == null)
|
||||
textures = new TextureItem(mBitmap);
|
||||
else {
|
||||
textures = pool.get();
|
||||
textures.bitmap = mBitmap;
|
||||
}
|
||||
}
|
||||
|
||||
TextureItem t = textures;
|
||||
t.vertices = TextureLayer.INDICES_PER_SPRITE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user