TileView的绘制流程
2017-05-11 15:29:20 0 举报
开源项目tileView的绘制流程
作者其他创作
大纲/内容
TileView
计算当前视角对应的Tile(用Snapshot来存储)
各种回调
mDetailLevelManager.updateViewport
if( detailLevelChanged ) { if( mDetailLevelChangeListener != null ) { mDetailLevelChangeListener.onDetailLevelChanged( mCurrentDetailLevel ); } }
TileCanvasViewGroup#mTilesInCurrentViewport初始化流程
TileView#resume public void resume() { setWillNotDraw( false ); updateViewport(); mTileCanvasViewGroup.updateTileSet( mDetailLevelManager.getCurrentDetailLevel() );//key point requestRender(); requestLayout(); }
getVisibleTilesFromLastViewportComputation
getRelativeScale()
// are there any new tiles the Executor isn't already aware of? boolean wereTilesAdded = mTilesInCurrentViewport.addAll( mDetailLevelToRender.getVisibleTilesFromLastViewportComputation() );
mDetailLevelChangeListener的初始化
invalidate
addDetailLevel
利用了Set#addAll的返回值得技巧来判断是否有数据变化
cleanup()
DetailLevelManager
mDetailLevelToRender.computeCurrentState()
int rowStart = (int) Math.floor( viewport.top / offsetHeight );int rowEnd = (int) Math.ceil( viewport.bottom / offsetHeight );int columnStart = (int) Math.floor( viewport.left / offsetWidth )int columnEnd = (int) Math.ceil( viewport.right / offsetWidth );
TileCanvasViewGroup#mDetailLevelToRender初始化流程
#computeCurrentState
drawableHeight = mDetailLevelManager.getScaledHeight();
#requestRender()
markTilesAsPrevious
TileCanvasViewGroup
mTilesInCurrentViewport.addAll
#drawTiles(Canvas)
updateTileSet
beginRenderTask
requestRender
drawableWidth = mDetailLevelManager.getScaledWidth()
mTileRenderPoolExecutor.queue
获取世界地图的大小(scale的)
beginRenderTask: 内部流
Rect viewport = new Rect( mDetailLevelManager.getComputedViewport() );
TileCanvasViewGroup#updateTileSet
Client
onDraw
备注依赖
TileCanvasViewGroup#updateTileSet public void updateTileSet( DetailLevel detailLevel ) { if( detailLevel == null ) { return; } if( detailLevel.equals( mDetailLevelToRender ) ) { return; } cancelRender(); markTilesAsPrevious(); mDetailLevelToRender = detailLevel; requestRender(); }
#addTileToCanvas
#onDraw()
requestRender最终会调用的onDraw
getCurrentDetailLevel()
TileCanvasViewGroup#mPreviouslyDrawnTiles初始化流程
public float getRelativeScale() { return mDetailLevelManager.getScale() / mScale; }
DetailLevelManager#mScale值得修改有两个来源:1. 直接调用TileView的setScale/该方法继承与ZoomPanLayout2. onScaleChanged会有回调自动调用
update
changed?
有这几个地方会导致绘制:1. 显示调用requestRender()/requestThrottledRender()2. onResume()-requestRender()
private void markTilesAsPrevious() { for( Tile tile : mTilesInCurrentViewport ) { if( tile.getState() == Tile.State.DECODED ) { mPreviouslyDrawnTiles.add( tile ); } } mTilesInCurrentViewport.clear(); }
DetailLevel
其中的Viewport更新分为:1. TileView#resume-updateViewport()2. TileView#onLayout -updateViewPort()3. TileView#onScrollChanged-updateViewPort()
这里面对requestRender所需要的成员变量进行了初始化
根据当前的世界地图计算视角
0 条评论
下一页
为你推荐
查看更多