TexturePool: add function to initialize item with bitmap
This commit is contained in:
parent
2e56e3facc
commit
8f0c51675d
@ -104,14 +104,10 @@ public class BitmapTileLayer extends TileLayer {
|
|||||||
return new BitmapTileLoader(this, mTileSource);
|
return new BitmapTileLoader(this, mTileSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
final static int TEXTURE_HEIGHT = 256;
|
|
||||||
final static int TEXTURE_WIDTH = 256;
|
|
||||||
final static int POOL_FILL = 40;
|
final static int POOL_FILL = 40;
|
||||||
|
|
||||||
/** pool shared by TextLayers */
|
/** pool shared by TextLayers */
|
||||||
final static TexturePool pool = new TexturePool(POOL_FILL,
|
final static TexturePool pool = new TexturePool(POOL_FILL) {
|
||||||
TEXTURE_WIDTH,
|
|
||||||
TEXTURE_HEIGHT) {
|
|
||||||
|
|
||||||
// int sum = 0;
|
// int sum = 0;
|
||||||
//
|
//
|
||||||
|
|||||||
@ -70,8 +70,7 @@ public class BitmapLayer extends TextureLayer {
|
|||||||
if (pool == null)
|
if (pool == null)
|
||||||
textures = new TextureItem(mBitmap);
|
textures = new TextureItem(mBitmap);
|
||||||
else {
|
else {
|
||||||
textures = pool.get();
|
textures = pool.get(mBitmap);
|
||||||
textures.bitmap = mBitmap;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -150,6 +150,8 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
|
|
||||||
private final int mHeight;
|
private final int mHeight;
|
||||||
private final int mWidth;
|
private final int mWidth;
|
||||||
|
private final boolean mUseBitmapPool;
|
||||||
|
|
||||||
//private final int mBitmapFormat;
|
//private final int mBitmapFormat;
|
||||||
//private final int mBitmapType;
|
//private final int mBitmapType;
|
||||||
|
|
||||||
@ -159,6 +161,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
super(maxFill);
|
super(maxFill);
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
|
mUseBitmapPool = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TexturePool(int maxFill) {
|
||||||
|
super(maxFill);
|
||||||
|
mWidth = 0;
|
||||||
|
mHeight = 0;
|
||||||
|
mUseBitmapPool = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -172,6 +182,9 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
public synchronized TextureItem get() {
|
public synchronized TextureItem get() {
|
||||||
TextureItem t = super.get();
|
TextureItem t = super.get();
|
||||||
|
|
||||||
|
if (!mUseBitmapPool)
|
||||||
|
return t;
|
||||||
|
|
||||||
synchronized (mBitmaps) {
|
synchronized (mBitmaps) {
|
||||||
int size = mBitmaps.size();
|
int size = mBitmaps.size();
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
@ -185,6 +198,13 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized TextureItem get(Bitmap bitmap) {
|
||||||
|
TextureItem t = super.get();
|
||||||
|
t.bitmap = bitmap;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TextureItem createItem() {
|
protected TextureItem createItem() {
|
||||||
return new TextureItem(this, -1);
|
return new TextureItem(this, -1);
|
||||||
@ -193,21 +213,14 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean clearItem(TextureItem t) {
|
protected boolean clearItem(TextureItem t) {
|
||||||
|
|
||||||
//if (t.ownBitmap) {
|
|
||||||
// t.bitmap = null;
|
|
||||||
// t.ownBitmap = false;
|
|
||||||
// releaseTexture(t);
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (t.ref)
|
if (t.ref)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
t.ready = false;
|
t.ready = false;
|
||||||
releaseBitmap(t);
|
|
||||||
|
|
||||||
// only add back to pool when a texture
|
if (mUseBitmapPool)
|
||||||
// is already assigned
|
releaseBitmap(t);
|
||||||
|
|
||||||
return t.id >= 0;
|
return t.id >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,21 +286,11 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
t.bitmap.uploadToTexture(true);
|
t.bitmap.uploadToTexture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (t.ownBitmap) {
|
|
||||||
// t.bitmap.uploadToTexture(false);
|
|
||||||
//} else
|
|
||||||
|
|
||||||
//if (t.width == mWidth && t.height == mHeight) {
|
|
||||||
// // use faster subimage upload
|
|
||||||
// t.bitmap.uploadToTexture(true);
|
|
||||||
//} else {
|
|
||||||
// t.bitmap.uploadToTexture(false);
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (TextureLayer.Renderer.debug)
|
if (TextureLayer.Renderer.debug)
|
||||||
GLUtils.checkGlError(TextureItem.class.getName());
|
GLUtils.checkGlError(TextureItem.class.getName());
|
||||||
|
|
||||||
releaseBitmap(t);
|
if (mUseBitmapPool)
|
||||||
|
releaseBitmap(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initTexture(TextureItem t) {
|
protected void initTexture(TextureItem t) {
|
||||||
@ -312,27 +315,13 @@ public class TextureItem extends Inlist<TextureItem> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pool for not-pooled textures. Disposed items will only be released
|
/* Pool for not-pooled textures. Disposed items will only be released
|
||||||
// on the GL-Thread and will not be put back in any pool.
|
* on the GL-Thread and will not be put back in any pool. */
|
||||||
final static TexturePool NOPOOL = new TexturePool(0, 0, 0) {
|
final static TexturePool NOPOOL = new TexturePool(0);
|
||||||
protected void releaseBitmap(TextureItem t) {
|
|
||||||
// TODO
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// public final static TexturePool nopool(){
|
|
||||||
// return NOPOOL;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static GL20 GL;
|
private static GL20 GL;
|
||||||
|
|
||||||
static void init(GL20 gl) {
|
static void init(GL20 gl) {
|
||||||
GL = gl;
|
GL = gl;
|
||||||
|
|
||||||
// mTexCnt = num;
|
|
||||||
// NOPOOL.init(num);
|
|
||||||
//
|
|
||||||
// mBitmaps.clear();
|
|
||||||
// mTexDisposed.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user