Qml界面渲染机制



  • 渲染层次:

    0_1531798264848_48a56a99-a2a7-4a1e-8d0e-f12d889d74a1-image.png

    渲染循环分三种,basic, windows, and threaded,其中Basic和Windows是单线程的,threaded在单独线程里面渲染场景,qt会根据平台自动选择一种,我电脑上已经验证是threaded

    qt.scenegraph.general: threaded render loop qt.scenegraph.general: Using sg animation driver qt.scenegraph.general: Animation Driver: using vsync: 16.67 ms

    同时可以知道画面垂直同步是16.67 ms,理论60Hz

    线程渲染循环中如何完成一帧

    0_1531798407892_935d0c1f-554a-4cbb-999a-a0966484548d-image.png

    1. A change occurs in the QML scene, causing QQuickItem::update() to be called. This can be the result of for instance an animation or user input. An event is posted to the render thread to initiate a new frame.
    2. The render thread prepares to draw a new frame and makes the OpenGL context current and initiates a block on the GUI thread.
    3. While the render thread is preparing the new frame, the GUI thread calls QQuickItem::updatePolish() to do final touch-up of items before they are rendered.
    4. GUI thread is blocked.
    5. The QQuickWindow::beforeSynchronizing() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to do any preparation required before calls to QQuickItem::updatePaintNode().
    6. Synchronization of the QML state into the scene graph. This is done by calling the QQuickItem::updatePaintNode() function on all items that have changed since the previous frame. This is the only time the QML items and the nodes in the scene graph interact.
    7. GUI thread block is released.
    8. The scene graph is rendered:
    9. The QQuickWindow::beforeRendering() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually beneath the QML scene.
    10. Items that have specified QSGNode::UsePreprocess, will have their QSGNode::preprocess() function invoked.
    11. The renderer processes the nodes and calls OpenGL functions.
    12. The QQuickWindow::afterRendering() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually over the QML scene.
    13. The rendered frame is swapped and QQuickWindow::frameSwapped() is emitted.
    14. While the render thread is rendering, the GUI is free to advance animations, process events, etc.
      The threaded renderer is currently used by default on Windows with opengl32.dll, Linux with non-Mesa based drivers, macOS, mobile platforms, and Embedded Linux with EGLFS but this is subject to change. It is possible to force use of the threaded renderer by setting QSG_RENDER_LOOP=threaded in the environment.

    非线程渲染

    0_1531798434302_91612780-f2cf-4fdb-b5a1-aeb004a1e7a2-image.png

    查看渲染方式:

    QLoggingCategory::setFilterRules(QStringLiteral("qt.scenegraph.general=true")); qSetMessagePattern("%{category}: %{message}");



  • @青山白云 对,Qt Quick内部实现还是根据屏幕的刷新率来的。不这么做的话,在不同平台上使用Animator做动画速度会出现不一致的现象。所以Qt的Animation Driver也是按照这样的思路规定16.67ms。


 

走马观花

最近的回复

  • @chinasmu Webkit网络的部分可能不是受到Qt控制的,扩展性较差,所以呢,还不能通过代码的方式侦听网络收发数据。但是WebEngine就可以。如果可以的话,试试Qt WebEngine。😺

    阅读更多
  • C

    我用qt建了个对话框程序,里面加了个webkit,请问有办法获取该控件的全部网络封包通信数据吗?
    不采用windows hook recv和send函数的形式,或者有没有第三方的控件可以这样做

    阅读更多
  • 这个错误不是编译器的错误,而是IntelliSense的错误。
    这种情况,可以不用太担心。

    如果你使用MSVC编译应用程序,那么最好安装Qt Visual Studio Addon,使用这个插件同步开发Qt应用程序。
    不过一个小小的建议,就是Qt Creator写Qt程序非常直观,不需要在Visual Studio中那么麻烦,而且Qt Creator是强制安装的,基本上你安装了Qt 5.12,就可以在安装的目录中找到它。QAxContainer是Qt的模块activeQt中的,需要在pro文件中写QT += axcontainer,才会找到这个类。

    阅读更多
  • C

    VS2017 Qt5.12
    新建一个空的QWidget对话框,编译执行
    可以成功生成并执行,但是错误列表里显示

    傲游截图20190217212931.png

    exe文件能够成功生成。

    另外的问题:我在vs2017编译环境中使用qt,需要用到 QAxContainer,我看帮助文档里说要在.pro中加入CONFIG+=qaxcontainer,但是vs2017创建的程序中没有.pro这个文件,那这句话应该加在哪里呢?

    还有我想建一个有浏览器控件的对话框程序,如果想在5.12版本中加入QtWebKit应该如何使用

    阅读更多

关注我们

微博
QQ群











召唤伊斯特瓦尔