Android 顯示系統模組載入以及呼叫流程

2021-07-26 12:30:25 字數 4097 閱讀 1595

開啟/dev/graphics/fb0這個裝置的呼叫過程如下:

1.在hwcomposer中,載入module

hwcomposer::hwcomposer(

const sp& flinger,

eventhandler& handler)

1)loadfbhalmodule()直接從下面的路徑開啟fb,初始化並儲存framebuffer_device_t型別成員變數mfbdev。

gralloc_device_open()->fb_device_open()->mapframebuffer() -> mapframebufferlocked()
這裡gralloc_device_open定義在hal層定義的:

檔案中

static

struct hw_module_methods_t gralloc_module_methods = ;

struct private_module_t hal_module_info_sym = ,

.registerbuffer = gralloc_register_buffer,

.unregisterbuffer = gralloc_unregister_buffer,

.lock = gralloc_lock,

.unlock = gralloc_unlock,

},.framebuffer = 0,

.flags = 0,

.numbuffers = 0,

.buffermask = 0,

.lock = pthread_mutex_initializer,

.currentbuffer = 0,

};

這個module會在hwcomposer::loadfbhalmodule()中被載入,呼叫對應的open函式。

看以下**注釋

int hwcomposer::loadfbhalmodule()

return framebuffer_open(module, &mfbdev);

}//這裡methods->open當然就是呼叫上面module的open函式,也就是gralloc_device_open()

static

inline

int framebuffer_open(const

struct hw_module_t* module,

struct framebuffer_device_t** device)

//由於第二個引數是gralloc_hardware_fb0,所以會跑到fb_device_open中

int gralloc_device_open(const hw_module_t* module, const

char* name,

hw_device_t** device)

else

return status;

}//由於name是gralloc_hardware_fb0,會跑到if語句裡進行初始化工作,包括開啟/dev/graphics/fb0等

int fb_device_open(hw_module_t const* module, const

char* name,

hw_device_t** device)

memset(dev, 0, sizeof(*dev));

/* initialize the procs */

dev->device.common.tag = hardware_device_tag;

dev->device.common.version = 0;

dev->device.common.module = const_cast

(module);

dev->device.common.close = fb_close;

dev->device.setswapinterval = fb_setswapinterval;

dev->device.post = fb_post;

dev->device.setupdaterect = 0;

dev->device.compositioncomplete = fb_compositioncomplete;

status = mapframebuffer((framebuffer_device_t*)dev);

private_module_t* m = (private_module_t*)dev->device.common.module;

if (status >= 0)

// close the gralloc module

gralloc_close(gralloc_device);

}return status;

}

2)loadhwcmodule()函式通過以下路徑開啟fb,初始化並儲存hwc_composer_device_1_t型別的成員變數mhwc。

hwcomposer::loadhwcmodule()->hw_get_module(hwc_hardware_module_id, &module)

然後在呼叫hwc_open_1(module, &mhwc)->hwc_device_open()->initcontext()->

copybit::copybit()[hwc_copybit.cpp]->hw_get_module(copybit_hardware_module_id, &module)

->open_copybit()->open("/dev/graphics/fb0", o_rdwr, 0);

這裡的module載入以及呼叫open函式的過程基本和上面的一樣,不多說了。

到此可以知道framework層是怎麼開啟的/dev/graphics/fb0節點,以待後續進行處理的!!

在su***ceflinger中最後進行資料重新整理的函式,我們知道是postframebuffer()函式。定義如下:

void su***ceflinger::postframebuffer()

/*if(cc_unlikely(atrace_enabled()))*/

#endif

const nsecs_t now = systemtime();

mdebuginswapbuffers = now;

hwcomposer& hwc(gethwcomposer());

if (hwc.initcheck() == no_error)

//這個函式當然就是呼叫hwcomposer::commit()函式,,不言而喻~

到這裡就可以知道怎麼載入的模組,也看了su***ceflinger通過hwcomposer和hwc.cpp模組的內容進行顯示資料的刷寫的過程。接下來看一下su***ceflinger,,

Android 之ko模組的自動載入

最近在做乙個觸控式遙控器,以控制android tv,商提供了觸控板驅動的source code,我將其編譯生成乙個適合我們平台的ko模組。但是有個問題,每次用時,必須手動insmod進去,很麻煩。於是乎,就想盡辦法,搜尋資料,如何將ko模組在系統開機時自動載入,終於成功。步驟如下 1.與andro...

Android顯示系統框架初探

一 前言 android顯示系統框架跟隨著谷歌android 8的treble架構改革而發生較大的變動,從此之後hal層就以單獨的hwc hwcomposer 程序而存在,su ceflinger程序通過hwbinder跟hwc程序打交道,兩兄弟從此相愛相恨。而linux核心顯示部分也從幀快取 fr...

Android網路載入時顯示進度條

在聯網獲取資料時,用乙個進度條提示使用者正在載入資料,以下講一下我是如何實現這種效果的。由於android的介面更新只能通過自己的ui執行緒進行操作,所以我們需要用到handler在進行更新介面的操作。1 宣告變數 private handler handler new handler privat...