自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

OpenHarmony 圖形子系統(tǒng)(二)weston compositor分析

系統(tǒng) OpenHarmony
我們熟悉了基于 Linux DRM的基礎(chǔ)顯示平臺,以及wayland 相關(guān)的幾個基礎(chǔ)概念。這節(jié)我們將對搭建在其上的 weston compositor 進行深入分析。

??想了解更多內(nèi)容,請訪問:??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

通過上一節(jié),我們熟悉了基于 Linux DRM的基礎(chǔ)顯示平臺,以及wayland 相關(guān)的幾個基礎(chǔ)概念。這節(jié)我們將對搭建在其上的 weston compositor 進行深入分析。

Weston 是基于Wayland 協(xié)議的 compositor 的參考實現(xiàn)。其它的實現(xiàn)比如 GNOME 和KDE 也默認(rèn)提供了基于Wayland display server 協(xié)議建立的全功能桌面環(huán)境。OpenHarmony 標(biāo)準(zhǔn)系統(tǒng)目前采用的是weston 的實現(xiàn)。

了解weston compositor 有利于我們對OpenHarmony 圖形子系統(tǒng)的移植適配及啟動問題進行調(diào)試。

Weston 結(jié)構(gòu)分析

下圖是 OpenHarmony-3.0-LTS 版本的圖形子系統(tǒng) compositor server端的結(jié)構(gòu)圖。

compositor 上端通過 wayland 協(xié)議與client 進行通訊。

server 端除了 weston外,還加載了窗口管理服務(wù)(wmserver)模塊和 vsync 模塊。另外加載了一個 ivi-shell 模塊,這個我們后面在分析client 端 WindowManager 時再說。

weston 下端依賴幾個display hdi 層相關(guān)的庫:

  • libdisplay_gfx 實現(xiàn)圖形的硬件加速接口。
  • libdisplay_gralloc:負(fù)責(zé)顯示模塊內(nèi)存的管理,包括內(nèi)存的申請和釋放、內(nèi)存映射等操作。

drm backend 中 renderer模塊通過 use_pixman 選項選擇使用 pixman renderer 還是 egl。 egl 是 rendering API(如 OpenGL,OpenGL ES) 與底層原生平臺窗口系統(tǒng)之間的接口。

pixman-render 中又通過 use_tde 變量來選擇是否使用 tde 硬件加速模塊。 TDE(Two Dimensional Engine)是海思的2D圖形加速引擎。Rockchip 對應(yīng)的叫 RGA (Raster Graphic Acceleration) 二維光柵圖形加速單元,用來加速了二維圖形操作。例如點/線繪制、圖像縮放、旋轉(zhuǎn)、位圖、圖像合成等。

目前 3.0-LTS 若是其它非海思平臺,若檢測不到tde 模塊,則會默認(rèn)使用 pixman 來進行軟件渲染。

關(guān)于Wayland

要知道 wayland 協(xié)議是被設(shè)計成”異步的面向?qū)ο蟆?asynchronous object-oriented protocol)的協(xié)議。面向?qū)ο?Object-oriented)表示 compositor 所提供的服務(wù)是以一系列貯存在同一個compositor 中的對象的方式呈現(xiàn)。

各個對象實現(xiàn)了一個接口(interface),接口有名字、若干的方法(request)及系列相關(guān)的events。接口協(xié)議可以在xml 文件中描述,編譯時有腳本可將其自動生成C 代碼(wayland_standard/wayland_scanner_wrapper.py)。

客戶端可以給對象發(fā)送請求,如果對象的接口支持這個請求的話。

compositor 中有一些wayland 的核心接口(core interfaces) 是必須要具備的,定義在 wayland_standard/protocol/wayland.xml中。此外特定的compositor 可以實現(xiàn)它們自己的接口作為擴展協(xié)議。每個接口協(xié)議都有版本號,以保證版本的兼容性。

知道上面的前置知識后,我們就可以開始分析weston 的代碼了。

weston 啟動流程偽代碼

weston 啟動流程比較長,我們只挑出我們感興趣的主干部分。整理一下流程,有助于后續(xù)調(diào)試的時候迅速回憶起看過的代碼。

wet_main(args)
weston_display_create() //創(chuàng)建 display 對象
load_configuration(&config) //根據(jù)啟動參數(shù),加載配置文件 weston.ini 中的配置
weston_compositor_create() //創(chuàng)建 compositor 實例
load_backend() //根據(jù)啟動參數(shù)-b,顯式加載后端顯示接口 drm-backend.so
WL_EXPORT weston_backend_init() //顯示后端drm-bakcend.so 初始化入口
drm_backend_create()
if use_pixman:
init_pixman() //根據(jù)啟動參數(shù) use_pixman, 在renderer pixman 或者 egl 二選一
pixman_render_init()
tde_renderer_alloc_hook()
tde_render_gfx_init()
dlopen(”libdisplay_gfx.so”)
GrallocInitialize()
→ peripheral/display “l(fā)ibdisplay_gralloc.so”
else:
init_egl()
VsyncModuleStart() //依賴圖形子系統(tǒng)中的 libvsync_module.so
InitSA() //注冊ID為VSYNC_MANAGER_ID的 Vsync Manager 服務(wù)
RegisterSystemAbility(VSYNC_MANAGER_ID)
VsyncMainThread()
load_modules() //加載weston.ini 里配置的 modules 項,3.0-LTS版本里加載了 libivi-controller.z.so,libwmserver.z.so 。 后面介紹 wmserver 窗口管理器模塊。
wl_display_run() //進入事件等待及常規(guī)任務(wù)循環(huán)
while(run)
wl_display_flush_clients()
wl_event_loop_dispatch()

然后來梳理一下我們最關(guān)心的 surface 提交, 然后重繪(repaint)及輸出流程。

surface 接口綁定及 surface commit 流程

這里就會涉及到一些接口實現(xiàn)的綁定。偽代碼中用 (->) 箭頭表示我們所關(guān)注的其中一個接口方法的實現(xiàn)。方法調(diào)用是當(dāng)client 端發(fā)送對應(yīng)的 wl_xxx 請求事件時被調(diào)用。

weston_compositor_create()
compositor_bind() //創(chuàng)建 compositor 時綁定 compositor_interface 接口實現(xiàn)
struct wl_compositor_interface compositor_interface //compositor 接口實現(xiàn)
→compositor_create_surface //創(chuàng)建surface 時綁定 surface 接口實現(xiàn)
struct wl_surface_interface surface_interface //surface 接口實現(xiàn)
→ surface_commit() //在 client 端調(diào)用 wl_surface_commit() 提交至此接口
weston_surface_commit_state()
pixman_render_attach() //若是新加入的surface 則會進行renderer attach
weston_surface_schedule_repaint(surface)//標(biāo)記 output 中 該surface 需要被 repaint

repaint 流程

當(dāng)有surface 被標(biāo)記成需要 repaint 時,repaint timer handler 會對這些surface 進行重繪后輸出顯示。

wl_event_loop //wayland 事件循環(huán)
output_repaint_timer_handler
backend→repaint_begin() //開始調(diào)用后端 repaint 接口
weston_output_repaint()
→drm_output_repaint()
drm_output_render() //渲染
if use_pixman:
drm_output_render_pixman()
→pixman_renderer_repaint_output()
repaint_surfaces()
draw_view()
repaint_region()
else:
drm_output_render_gl()
drm_repaint_flush() //合成重繪后的畫面刷新輸出
drm_pending_state_apply() //kms

復(fù)制先更新這些,偽代碼部分可以對照著源碼多梳理幾遍。后面將編寫一個簡單的client,熟悉其核心接口對象(core interfaces)。然后以其為基礎(chǔ)分析圖形子系統(tǒng)中如何對其進行封裝適配,增加WM 窗口管理,Vsync 幀同步,內(nèi)存管理等模塊。

??想了解更多內(nèi)容,請訪問:??

??51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)??

??https://harmonyos.51cto.com??

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-12-17 16:42:09

鴻蒙HarmonyOS應(yīng)用

2013-01-06 13:06:02

2023-06-28 15:00:02

開源鴻蒙輸入系統(tǒng)架構(gòu)

2023-03-07 15:54:45

鴻蒙Mesa庫

2022-03-18 16:07:04

Graphic子系統(tǒng)鴻蒙

2023-04-12 15:31:11

系統(tǒng)服務(wù)管理鴻蒙

2022-01-06 16:17:58

鴻蒙HarmonyOS應(yīng)用

2022-02-17 20:57:07

OpenHarmon操作系統(tǒng)鴻蒙

2021-09-18 14:40:37

鴻蒙HarmonyOS應(yīng)用

2021-11-08 15:04:47

鴻蒙HarmonyOS應(yīng)用

2021-09-13 15:15:18

鴻蒙HarmonyOS應(yīng)用

2023-04-06 09:14:11

多模輸入子系統(tǒng)鴻蒙

2022-04-19 11:23:26

release3.1子系統(tǒng)鴻蒙

2022-01-10 15:30:11

鴻蒙HarmonyOS應(yīng)用

2022-05-10 11:17:27

電話子系統(tǒng)數(shù)據(jù)服務(wù)模塊

2021-11-18 10:28:03

鴻蒙HarmonyOS應(yīng)用

2021-09-17 14:38:58

鴻蒙HarmonyOS應(yīng)用

2022-05-24 15:46:51

Wi-FiSTA模式

2022-01-13 10:11:59

鴻蒙HarmonyOS應(yīng)用

2009-10-12 12:46:55

Linux內(nèi)核SCSI IO
點贊
收藏

51CTO技術(shù)棧公眾號