資源描述:
《ANDROID圖形系統(tǒng)詳解》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、ANDROID圖形系統(tǒng)詳解木文試圖講述Android圖形系統(tǒng)的底層實(shí)現(xiàn)。Android圖形系統(tǒng)底層實(shí)現(xiàn)非常復(fù)雜,文檔較少,沒(méi)冇使用比較流行的圖形組建如Xwindow,Cairo等。Android中的圖形系統(tǒng)采用Client/Server架構(gòu)。Server(即SurfaceFlingcr)主耍由c++代碼編寫而成。Client端代碼分為兩部分,一部分是由Java提供的供應(yīng)用使用的api,另一部分則是由C++寫成的底層實(shí)現(xiàn)。下圖概要介紹了android圖形系統(tǒng)的架構(gòu)以及使用到的主要組件。Android圖形系統(tǒng)中一個(gè)重要的概念和線索是sur
2、face?View及其子類(如TextView,Button)要畫在surface上。每個(gè)surface創(chuàng)建一個(gè)Canvas對(duì)象(但屬性時(shí)常改變),用來(lái)管理view在surfaceJ:的繪圖操作,如畫點(diǎn)畫線。每個(gè)canvas對(duì)象對(duì)應(yīng)一個(gè)bitmap,存儲(chǔ)畫在surface上的內(nèi)容。每個(gè)Surface通常對(duì)應(yīng)兩個(gè)buffer,一個(gè)frontbuffer,一個(gè)backbuffer<>其中,backbuffer就是canvas繪圖時(shí)對(duì)應(yīng)的bitmap(研究android_view_Surface.cpp::lockCanvas)。因此,繪畫
3、總是在backbuffcr_E,需要更新時(shí),則將backbuffer和frontbuffer互換。ThewindowistiedtoaSurfaceandtheViewRootaskstheSurfaceforaCanvasthatisthenusedbytheViewstodrawonto.AfterViewdrawitsdatatocanvas,ViewRootwillcallsurface.unlockCanvasAndPost(canvas)toschedulesurfaceFlinger::composeSurfaces()
4、whichdotheactuallydisplaytodisplaypanel.SurfaceFlingerhandlestotransfersdrawndataincanvastosurfacefrontbufferorbackbufferExceptforSurfacoVicws,diffcrcntviewswithinthesameViewRootsharethesamesurface.Layer的概念:每個(gè)surface又對(duì)應(yīng)一個(gè)layer,SurfaceFlinger負(fù)責(zé)將各個(gè)layer的frontbuffer合成(comp
5、osite)繪制到屏幕上。ALayerissomethingthatcanbecompositedbySurfaceFlinger(shouldhavebeencalledLayerFlinger).ThereareseveraltypesofLayersifyoulookinthecode,inparticulartheregularones(Layer,cpp),theyarebackedbyaSurface,andtheLayerBuffer(verybadlychosenname)whichdon'thaveabackings
6、tore,butreceiveonefromtheirclient..NotethattheGGLSurfacetype,shouldhavebeencalledGGLBufferMultiplelayersarejustcompositedtothefinalbufferintheirZorder.有幾個(gè)對(duì)象與Surface概念緊密和關(guān):1.JavaSurface(framcworks/base/corc/java/android/vicw/Surfacc.java)。該對(duì)?象被應(yīng)用間接調(diào)用(通過(guò)SurfaceView,ViewRo
7、ot等),應(yīng)用需要?jiǎng)?chuàng)建surface,(并同時(shí)創(chuàng)建canvas),將圖形繪制到這個(gè)対象上并最終投遞到屏幕上。2.C++Surface(frameworks/base/1ibs/ui/Surface.cppo這個(gè)對(duì)象被JavaSurface通過(guò)Jni調(diào)用,實(shí)現(xiàn)JavaSurface的功能3.ISurfacc(以及其派生類BnSurfacc)<>這個(gè)對(duì)象是應(yīng)用和server間的接CihSurface創(chuàng)建這個(gè)ISurface(BnSurface)并發(fā)送命令,如更新surface內(nèi)容到屏幕上。Server端接受這個(gè)命令并執(zhí)行相應(yīng)操作。研究一個(gè)
8、surface如何創(chuàng)建的關(guān)鍵路徑如下:1.framcworks/basc/corc/java/android/vicw/Surfacc.javaSurface::Surface()2.frameworks/base/co