1 /*
2     KWin - the KDE window manager
3     This file is part of the KDE project.
4 
5     SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com>
6     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
7 
8     SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 #ifndef KWIN_DRM_BUFFER_GBM_H
11 #define KWIN_DRM_BUFFER_GBM_H
12 
13 #include "drm_buffer.h"
14 
15 #include <QSharedPointer>
16 
17 struct gbm_bo;
18 
19 namespace KWaylandServer
20 {
21 class ClientBuffer;
22 }
23 
24 namespace KWin
25 {
26 
27 class GbmSurface;
28 
29 class GbmBuffer : public QObject
30 {
31     Q_OBJECT
32 public:
33     GbmBuffer(GbmSurface *surface, gbm_bo *bo);
34     GbmBuffer(gbm_bo *buffer, KWaylandServer::ClientBuffer *clientBuffer);
35     virtual ~GbmBuffer();
36 
getBo()37     gbm_bo* getBo() const {
38         return m_bo;
39     }
40 
41     void releaseBuffer();
42 
43     bool map(uint32_t flags);
mappedData()44     void *mappedData() const {
45         return m_data;
46     }
stride()47     uint32_t stride() const {
48         return m_stride;
49     }
50 
51 protected:
52     GbmSurface *m_surface = nullptr;
53     gbm_bo *m_bo = nullptr;
54     KWaylandServer::ClientBuffer *m_clientBuffer = nullptr;
55 
56     void *m_data = nullptr;
57     void *m_mapping = nullptr;
58     uint32_t m_stride = 0;
59 };
60 
61 class DrmGbmBuffer : public DrmBuffer, public GbmBuffer
62 {
63 public:
64     DrmGbmBuffer(DrmGpu *gpu, GbmSurface *surface, gbm_bo *bo);
65     DrmGbmBuffer(DrmGpu *gpu, gbm_bo *buffer, KWaylandServer::ClientBuffer *clientBuffer);
66     ~DrmGbmBuffer() override;
67 
needsModeChange(DrmBuffer * b)68     bool needsModeChange(DrmBuffer *b) const override {
69         if (DrmGbmBuffer *sb = dynamic_cast<DrmGbmBuffer*>(b)) {
70             return hasBo() != sb->hasBo();
71         } else {
72             return true;
73         }
74     }
75 
hasBo()76     bool hasBo() const {
77         return m_bo != nullptr;
78     }
79 
80 private:
81     void initialize();
82 };
83 
84 }
85 
86 #endif
87 
88