sync on ExtrusionLayer.vertexPool instead of each Vertex

This commit is contained in:
Hannes Janetzek 2014-05-28 15:06:49 +02:00
parent 037c25153b
commit a26aa9de15

View File

@ -30,7 +30,7 @@ import org.oscim.utils.KeyMap.HashItem;
import org.oscim.utils.Tessellator; import org.oscim.utils.Tessellator;
import org.oscim.utils.geom.LineClipper; import org.oscim.utils.geom.LineClipper;
import org.oscim.utils.pool.Inlist; import org.oscim.utils.pool.Inlist;
import org.oscim.utils.pool.SyncPool; import org.oscim.utils.pool.Pool;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -111,17 +111,19 @@ public class ExtrusionLayer extends RenderElement {
mCurIndices = new VertexItem[5]; mCurIndices = new VertexItem[5];
mIndices[4] = mCurIndices[4] = VertexItem.pool.get(); mIndices[4] = mCurIndices[4] = VertexItem.pool.get();
synchronized (vertexPool) {
mVertexMap = vertexMapPool.get(); mVertexMap = vertexMapPool.get();
} }
}
static SyncPool<Vertex> vertexPool = new SyncPool<Vertex>(8192, false) { static Pool<Vertex> vertexPool = new Pool<Vertex>() {
@Override @Override
protected Vertex createItem() { protected Vertex createItem() {
return new Vertex(); return new Vertex();
} }
}; };
static SyncPool<KeyMap<Vertex>> vertexMapPool = new SyncPool<KeyMap<Vertex>>(64, false) { static Pool<KeyMap<Vertex>> vertexMapPool = new Pool<KeyMap<Vertex>>() {
@Override @Override
protected KeyMap<Vertex> createItem() { protected KeyMap<Vertex> createItem() {
return new KeyMap<Vertex>(2048); return new KeyMap<Vertex>(2048);
@ -160,6 +162,7 @@ public class ExtrusionLayer extends RenderElement {
float[] points = element.points; float[] points = element.points;
int vertexCnt = sumVertices; int vertexCnt = sumVertices;
synchronized (vertexPool) {
Vertex key = vertexPool.get(); Vertex key = vertexPool.get();
double scale = S * Tile.SIZE / 4096; double scale = S * Tile.SIZE / 4096;
@ -267,7 +270,7 @@ public class ExtrusionLayer extends RenderElement {
} }
vertexPool.release(key); vertexPool.release(key);
}
sumVertices = vertexCnt; sumVertices = vertexCnt;
} }
@ -649,11 +652,7 @@ public class ExtrusionLayer extends RenderElement {
public void compile(ShortBuffer vertexBuffer, ShortBuffer indexBuffer) { public void compile(ShortBuffer vertexBuffer, ShortBuffer indexBuffer) {
mClipper = null; mClipper = null;
if (mVertexMap != null) { releaseVertexPool();
vertexPool.releaseAll(mVertexMap.releaseItems());
mVertexMap = vertexMapPool.release(mVertexMap);
mVertexMap = null;
}
if (sumVertices == 0) { if (sumVertices == 0) {
return; return;
@ -682,18 +681,23 @@ public class ExtrusionLayer extends RenderElement {
protected void clear() { protected void clear() {
mClipper = null; mClipper = null;
if (mVertexMap != null) {
vertexPool.releaseAll(mVertexMap.releaseItems());
mVertexMap = vertexMapPool.release(mVertexMap);
mVertexMap = null;
}
if (mIndices != null) { if (mIndices != null) {
for (int i = 0; i <= IND_MESH; i++) for (int i = 0; i <= IND_MESH; i++)
mIndices[i] = VertexItem.pool.releaseAll(mIndices[i]); mIndices[i] = VertexItem.pool.releaseAll(mIndices[i]);
mIndices = null; mIndices = null;
mVertices = VertexItem.pool.releaseAll(mVertices); mVertices = VertexItem.pool.releaseAll(mVertices);
} }
releaseVertexPool();
}
void releaseVertexPool() {
if (mVertexMap == null)
return;
synchronized (vertexPool) {
vertexPool.releaseAll(mVertexMap.releaseItems());
mVertexMap = vertexMapPool.release(mVertexMap);
}
} }
public ExtrusionLayer next() { public ExtrusionLayer next() {