【问题标题】:QML DropShadow performance issue on android appandroid应用程序上的QML DropShadow性能问题
【发布时间】:2021-04-13 16:17:12
【问题描述】:

我前段时间偶然发现了这个问题并发表了这篇文章:Is my QML android application running on software and how can I fix this?

答案表明应用程序实际上是在 GPU 上呈现的,我只需要使用分析器优化我的代码,但我没有发现任何复杂的绑定或任何可以显着优化的东西。但我确实注意到阴影是导致所有滞后的原因。我决定尝试一下,并创建了一个非常简单的程序:两个旋转的矩形,它们都应用了阴影。


代码如下:

import QtQuick 2.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.0

import MyFpsText 1.0


Window {
    id: mw
    visible: true

    MyFpsText {
        anchors.right: parent.right
        anchors.top: parent.top

        width: 100
        height: 100

        Text {
            anchors.centerIn: parent
            font.pixelSize: 20
            text: parent.fps
        }
    }

    Rectangle {
        id: rect1
        anchors.horizontalCenter: parent.horizontalCenter
        y: 200

        width: 200
        height: 50

        color: "skyblue";

        layer.enabled: true
        layer.effect: DropShadow {
            radius: 50
            samples: 101
        }
    }

    Rectangle {
        id: rect2
        anchors.horizontalCenter: parent.horizontalCenter
        y: 500

        width: 200
        height: 50

        color: "skyblue";

        layer.enabled: true
        layer.effect: DropShadow {
            radius: 50
            samples: 101
        }
    }


    RotationAnimator {
        target: rect1

        running: true
        loops: Animation.Infinite

        from: 0
        to: 360
        duration: 2000
    }
}

我还使用了从 here 获取的自定义元素 MyFpsText


现在是结果。 Stack Overflow 不允许超过 2 MB 的 gif,所以它们在 imgur 上:https://imgur.com/a/G0LoRsy

  1. 首先,没有阴影 - 一切都很好,120fps

  2. Shadow 参数:radius: 30samples: 61(在官方文档中建议,samples = 2 * radius + 1)。当 fps 降至 30 时,延迟已经很明显了

  3. 最糟糕的是:radius: 50, fps -- 11


所以。这绝对不是一个糟糕的代码问题,并且应用程序是在硬件上呈现的(根据上一篇文章的答案)。那是什么?我该怎么办?

我使用的是 Qt 5.12.2


另外,还有一个可能相关的问题。桌面上也有类似的问题。虽然这与 fps 无关:当我调整窗口大小时 UI 会滞后(对于任何 qml 应用程序,这个或我制作的任何其他应用程序)。这个问题虽然可以通过设置qputenv("QT_OPENGL", "angle"); 解决,但有人说这更像是一种黑客攻击,angle 是 CPU 渲染的(然而,由于某种原因它运行得更好,但无论如何)。

我发现this post 说它已在 qt 5.9.2 中修复,但我使用的是 qt 5.15.2 并且未修复。

【问题讨论】:

    标签: c++ qt qml


    【解决方案1】:

    我猜如果你打开cached属性你会看到更好的结果:

    https://doc.qt.io/qt-5/qml-qtgraphicaleffects-dropshadow.html#cached-prop

    【讨论】:

    • 哇,它确实有效,我以为我以前尝试过。谢谢!没想到这么简单……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 2013-03-02
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2017-05-28
    相关资源
    最近更新 更多