Qt eglfs程序清屏

前言

最近遇到一個問題,在嵌入式平臺上使用eglfs做顯示後端的時候,Qt程序起來會清屏,也就是屏幕顯示純黑色,如果Qt程序比較大,在顯示開機logo之後會有比較長的一段時間黑屏才能顯示Qt的界面,用戶體驗不佳

解決

在跑Qt程序之前執行下面的環境變量,可以打印一些log,並指定顯示後端爲eglfs

export QT_QPA_PLATFORM=eglfs
export QT_LOGGING_RULES=qt.qpa.*=true
export QT_QPA_EGLFS_DEBUG=1

在跟蹤了一段時間代碼後,終於發現清屏的動作在哪裏了,看下面的文件

qt-everywhere-opensource-src-5.10.1/qtbase/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp

注意這個文件對應的so是

libQt5EglFSDeviceIntegration.so
libQt5EglFSDeviceIntegration.so.5
libQt5EglFSDeviceIntegration.so.5.10
libQt5EglFSDeviceIntegration.so.5.10.1

這個文件裏面的initialize函數在調用eglInitialize時清屏了

void QEglFSIntegration::initialize()
{
    qt_egl_device_integration()->platformInit();

    m_display = qt_egl_device_integration()->createDisplay(nativeDisplay());
    if (Q_UNLIKELY(m_display == EGL_NO_DISPLAY))
        qFatal("Could not open egl display");

    EGLint major, minor;
    if (Q_UNLIKELY(!eglInitialize(m_display, &major, &minor)))
        qFatal("Could not initialize egl display");

    m_inputContext = QPlatformInputContextFactory::create();

    m_vtHandler.reset(new QFbVtHandler);

    if (qt_egl_device_integration()->usesDefaultScreen())
        addScreen(new QEglFSScreen(display()));
    else
        qt_egl_device_integration()->screenInit();

    // Input code may rely on the screens, so do it only after the screen init.
    if (!m_disableInputHandlers)
        createInputHandlers();
}

然後在eglInitialize函數中搜索到了環境變量MALI_NOCLEAR,是libMali.so提供的opengles庫,因此在跑Qt程序之前導入一下環境變量即可

export MALI_NOCLEAR=1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章