On options change set 'clearMap' flag instead of direct clearAndRedraw

This commit is contained in:
Hannes Janetzek
2013-02-25 05:07:24 +01:00
parent ecedccb265
commit a581996f25
3 changed files with 135 additions and 121 deletions

View File

@@ -563,7 +563,7 @@ public class GLRenderer implements GLSurfaceView.Renderer {
@Override @Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) { public void onSurfaceChanged(GL10 glUnused, int width, int height) {
Log.d(TAG, "SurfaceChanged:" + mNewSurface + " " + width + " " + height); Log.d(TAG, "SurfaceChanged:" + mNewSurface + " " + width + "x" + height);
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
return; return;

View File

@@ -51,10 +51,8 @@ public class TileManager {
private final MapView mMapView; private final MapView mMapView;
private final MapViewPosition mMapViewPosition; private final MapViewPosition mMapViewPosition;
private final MapPosition mMapPosition;
private boolean mInitialized; private boolean mInitialized;
private int mWidth = 0;
private int mHeight = 0;
// cache for all tiles // cache for all tiles
private MapTile[] mTiles; private MapTile[] mTiles;
@@ -85,7 +83,6 @@ public class TileManager {
public TileManager(MapView mapView) { public TileManager(MapView mapView) {
mMapView = mapView; mMapView = mapView;
mMapViewPosition = mapView.getMapViewPosition(); mMapViewPosition = mapView.getMapViewPosition();
mMapPosition = new MapPosition();
mJobs = new ArrayList<JobTile>(); mJobs = new ArrayList<JobTile>();
mTiles = new MapTile[GLRenderer.CACHE_TILES]; mTiles = new MapTile[GLRenderer.CACHE_TILES];
@@ -99,32 +96,16 @@ public class TileManager {
public void destroy() { public void destroy() {
// there might be some leaks in here // there might be some leaks in here
// ... free pools // ... free static pools
} }
/** public synchronized void init(int width, int height) {
* Update list of visible tiles and passes them to TileManager, when not
* available tiles are created and added to JobQueue (mapView.addJobs) for
* loading by TileGenerator class
*
* @param clear
* whether to clear and reload all tiles
*/
public synchronized void updateMap(final boolean clear) {
boolean changedPos = false;
if (mMapView == null) // sync with GLRender thread
return; // ... and labeling thread?
if (clear || !mInitialized) {
// make sure onDrawFrame is not running
// - and labeling thread?
GLRenderer.drawlock.lock(); GLRenderer.drawlock.lock();
// clear all tiles references if (mInitialized) {
Log.d(TAG, "CLEAR " + mInitialized);
if (clear) {
// pass VBOs and VertexItems back to pools // pass VBOs and VertexItems back to pools
for (int i = 0; i < mTilesSize; i++) for (int i = 0; i < mTilesSize; i++)
clearTile(mTiles[i]); clearTile(mTiles[i]);
@@ -134,48 +115,64 @@ public class TileManager {
VertexPool.init(); VertexPool.init();
} }
// clear cache index
QuadTree.init(); QuadTree.init();
// clear references to cached MapTiles
Arrays.fill(mTiles, null); Arrays.fill(mTiles, null);
mTilesSize = 0; mTilesSize = 0;
mTilesCount = 0; mTilesCount = 0;
// clear all references to previous tiles
for (TileSet td : mTileSets) { for (TileSet td : mTileSets) {
Arrays.fill(td.tiles, null); Arrays.fill(td.tiles, null);
td.cnt = 0; td.cnt = 0;
} }
// set up TileData arrays that are passed to gl-thread // set up TileSet large enough to hold current tiles
int num = Math.max(mWidth, mHeight); int num = Math.max(width, height);
int size = Tile.TILE_SIZE >> 1; int size = Tile.TILE_SIZE >> 1;
int numTiles = (num * num) / (size * size) * 4; int numTiles = (num * num) / (size * size) * 4;
mNewTiles = new TileSet(numTiles); mNewTiles = new TileSet(numTiles);
mCurrentTiles = new TileSet(numTiles); mCurrentTiles = new TileSet(numTiles);
Log.d(TAG, "max tiles: " + numTiles);
// make sure mMapPosition will be updated
mMapPosition.zoomLevel = -1;
mInitialized = true; mInitialized = true;
GLRenderer.drawlock.unlock(); GLRenderer.drawlock.unlock();
} }
MapPosition mapPosition = mMapPosition; /**
float[] coords = mTileCoords; * Update list of visible tiles and passes them to TileManager, when not
* available tiles are created and added to JobQueue (mapView.addJobs) for
synchronized (mMapViewPosition) { * loading by TileGenerator class
changedPos = mMapViewPosition.getMapPosition(mapPosition); *
mMapViewPosition.getMapViewProjection(coords); * @param mapPosition
} * current MapPosition
*/
if (changedPos) { public synchronized void updateMap(MapPosition mapPosition) {
mMapView.render(); if (!mInitialized) {
} else { Log.d(TAG, "not initialized");
return; return;
} }
//MapPosition mapPosition = mMapPosition;
float[] coords = mTileCoords;
//synchronized (mMapViewPosition) {
// changedPos = mMapViewPosition.getMapPosition(mapPosition);
mMapViewPosition.getMapViewProjection(coords);
//}
//if (changedPos) {
// mMapView.render();
//} else {
// return;
//}
// load some tiles more than currently visible // load some tiles more than currently visible
// TODO limit how many more... // TODO limit how many more...
float scale = mapPosition.scale * 0.5f; float scale = mapPosition.scale * 0.7f;
float px = (float) mapPosition.x; float px = (float) mapPosition.x;
float py = (float) mapPosition.y; float py = (float) mapPosition.y;
@@ -590,13 +587,6 @@ public class TileManager {
return true; return true;
} }
public void onSizeChanged(int w, int h) {
Log.d(TAG, "onSizeChanged" + w + " " + h);
mWidth = w;
mHeight = h;
}
private final ScanBox mScanBox = new ScanBox() { private final ScanBox mScanBox = new ScanBox() {
@Override @Override
public void setVisible(int y, int x1, int x2) { public void setVisible(int y, int x1, int x2) {

View File

@@ -98,7 +98,10 @@ public class MapView extends RelativeLayout {
private String mRenderTheme; private String mRenderTheme;
private DebugSettings mDebugSettings; private DebugSettings mDebugSettings;
private boolean mClearTiles; private boolean mClearMap;
private int mWidth;
private int mHeight;
// FIXME: keep until old pbmap reader is removed // FIXME: keep until old pbmap reader is removed
public static boolean enableClosePolygons = false; public static boolean enableClosePolygons = false;
@@ -198,9 +201,41 @@ public class MapView extends RelativeLayout {
// if (testRegionZoom) // if (testRegionZoom)
// mRegionLookup = new RegionLookup(this); // mRegionLookup = new RegionLookup(this);
clearMap();
} }
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
// mMapZoomControlsjonMapViewTouchEvent(motionEvent.getAction()
// & MotionEvent.ACTION_MASK);
if (this.isClickable())
return mTouchEventHandler.handleMotionEvent(motionEvent);
return false;
}
@Override
protected synchronized void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) {
Log.d(TAG, "onSizeChanged: " + width + "x" + height);
mJobQueue.clear();
mapWorkersPause(true);
super.onSizeChanged(width, height, oldWidth, oldHeight);
mWidth = width;
mHeight = height;
if (width != 0 && height != 0)
mMapViewPosition.setViewport(width, height);
clearMap();
mapWorkersProceed();
}
public void render() { public void render() {
if (!MapView.debugFrameTime) if (!MapView.debugFrameTime)
mGLView.requestRender(); mGLView.requestRender();
@@ -244,44 +279,46 @@ public class MapView extends RelativeLayout {
return mRotationEnabled; return mRotationEnabled;
} }
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
// mMapZoomControls.onMapViewTouchEvent(motionEvent.getAction()
// & MotionEvent.ACTION_MASK);
if (this.isClickable())
return mTouchEventHandler.handleMotionEvent(motionEvent);
return false;
}
/** /**
* Calculates all necessary tiles and adds jobs accordingly. * Calculates all necessary tiles and adds jobs accordingly.
* *
* @param changedPos TODO * @param forceRedraw TODO
*/ */
public void redrawMap(boolean changedPos) { public void redrawMap(boolean forceRedraw) {
if (mPausing || this.getWidth() == 0 || this.getHeight() == 0) if (mPausing || mWidth == 0 || mHeight == 0)
return; return;
//if (changedPos) if (forceRedraw)
// render(); render();
if (mClearMap){
mTileManager.init(mWidth, mHeight);
mClearMap = false;
// make sure mMapPosition will be updated
mMapPosition.zoomLevel = -1;
// TODO clear overlays
}
if (AndroidUtils.currentThreadIsUiThread()) {
boolean changed = mMapViewPosition.getMapPosition(mMapPosition); boolean changed = mMapViewPosition.getMapPosition(mMapPosition);
//Log.d(TAG, "redraw " + changed + " " + forceRedraw);
// required when not changed?
if (AndroidUtils.currentThreadIsUiThread())
mOverlayManager.onUpdate(mMapPosition, changed); mOverlayManager.onUpdate(mMapPosition, changed);
if (changed) {
mTileManager.updateMap(mMapPosition);
} }
mTileManager.updateMap(mClearTiles);
mClearTiles = false;
} }
public void clearAndRedrawMap() { private void clearMap(){
if (mPausing || this.getWidth() == 0 || this.getHeight() == 0) // clear tile and overlay data before next draw
return; mClearMap = true;
//if (AndroidUtils.currentThreadIsUiThread())
mTileManager.updateMap(true);
} }
/** /**
@@ -291,7 +328,7 @@ public class MapView extends RelativeLayout {
public void setDebugSettings(DebugSettings debugSettings) { public void setDebugSettings(DebugSettings debugSettings) {
mDebugSettings = debugSettings; mDebugSettings = debugSettings;
TileGenerator.setDebugSettings(debugSettings); TileGenerator.setDebugSettings(debugSettings);
clearAndRedrawMap(); clearMap();
} }
/** /**
@@ -332,13 +369,13 @@ public class MapView extends RelativeLayout {
* *
* @param options * @param options
* the new MapDatabase options. * the new MapDatabase options.
* @return ... * @return true if MapDatabase changed
*/ */
public boolean setMapDatabase(MapOptions options) { public boolean setMapDatabase(MapOptions options) {
if (debugDatabase) if (debugDatabase)
return false; return false;
Log.i(TAG, "setMapDatabase " + options.db.name()); Log.i(TAG, "setMapDatabase: " + options.db.name());
if (mMapOptions != null && mMapOptions.equals(options)) if (mMapOptions != null && mMapOptions.equals(options))
return true; return true;
@@ -346,7 +383,6 @@ public class MapView extends RelativeLayout {
mapWorkersPause(true); mapWorkersPause(true);
mJobQueue.clear(); mJobQueue.clear();
mClearTiles = true;
mMapOptions = options; mMapOptions = options;
for (int i = 0; i < mNumMapWorkers; i++) { for (int i = 0; i < mNumMapWorkers; i++) {
@@ -370,6 +406,8 @@ public class MapView extends RelativeLayout {
else else
MapView.enableClosePolygons = false; MapView.enableClosePolygons = false;
clearMap();
mapWorkersProceed(); mapWorkersProceed();
return true; return true;
@@ -400,7 +438,9 @@ public class MapView extends RelativeLayout {
if (ret) { if (ret) {
mRenderTheme = internalRenderTheme.name(); mRenderTheme = internalRenderTheme.name();
} }
clearAndRedrawMap();
clearMap();
return ret; return ret;
} }
@@ -424,7 +464,8 @@ public class MapView extends RelativeLayout {
if (ret) { if (ret) {
mRenderTheme = renderThemePath; mRenderTheme = renderThemePath;
} }
clearAndRedrawMap();
clearMap();
} }
private boolean setRenderTheme(Theme theme) { private boolean setRenderTheme(Theme theme) {
@@ -456,26 +497,9 @@ public class MapView extends RelativeLayout {
} }
mapWorkersProceed(); mapWorkersProceed();
} }
return false; return false;
} }
@Override
protected synchronized void onSizeChanged(int width, int height,
int oldWidth, int oldHeight) {
mJobQueue.clear();
mapWorkersPause(true);
Log.d(TAG, "onSizeChanged" + width + " " + height);
super.onSizeChanged(width, height, oldWidth, oldHeight);
if (width != 0 && height != 0)
mMapViewPosition.setViewport(width, height);
mTileManager.onSizeChanged(width, height);
mapWorkersProceed();
}
void destroy() { void destroy() {
for (MapWorker mapWorker : mMapWorkers) { for (MapWorker mapWorker : mMapWorkers) {