Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandquickhardwarelayer.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtWaylandCompositor/private/qwlhardwarelayerintegration_p.h>
8#include <QtWaylandCompositor/private/qwlhardwarelayerintegrationfactory_p.h>
9
10#include <QtCore/private/qobject_p.h>
11#include <QMatrix4x4>
12
14
25
27
28QtWayland::HardwareLayerIntegration *QWaylandQuickHardwareLayerPrivate::layerIntegration()
29{
30 if (!s_hardwareLayerIntegration) {
31 QStringList keys = QtWayland::HardwareLayerIntegrationFactory::keys();
32
33 QString environmentKey = QString::fromLocal8Bit(qgetenv("QT_WAYLAND_HARDWARE_LAYER_INTEGRATION").constData());
34 if (!environmentKey.isEmpty()) {
35 if (keys.contains(environmentKey)) {
36 s_hardwareLayerIntegration = QtWayland::HardwareLayerIntegrationFactory::create(environmentKey, QStringList());
37 } else {
38 qWarning() << "Unknown hardware layer integration:" << environmentKey
39 << "Valid layer integrations are" << keys;
40 }
41 } else if (!keys.isEmpty()) {
42 s_hardwareLayerIntegration = QtWayland::HardwareLayerIntegrationFactory::create(keys.first(), QStringList());
43 } else {
44 qWarning() << "No wayland hardware layer integrations found";
45 }
46 }
47
48 return s_hardwareLayerIntegration;
49}
50
51/*!
52 * \qmltype WaylandHardwareLayer
53 * \inqmlmodule QtWayland.Compositor
54 * \preliminary
55 * \brief Makes a parent WaylandQuickItem use hardware layers for rendering.
56 *
57 * This item needs to be a descendant of a WaylandQuickItem or a derivative,
58 * (i.e. ShellSurfaceItem or similar)
59 *
60 * The Surface of the parent WaylandQuickItem will be drawn in a hardware specific way instead
61 * of the regular way using the QtQuick scene graph. On some platforms, the WaylandQuickItem's
62 * current buffer and the scene graph can be blended in a separate step. This makes it possible for
63 * clients to update continuously without triggering a full redraw of the compositor scene graph for
64 * each frame.
65 *
66 * The preferred hardware layer integration may be overridden by setting the
67 * QT_WAYLAND_HARDWARE_LAYER_INTEGRATION environment variable.
68 */
69
70QWaylandQuickHardwareLayer::QWaylandQuickHardwareLayer(QObject *parent)
71 : QObject(*new QWaylandQuickHardwareLayerPrivate(), parent)
72{
73}
74
75QWaylandQuickHardwareLayer::~QWaylandQuickHardwareLayer()
76{
77 Q_D(QWaylandQuickHardwareLayer);
78 if (d->layerIntegration())
79 d->layerIntegration()->remove(this);
80}
81
82/*!
83 * \qmlproperty int QtWayland.Compositor::WaylandHardwareLayer::stackingLevel
84 *
85 * This property holds the stacking level of this hardware layer relative to other hardware layers,
86 * and can be used to sort hardware layers. I.e. a layer with a higher level is rendered on top of
87 * one with a lower level.
88 *
89 * Layers with level 0 will be drawn in an implementation defined order on top of the compositor
90 * scene graph.
91 *
92 * Layers with a level below 0 are drawn beneath the compositor scene graph, if supported by the
93 * hardware layer integration.
94 */
95int QWaylandQuickHardwareLayer::stackingLevel() const
96{
97 Q_D(const QWaylandQuickHardwareLayer);
98 return d->m_stackingLevel;
99}
100
101void QWaylandQuickHardwareLayer::setStackingLevel(int level)
102{
103 Q_D(QWaylandQuickHardwareLayer);
104 if (level == d->m_stackingLevel)
105 return;
106
107 d->m_stackingLevel = level;
108 emit stackingLevelChanged();
109}
110
111QWaylandQuickItem *QWaylandQuickHardwareLayer::waylandItem() const
112{
113 Q_D(const QWaylandQuickHardwareLayer);
114 return d->m_waylandItem;
115}
116
117void QWaylandQuickHardwareLayer::classBegin()
118{
119 Q_D(QWaylandQuickHardwareLayer);
120 for (QObject *p = parent(); p != nullptr; p = p->parent()) {
121 if (auto *waylandItem = qobject_cast<QWaylandQuickItem *>(p)) {
122 d->m_waylandItem = waylandItem;
123 break;
124 }
125 }
126}
127
128void QWaylandQuickHardwareLayer::componentComplete()
129{
130 Q_D(QWaylandQuickHardwareLayer);
131 Q_ASSERT(d->m_waylandItem);
132 if (auto integration = d->layerIntegration())
133 integration->add(this);
134 else
135 qWarning() << "No hardware layer integration. WaylandHarwareLayer has no effect.";
136}
137
138void QWaylandQuickHardwareLayer::setSceneGraphPainting(bool enable)
139{
140 waylandItem()->setPaintEnabled(enable);
141}
142
143// This should be called if QWaylandQuickHardwareLayer used as a native instance, not a qml component.
144void QWaylandQuickHardwareLayer::initialize()
145{
146 classBegin();
147 componentComplete();
148}
149
150QT_END_NAMESPACE
151
152#include "moc_qwaylandquickhardwarelayer_p.cpp"
static QtWayland::HardwareLayerIntegration * s_hardwareLayerIntegration
Combined button and popup list for selecting options.