• KWin、libdrm、DRM从上到下全过程 —— drmModeAddFBxxx(2)


    接前一篇文章:KWin、libdrm、DRM从上到下全过程 —— drmModeAddFBxxx(1)

    上回书说到drmModeAddFB、drmModeAddFB2和drmModeAddFB2WithModifiers函数最终“三分归一统”,在内核层统一调用到drm_mode_addfb2函数。

    这里我们先不急于往下分析drm_mode_addfb2函数,而是再来回顾一下之前的逐步合并统一的过程,以加深理解。如下图所示:

    重点关注函数两次合并过程中同级函数的差异:

    第1次合并

    • DRM <——> libdrm

    drmModeAddFB2(buffer->gpu()->fd(), size.width(), size.height(), buffer->format(), handles.data(), strides.data(), offsets.data(), &framebufferId, 0);

    drmModeAddFB2WithModifiers(buffer->gpu()->fd(), size.width(), size.height(), buffer->format(), handles.data(), strides.data(), offsets.data(), modifier, &framebufferId, DRM_MODE_FB_MODIFIERS);

    1. drm_public int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
    2. uint32_t pixel_format, const uint32_t bo_handles[4],
    3. const uint32_t pitches[4], const uint32_t offsets[4],
    4. uint32_t *buf_id, uint32_t flags)
    5. {
    6. return drmModeAddFB2WithModifiers(fd, width, height,
    7. pixel_format, bo_handles,
    8. pitches, offsets, NULL,
    9. buf_id, flags);
    10. }
    1. drm_public int drmModeAddFB2WithModifiers(int fd, uint32_t width,
    2. uint32_t height, uint32_t pixel_format, const uint32_t bo_handles[4],
    3. const uint32_t pitches[4], const uint32_t offsets[4],
    4. const uint64_t modifier[4], uint32_t *buf_id, uint32_t flags)
    5. {
    6. ……
    7. }
    •  libdrm <——> DRM
    1. drm_public int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
    2. uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
    3. uint32_t *buf_id)
    4. {
    5. struct drm_mode_fb_cmd f;
    6. int ret;
    7. memclear(f);
    8. f.width = width;
    9. f.height = height;
    10. f.pitch = pitch;
    11. f.bpp = bpp;
    12. f.depth = depth;
    13. f.handle = bo_handle;
    14. if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB, &f)))
    15. return ret;
    16. *buf_id = f.fb_id;
    17. return 0;
    18. }
    1. drm_public int drmModeAddFB2WithModifiers(int fd, uint32_t width,
    2. uint32_t height, uint32_t pixel_format, const uint32_t bo_handles[4],
    3. const uint32_t pitches[4], const uint32_t offsets[4],
    4. const uint64_t modifier[4], uint32_t *buf_id, uint32_t flags)
    5. {
    6. struct drm_mode_fb_cmd2 f;
    7. int ret;
    8. memclear(f);
    9. f.width = width;
    10. f.height = height;
    11. f.pixel_format = pixel_format;
    12. f.flags = flags;
    13. memcpy(f.handles, bo_handles, 4 * sizeof(bo_handles[0]));
    14. memcpy(f.pitches, pitches, 4 * sizeof(pitches[0]));
    15. memcpy(f.offsets, offsets, 4 * sizeof(offsets[0]));
    16. if (modifier)
    17. memcpy(f.modifier, modifier, 4 * sizeof(modifier[0]));
    18. if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f)))
    19. return ret;
    20. *buf_id = f.fb_id;
    21. return 0;
    22. }

    第2次合并

    1. int drm_mode_addfb_ioctl(struct drm_device *dev,
    2. void *data, struct drm_file *file_priv)
    3. {
    4. return drm_mode_addfb(dev, data, file_priv);
    5. }
    1. int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or,
    2. struct drm_file *file_priv)
    3. {
    4. struct drm_mode_fb_cmd2 r = {};
    5. int ret;
    6. ……
    7. /* convert to new format and call new ioctl */
    8. r.fb_id = or->fb_id;
    9. r.width = or->width;
    10. r.height = or->height;
    11. r.pitches[0] = or->pitch;
    12. r.handles[0] = or->handle;
    13. ret = drm_mode_addfb2(dev, &r, file_priv);
    14. if (ret)
    15. return ret;
    16. or->fb_id = r.fb_id;
    17. return 0;
    18. }
    1. int drm_mode_addfb2_ioctl(struct drm_device *dev,
    2. void *data, struct drm_file *file_priv)
    3. {
    4. #ifdef __BIG_ENDIAN
    5. ……
    6. #endif
    7. return drm_mode_addfb2(dev, data, file_priv);
    8. }

    由代码可以看到,drm_mode_addfb函数中存在由drm_mode_fb_cmd结构向drm_mode_fb_cmd2结构的转换,这样两者才能最终统一起来。

    欲知后事如何,且看下回分解。

  • 相关阅读:
    用户运营的常用工具和运营策略
    spring6-IOC容器
    javacc之路0--- 安装与使用
    2022.8.9考试独特的投标拍卖--800题解
    H3C 交换机配置SSH
    借助拧紧曲线高效管理螺栓装配防错——SunTorque智能扭矩系统
    (学习日报)2022.7.20
    【C++从0到王者】第三十六站:哈希
    固高机器人控制器开发笔记
    XSS详解及复现gallerycms字符长度限制短域名绕过
  • 原文地址:https://blog.csdn.net/phmatthaus/article/details/133749323