PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/compositor/compositor_api/qwaylandquickhardwarelayer.cpp

https://gitlab.com/f3822/qtwayland
C++ | 175 lines | 94 code | 21 blank | 60 comment | 14 complexity | aa670a351f964779cce785d540f8dc14 MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2018 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the plugins of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:GPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU
  19. ** General Public License version 3 or (at your option) any later version
  20. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  21. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  22. ** included in the packaging of this file. Please review the following
  23. ** information to ensure the GNU General Public License requirements will
  24. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  25. **
  26. ** $QT_END_LICENSE$
  27. **
  28. ****************************************************************************/
  29. #include "qwaylandquickhardwarelayer_p.h"
  30. #include <QtWaylandCompositor/private/qwlhardwarelayerintegration_p.h>
  31. #include <QtWaylandCompositor/private/qwlhardwarelayerintegrationfactory_p.h>
  32. #include <QtCore/private/qobject_p.h>
  33. #include <QMatrix4x4>
  34. QT_BEGIN_NAMESPACE
  35. class QWaylandQuickHardwareLayerPrivate : public QObjectPrivate
  36. {
  37. Q_DECLARE_PUBLIC(QWaylandQuickHardwareLayer)
  38. public:
  39. QtWayland::HardwareLayerIntegration *layerIntegration();
  40. QWaylandQuickItem *m_waylandItem = nullptr;
  41. int m_stackingLevel = 0;
  42. QMatrix4x4 m_matrixFromRenderThread;
  43. static QtWayland::HardwareLayerIntegration *s_hardwareLayerIntegration;
  44. };
  45. QtWayland::HardwareLayerIntegration *QWaylandQuickHardwareLayerPrivate::s_hardwareLayerIntegration = nullptr;
  46. QtWayland::HardwareLayerIntegration *QWaylandQuickHardwareLayerPrivate::layerIntegration()
  47. {
  48. if (!s_hardwareLayerIntegration) {
  49. QStringList keys = QtWayland::HardwareLayerIntegrationFactory::keys();
  50. QString environmentKey = QString::fromLocal8Bit(qgetenv("QT_WAYLAND_HARDWARE_LAYER_INTEGRATION").constData());
  51. if (!environmentKey.isEmpty()) {
  52. if (keys.contains(environmentKey)) {
  53. s_hardwareLayerIntegration = QtWayland::HardwareLayerIntegrationFactory::create(environmentKey, QStringList());
  54. } else {
  55. qWarning() << "Unknown hardware layer integration:" << environmentKey
  56. << "Valid layer integrations are" << keys;
  57. }
  58. } else if (!keys.isEmpty()) {
  59. s_hardwareLayerIntegration = QtWayland::HardwareLayerIntegrationFactory::create(keys.first(), QStringList());
  60. } else {
  61. qWarning() << "No wayland hardware layer integrations found";
  62. }
  63. }
  64. return s_hardwareLayerIntegration;
  65. }
  66. /*!
  67. * \qmltype WaylandHardwareLayer
  68. * \inqmlmodule QtWayland.Compositor
  69. * \preliminary
  70. * \brief Makes a parent WaylandQuickItem use hardware layers for rendering.
  71. *
  72. * This item needs to be a descendant of a WaylandQuickItem or a derivative,
  73. * (i.e. ShellSurfaceItem or similar)
  74. *
  75. * The Surface of the parent WaylandQuickItem will be drawn in a hardware specific way instead
  76. * of the regular way using the QtQuick scene graph. On some platforms, the WaylandQuickItem's
  77. * current buffer and the scene graph can be blended in a separate step. This makes it possible for
  78. * clients to update continuously without triggering a full redraw of the compositor scene graph for
  79. * each frame.
  80. *
  81. * The preferred hardware layer integration may be overridden by setting the
  82. * QT_WAYLAND_HARDWARE_LAYER_INTEGRATION environment variable.
  83. */
  84. QWaylandQuickHardwareLayer::QWaylandQuickHardwareLayer(QObject *parent)
  85. : QObject(*new QWaylandQuickHardwareLayerPrivate(), parent)
  86. {
  87. }
  88. QWaylandQuickHardwareLayer::~QWaylandQuickHardwareLayer()
  89. {
  90. Q_D(QWaylandQuickHardwareLayer);
  91. if (d->layerIntegration())
  92. d->layerIntegration()->remove(this);
  93. }
  94. /*!
  95. * \qmlproperty int QtWaylandCompositor::WaylandHardwareLayer::stackingLevel
  96. *
  97. * This property holds the stacking level of this hardware layer relative to other hardware layers,
  98. * and can be used to sort hardware layers. I.e. a layer with a higher level is rendered on top of
  99. * one with a lower level.
  100. *
  101. * Layers with level 0 will be drawn in an implementation defined order on top of the compositor
  102. * scene graph.
  103. *
  104. * Layers with a level below 0 are drawn beneath the compositor scene graph, if supported by the
  105. * hardware layer integration.
  106. */
  107. int QWaylandQuickHardwareLayer::stackingLevel() const
  108. {
  109. Q_D(const QWaylandQuickHardwareLayer);
  110. return d->m_stackingLevel;
  111. }
  112. void QWaylandQuickHardwareLayer::setStackingLevel(int level)
  113. {
  114. Q_D(QWaylandQuickHardwareLayer);
  115. if (level == d->m_stackingLevel)
  116. return;
  117. d->m_stackingLevel = level;
  118. emit stackingLevelChanged();
  119. }
  120. QWaylandQuickItem *QWaylandQuickHardwareLayer::waylandItem() const
  121. {
  122. Q_D(const QWaylandQuickHardwareLayer);
  123. return d->m_waylandItem;
  124. }
  125. void QWaylandQuickHardwareLayer::classBegin()
  126. {
  127. Q_D(QWaylandQuickHardwareLayer);
  128. for (QObject *p = parent(); p != nullptr; p = p->parent()) {
  129. if (auto *waylandItem = qobject_cast<QWaylandQuickItem *>(p)) {
  130. d->m_waylandItem = waylandItem;
  131. break;
  132. }
  133. }
  134. }
  135. void QWaylandQuickHardwareLayer::componentComplete()
  136. {
  137. Q_D(QWaylandQuickHardwareLayer);
  138. Q_ASSERT(d->m_waylandItem);
  139. if (auto integration = d->layerIntegration())
  140. integration->add(this);
  141. else
  142. qWarning() << "No hardware layer integration. WaylandHarwareLayer has no effect.";
  143. }
  144. void QWaylandQuickHardwareLayer::setSceneGraphPainting(bool enable)
  145. {
  146. waylandItem()->setPaintEnabled(enable);
  147. }
  148. // This should be called if QWaylandQuickHardwareLayer used as a native instance, not a qml component.
  149. void QWaylandQuickHardwareLayer::initialize()
  150. {
  151. classBegin();
  152. componentComplete();
  153. }
  154. QT_END_NAMESPACE