webview渲染流程
<span style="color: #000000;">文档标记说明</p><p>################# 消息边界</p><p></span>+++++++++++++++++<span style="color: #000000;"> 区域分隔 </p><p>$$$$$$$$$$$$$$$$$ 线程边界</p><p></span>~~~~~~~~~~~~~~~~~<span style="color: #000000;"> 进程边界</p><p></span>-----------------<span style="color: #000000;"> 代码块功能模块分隔</p><p></span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>创建GLES20Canvas Render</p><p>GLES20Canvas() [GLES20Canvas.java]</p><p> </span>|--><span style="color: #000000;"> android_view_GLES20Canvas_createLayerRenderer() [android_view_GLES20Canvas.cpp]</p><p> </span>|--> OpenGLRenderer* renderer = <span style="color: #0000ff;">new</span><span style="color: #000000;"> LayerRenderer(layer);</p><p></span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>Fragment </p><p> </span>|-->LocalActivityManager.startActivity() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">LocalActivityManager.java]</p><p> </span>|-->LocalActivityManager.moveToState() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">LocalActivityManager.java]</p><p> </span>|-->ActivityThread.startActivityNow() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">ActivityThread.java]</p><p></span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p><p>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>Launcher 启动 Activity 流程</p><p></span>|--><span style="color: #000000;">Activity.startActivity()</p><p> </span>|--><span style="color: #000000;">mInstrumentation.execStartActivity()</p><p> </span>|--><span style="color: #000000;">ActivityManagerProxy.startActivity() </p><p>~~~~~~~~~~~~~~~~~~~~~~</span>| |<span style="color: #000000;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><p>Process.ActivityManagerService </p><p> </span>|--><span style="color: #000000;">ActivityManagerService.startActivityAsUser</p><p> </span>|--><span style="color: #000000;"> ...</p><p> </span>|-->ActivityManagerService.startProcessLocked() [frameworks/<span style="color: #0000ff;">base</span>/services/java/com/android/server/am/<span style="color: #000000;">ActivityManagerService.java]</p><p>~~~~~~~~~~~~~~~~~~~~~~</span>| |<span style="color: #000000;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><p>Process.Activity</p><p> </span>|--><span style="color: #000000;">ActivityThread.main()</p><p> </span>|-->ActivityThread.attach(<span style="color: #0000ff;">false</span><span style="color: #000000;">)</p><p> </span>|-->ActivityManagerProxy.attachApplication() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">ActivityManagerNative.java]</p><p>~~~~~~~~~~~~~~~~~~~~~~</span>| |<span style="color: #000000;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><p>Process.ActivityManagerService </p><p> </span>|--><span style="color: #000000;">ActivityManagerService.attachApplication()</p><p> </span>|--><span style="color: #000000;">ActivityManagerService.attachApplicationLocked() </p><p> </span>|-->mMainStack.topRunningActivityLocked() [frameworks/<span style="color: #0000ff;">base</span>/services/java/com/android/server/am/<span style="color: #000000;">ActivityStack.java]</p><p> </span>|--><span style="color: #000000;">mMainStack.realStartActivityLocked()</p><p> </span>|-->ApplicationThreadProxy.scheduleLaunchActivity() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">ApplicationThreadNative.java]</p><p>~~~~~~~~~~~~~~~~~~~~~~</span>| |<span style="color: #000000;">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p><p>Process.Activity </p><p> </span>|--><span style="color: #000000;">ApplicationThread.scheduleLaunchActivity() </p><p> </span>|-->ApplicationThread.queueOrSendMessage() <span style="color: #008000;">//</span><span style="color: #008000;"> Binder</span></p><p>#########################| sendMessage |<span style="color: #000000;">################################################################### </p><p> H mH ActivityThread.mLooper </p><p>########################</span>| handleMessage|<span style="color: #000000;"> ################################################################## </p><p> </span>|--><span style="color: #000000;">ActivityThread.handleMessage </p><p> </span>|--><span style="color: #000000;">ActivityThread.handleLaunchActivity() </p><p> . </span>|--><span style="color: #000000;">ActivityThread.performLaunchActivity() </p><p> . </span>|-->mInstrumentation.newActivity() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Instrumentation.java]</p><p> . </span>|-->LoadedApk.makeApplication() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">LoadedApk.java]</p><p> . </span>|--><span style="color: #000000;">ActivityThread.createBaseContextForActivity() </p><p> . </span>|-->activity.attach() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Activity.java]</p><p> . </span>|-->PolicyManager.makeNewWindow(<span style="color: #0000ff;">this)</span>[frameworks/<span style="color: #0000ff;">base</span>/core/j×/com/android/<span style="color: #0000ff;">inter</span>/policy/<span style="color: #000000;">PolicyManager.java]</p><p> . </span>|--><span style="color: #000000;">PhoneWindow.setWindowManager()</p><p> . </span>|--><span style="color: #000000;">getSystemService(Context.WINDOW_SERVICE)</p><p> . </span>|--><span style="color: #000000;">WindowManagerImpl.createLocalWindowManager(); 创建窗口mWindowManager</p><p> . </span>|--><span style="color: #000000;">mInstrumentation.callActivityOnCreate() </p><p> . </span>|-->activity.performCreate() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Activity.java]</p><p> . </span>|--><span style="color: #000000;">Activity.onCreate()</p><p> . </span>|--><span style="color: #000000;">Activity.setContentView()</p><p> . </span>|-->PhoneWindow.setContentView() [*/policy/impl/<span style="color: #000000;">PhoneWindow.java]</p><p> . </span>|--><span style="color: #000000;">PhoneWindow.installDecor()</p><p> . </span>|-->mContentParent =<span style="color: #000000;"> PhoneWindow.generateLayout(mDecor)</p><p> . </span>|-->activity.performStart() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Activity.java]</p><p> . </span>|--><span style="color: #000000;">mInstrumentation.callActivityOnRestoreInstanceState() </p><p> . </span>|-->activity.performRestoreInstanceState() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Activity.java]</p><p> . </span>|-->mInstrumentation.callActivityOnPostCreate() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Instrumentation.java]</p><p> . </span>|-->activity.onPostCreate() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/app/<span style="color: #000000;">Activity.java]</p><p> </span>|--><span style="color: #000000;">ActivityThread.handleResumeActivity() 激活 Activity</p><p> </span>|--><span style="color: #000000;">ActivityThread.performResumeActivity()</p><p> </span>|--><span style="color: #000000;">Activity.performResume()</p><p> </span>|--><span style="color: #000000;">Activity.performRestart()</p><p> . </span>|--><span style="color: #000000;">Instrumentation.callActivityOnRestart()</p><p> . </span>|--><span style="color: #000000;">Activity.onRestart()</p><p> </span>|--><span style="color: #000000;">Activity.performStart() </p><p> . </span>|--><span style="color: #000000;">Instrumentation.callActivityOnStart()</p><p> . </span>|--><span style="color: #000000;">Activity.onStart()</p><p> </span>|--><span style="color: #000000;">Instrumentation.callActivityOnResume()</p><p> . </span>|--><span style="color: #000000;">Activity.onResume()</p><p> </span>|--><span style="color: #000000;">Activity.onPostResume()</p><p> </span>|-->WindowManagerImpl.addView() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">WindowManagerImpl.java]</p><p> </span>|-->WindowManagerGlobal.addView() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">WindowManagerGlobal.java]</p><p> </span>|-->root = <span style="color: #0000ff;">new</span><span style="color: #000000;"> ViewRootImpl() 创建root 绑定窗口系统</p><p> </span>|--><span style="color: #000000;">ViewRootImpl.setView(PhoneWindow.getDecorView()) </p><p> </span>|-->mAttachInfo.mRootView =<span style="color: #000000;"> DecorView;</p><p> </span>/<----------------------|--><span style="color: #000000;">ViewRootImpl.requestLayout() 第一次布局调度</p><p> </span>| |--><span style="color: #000000;">(DecorView)view.assignParent(ViewRootImpl) </p><p> </span>| </p><p> |</p><p> |</p><p> | </p><p> |</p><p> |</p><p> |</p><p>+++++++++++++++++|+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>sw 渲染流程 </span>|<span style="color: #000000;"></p><p> \</span>/</p><p>|--><span style="color: #000000;">ViewRootImpl.requestLayout() </p><p></span>|--><span style="color: #000000;">ViewRootImpl.invalidate() </p><p> </span>|-->ViewRootImpl.scheduleTraversals [frameroks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewRootImpl.java] </p><p> </p><p>#########################</span>| postCallback |<span style="color: #000000;">############################################################# </p><p> ViewRootImple.ViewRootHandler mHandler </p><p>########################</span>| Callback|<span style="color: #000000;"> ################################################################## </p><p></span><@@MessageHandler name=Travdersalrunnable > </p><p>|-->ViewRootImpl.TraversalRunnable.run() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewRootImpl.java] </p><p> </span>|-->ViewRootImpl.doTraversal() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewRootImpl.java] </p><p> </span>|-->ViewRootImpl.performTraversals() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewRootImpl.java] </p><p> </span>|--><span style="color: #000000;">ViewRootImpl.performMeasure() or ViewRootImpl.measureHierarchy(view host) 计算subtree</p><p> </span>|--><span style="color: #000000;">ViewRootImpl.performLayout()</p><p> </span>|--><span style="color: #000000;">ViewRootImpl.measureHierarchy()</p><p> </span>|--><span style="color: #000000;">DecorView.layout()</p><p> </span>|--><span style="color: #000000;">ViewRootImpl.performDraw() </p><p> </span>|--><span style="color: #000000;">ViewRootImpl.draw() </p><p> </span>/----->|--><span style="color: #000000;">ViewGroup.drawChild() </p><p> </span>| |--><span style="color: #000000;">View.draw(Canvas,ViewGroup) </p><p> </span>| |-->{ <span style="color: #0000ff;">if</span><span style="color: #000000;">( hasDisplayList) } </p><p> </span>| . |((HardwareCanvas) canvas).drawDisplayList() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">HardwareCanvas.java]</p><p>sw </span>| . |-->GLES20Canvas.drawDisplayList() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">GLES20Canvas.java]</p><p> </span>| . |-->android_view_GLES20Canvas_drawDisplayList() [frameworks/<span style="color: #0000ff;">base</span>/core/jni/<span style="color: #000000;">android_view_GLES20Canvas.cpp]</p><p> </span>| . |--><span style="color: #000000;">OpenGLRenderer::drawDisplayList()</p><p> </span>|<span style="color: #000000;"> .</p><p> </span>| |-->view.draw(Canvas) [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">view.java]</p><p> </span>| |-->background.draw(canvas) <span style="color: #800080;">1</span><span style="color: #000000;">. Draw the background</p><p> </span>| |-->canvas.saveLayer() <span style="color: #800080;">2</span>. save the canvas<span style="color: #800000;">'</span><span style="color: #800000;"> layers</span></p><p> | |-->ViewGroup.dispatchDraw(canvas) <span style="color: #800080;">4</span>. Draw children [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewGroup.java]</p><p> \</span><--------------------|--><span style="color: #000000;">ViewGroup.drawChild()</p><p> </span>|-->canvas.drawRect <span style="color: #800080;">5</span><span style="color: #000000;">. draw the fading edges and restore layers</p><p> </span>|-->View.onDrawScrollBars <span style="color: #800080;">6</span>. Draw decorations [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/<span style="color: #000000;">ViewGroup.java]</p><p> </span>|-->View.onDraw(canvas) <span style="color: #800080;">3</span>. Draw view<span style="color: #800000;">'</span><span style="color: #800000;">s content</span></p><p> || </p><p>--------------------------------||----------------------------------------------------------------------------------------------------------<span style="color: #000000;"></p><p> webview \</span>/</p><p> |--><span style="color: #000000;">onDraw(Canvas canvas) [WebViewClassic.java]</p><p> </span>|--><span style="color: #000000;">drawContent(Canvas canvas) [WebViewClassic.java]</p><p> </span>----------------------------------------------------------------------------------------------------------------</p><p> |-->nativeDraw(canvas, mVisibleContentRect, mBackgroundColor) [webkit/android/nav/<span style="color: #000000;">WebView.cpp]</p><p> sw . </span>|-->draw() [webkit/android/nav/<span style="color: #000000;">WebView.cpp]</p><p> . { m_baseLayer</span>-><span style="color: #000000;">draw() } </p><p> . </span>|--> Layer::draw() [frameworks/native/services/surfaceflinger/<span style="color: #000000;">layer.cpp]</p><p> . </span>|--> Layer::onDraw() [frameworks/native/services/surfaceflinger/<span style="color: #000000;">layer.cpp]</p><p> .</p><p> </span>---------------------------------------------------------------------------------------------------------------- </p><p> |-->functor = nativeCreateDrawGLFunction() [webkit/android/nav/<span style="color: #000000;">WebView.cpp]</p><p> </span>|-->((HardwareCanvas) canvas).callDrawGLFunction(functor) [*/android/webkit/<span style="color: #000000;">WebViewClassic.java] </p><p> </span>|--><span style="color: #000000;">callDrawGLFunction() [GLES20Canvas.java]</p><p> hw </span>|--><span style="color: #000000;"> android_view_GLES20Canvas_callDrawGLFunction() [android_view_GLES20Canvas.cpp] </p><p> </span>|-->OpenGLRenderer::callDrawGLFunction() [frameworks/<span style="color: #0000ff;">base</span>/libs/hwui/<span style="color: #000000;">OpenGLRenderer.cpp]</p><p> </span>|--> mFunctors.add(functor); -------><span style="color: #000000;">\ </p><p> ###################################</span>| add |#########################################################|<span style="color: #000000;">######### </p><p> SortedVector</span><Functor*> mFunctors 异步 |<span style="color: #000000;"></p><p> ##################################</span>| invoke| #######################################################|<span style="color: #000000;">######### </span>| |</p><p> |</p><p> |</p><p>-------------------------------------------------------------------------------------------------------------------------------|----------<span style="color: #000000;"> </p><p>hw 渲染流程 </span>|</p><p> |</p><p>|-->ViewRootImpl.requestLayout() |</p><p>|-->ViewRootImpl.invalidate() | </p><p> |-->ViewRootImpl.scheduleTraversals [frameroks/<span style="color: #0000ff;">base</span>/core/java/android/view/ViewRootImpl.java] |</p><p> |<span style="color: #000000;"></p><p>#########################</span>| postCallback |############################################################# |<span style="color: #000000;"> </p><p> ViewRootImple.ViewRootHandler mHandler </span>|<span style="color: #000000;"> </p><p>########################</span>| Callback| ################################################################## |</p><p><@@MessageHandler name=Travdersalrunnable > |</p><p>|-->ViewRootImpl.TraversalRunnable.run() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/ViewRootImpl.java] | </p><p> |-->ViewRootImpl.doTraversal() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/ViewRootImpl.java] |</p><p> |-->ViewRootImpl.performTraversals() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/ViewRootImpl.java] |</p><p> |-->ViewRootImpl.performMeasure() or ViewRootImpl.measureHierarchy(view host) 计算subtree |</p><p> |-->ViewRootImpl.performLayout() |</p><p> |-->ViewRootImpl.measureHierarchy() |</p><p> |-->DecorView.layout() |<span style="color: #000000;"></p><p>hw </span>|-->ViewRootImpl.performDraw() |</p><p> |-->ViewRootImpl.draw() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/ViewRootImpl.java] |<span style="color: #000000;"></p><p> { attachInfo.mHardwareRenderer.draw } </span>|</p><p> |-->hardwareRenderer.draw() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/hardwareRenderer.java] | </p><p> |-->hardwareRenderer.drawDisplayList() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/hardwareRenderer.java] |</p><p> |-->handleFunctorStatus() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/HardwareRenderer.java] |</p><p> |-->mHandler.postDelayed() [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/HardwareRenderer.java] |</p><p> |</p><p><@@/MessageHandler> |<span style="color: #000000;"></p><p>###################################</span>| post |###################################################################### |<span style="color: #000000;"></p><p> View.Handler mHandler </span>= ViewRootImple.ViewRootHandler mHandler |<span style="color: #000000;"></p><p>#################################</span>| CallBack |###################################################################### | </p><p> |-->HardwareRenderer.HardwareFunctorsRunnable.run [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/HardwareRenderer.java] |<span style="color: #000000;"></p><p> { mCanvas.invokeFunctors(mRedrawClip) } </span>|</p><p> |-->GLES20Canvas.invokeFunctors [frameworks/<span style="color: #0000ff;">base</span>/core/java/android/view/GLES20Canvas.java] |</p><p> |--> android_view_GLES20Canvas_invokeFunctors [framework/<span style="color: #0000ff;">base</span>/core/jni/android_view_GLES20Canvas.cpp] |</p><p> |-->OpenGLRenderer::invokeFunctors [frameworks/<span style="color: #0000ff;">base</span>/libs/hwui/OpenGLRenderer.cpp] <---------------------------/<span style="color: #000000;"></p><p> { Functor</span>* f = functors.itemAt(i); result |= (*f)(DrawGlInfo::kModeProcess, &<span style="color: #000000;">info) }</p><p> </span>|-->GLDrawFunctor() <-- (*wvInstance.*funcPtr)() [webkit/android/nav/<span style="color: #000000;">WebView.cpp:GLDrawFunctor]</p><p> </span>|-->drawGL() [webkit/android/nav/<span style="color: #000000;">WebView.cpp]</p><p> </span>|-->m_glWebViewState = <span style="color: #0000ff;">new</span><span style="color: #000000;"> GLWebViewState()</p><p> </span>|-->(GLWebViewState)m_glWebViewState->drawGL() [webkit/android/nav/<span style="color: #000000;">GLWebViewState.cpp]</p><p> </span>|-->tilesManager = TilesManager::instance() [webcore/platform/graphics/android/rendering/<span style="color: #000000;">TilesManager.cpp]</p><p> </span>|-->tilesManager->updateTilesIfContextVerified() <span style="color: #008000;">//</span><span style="color: #008000;"> 创建/更新 Tile纹理</span></p><p> . |--><span style="color: #000000;">TransferQueue::updateDirtyTiles() </p><p> . . </span>|--><span style="color: #000000;">TransferQueue.updatePureColorTiles()</p><p> . . #################################################</span>| TexturesGenerator.add |<span style="color: #000000;">#######</p><p> . . TileManager</span>-><span style="color: #000000;">m_transferQueue</p><p> . . ######################</span>| |<span style="color: #000000;">###################################################</p><p> . . { </span><span style="color: #0000ff;">for</span> each Item <span style="color: #0000ff;">in</span><span style="color: #000000;"> m_transferQueueSize }</p><p> </span>---------------------.--------------------------------------------------------------------------------------------------------<span style="color: #000000;"></p><p> GpuUpload . . </span>|-->(GLConsumer)m_sharedSurfaceTexture->updateTexImage() [frameworks/native/libs/gui/<span style="color: #000000;">GLConsumer.cpp]</p><p> . . . </span>|-->GLConsumer.acquireBufferLocked(&<span style="color: #000000;">item) </p><p> . . . </span>|-->ConsumerBase::acquireBufferLocked(item) [frameworks/native/libs/gui/<span style="color: #000000;">ConsumerBase.cpp]</p><p> . . . </span>|-->mBufferQueue->acquireBuffer(item) [frameworks/native/libs/gui/<span style="color: #000000;">BufferQueue.cpp]</p><p> . . .</p><p> . . . </span>-------------| <span style="color: #0000ff;">set</span> mbuf(slotindex)|------------------------------------------------<span style="color: #000000;"></p><p> . . . Slot mSlots[]</p><p> . . . </span>---------------| mCurrentTexture |--------------------------------------------------<span style="color: #000000;"> </p><p> . . . </p><p> . . . </span>|-->GLConsumer.releaseAndUpdateLocked(item) <span style="color: #800080;">1</span>. item.mgraphicBuffer-><span style="color: #000000;">EGLImage Tile</p><p> . . .</p><p> . . . </span>---------------------------| <span style="color: #0000ff;">set</span> |--------------------------------------------------------<span style="color: #000000;"></p><p> . . . mEglSlots[buf].mEglImage</p><p> . . . </span>----------------------| mCurrentTexture |--------------------------------------------------<span style="color: #000000;"></p><p> . . .</p><p> . . . </span>|--><span style="color: #000000;">GLConsumer.bindTextureImageLocked() </p><p> . . . </span>|-->glEGLImageTargetTexture2DOES() <span style="color: #800080;">2</span>. EGLImage -><span style="color: #000000;"> texture m_sharedSurfaceTextureId</p><p> . . . </span>|-->GLConsumer::doGLFenceWaitLocked() <span style="color: #008000;">//</span><span style="color: #008000;"> Wait for the new buffer to be ready.</span></p><p> ---------------------.-------------------------------------------------------------------------------------------------------<span style="color: #000000;"> </p><p> . . </span>|-->destTexture-><span style="color: #000000;">requireGLTexture()</p><p> </span>---------------------.-------------------------------------------------------------------------------------------------------<span style="color: #000000;"></p><p> CpuUpload . . </span>|--><span style="color: #000000;">GLUtils::updateTextureWithBitmap(TileTexture.m_ownTextureId,m_transferQueue[index].bitmap)</p><p> </span>---------------------.-------------------------------------------------------------------------------------------------------<span style="color: #000000;"></p><p> GpuUpload . . </span>|-->TransferQueue::blitTileFromQueue() m_sharedSurfaceTextureId->m_fboID-><span style="color: #000000;">TileTexture.m_ownTextureId</p><p> </span>---------------------.-------------------------------------------------------------------------------------------------------<span style="color: #000000;"></p><p> . . </span>|-->m_transferQueueItemCond.signal() --------------------------------------------------------------><span style="color: #000000;">\</p><p> </span>|</p><p> |-->tilesManager->gatherTextures() |</p><p> |-->ImagesManager::instance()->prepareTextures[webcore/platform/graphics<span style="color: #008000;">/*</span><span style="color: #008000;">/rendering/ImagesManager.cpp] |</p><p> |-->GLWebViewState::setupDrawing() [webkit/android/nav/GLWebViewState.cpp] |</p><p> . |-->tilesManager->shader()->initGLResources()[webcore/plat/gfx/</span><span style="color: #008000;">*/</span>rendering/ShaderProgram.cpp] |<span style="color: #000000;"></p><p> . </span>|-->tilesManager->transferQueue()->initGLResources() init fbo,bufferQueue,GLConsumer sharedSurface |<span style="color: #000000;"></p><p> painting . </span>|-->shader->setupDrawing() |<span style="color: #000000;"></p><p> . </span>|</p><p> |-->SurfaceCollectionManager::drawGL() [webcore/plat*/gfx/rendering/SurfaceCollectionManager.cpp] |</p><p> ------------------------------------------------------------------------------------------------------------------------------|-----<span style="color: #000000;"></p><p> m_paintingCollection </span>|-->m_paintingCollection->prepareGL() [webcore/plat*/gfx/rendering/SurfaceCollection.cpp] |<span style="color: #000000;"></p><p> . { m_paintingCollection</span>->isReady() } |<span style="color: #000000;"></p><p> . </span>|-->SurfaceCollectionManager.swap() |<span style="color: #000000;"></p><p> . </span>|-->m_drawingCollection = m_paintingCollection; paintingcollection->drawingcollection |<span style="color: #000000;"></p><p> . </span>|-->m_paintingCollection = m_queuedCollection; drawingcollection->m_paintingCollection |<span style="color: #000000;"></p><p> . </span>|-->m_queuedCollection = <span style="color: #800080;">0</span> ; |</p><p> ----or------------------------------------------------------------------------------------------------------------------------|-----<span style="color: #000000;"></p><p> m_drawingCollection </span>|-->m_paintingCollection->prepareGL() [webcore/plat*/gfx/rendering/SurfaceCollection.cpp] |</p><p> ------------------------------------------------------------------------------------------------------------------------------|-----<span style="color: #000000;"></p><p> {either a swap just occurred, or there </span><span style="color: #0000ff;">is</span> no more work to be done: <span style="color: #0000ff;">do</span> a full draw} |</p><p> |-->m_drawingCollection->swapTiles() |<span style="color: #000000;"></p><p> {(didCollectionSwap </span>&& m_paintingCollection)} |</p><p> |-->m_paintingCollection->prepareGL() |</p><p> ------------------------------------------------------------------------------------------------------------------------------|-----</p><p> |-->SurfaceCollection::prepareGL() |<span style="color: #000000;"></p><p> . { </span><span style="color: #0000ff;">for</span> each surface <span style="color: #0000ff;">in</span> WTF::Vector<Surface*> m_surfaces } |<span style="color: #000000;"></p><p> . </span>|-->m_surfaces[i]->prepareGL() [webcore/plat*/gfx/rendering/Surface.cpp] |<span style="color: #000000;"></p><p> . </span>|-->m_surfaceBacking->prepareGL() |</p><p> ---------------------------------------------------------------------------------------------------------|------<span style="color: #000000;"></p><p> . </span>|-->m_backTileGrid->prepareGL() |<span style="color: #000000;"></p><p> . </span>|-->SurfaceBacking.swapTileGrids() [webcore/plat*/gfx/rendering/SurfaceBacking.cpp] |<span style="color: #000000;"></p><p> . </span>|-->m_frontTileGrid->swapTiles() |</p><p> ---------------------------------------------------------------------------------------------------------|------<span style="color: #000000;"></p><p> . </span>|-->m_frontTileGrid->prepareGL() |</p><p> ---------------------------------------------------------------------------------------------------------|------<span style="color: #000000;"></p><p> . </span>|-->TileGrid::prepareGL() m_backTileGrid m_frontTileGrid m_lowResTileGrid |<span style="color: #000000;"></p><p> . </span>|-->TileGrid.computeTilesArea() [webcore/plat*/gfx/rendering/TileGrid.cpp] |<span style="color: #000000;"></p><p> . { </span><span style="color: #0000ff;">for</span> each (x,y) <span style="color: #0000ff;">in</span> m_area } |<span style="color: #000000;"></p><p> . </span>|-->TileGrid.prepareTile(x,y) |<span style="color: #000000;"></p><p> . </span>|-->Tile* tile = getTile(x, y) |<span style="color: #000000;"></p><p> . </span>|-->tile->setContents() |<span style="color: #000000;"></p><p> . </span>|-->operation = <span style="color: #0000ff;">new</span> PaintTileOperation[*/PaintTileOperation.cpp] |<span style="color: #000000;"></p><p> . </span>|-->tilesManager->scheduleOperation(operation) |<span style="color: #000000;"></p><p> . </span>|-->m_textureGenerators[m_scheduleThread]->scheduleOperation() |<span style="color: #000000;"></p><p> . </span>|-->TexturesGenerator::scheduleOperation () |<span style="color: #000000;"></p><p> . </span>|-->mRequestedOperations.append(operation) |<span style="color: #000000;"></p><p> . ##############################</span>| |####################### |<span style="color: #000000;"></p><p> . . WTF::Vector</span><QueuedOperation*> mRequestedOperations |<span style="color: #000000;"></p><p> . . ################################################################# </span>|</p><p> /<-------------------------------------- |-->mRequestedOperationsCond.signal() |</p><p> ----------------------|--------.------------------------------------------------------------------------------------------------------|------- </p><p> | |-->m_drawingCollection->drawGL() [webcore/plat*/gfx/rendering/SurfaceCollection.cpp] |</p><p> | |-->(BaseLayerAndroid*)m_compositedRoot->drawTreeSurfacesGL() |</p><p> | /-----> |-->LayerAndroid::drawTreeSurfacesGL() |</p><p> | | |-->LayerAndroid.drawSurfaceAndChildrenGL [webcore/plat*/gfx/android/LayerAndroid.cpp] |</p><p> | | ( { <span style="color: #0000ff;">this</span>.surface()->getFirstLayer() == <span style="color: #0000ff;">this</span> } ) |</p><p> | /<--|---------------|-->surface()->drawGL() |</p><p> | | | |-->Layer::getChild() |</p><p> | | | |-->sublayers.append(SkTDArray<Layer*> m_children) |</p><p> | | | { <span style="color: #0000ff;">for</span> each layer <span style="color: #0000ff;">in</span> sublayers } |</p><p> | | \---loop--------|-->sublayers[i]->drawTreeSurfacesGL() |</p><p> | | |</p><p> | \------------------>|-->Surface::drawGL() [webcore/plat*/gfx/rendering/SurfaceCollection.cpp] |</p><p> | |-->m_surfaceBacking->drawGL |</p><p> | . { draw low res prefetch page <span style="color: #0000ff;">if</span> zooming or front texture missing content } |</p><p> | . |-->m_lowResTileGrid->drawGL() aggressiveRendering && isMissingContent() |</p><p> | . |-->m_frontTileGrid->drawGL() |</p><p> | . |-->m_area=TileGrid.computeTilesArea() |</p><p> | . |{ <span style="color: #0000ff;">for</span> each tile <span style="color: #0000ff;">in</span> TileGrid.m_tiles} |</p><p> | . |-->Tile* tile = m_tiles[i] |</p><p> | . |-->tile->isTileVisible(m_area) <span style="color: #0000ff;">if</span>(tile <span style="color: #0000ff;">in</span> m_area) |<span style="color: #000000;"></p><p> Compositing </span>| . |-->tile->drawGL() |</p><p> | . |-->m_frontTexture->drawGL() |</p><p> | . |-->TilesManager::instance()->shader()->drawQuad() |</p><p> | . |-->matrix = getTileProjectionMatrix(data) drawGl Position |</p><p> | . |-->ShaderProgram.drawQuadInternal() |</p><p> | .{ <span style="color: #008000;">//</span><span style="color: #008000;"> draw member layers (draws image textures, glextras) } |</span></p><p> | .{ <span style="color: #0000ff;">for</span> each layer <span style="color: #0000ff;">in</span> Vector<LayerAndroid*> m_layers } |</p><p> | |-->m_layers[i]->drawGL() |</p><p> | |</p><p> | |</p><p> | |</p><p> ---------------------|---------------------------------------------------------------------------------------------------------------|------- </p><p> | <span style="color: #800080;">1</span> |<span style="color: #000000;"></p><p>$$$$$$$$$$$$$$$$$$$$$$$$$</span>|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$|<span style="color: #000000;">$$$$$$$$$</p><p>TexturesGenerator 线程</span>+++|++++++++++ 线程边界 | $$$$$$$$$$$$$$$$$$$$$$$$$|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$|<span style="color: #000000;">$$$$$$$$$</p><p> </span>|-->TexturesGenerator::th|readLoop() NUM_TEXTURES_GENERATORS | </p><p> |-->mRequestedOperati|onsCond.wait(mRequestedOperationsLock) |<span style="color: #000000;"></p><p> . </span>| +++++++++++++ |<span style="color: #000000;"></p><p> .#################</span>|###########################| wait |########################### |<span style="color: #000000;"> </p><p> . </span>| mRequestedOperationsCond |<span style="color: #000000;"></p><p> .###############</span>| |signal |###################################################### |<span style="color: #000000;"> </p><p> . </span>+++++++++++++ |<span style="color: #000000;"></p><p> .############################################################## </span>|<span style="color: #000000;"></p><p> . WTF::Vector</span><QueuedOperation*> mRequestedOperations |<span style="color: #000000;"></p><p> .#####################</span>| |############################## |</p><p> |-->currentOperation = popNext(); |</p><p> |-->BaseRenderer::swapRendererIfNeeded(m_renderer) |</p><p> |-->currentOperation->run(m_renderer) [webcore/plat*/gfx/rendering/PaintTileOperation.cpp] |</p><p> |-->m_tile->paintBitmap(m_painter, renderer) [webcore/plat*/gfx/rendering/Tile.cpp] |</p><p> |-->TextureInfo* textureInfo = texture->getTextureInfo() [webcore/plat*/gfx/rendering/TileTexture.h] |</p><p> |-->(BaseRenderer)renderer->renderTiledContent(renderInfo) [webcore/plat*/gfx/rendering/BaseRenderer.cpp] |</p><p> |-->InstrumentedPlatformCanvas canvas() [webcore/plat*/gfx/rendering/InstrumentedPlatformCanvas.cpp] |</p><p>--------------------------------------------------------------------------------------------------------------------------------------- |<span style="color: #000000;"></p><p>RasterRenderer </span>|-->RasterRenderer::setupCanvas 子类override [webcore/plat*/gfx/rendering/RasterRenderer.cpp] |<span style="color: #000000;"></p><p> . </span>|-->SkDevice* device = <span style="color: #0000ff;">new</span> SkDevice(m_bitmap) |<span style="color: #000000;"></p><p> . </span>|-->canvas->setDevice(device) |</p><p> |-->renderInfo.tilePainter->paint(&canvas); TilePainter子类override |</p><p> |-->BaseRenderer.checkForPureColor(renderInfo, canvas) 子类override [webcore/plat*/gfx/rendering/BaseRenderer.cpp] |<span style="color: #000000;"></p><p> . </span>|-->RasterRenderer::deviceCheckForPureColor(renderInfo, &canvas) |</p><p> |-->RasterRenderer::renderingComplete(RasterRenderer.cpp) |<span style="color: #000000;"></p><p> . </span>|-->GLUtils::paintTextureWithBitmap() [webcore/plat*/gfx/rendering/GLUtils.cpp] |</p><p> ------------------------------------------------------------------------------------------------------------------ |<span style="color: #000000;"></p><p> . </span>|-->GLUtils::skipTransferForPureColor(renderInfo, bitmap) |<span style="color: #000000;"></p><p> . . </span>|-->TilesManager::instance()->transferQueue()->addItemInPureColorQueue(renderInfo) |<span style="color: #000000;"></p><p> . . </span>|-->TransferQueue.addItemCommon(renderInfo, GpuUpload, (TileTransferData)&data) |</p><p> -------------.---------------------------------------------------------------------------------------------------- |<span style="color: #000000;"></p><p> . </span>|-->GLUtils::updateQueueWithBitmap() |<span style="color: #000000;"></p><p> . </span>|-->TilesManager::instance()->transferQueue()->updateQueueWithBitmap(renderInfo, bitmap) |<span style="color: #000000;"></p><p> . </span>|-->TransferQueue::updateQueueWithBitmap |<span style="color: #000000;"></p><p> . . </span>|-->TransferQueue.tryUpdateQueueWithBitmap(renderInfo, bitmap) /<--------------<--+<span style="color: #000000;"></p><p> . . </span>|-->readyForUpdate() | |<span style="color: #000000;"></p><p> . . .########################</span>| wait |##########################################|####### |<span style="color: #000000;"></p><p> . . . m_transferQueueItemCond.wait(m_transferQueueItemLocks)sferQueueItemCond </span>| |<span style="color: #000000;"></p><p> . . .######################################################################</span>| signal |### |<span style="color: #000000;"></p><p> . . . </span>++++++++++ |</p><p> --------.--------------.-------.---------------------------------------------------------------------------------------- |<span style="color: #000000;"></p><p> . . </span>|-->GLUtils::updateSharedSurfaceTextureWithBitmap(m_ANW.<span style="color: #0000ff;">get</span>(), bitmap) |<span style="color: #000000;"></p><p> . . . </span>|-->ANativeWindow_Buffer buffer [frameworks/native/include/android/Native_window.h] |<span style="color: #000000;"></p><p> . . . </span>|-->ANativeWindow_lock(anw, &buffer, <span style="color: #800080;">0</span>) |<span style="color: #000000;"></p><p> GpuUpload . . . </span>|-->bitmap.lockPixels() |<span style="color: #000000;"></p><p> . . . </span>|-->buffer.bits <-- bitmap.getPixels() |<span style="color: #000000;"></p><p> . . . </span>|-->bitmap.unlockPixels() |<span style="color: #000000;"></p><p> . . . </span>|-->ANativeWindow_unlockAndPost() |</p><p> --------.--------------.-------.---------------------------------------------------------------------------------------- |<span style="color: #000000;"></p><p> . . </span>|-->TransferQueue.addItemInTransferQueue(renderInfo, currentUploadType, bitmap) |<span style="color: #000000;"></p><p> . . . </span>|-->m_transferQueueIndex = (m_transferQueueIndex + <span style="color: #800080;">1</span>) % m_transferQueueSize |<span style="color: #000000;"></p><p> . . . </span>|-->TileTransferData* data = &m_transferQueue[index] |<span style="color: #000000;"></p><p> . . . </span>|-->TransferQueue.addItemCommon(renderInfo, type, data) |</p><p> --------.--------------.-------.---------------------------------------------------------------------------------------- |<span style="color: #000000;"></p><p> CpuUpload . . . </span>|-->(*m_transferQueue[index].bitmap) = bitmap |</p><p> --------.--------------.------------------------------------------------------------------------------------------------ |<span style="color: #000000;"></p><p> . </span>|-->tile->backTextureTransferFail() mark to be retransferred |</p><p>------------------.----------------------------------------------------------------------------------------------------------------- |<span style="color: #000000;"> GaneshRenderer </span>|-->GaneshRenderer::setupCanvas() [webcore/plat*/gfx/rendering/GaneshRenderer.cpp] |<span style="color: #000000;"></p><p> . </span>|-->GaneshContext* ganesh = GaneshContext::instance() |<span style="color: #000000;"></p><p> . </span>|-->TransferQueue* tileQueue = TilesManager::instance()->transferQueue() |</p><p> | |-->tileQueue->readyForUpdate() /<----------------------------<-------------/<span style="color: #000000;"> </p><p> . . </span>+++++++++++++ |<span style="color: #000000;"> </p><p> .###.####</span>| wait |########################################################|<span style="color: #000000;">################</p><p>not available now . . Condition m_transferQueueItemCond </span>|<span style="color: #000000;"></p><p> .###.##################################################################</span>| signal |<span style="color: #000000;">#########</p><p> . . </span>+++++++++++++<span style="color: #000000;"></p><p> . </span>|-->device = ganesh->getDeviceForTile(renderInfo) <span style="color: #0000ff;">get</span> device <span style="color: #0000ff;">for</span> SkCanvas and <span style="color: #0000ff;">set</span><span style="color: #000000;"> EGLContext</p><p> . . </span>|-->display =<span style="color: #000000;"> eglGetDisplay(EGL_DEFAULT_DISPLAY)</p><p> . . </span>|-->eglInitialize(display, &majorVersion, &<span style="color: #000000;">minorVersion)</p><p> . . </span>|-->eglChooseConfig(display, configAttribs, &m_surfaceConfig, <span style="color: #800080;">1</span>, &<span style="color: #000000;">numConfigs)</p><p> . . </span>|-->m_surfaceContext =<span style="color: #000000;"> eglCreateContext(display, m_surfaceConfig, NULL, contextAttribs)</p><p> . . </span>|-->TransferQueue* tileQueue = TilesManager::instance()-><span style="color: #000000;">transferQueue()</p><p> . . </span>|-->ANativeWindow* anw = tileQueue->m_ANW.<span style="color: #0000ff;">get</span><span style="color: #000000;">(); </p><p> . . </span>|--><span style="color: #000000;">ANativeWindow_setBuffersGeometry()</p><p> . . </span>|-->tileQueue->m_eglSurface =<span style="color: #000000;"> eglCreateWindowSurface(display, m_surfaceConfig, anw, NULL);</p><p> . . </span>|-->eglMakeCurrent(display, tileQueue->m_eglSurface, tileQueue-><span style="color: #000000;">m_eglSurface, m_surfaceContext)</p><p> . . </p><p> . . </span>|-->GrContext* grContext =<span style="color: #000000;"> getGrContext()</p><p> . . </span>|-->GrRenderTarget* renderTarget = grContext-><span style="color: #000000;">createPlatformRenderTarget(renderTargetDesc)</p><p> . . </span>|-->m_tileDeviceSurface = <span style="color: #0000ff;">new</span><span style="color: #000000;"> SkGpuDevice(grContext, renderTarget)</p><p> . </span>|-->canvas-><span style="color: #000000;">setDevice(m_tileDeviceSurface)</p><p> </span>|-->renderInfo.tilePainter->paint(&<span style="color: #000000;">canvas);</p><p> </span>|--><span style="color: #000000;">BaseRenderer.checkForPureColor(renderInfo, canvas)</p><p> . </span>|--><span style="color: #000000;">GaneshRenderer::deviceCheckForPureColor(){}</p><p> </span>| --><span style="color: #000000;">GaneshRenderer::renderingComplete(GaneshRenderer.cpp)</p><p> . </span>|-->GaneshContext::instance()-><span style="color: #000000;">flush()</p><p> . </span>|-->TransferQueue* tileQueue = TilesManager::instance()-><span style="color: #000000;">transferQueue()</p><p> . </span>|-->eglSwapBuffers(eglGetCurrentDisplay(), tileQueue-><span style="color: #000000;">m_eglSurface)</p><p> . </span>|-->tileQueue->addItemInTransferQueue(&<span style="color: #000000;">renderInfo, GpuUpload, dummyBitmap)</p><p> . </span>|-->m_transferQueueIndex = (m_transferQueueIndex + <span style="color: #800080;">1</span>) %<span style="color: #000000;"> m_transferQueueSize </p><p> . </span>|-->TileTransferData* data = &<span style="color: #000000;">m_transferQueue[index] </p><p> . </span>|--><span style="color: #000000;">TransferQueue.addItemCommon(renderInfo, type, data) </p><p> </span>--------.--------------.-------.----------------------------------------------------------------------------------------<span style="color: #000000;"> </p><p> CpuUpload . </span>|-->(*m_transferQueue[index].bitmap) =<span style="color: #000000;"> bitmap </p><p> </span>--------.--------------.------------------------------------------------------------------------------------------------</p><p>------------------.------------------|---------------------------------------------------<span style="color: #000000;"></p><p> . </span>|<span style="color: #000000;"></p><p> . </span>|<span style="color: #000000;"></p><p> \</span>/<span style="color: #000000;"></p><p> TransferQueue.addItemInTransferQueue(renderInfo, currentUploadType, bitmap)</p><p>#################################</span>| |<span style="color: #000000;">################################################################ </p><p> TileManager</span>->m_transferQueue --><span style="color: #000000;"> QueueBuffer (GraphicBuffer) </p><p>#################################</span>| |<span style="color: #000000;">###################################################################### </p><p> TilesManager::updateTilesIfContextVerified(TilesManager.cpp)</p><p></span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>android 线程启动 </span><span style="color: #0000ff;">new</span> xxthread()->run ---> _threadLoop()---><span style="color: #000000;"> readyToRun() </p><p> threadLoop</p><p> </p><p></span>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000000;"></p><p>关键代码</p><p>TileManager</p><p>TransferQueue.cpp</p><p>GLComsumer.cpp (SurfaceTexture)</p><p>Tile.h</span>/.cpp
分类: Android