On options change set 'clearMap' flag instead of direct clearAndRedraw
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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,7 +96,50 @@ 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) {
|
||||||
|
|
||||||
|
// sync with GLRender thread
|
||||||
|
// ... and labeling thread?
|
||||||
|
GLRenderer.drawlock.lock();
|
||||||
|
|
||||||
|
if (mInitialized) {
|
||||||
|
// pass VBOs and VertexItems back to pools
|
||||||
|
for (int i = 0; i < mTilesSize; i++)
|
||||||
|
clearTile(mTiles[i]);
|
||||||
|
} else {
|
||||||
|
// mInitialized is set when surface changed
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// clear all references to previous tiles
|
||||||
|
for (TileSet td : mTileSets) {
|
||||||
|
Arrays.fill(td.tiles, null);
|
||||||
|
td.cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set up TileSet large enough to hold current tiles
|
||||||
|
int num = Math.max(width, height);
|
||||||
|
int size = Tile.TILE_SIZE >> 1;
|
||||||
|
int numTiles = (num * num) / (size * size) * 4;
|
||||||
|
mNewTiles = new TileSet(numTiles);
|
||||||
|
mCurrentTiles = new TileSet(numTiles);
|
||||||
|
Log.d(TAG, "max tiles: " + numTiles);
|
||||||
|
|
||||||
|
mInitialized = true;
|
||||||
|
|
||||||
|
GLRenderer.drawlock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,75 +147,32 @@ public class TileManager {
|
|||||||
* available tiles are created and added to JobQueue (mapView.addJobs) for
|
* available tiles are created and added to JobQueue (mapView.addJobs) for
|
||||||
* loading by TileGenerator class
|
* loading by TileGenerator class
|
||||||
*
|
*
|
||||||
* @param clear
|
* @param mapPosition
|
||||||
* whether to clear and reload all tiles
|
* current MapPosition
|
||||||
*/
|
*/
|
||||||
public synchronized void updateMap(final boolean clear) {
|
public synchronized void updateMap(MapPosition mapPosition) {
|
||||||
boolean changedPos = false;
|
if (!mInitialized) {
|
||||||
|
Log.d(TAG, "not initialized");
|
||||||
if (mMapView == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (clear || !mInitialized) {
|
|
||||||
// make sure onDrawFrame is not running
|
|
||||||
// - and labeling thread?
|
|
||||||
GLRenderer.drawlock.lock();
|
|
||||||
|
|
||||||
// clear all tiles references
|
|
||||||
Log.d(TAG, "CLEAR " + mInitialized);
|
|
||||||
|
|
||||||
if (clear) {
|
|
||||||
// pass VBOs and VertexItems back to pools
|
|
||||||
for (int i = 0; i < mTilesSize; i++)
|
|
||||||
clearTile(mTiles[i]);
|
|
||||||
} else {
|
|
||||||
// mInitialized is set when surface changed
|
|
||||||
// and VBOs might be lost
|
|
||||||
VertexPool.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
QuadTree.init();
|
|
||||||
|
|
||||||
Arrays.fill(mTiles, null);
|
|
||||||
mTilesSize = 0;
|
|
||||||
mTilesCount = 0;
|
|
||||||
|
|
||||||
for (TileSet td : mTileSets) {
|
|
||||||
Arrays.fill(td.tiles, null);
|
|
||||||
td.cnt = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up TileData arrays that are passed to gl-thread
|
|
||||||
int num = Math.max(mWidth, mHeight);
|
|
||||||
int size = Tile.TILE_SIZE >> 1;
|
|
||||||
int numTiles = (num * num) / (size * size) * 4;
|
|
||||||
mNewTiles = new TileSet(numTiles);
|
|
||||||
mCurrentTiles = new TileSet(numTiles);
|
|
||||||
|
|
||||||
// make sure mMapPosition will be updated
|
|
||||||
mMapPosition.zoomLevel = -1;
|
|
||||||
mInitialized = true;
|
|
||||||
|
|
||||||
GLRenderer.drawlock.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapPosition mapPosition = mMapPosition;
|
//MapPosition mapPosition = mMapPosition;
|
||||||
float[] coords = mTileCoords;
|
float[] coords = mTileCoords;
|
||||||
|
|
||||||
synchronized (mMapViewPosition) {
|
//synchronized (mMapViewPosition) {
|
||||||
changedPos = mMapViewPosition.getMapPosition(mapPosition);
|
// changedPos = mMapViewPosition.getMapPosition(mapPosition);
|
||||||
mMapViewPosition.getMapViewProjection(coords);
|
mMapViewPosition.getMapViewProjection(coords);
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (changedPos) {
|
//if (changedPos) {
|
||||||
mMapView.render();
|
// mMapView.render();
|
||||||
} else {
|
//} else {
|
||||||
return;
|
// 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) {
|
||||||
|
|||||||
@@ -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 (AndroidUtils.currentThreadIsUiThread()) {
|
if (mClearMap){
|
||||||
boolean changed = mMapViewPosition.getMapPosition(mMapPosition);
|
mTileManager.init(mWidth, mHeight);
|
||||||
|
mClearMap = false;
|
||||||
|
|
||||||
mOverlayManager.onUpdate(mMapPosition, changed);
|
// make sure mMapPosition will be updated
|
||||||
|
mMapPosition.zoomLevel = -1;
|
||||||
|
|
||||||
|
// TODO clear overlays
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean changed = mMapViewPosition.getMapPosition(mMapPosition);
|
||||||
|
|
||||||
|
//Log.d(TAG, "redraw " + changed + " " + forceRedraw);
|
||||||
|
|
||||||
|
// required when not changed?
|
||||||
|
if (AndroidUtils.currentThreadIsUiThread())
|
||||||
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user