Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_object_plane.cpp
Show All 12 Lines | |||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "drm_object_plane.h" | 20 | #include "drm_object_plane.h" | ||
21 | #include "drm_backend.h" | ||||
21 | #include "drm_buffer.h" | 22 | #include "drm_buffer.h" | ||
22 | #include "drm_pointer.h" | 23 | #include "drm_pointer.h" | ||
23 | #include "logging.h" | 24 | #include "logging.h" | ||
24 | 25 | | |||
25 | namespace KWin | 26 | namespace KWin | ||
26 | { | 27 | { | ||
27 | 28 | | |||
28 | DrmPlane::DrmPlane(uint32_t plane_id, int fd) | 29 | DrmPlane::DrmPlane(uint32_t plane_id, DrmBackend *backend) | ||
29 | : DrmObject(plane_id, fd) | 30 | : DrmObject(plane_id, backend) | ||
30 | { | 31 | { | ||
31 | } | 32 | } | ||
32 | 33 | | |||
33 | DrmPlane::~DrmPlane() = default; | 34 | DrmPlane::~DrmPlane() | ||
35 | { | ||||
36 | delete m_current; | ||||
37 | delete m_next; | ||||
38 | } | ||||
34 | 39 | | |||
35 | bool DrmPlane::init() | 40 | bool DrmPlane::atomicInit() | ||
36 | { | 41 | { | ||
37 | qCDebug(KWIN_DRM) << "Initialize plane" << m_id; | 42 | qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id; | ||
38 | ScopedDrmPointer<_drmModePlane, &drmModeFreePlane> p(drmModeGetPlane(m_fd, m_id)); | 43 | ScopedDrmPointer<_drmModePlane, &drmModeFreePlane> p(drmModeGetPlane(m_backend->fd(), m_id)); | ||
39 | 44 | | |||
40 | if (!p) { | 45 | if (!p) { | ||
41 | qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id; | 46 | qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id; | ||
42 | return false; | 47 | return false; | ||
43 | } | 48 | } | ||
44 | 49 | | |||
45 | m_possibleCrtcs = p->possible_crtcs; | 50 | m_possibleCrtcs = p->possible_crtcs; | ||
46 | 51 | | |||
47 | m_formats.resize(p->count_formats); | 52 | int count_formats = p->count_formats; | ||
48 | for (int i = 0; i < p->count_formats; i++) { | 53 | m_formats.resize(count_formats); | ||
54 | for (int i = 0; i < count_formats; i++) { | ||||
49 | m_formats[i] = p->formats[i]; | 55 | m_formats[i] = p->formats[i]; | ||
50 | } | 56 | } | ||
51 | 57 | | |||
52 | if (!initProps()) { | 58 | if (!initProps()) { | ||
53 | return false; | 59 | return false; | ||
54 | } | 60 | } | ||
55 | return true; | 61 | return true; | ||
56 | } | 62 | } | ||
Show All 15 Lines | 65 | { | |||
72 | }; | 78 | }; | ||
73 | 79 | | |||
74 | QVector<QByteArray> typeNames = { | 80 | QVector<QByteArray> typeNames = { | ||
75 | QByteArrayLiteral("Primary"), | 81 | QByteArrayLiteral("Primary"), | ||
76 | QByteArrayLiteral("Cursor"), | 82 | QByteArrayLiteral("Cursor"), | ||
77 | QByteArrayLiteral("Overlay"), | 83 | QByteArrayLiteral("Overlay"), | ||
78 | }; | 84 | }; | ||
79 | 85 | | |||
80 | drmModeObjectProperties *properties = drmModeObjectGetProperties(m_fd, m_id, DRM_MODE_OBJECT_PLANE); | 86 | drmModeObjectProperties *properties = drmModeObjectGetProperties(m_backend->fd(), m_id, DRM_MODE_OBJECT_PLANE); | ||
81 | if (!properties){ | 87 | if (!properties){ | ||
82 | qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ; | 88 | qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ; | ||
83 | return false; | 89 | return false; | ||
84 | } | 90 | } | ||
85 | 91 | | |||
86 | int propCount = int(PropertyIndex::Count); | 92 | int propCount = int(PropertyIndex::Count); | ||
87 | for (int j = 0; j < propCount; ++j) { | 93 | for (int j = 0; j < propCount; ++j) { | ||
88 | if (j == int(PropertyIndex::Type)) { | 94 | if (j == int(PropertyIndex::Type)) { | ||
89 | initProp(j, properties, typeNames); | 95 | initProp(j, properties, typeNames); | ||
90 | } else { | 96 | } else { | ||
91 | initProp(j, properties); | 97 | initProp(j, properties); | ||
92 | } | 98 | } | ||
93 | } | 99 | } | ||
94 | 100 | | |||
95 | drmModeFreeObjectProperties(properties); | 101 | drmModeFreeObjectProperties(properties); | ||
96 | return true; | 102 | return true; | ||
97 | } | 103 | } | ||
98 | 104 | | |||
99 | DrmPlane::TypeIndex DrmPlane::type() | 105 | DrmPlane::TypeIndex DrmPlane::type() | ||
100 | { | 106 | { | ||
101 | uint64_t value = propValue(int(PropertyIndex::Type)); | 107 | uint64_t v = value(int(PropertyIndex::Type)); | ||
102 | int typeCount = int(TypeIndex::Count); | 108 | int typeCount = int(TypeIndex::Count); | ||
103 | for (int i = 0; i < typeCount; i++) { | 109 | for (int i = 0; i < typeCount; i++) { | ||
104 | if (m_props[int(PropertyIndex::Type)]->enumMap(i) == value) { | 110 | if (m_props[int(PropertyIndex::Type)]->enumMap(i) == v) { | ||
105 | return TypeIndex(i); | 111 | return TypeIndex(i); | ||
106 | } | 112 | } | ||
107 | } | 113 | } | ||
108 | return TypeIndex::Overlay; | 114 | return TypeIndex::Overlay; | ||
109 | } | 115 | } | ||
110 | 116 | | |||
111 | bool DrmPlane::isCrtcSupported(uint32_t crtc) | 117 | void DrmPlane::setNext(DrmBuffer *b){ | ||
112 | { | 118 | setValue(int(PropertyIndex::FbId), b ? b->bufferId() : 0); | ||
113 | ScopedDrmPointer<_drmModeRes, &drmModeFreeResources> res(drmModeGetResources(m_fd)); | 119 | m_next = b; | ||
114 | if (!res) { | | |||
115 | qCWarning(KWIN_DRM) << "Failed to get drm resources"; | | |||
116 | } | | |||
117 | for (int c = 0; c < res->count_crtcs; c++) { | | |||
118 | if (res->crtcs[c] != crtc) { | | |||
119 | continue; | | |||
120 | } | | |||
121 | qCDebug(KWIN_DRM) << "Mask " << m_possibleCrtcs << ", idx " << c; | | |||
122 | if (m_possibleCrtcs & (1 << c)) { | | |||
123 | return true; | | |||
124 | } | | |||
125 | } | | |||
126 | qCDebug(KWIN_DRM) << "CRTC" << crtc << "not supported"; | | |||
127 | return false; | | |||
128 | } | | |||
129 | | ||||
130 | | ||||
131 | void DrmPlane::setFormats(uint32_t const *f, int fcount) | | |||
132 | { | | |||
133 | m_formats.resize(fcount); | | |||
134 | for (int i = 0; i < fcount; i++) { | | |||
135 | m_formats[i] = *f; | | |||
136 | } | | |||
137 | } | 120 | } | ||
138 | 121 | | |||
139 | DrmObject::AtomicReturn DrmPlane::atomicReqPlanePopulate(drmModeAtomicReq *req) | 122 | bool DrmPlane::atomicPopulate(drmModeAtomicReq *req) | ||
140 | { | 123 | { | ||
141 | bool ret = true; | 124 | bool ret = true; | ||
142 | 125 | | |||
143 | if (m_next) { | 126 | for (int i = 1; i < m_props.size(); i++) { | ||
144 | setPropValue(int(PropertyIndex::FbId), m_next->bufferId()); | 127 | ret &= atomicAddProperty(req, i, m_props[i]->value()); | ||
145 | } else { | | |||
146 | setPropValue(int(PropertyIndex::FbId), 0); | | |||
147 | setPropValue(int(PropertyIndex::SrcX), 0); | | |||
148 | setPropValue(int(PropertyIndex::SrcY), 0); | | |||
149 | setPropValue(int(PropertyIndex::SrcW), 0); | | |||
150 | setPropValue(int(PropertyIndex::SrcH), 0); | | |||
151 | setPropValue(int(PropertyIndex::CrtcX), 0); | | |||
152 | setPropValue(int(PropertyIndex::CrtcY), 0); | | |||
153 | setPropValue(int(PropertyIndex::CrtcW), 0); | | |||
154 | setPropValue(int(PropertyIndex::CrtcH), 0); | | |||
155 | } | | |||
156 | | ||||
157 | m_propsPending = 0; | | |||
158 | | ||||
159 | for (int i = int(PropertyIndex::SrcX); i < int(PropertyIndex::CrtcId); i++) { | | |||
160 | ret &= atomicAddProperty(req, i, propValue(i)); | | |||
161 | } | 128 | } | ||
162 | ret &= atomicAddProperty(req, int(PropertyIndex::CrtcId), m_next ? propValue(int(PropertyIndex::CrtcId)) : 0); | | |||
163 | 129 | | |||
164 | if (!ret) { | 130 | if (!ret) { | ||
165 | qCWarning(KWIN_DRM) << "Failed to populate atomic plane" << m_id; | 131 | qCWarning(KWIN_DRM) << "Failed to populate atomic plane" << m_id; | ||
166 | return DrmObject::AtomicReturn::Error; | 132 | return false; | ||
133 | } | ||||
134 | return true; | ||||
135 | } | ||||
136 | | ||||
137 | void DrmPlane::flipBuffer() | ||||
138 | { | ||||
139 | m_current = m_next; | ||||
140 | m_next = nullptr; | ||||
167 | } | 141 | } | ||
168 | if (!m_propsPending) { | 142 | | ||
169 | return DrmObject::AtomicReturn::NoChange; | 143 | void DrmPlane::flipBufferWithDelete() | ||
144 | { | ||||
145 | if (m_current != m_next) { | ||||
146 | delete m_current; | ||||
170 | } | 147 | } | ||
171 | return DrmObject::AtomicReturn::Success; | 148 | flipBuffer(); | ||
172 | } | 149 | } | ||
173 | 150 | | |||
174 | } | 151 | } |