fix: unlock tiles properly onResume

This commit is contained in:
Hannes Janetzek 2012-11-07 23:13:57 +01:00
parent 7dd171dc24
commit dd64d6da26
7 changed files with 61 additions and 84 deletions

View File

@ -140,12 +140,6 @@ public class MapDatabase implements IMapDatabase {
mLastRequest = SystemClock.elapsedRealtime();
// FIXME remove this stuff
if (!mTile.isLoading) {
Log.d(TAG, "loading canceled " + mTile);
result = QueryResult.FAILED;
}
cacheFinish(tile, f, result == QueryResult.SUCCESS);
return result;

View File

@ -180,12 +180,9 @@ public class MapDatabase implements IMapDatabase {
try {
if (USE_LW_HTTP) {
if (lwHttpSendRequest(tile)) {
if (lwHttpReadHeader() > 0) {
cacheBegin(tile, f);
decode();
}
if (lwHttpSendRequest(tile) && lwHttpReadHeader() > 0) {
cacheBegin(tile, f);
decode();
} else {
result = QueryResult.FAILED;
}
@ -254,12 +251,6 @@ public class MapDatabase implements IMapDatabase {
if (USE_APACHE_HTTP)
mRequest = null;
// FIXME remove this stuff
if (!mTile.isLoading) {
Log.d(TAG, "loading canceled " + mTile);
result = QueryResult.FAILED;
}
cacheFinish(tile, f, result == QueryResult.SUCCESS);
return result;
@ -877,6 +868,7 @@ public class MapDatabase implements IMapDatabase {
mBufferSize += len;
}
return read;
}

View File

@ -14,8 +14,8 @@
*/
package org.oscim.generator;
import org.oscim.renderer.TileManager;
import org.oscim.renderer.TileGenerator;
import org.oscim.renderer.TileManager;
import org.oscim.utils.PausableThread;
/**
@ -66,9 +66,9 @@ public class MapWorker extends PausableThread {
// Log.d("...", "load: " + tile);
boolean success = mMapGenerator.executeJob(tile);
mMapGenerator.executeJob(tile);
if (!isInterrupted() && success) {
if (!isInterrupted()) {
mTileManager.passTile(tile);
}
}

View File

@ -301,17 +301,16 @@ public class GLRenderer implements GLSurfaceView.Renderer {
}
private static boolean uploadTileData(MapTile tile) {
// synchronized (tile) {
tile.isReady = uploadLayers(tile.layers, tile.vbo, true);
if (!tile.isReady) {
tile.layers.clear();
tile.layers = null;
if (tile.layers != null) {
tile.isReady = uploadLayers(tile.layers, tile.vbo, true);
if (!tile.isReady) {
tile.layers.clear();
tile.layers = null;
}
}
tile.newData = false;
// Log.d(TAG, "uploaded " + tile.isReady + " " + tile);
// }
return tile.isReady;
}
@ -728,16 +727,14 @@ public class GLRenderer implements GLSurfaceView.Renderer {
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
Log.d(TAG, "SurfaceChanged:" + width + " " + height);
mDrawTiles = null;
Log.d(TAG, "SurfaceChanged:" + mNewSurface + " " + width + " " + height);
if (width <= 0 || height <= 0)
return;
boolean changed = true;
if (mWidth == width || mHeight == height)
changed = false;
// boolean changed = true;
// if (mWidth == width || mHeight == height)
// changed = false;
mWidth = width;
mHeight = height;
@ -767,13 +764,14 @@ public class GLRenderer implements GLSurfaceView.Renderer {
GLES20.glViewport(0, 0, width, height);
if (!changed && !mNewSurface) {
if (!mNewSurface) {
mMapView.redrawMap();
return;
}
mNewSurface = false;
mBufferMemoryUsage = 0;
mDrawTiles = null;
int numTiles = (mWidth / (Tile.TILE_SIZE / 2) + 2)
* (mHeight / (Tile.TILE_SIZE / 2) + 2);
@ -791,7 +789,6 @@ public class GLRenderer implements GLSurfaceView.Renderer {
vertexArray[0] = false;
vertexArray[1] = false;
// FIXME this should be synchronized
mMapView.redrawMap();
}
@ -800,10 +797,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
// String ext = GLES20.glGetString(GLES20.GL_EXTENSIONS);
// Log.d(TAG, "Extensions: " + ext);
// GLES20.GL_POLYGON_OFFSET_UNITS
LineRenderer.init();
PolygonRenderer.init();
// TextRenderer.init();
TextureRenderer.init();
TextureObject.init(10);
@ -818,4 +813,8 @@ public class GLRenderer implements GLSurfaceView.Renderer {
private boolean mNewSurface;
private static final boolean debugView = false;
void clearBuffer() {
mNewSurface = true;
}
}

View File

@ -423,7 +423,7 @@ public class TileGenerator implements IRenderCallback, IMapDatabaseCallback {
mLayers = new Layers();
if (mMapDatabase.executeQuery(tile, this) != QueryResult.SUCCESS) {
Log.d(TAG, "Failed loading: " + tile);
//Log.d(TAG, "Failed loading: " + tile);
mLayers.clear();
mLayers = null;
mLabels = null;

View File

@ -16,7 +16,6 @@ package org.oscim.renderer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.locks.ReentrantLock;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
@ -61,7 +60,7 @@ public class TileManager {
private static float[] mTileCoords = new float[8];
static int mUpdateCnt;
static ReentrantLock tilelock = new ReentrantLock();
static Object tilelock = new Object();
static Tiles mCurrentTiles;
/* package */static Tiles mNewTiles;
@ -134,12 +133,12 @@ public class TileManager {
}
private TileManager(MapView mapView) {
Log.d(TAG, "init TileManager");
mMapView = mapView;
mMapViewPosition = mapView.getMapViewPosition();
mJobList = new ArrayList<JobTile>();
mTiles = new ArrayList<MapTile>();
mTiles = new ArrayList<MapTile>(200);
mTilesLoaded = new ArrayList<MapTile>(30);
// this is probably a good place to init these
@ -165,45 +164,40 @@ public class TileManager {
if (mMapView == null)
return;
// FIXME too messy!
if (clear || mInitial) {
// make sure onDrawFrame is not running
// make sure onDrawFrame is not running, and labeling thread?
GLRenderer.drawlock.lock();
// remove all tiles references
// clear all tiles references
Log.d(TAG, "CLEAR " + mInitial);
mUpdateCnt = 0;
if (clear) {
// pass VBOs and VertexItems back to pools
for (MapTile t : mTiles)
clearTile(t);
} else {
VertexPool.init();
}
//VertexPool.init();
QuadTree.init();
mTiles.clear();
mTilesLoaded.clear();
QuadTree.init();
// set up TileData arrays that are passed to gl-thread
int num = mWidth;
if (mWidth < mHeight)
num = mHeight;
int num = Math.max(mWidth, mHeight);
int size = Tile.TILE_SIZE >> 1;
int numTiles = (num * num) / (size * size) * 4;
// mRenderer.clearTiles(numTiles);
mNewTiles = new Tiles(numTiles);
mCurrentTiles = new Tiles(numTiles);
// MapInfo mapInfo = mMapView.getMapDatabase().getMapInfo();
// if (mapInfo != null)
// mZoomLevels = mapInfo.zoomLevel;
GLRenderer.drawlock.unlock();
// .. make sure mMapPosition will be updated
mMapPosition.zoomLevel = -1;
mInitial = false;
}
@ -253,8 +247,7 @@ public class TileManager {
return td;
// dont flip new/currentTiles while copying
TileManager.tilelock.lock();
try {
synchronized (TileManager.tilelock) {
MapTile[] newTiles = mCurrentTiles.tiles;
int cnt = mCurrentTiles.cnt;
@ -264,9 +257,13 @@ public class TileManager {
MapTile[] nextTiles;
if (td == null)
if (td == null) {
td = new Tiles(newTiles.length);
} else if (td.serial > mUpdateCnt) {
Log.d(TAG, "ignore previous tile data " + td.cnt);
// tile data was cleared, ignore tiles
td.cnt = 0;
}
nextTiles = td.tiles;
// unlock previously active tiles
@ -278,8 +275,6 @@ public class TileManager {
td.serial = mUpdateCnt;
td.cnt = cnt;
} finally {
TileManager.tilelock.unlock();
}
return td;
@ -313,7 +308,7 @@ public class TileManager {
MapTile[] newTiles = mNewTiles.tiles;
MapTile[] curTiles = mCurrentTiles.tiles;
boolean changed = false;
boolean changed = (mNewTiles.cnt != mCurrentTiles.cnt);
for (int i = 0, n = mNewTiles.cnt; i < n && !changed; i++) {
MapTile t = newTiles[i];
@ -330,8 +325,7 @@ public class TileManager {
}
if (changed) {
TileManager.tilelock.lock();
try {
synchronized (TileManager.tilelock) {
for (int i = 0, n = mNewTiles.cnt; i < n; i++)
newTiles[i].lock();
@ -343,8 +337,6 @@ public class TileManager {
mNewTiles = tmp;
mUpdateCnt++;
} finally {
TileManager.tilelock.unlock();
}
// Log.d(TAG, "tiles: " + tileCounter + " " + BufferObject.counter
@ -615,12 +607,12 @@ public class TileManager {
public synchronized boolean passTile(JobTile jobTile) {
MapTile tile = (MapTile) jobTile;
// if (!tile.isLoading) {
// // no one should be able to use this tile now, TileGenerator passed
// // it, GL-Thread does nothing until newdata is set.
// Log.d(TAG, "passTile: canceled " + tile);
// return true;
// }
if (!tile.isLoading) {
// no one should be able to use this tile now, TileGenerator passed
// it, GL-Thread does nothing until newdata is set.
//Log.d(TAG, "passTile: failed loading " + tile);
return true;
}
if (tile.vbo != null) {
// BAD Things(tm) happend...

View File

@ -99,6 +99,8 @@ public class MapView extends RelativeLayout {
private String mRenderTheme;
private Map<String, String> mMapOptions;
private boolean mClearTiles;
/**
* @param context
* the enclosing MapActivity instance.
@ -310,15 +312,16 @@ public class MapView extends RelativeLayout {
mOverlayManager.onUpdate(mMapPosition, changed);
}
mTileManager.updateMap(false);
mTileManager.updateMap(mClearTiles);
mClearTiles = false;
}
public void clearAndRedrawMap() {
if (mPausing || this.getWidth() == 0 || this.getHeight() == 0)
return;
if (AndroidUtils.currentThreadIsUiThread())
mTileManager.updateMap(true);
//if (AndroidUtils.currentThreadIsUiThread())
mTileManager.updateMap(true);
}
/**
@ -415,28 +418,25 @@ public class MapView extends RelativeLayout {
if (debugDatabase)
return;
TileGenerator tileGenerator;
Log.i(TAG, "setMapDatabase " + mapDatabaseType.name());
if (mMapDatabaseType == mapDatabaseType)
return;
mMapDatabaseType = mapDatabaseType;
mapWorkersPause(true);
for (MapWorker mapWorker : mMapWorkers) {
tileGenerator = mapWorker.getMapGenerator();
TileGenerator tileGenerator = mapWorker.getMapGenerator();
tileGenerator.setMapDatabase(MapDatabaseFactory
.createMapDatabase(mapDatabaseType));
}
mJobQueue.clear();
mClearTiles = true;
setMapOptions(null);
mapWorkersProceed();
}