synchronize clearing TileLayer on its TileRenderer instead of global MapRenderer.drawlock
This commit is contained in:
parent
2de6576765
commit
348e63b4fb
@ -24,9 +24,12 @@ import org.oscim.map.Map;
|
|||||||
import org.oscim.tiling.TileLoader;
|
import org.oscim.tiling.TileLoader;
|
||||||
import org.oscim.tiling.TileManager;
|
import org.oscim.tiling.TileManager;
|
||||||
import org.oscim.tiling.TileRenderer;
|
import org.oscim.tiling.TileRenderer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public abstract class TileLayer<T extends TileLoader> extends Layer implements Map.UpdateListener {
|
public abstract class TileLayer<T extends TileLoader> extends Layer implements Map.UpdateListener {
|
||||||
//static final Logger log = LoggerFactory.getLogger(TileLayer.class);
|
static final Logger log = LoggerFactory.getLogger(TileLayer.class);
|
||||||
|
|
||||||
private final static int MAX_ZOOMLEVEL = 17;
|
private final static int MAX_ZOOMLEVEL = 17;
|
||||||
private final static int MIN_ZOOMLEVEL = 2;
|
private final static int MIN_ZOOMLEVEL = 2;
|
||||||
private final static int CACHE_LIMIT = 250;
|
private final static int CACHE_LIMIT = 250;
|
||||||
@ -37,8 +40,6 @@ public abstract class TileLayer<T extends TileLoader> extends Layer implements M
|
|||||||
protected final int mNumTileLoader = 4;
|
protected final int mNumTileLoader = 4;
|
||||||
protected final ArrayList<T> mTileLoader;
|
protected final ArrayList<T> mTileLoader;
|
||||||
|
|
||||||
protected boolean mInitial = true;
|
|
||||||
|
|
||||||
public TileLayer(Map map) {
|
public TileLayer(Map map) {
|
||||||
this(map, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT);
|
this(map, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL, CACHE_LIMIT);
|
||||||
}
|
}
|
||||||
@ -71,10 +72,13 @@ public abstract class TileLayer<T extends TileLoader> extends Layer implements M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapUpdate(MapPosition mapPosition, boolean changed, boolean clear) {
|
public void onMapUpdate(MapPosition mapPosition, boolean changed, boolean clear) {
|
||||||
if (clear || mInitial) {
|
if (clear) {
|
||||||
mRenderLayer.clearTiles();
|
// sync with TileRenderer
|
||||||
mTileManager.init(mInitial);
|
synchronized (mRenderLayer) {
|
||||||
mInitial = false;
|
mRenderLayer.clearTiles();
|
||||||
|
mTileManager.init();
|
||||||
|
}
|
||||||
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,16 +91,13 @@ public abstract class TileLayer<T extends TileLoader> extends Layer implements M
|
|||||||
for (T loader : mTileLoader) {
|
for (T loader : mTileLoader) {
|
||||||
loader.pause();
|
loader.pause();
|
||||||
loader.interrupt();
|
loader.interrupt();
|
||||||
|
try {
|
||||||
|
loader.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
loader.cleanup();
|
loader.cleanup();
|
||||||
|
|
||||||
//try {
|
|
||||||
// tileWorker.join(10000);
|
|
||||||
//} catch (InterruptedException e) {
|
|
||||||
// // restore the interrupted status
|
|
||||||
// Thread.currentThread().interrupt();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
mTileManager.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void notifyLoaders() {
|
void notifyLoaders() {
|
||||||
@ -110,11 +111,12 @@ public abstract class TileLayer<T extends TileLoader> extends Layer implements M
|
|||||||
if (!loader.isPausing())
|
if (!loader.isPausing())
|
||||||
loader.pause();
|
loader.pause();
|
||||||
}
|
}
|
||||||
if (wait) {
|
if (!wait)
|
||||||
for (T loader : mTileLoader) {
|
return;
|
||||||
if (!loader.isPausing())
|
|
||||||
loader.awaitPausing();
|
for (T loader : mTileLoader) {
|
||||||
}
|
if (!loader.isPausing())
|
||||||
|
loader.awaitPausing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,10 +90,6 @@ public class MapRenderer {
|
|||||||
|
|
||||||
private static volatile boolean mUpdateColor = false;
|
private static volatile boolean mUpdateColor = false;
|
||||||
|
|
||||||
// drawlock to synchronize Main- and GL-Thread
|
|
||||||
// static ReentrantLock tilelock = new ReentrantLock();
|
|
||||||
public static Object drawlock = new Object();
|
|
||||||
|
|
||||||
public static long frametime;
|
public static long frametime;
|
||||||
|
|
||||||
// Do not use the same buffer to upload data within a frame twice
|
// Do not use the same buffer to upload data within a frame twice
|
||||||
@ -210,13 +206,8 @@ public class MapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDrawFrame() {
|
public void onDrawFrame() {
|
||||||
|
frametime = System.currentTimeMillis();
|
||||||
// prevent main thread recreating all tiles (updateMap)
|
draw();
|
||||||
// while rendering is going on.
|
|
||||||
synchronized (drawlock) {
|
|
||||||
frametime = System.currentTimeMillis();
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
mBufferPool.releaseBuffers();
|
mBufferPool.releaseBuffers();
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ public abstract class TileLoader extends PausableThread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWork() {
|
protected void doWork() {
|
||||||
|
|
||||||
MapTile tile = mTileManager.getTileJob();
|
MapTile tile = mTileManager.getTileJob();
|
||||||
|
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
@ -53,7 +54,7 @@ public abstract class TileLoader extends PausableThread {
|
|||||||
success = executeJob(tile);
|
success = executeJob(tile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInterrupted())
|
if (isInterrupted())
|
||||||
|
@ -132,11 +132,6 @@ public class TileManager {
|
|||||||
mUpdateSerial = 0;
|
mUpdateSerial = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
|
||||||
// there might be some leaks in here
|
|
||||||
// ... free static pools
|
|
||||||
}
|
|
||||||
|
|
||||||
private int[] mZoomTable;
|
private int[] mZoomTable;
|
||||||
|
|
||||||
public void setZoomTable(int[] zoomLevel) {
|
public void setZoomTable(int[] zoomLevel) {
|
||||||
@ -144,40 +139,23 @@ public class TileManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(boolean first) {
|
public void init() {
|
||||||
|
// pass VBOs and VertexItems back to pools
|
||||||
|
for (int i = 0; i < mTilesSize; i++)
|
||||||
|
clearTile(mTiles[i]);
|
||||||
|
|
||||||
// sync with GLRender thread
|
// clear references to cached MapTiles
|
||||||
// ... and labeling thread?
|
Arrays.fill(mTiles, null);
|
||||||
synchronized (MapRenderer.drawlock) {
|
mTilesSize = 0;
|
||||||
|
mTilesCount = 0;
|
||||||
|
|
||||||
if (!first) {
|
// set up TileSet large enough to hold current tiles
|
||||||
// pass VBOs and VertexItems back to pools
|
int num = Math.max(mMap.getWidth(), mMap.getHeight());
|
||||||
for (int i = 0; i < mTilesSize; i++)
|
int size = Tile.SIZE >> 1;
|
||||||
clearTile(mTiles[i]);
|
int numTiles = (num * num) / (size * size) * 4;
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME any of this still needed?
|
mNewTiles = new TileSet(numTiles);
|
||||||
// mInitialized is set when surface changed
|
mCurrentTiles = new TileSet(numTiles);
|
||||||
// and VBOs might be lost
|
|
||||||
// VertexPool.init();
|
|
||||||
// clear cache index
|
|
||||||
// QuadTree.init();
|
|
||||||
|
|
||||||
// clear references to cached MapTiles
|
|
||||||
Arrays.fill(mTiles, null);
|
|
||||||
mTilesSize = 0;
|
|
||||||
mTilesCount = 0;
|
|
||||||
|
|
||||||
// set up TileSet large enough to hold current tiles
|
|
||||||
int num = Math.max(mMap.getWidth(), mMap.getHeight());
|
|
||||||
int size = Tile.SIZE >> 1;
|
|
||||||
int numTiles = (num * num) / (size * size) * 4;
|
|
||||||
|
|
||||||
mNewTiles = new TileSet(numTiles);
|
|
||||||
mCurrentTiles = new TileSet(numTiles);
|
|
||||||
log.debug("max tiles: " + numTiles);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,7 +165,7 @@ public class TileManager {
|
|||||||
* @param pos
|
* @param pos
|
||||||
* current MapPosition
|
* current MapPosition
|
||||||
*/
|
*/
|
||||||
public synchronized boolean update(MapPosition pos) {
|
public boolean update(MapPosition pos) {
|
||||||
// clear JobQueue and set tiles to state == NONE.
|
// clear JobQueue and set tiles to state == NONE.
|
||||||
// one could also append new tiles and sort in JobQueue
|
// one could also append new tiles and sort in JobQueue
|
||||||
// but this has the nice side-effect that MapWorkers dont
|
// but this has the nice side-effect that MapWorkers dont
|
||||||
|
@ -64,8 +64,11 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
mAlpha = alpha;
|
mAlpha = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* synced with clearTiles
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void update(MapPosition pos, boolean positionChanged, Matrices m) {
|
protected synchronized void update(MapPosition pos, boolean positionChanged, Matrices m) {
|
||||||
|
|
||||||
if (mAlpha == 0) {
|
if (mAlpha == 0) {
|
||||||
mTileManager.releaseTiles(mDrawTiles);
|
mTileManager.releaseTiles(mDrawTiles);
|
||||||
@ -106,9 +109,7 @@ public class TileRenderer extends LayerRenderer {
|
|||||||
public void clearTiles() {
|
public void clearTiles() {
|
||||||
// Clear all references to MapTiles as all current
|
// Clear all references to MapTiles as all current
|
||||||
// tiles will also be removed from TileManager.
|
// tiles will also be removed from TileManager.
|
||||||
synchronized (MapRenderer.drawlock) {
|
mDrawTiles = new TileSet();
|
||||||
mDrawTiles = new TileSet();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** compile tile layer data and upload to VBOs */
|
/** compile tile layer data and upload to VBOs */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user