Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_buffer.h
Show All 28 Lines | |||||
29 | namespace KWin | 29 | namespace KWin | ||
30 | { | 30 | { | ||
31 | 31 | | |||
32 | class DrmBackend; | 32 | class DrmBackend; | ||
33 | 33 | | |||
34 | class DrmBuffer | 34 | class DrmBuffer | ||
35 | { | 35 | { | ||
36 | public: | 36 | public: | ||
37 | ~DrmBuffer(); | 37 | DrmBuffer(DrmBackend *backend); | ||
38 | ~DrmBuffer() = default; | ||||
39 | | ||||
40 | virtual bool modeChange(DrmBuffer *b) const = 0; | ||||
38 | 41 | | |||
39 | bool map(QImage::Format format = QImage::Format_RGB32); | | |||
40 | QImage *image() const { | | |||
41 | return m_image; | | |||
42 | } | | |||
43 | quint32 handle() const { | | |||
44 | return m_handle; | | |||
45 | } | | |||
46 | const QSize &size() const { | | |||
47 | return m_size; | | |||
48 | } | | |||
49 | quint32 bufferId() const { | 42 | quint32 bufferId() const { | ||
50 | return m_bufferId; | 43 | return m_bufferId; | ||
51 | } | 44 | } | ||
52 | quint32 stride() const { | 45 | quint32 stride() const { | ||
53 | return m_stride; | 46 | return m_stride; | ||
54 | } | 47 | } | ||
55 | gbm_bo *gbm() const { | 48 | | ||
56 | return m_bo; | 49 | virtual void releaseGbm() {} | ||
50 | | ||||
51 | protected: | ||||
52 | DrmBackend *m_backend; | ||||
53 | quint32 m_bufferId = 0; | ||||
54 | quint32 m_stride = 0; | ||||
55 | quint64 m_bufferSize = 0; | ||||
56 | }; | ||||
57 | | ||||
58 | class DrmSurfaceBuffer : public DrmBuffer | ||||
graesslin: maybe ifdef the complete DrmSurfaceBuffer based on HAVE_GBM? Might simplify the ifdef logic in… | |||||
59 | { | ||||
60 | public: | ||||
61 | DrmSurfaceBuffer(DrmBackend *backend, gbm_surface *surface); | ||||
62 | ~DrmSurfaceBuffer(); | ||||
63 | | ||||
64 | bool modeChange(DrmBuffer *b) const override { | ||||
65 | return isGbm() != static_cast<DrmSurfaceBuffer*>(b)->isGbm(); | ||||
57 | } | 66 | } | ||
67 | | ||||
58 | bool isGbm() const { | 68 | bool isGbm() const { | ||
59 | return m_bo != nullptr; | 69 | return m_bo != nullptr; | ||
60 | } | 70 | } | ||
61 | bool deleteAfterPageFlip() const { | 71 | void releaseGbm() override; | ||
62 | return m_deleteAfterPageFlip; | | |||
63 | } | | |||
64 | | ||||
65 | void releaseGbm(); | | |||
66 | 72 | | |||
67 | private: | 73 | private: | ||
68 | friend class DrmBackend; | | |||
69 | DrmBuffer(DrmBackend *backend, const QSize &size); | | |||
70 | DrmBuffer(DrmBackend *backend, gbm_surface *surface); | | |||
71 | DrmBackend *m_backend; | | |||
72 | gbm_surface *m_surface = nullptr; | 74 | gbm_surface *m_surface = nullptr; | ||
73 | gbm_bo *m_bo = nullptr; | 75 | gbm_bo *m_bo = nullptr; | ||
74 | QSize m_size; | 76 | }; | ||
77 | | ||||
78 | class DrmDumbBuffer : public DrmBuffer | ||||
79 | { | ||||
80 | public: | ||||
81 | DrmDumbBuffer(DrmBackend *backend, const QSize &size); | ||||
82 | ~DrmDumbBuffer(); | ||||
83 | | ||||
84 | bool modeChange(DrmBuffer *b) const override { | ||||
85 | return m_stride == b->stride(); | ||||
86 | } | ||||
87 | | ||||
88 | bool map(QImage::Format format = QImage::Format_RGB32); | ||||
89 | quint32 handle() const { | ||||
90 | return m_handle; | ||||
91 | } | ||||
92 | QImage *image() const { | ||||
93 | return m_image; | ||||
94 | } | ||||
95 | const QSize &size() const { | ||||
96 | return m_size; | ||||
97 | } | ||||
98 | | ||||
99 | private: | ||||
75 | quint32 m_handle = 0; | 100 | quint32 m_handle = 0; | ||
76 | quint32 m_bufferId = 0; | | |||
77 | quint32 m_stride = 0; | | |||
78 | quint64 m_bufferSize = 0; | 101 | quint64 m_bufferSize = 0; | ||
79 | void *m_memory = nullptr; | 102 | void *m_memory = nullptr; | ||
80 | QImage *m_image = nullptr; | 103 | QImage *m_image = nullptr; | ||
81 | bool m_deleteAfterPageFlip = false; | 104 | QSize m_size; | ||
82 | }; | 105 | }; | ||
83 | 106 | | |||
84 | } | 107 | } | ||
85 | 108 | | |||
86 | #endif | 109 | #endif | ||
87 | 110 | |
maybe ifdef the complete DrmSurfaceBuffer based on HAVE_GBM? Might simplify the ifdef logic in other areas.
Or: move the DrmSurfaceBuffer into a dedicated .h and .cpp file and only include the .cpp if we have gbm. Then we don't need any ifdefs at all.