KWin全解析 —— overview.md(3)

本文详细解读了KWin中的DRI(DirectRenderingInfrastructure)框架下,GBM(GenericBufferManager)API的工作原理,包括gbm_buffer和gbm_surface对象,以及GBM_FORMAT_*的使用。还介绍了GBM中的内存布局修饰符和如何处理不同GPU驱动兼容性问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接前一篇文章:KWin全解析 —— overview.md(2)

本文继续解析KWin源码src/backends/drm/overview.md文件的其余内容。

第16段

# gbm

The generic buffer manager API allows us to allocate buffers in graphics memory with a few properties. It's a relatively straight forward API:

- `gbm_bo` is a gbm buffer. It can be manually created and destroyed

- `gbm_surface` is a gbm surface, which allows us to create an egl surface that's using gbm buffers. With it we can render in egl and then create framebuffers from the things rendered in egl and present them on the display

- the `GBM_FORMAT_*` defines are just copies of the `DRM_FORMAT_*` defines in drm_fourcc.h and describe a buffer format. For example `DRM_FORMAT_XRGB8888` describes a buffer with 8 bits of red, 8 bits of green, 8 bits of blue and 8 bits of unused alpha (that's what the `X` stands for). Do not use the `GBM_BO_FORMAT_*` enum, it can cause problems! In general, ignore the buffer formats from the gbm header and instead use what drm_fourcc.h provides

- modifiers describe the actual memory layout that needs to be assumed for accessing the buffer. Older drivers like `radeon` don't support modifiers at all, on the other end of the spectrum the NVidia driver requires them. When we don't use functions that have us explicitly provide modifiers that's called an "implicit modifier" - that means the driver automatically picks a modifier for the use case. With implicit modifiers we have no guarantees about multi-gpu compatibility by default, instead the `GBM_BO_USE_LINEAR` usage flag has to be set when creating the buffer to enforce a linear format that all drivers can access without messing up the image

gbm(通用缓冲区管理器)

通用缓冲区管理器API允许我们使用一些属性在图形内存中分配缓冲区。这是一个相对直接的API:

  • gbm_bo

gbm_bo是一个gbm缓冲区。它可以被手动创建和销毁。

  • gbm_surface

gbm_surface是一个gbm表面,它允许我们创建一个使用gbm缓冲区的egl表面。有了它,我们可以在egl中进行渲染,然后由egl中渲染的内容创建帧缓冲区,并将其显示在显示器上。

  • GBM_FORMAT_*

“GBM_FORMAT_*”定义只是drm_fourcc.h中定义的`DRM_FORMAT_*`的副本,描述缓冲区格式。例如:DRM_FORMAT_XRGB8888描述了一个具有8位红色、8位绿色、8位蓝色和8位未使用阿尔法(透明度)(这就是“X”的含义)的缓冲区。不要使用“GBM_BO_FORMAT_*”枚举,它可能会导致问题!通常,忽略gbm头文件中的缓冲区格式,而是使用drm_fourcc.h提供的内容。

  • modifiers(修饰符、修改器)

modifiers描述实际内存布局,其用来访问缓冲区。像“radeon”这样的老款驱动程序根本不支持modifier,另一方面,英伟达驱动程序需要它们。当不使用让我们显式提供被称为“隐式修饰符”的修饰符的函数时,这意味着驱动程序会自动为用例选择一个修饰符。使用隐式修饰符,默认情况下我们不能保证多gpu兼容性,相反,在创建缓冲区时必须设置“GBM_BO_USE_LINEAR”使用标志,以强制执行所有驱动程序都可以访问的线性格式,而不会弄乱图像。

第17段

For gbm most of the upstream documentation is contained in https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/gbm/main/gbm.c

对于gbm,大部分上游文档包含在:

https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/gbm/main/gbm.c

至此,KWin下src/backends/drm/overview.md文件内容就全部解析完了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝天居士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值