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