接前一篇文章:KWin全解析 —— overview.md(1)
本文继续解析KWin源码src/backends/drm/overview.md文件的其余内容。
第10段
There's two APIs for drm, legacy and atomic modesetting (AMS).
drm中有两个APIs,legacy(旧有)和atomic modesetting(AMS)。
第11段
Legacy only exposes connectors and crtcs, and only some of their properties. You first enable a connector and set a mode with `drmModeSetCrtc` and then push new frames with `drmModePageFlip`. `drmModePageFlip` has two flags we care about:
- `DRM_MODE_PAGE_FLIP_EVENT` tells the kernel to generate a page flip event for the crtc, which tells us when the new framebuffer has actually been set / when the old one is not needed anymore
- `DRM_MODE_PAGE_FLIP_ASYNC` tells the kernel that it should immediately apply the new framebuffer without waiting. This may cause tearing
legacy只暴露给connector和crtc,以及它们的一些属性。首先使能connector并使用drmModeSetCrtc函数设置模式,然后使用drmModePageFlip函数推送新帧。drmModePageFlip函数有两个我们关心的标志:
- DRM_MODE_PAGE_FLIP_EVENT
DRM_MODE_PAGE_FLIP_EVENT告诉内核为crtc生成一个页面翻转事件,它告诉何时新的帧缓冲区被实际设置/何时旧的帧缓冲区不再需要。
- DRM_MODE_PAGE_FLIP_ASYNC
DRM_MODE_PAGE_FLIP_ASYNC告诉内核应该立即应用新的帧缓冲区,而不需要等待。这可能会导致撕裂。
第12段
For dynamic power management (dpms) you set the dpms property with `drmModeObjectSetProperty` and the kernel will handle the rest behind the scenes, or fail the request. Same story with `VRR_ENABLED`, `overscan` and similar.
对于动态电源管理(dpms),可以使用drmModeObjectSetProperty函数设置dpms属性,内核将在后台处理其余内容,或者使请求失败。与“VRR_ENABLED”、“overscan”和类似的情况相同。
第13段
With atomic modesetting all objects and properties are exposed. AMS works very differently from legacy: it has one generic function `drmModeAtomicCommit` that is used for pretty much everything. How this function works is that you first fill a `drmModeAtomicReq` with the properties you want to set, then you call `drmModeAtomicCommit` with some combination of flags. These flags decide on what the function actually does:
- `DRM_MODE_ATOMIC_TEST_ONLY` only tests whether or not the configuration would work but is guaranteed to not change anything
- `DRM_MODE_PAGE_FLIP_EVENT` tells the kernel that it should generate a page flip event for all crtcs that we change in the commit
- `DRM_MODE_ATOMIC_NONBLOCK` tells the kernel to make this function not blocking; it should not wait until things are actually applied before returning
- `DRM_MODE_ATOMIC_ALLOW_MODESET` tells the kernel that it is allowed to make our changes happen with a modeset, that is an event that can cause the display(s) to flicker or black out for a moment
- `DRM_MODE_PAGE_FLIP_ASYNC` is currently *not* supported. All requests with this flag set fail
通过atomic modesetting(AMS),所有对象和属性都将被公开。AMS的工作方式与legacy(旧有,传统)非常不同:它有一个通用函数drmModeAtomicCommit,用于几乎所有内容。这个函数的工作原理是:首先用要设置的属性填充drmModeAtomicReq,然后用一些标志组合调用drmModeAtomicCommit函数。这些标志决定了函数的实际功能:
- DRM_MODE_ATOMIC_TEST_ONLY
DRM_MODE_ATOMIC_TEST_ONLY只测试配置是否有效,但保证不会更改任何内容。
- DRM_MODE_PAGE_FLIP_EVENT
DRM_MODE_PAGE_FLIP_EVENT告诉内核为crtc生成一个页面翻转事件告诉内核,它应该为我们在提交中更改的所有crtc生成一个页面翻转事件。
- DRM_MODE_ATOMIC_NONBLOCK
DRM_MODE_ATOMIC_NONBLOCK告诉内核使这个函数不阻塞;它不应该等到事物实际应用后才返回。
- DRM_MODE_ATOMIC_ALLOW_MODESET
DRM_MODE_ATOMIC_ALLOW_MODESET告诉内核允许使用modeset进行更改,这是一个可能导致显示器闪烁或熄灭一段时间的事件。
- DRM_MODE_PAGE_FLIP_ASYNC
DRM_MODE_PAGE_FLIP_ASYNC当前不支持。设置了此标志的所有请求都失败。
第15段
Some upstream documentation can be found at https://www.kernel.org/doc/html/latest/gpu/drm-kms.html, https://01.org/linuxgraphics/gfx-docs/drm/drm-kms-properties.html and in the files at https://github.com/torvalds/linux/tree/master/drivers/gpu/drm.
一些上游文档:
https://www.kernel.org/doc/html/latest/gpu/drm-kms.html,
https://01.org/linuxgraphics/gfx-docs/drm/drm-kms-properties.html,
以及
https://github.com/torvalds/linux/tree/master/drivers/gpu/drm
中的文件(实际上就是Linux内核源码根目录/drivers/gpu/drm/目录下的各文件)。
第16段
For a lot of documentation on properties and capabilities of devices there's also https://drmdb.emersion.fr/
对于许多关于设备属性和能力的文档可参见:。https://drmdb.emersion.fr/
余下内容请参见下一篇文章。