Qt在ARM中,如何使用drmModeObjectSetProperty 设置 Plane 的 zpos 值

在 Qt 中直接使用 drmModeObjectSetProperty 设置 Plane 的 zpos 值需要结合 Linux DRM/KMS API 和 Qt 的底层窗口系统(如 eglfs 平台插件)。以下是详细步骤和代码示例:

1. 原理说明

  • DRM/KMS 基础

    • Plane:负责图层合成(如 Overlay、Primary、Cursor Plane)。

    • zpos 属性:控制 Plane 的层级顺序(值越大,显示越靠前)。

  • Qt 与 DRM :Qt 的 eglfs 平台插件默认使用 DRM/KMS 渲染,但未直接暴露 Plane 控制接口,需通过 libdrm 直接操作。

2. 准备工作

2.1 添加依赖

确保项目包含 libdrm 头文件和库:

安装 libdrm 开发包(Debian/Ubuntu)

sudo apt-get install libdrm-dev

.pro 文件中链接库:

qmake

LIBS += -ldrm

2.2 权限配置

确保应用程序有权访问 /dev/dri/card* 设备:

sudo usermod -aG video your_username # 将用户加入 video 组

3. 完整示例

cpp 复制代码
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <xf86drm.h>
#include <xf86drmMode.h>

int main(int argc, char *argv[]) {
    QGuiApplication app(argc, argv);

    // 1. 打开 DRM 设备
    int drm_fd = openDrmDevice();
    if (drm_fd < 0) {
        qFatal("Failed to open DRM device");
    }

    // 2. 获取 Plane 资源
    drmModePlaneResPtr plane_res = drmModeGetPlaneResources(drm_fd);
    if (!plane_res) {
        close(drm_fd);
        qFatal("Failed to get plane resources");
    }

    // 3. 遍历所有 Plane,查找可设置 zpos 的 Plane
    for (uint32_t i = 0; i < plane_res->count_planes; i++) {
        drmModePlanePtr plane = drmModeGetPlane(drm_fd, plane_res->planes[i]);
        if (!plane) continue;

        // 4. 查找 zpos 属性 ID
        uint32_t zpos_prop_id = findZposPropertyId(drm_fd, plane);
        if (zpos_prop_id) {
            // 5. 设置 zpos 值(示例:设置为最大值)
            if (setPlaneZpos(drm_fd, plane->plane_id, zpos_prop_id, 255)) {
                qDebug() << "Successfully set zpos for plane" << plane->plane_id;
            } else {
                qWarning() << "Failed to set zpos for plane" << plane->plane_id;
            }
        }

        drmModeFreePlane(plane);
    }

    // 6. 清理资源
    drmModeFreePlaneResources(plane_res);
    close(drm_fd);

    // 启动 Qt 应用
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

5. 关键注意事项

  1. Qt 平台插件选择

    • 运行应用时指定 eglfs 平台:

      ./your_app -platform eglfs

    • 确保 Qt 编译时启用了 eglfs 支持。

  2. Plane 类型限制

    • 仅支持 DRM_PLANE_TYPE_OVERLAYDRM_PLANE_TYPE_PRIMARY 类型的 Plane。

    • 通过 drmModeGetPlane 检查 plane->possible_crtcs 确认 Plane 是否可用。

  3. 属性兼容性

    • 不同硬件(如 i.MX6、Rockchip、Intel)的 DRM 驱动可能对 zpos 的支持不同,需查阅硬件文档。

    • 使用 drmModeGetProperty 检查属性是否可写(prop->flags & DRM_MODE_PROP_RANGE)。

  4. 时序控制

    • 在 Qt 窗口初始化完成后操作 Plane,避免与 Qt 内部 DRM 调用冲突。

    • 若动态调整 zpos,需通过信号/槽机制在合适的时机触发。

相关推荐
誰能久伴不乏13 分钟前
ibmodbus “Invalid argument“ 错误的排查与修复
c++·qt·modbus
handler0115 分钟前
【C++】二叉搜索树详解及其模拟实现(代码)
开发语言·c++·算法·c··二叉搜索树·搜索树
luj_176817 分钟前
残熵算法的稳健防灾逻辑
c语言·开发语言·c++·经验分享·算法
一只鹿鹿鹿44 分钟前
信息化项目管理规范(参考Word文件)
java·大数据·运维·开发语言·数据库
XGeFei1 小时前
python中子线程与主线程的关系
开发语言·python
Chase_______1 小时前
【Java杂项】final 关键字详解:变量、方法、类限制与引用可变性
java·开发语言·python
ruxingli1 小时前
Golang iota详解
开发语言·后端·golang
我材不敲代码1 小时前
Python venv 虚拟环境从入门到精通 + uv 高性能替代工具实战指南
开发语言·python·uv
肥or胖1 小时前
Qt中OpenGL快速入门
qt·音视频·opengl
l1t1 小时前
DeepSeek总结的使用实体-组件-系统和基于存在性处理进行Python编程18-20
开发语言·python