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 
30 #ifndef VSP2HARDWARELAYERINTEGRATION_H
31 #define VSP2HARDWARELAYERINTEGRATION_H
32 
33 #include <QtWaylandCompositor/private/qwlhardwarelayerintegration_p.h>
34 #include <private/qobject_p.h>
35 
36 #include <QPoint>
37 #include <QSize>
38 
39 struct wl_kms_buffer;
40 
41 QT_BEGIN_NAMESPACE
42 
43 class QScreen;
44 class QWaylandSurface;
45 class QWaylandQuickHardwareLayer;
46 
47 class Vsp2Layer;
48 
49 class Vsp2HardwareLayerIntegration : public QtWayland::HardwareLayerIntegration
50 {
51     Q_OBJECT
52 public:
53     explicit Vsp2HardwareLayerIntegration();
54 
55     void add(QWaylandQuickHardwareLayer *layer) override;
56     void remove(QWaylandQuickHardwareLayer *layer) override;
57 
58     void sendFrameCallbacks();
59     QVector<QSharedPointer<Vsp2Layer>> m_layers;
60 private:
61     void enableVspLayers();
62     void disableVspLayers();
63     void sortLayersByDepth();
64     void recreateVspLayers();
65     friend class Vsp2Layer;
66 };
67 
68 struct Vsp2Buffer
69 {
70     explicit Vsp2Buffer() = default;
71     explicit Vsp2Buffer(wl_kms_buffer *kmsBuffer);
72 
73     int dmabufFd = -1;
74     uint bytesPerLine = 0;
75     uint drmPixelFormat = 0;
76     QSize size;
77 };
78 
79 class Vsp2Layer : public QObject
80 {
81     Q_OBJECT
82 public:
83     explicit Vsp2Layer(QWaylandQuickHardwareLayer *m_hwLayer, Vsp2HardwareLayerIntegration *integration);
84     void enableVspLayer();
85     void disableVspLayer();
isEnabled()86     bool isEnabled() { return m_layerIndex != -1; }
hwLayer()87     QWaylandQuickHardwareLayer *hwLayer() const { return m_hwLayer; }
88 
89 public slots:
90     void handleBufferCommitted();
91     void handleSurfaceChanged();
92     void updatePosition();
93     void updateOpacity();
94 
95 private:
96     wl_kms_buffer *nextKmsBuffer();
97     int m_layerIndex = -1;
98     QScreen *m_screen = nullptr;
99     QPoint m_position;
100     QWaylandQuickHardwareLayer *m_hwLayer = nullptr;
101     QWaylandSurface *m_surface = nullptr;
102     Vsp2Buffer m_buffer;
103 };
104 
105 QT_END_NAMESPACE
106 
107 #endif // VSP2HARDWARELAYERINTEGRATION_H
108