Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_backend.cpp
Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 313 | if (m_planes.isEmpty()) { | |||
---|---|---|---|---|---|
315 | m_atomicModeSetting = false; | 315 | m_atomicModeSetting = false; | ||
316 | } | 316 | } | ||
317 | } | 317 | } | ||
318 | } else { | 318 | } else { | ||
319 | qCWarning(KWIN_DRM) << "drmSetClientCap for Atomic Mode Setting failed. Using legacy mode."; | 319 | qCWarning(KWIN_DRM) << "drmSetClientCap for Atomic Mode Setting failed. Using legacy mode."; | ||
320 | } | 320 | } | ||
321 | } | 321 | } | ||
322 | 322 | | |||
323 | DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd)); | | |||
324 | drmModeRes *res = resources.data(); | | |||
325 | if (!resources) { | | |||
326 | qCWarning(KWIN_DRM) << "drmModeGetResources failed"; | | |||
327 | return; | | |||
328 | } | | |||
329 | | ||||
330 | for (int i = 0; i < res->count_connectors; ++i) { | | |||
331 | m_connectors << new DrmConnector(res->connectors[i], m_fd); | | |||
332 | } | | |||
333 | for (int i = 0; i < res->count_crtcs; ++i) { | | |||
334 | m_crtcs << new DrmCrtc(res->crtcs[i], this, i); | | |||
335 | } | | |||
336 | | ||||
337 | if (m_atomicModeSetting) { | | |||
338 | auto tryAtomicInit = [] (DrmObject *obj) -> bool { | | |||
339 | if (obj->atomicInit()) { | | |||
340 | return false; | | |||
341 | } else { | | |||
342 | delete obj; | | |||
343 | return true; | | |||
344 | } | | |||
345 | }; | | |||
346 | m_connectors.erase(std::remove_if(m_connectors.begin(), m_connectors.end(), tryAtomicInit), m_connectors.end()); | | |||
347 | m_crtcs.erase(std::remove_if(m_crtcs.begin(), m_crtcs.end(), tryAtomicInit), m_crtcs.end()); | | |||
348 | } | | |||
349 | | ||||
350 | initCursor(); | 323 | initCursor(); | ||
351 | updateOutputs(); | 324 | if (!updateOutputs()) | ||
325 | return; | ||||
352 | 326 | | |||
353 | if (m_outputs.isEmpty()) { | 327 | if (m_outputs.isEmpty()) { | ||
354 | qCDebug(KWIN_DRM) << "No connected outputs found on startup."; | 328 | qCDebug(KWIN_DRM) << "No connected outputs found on startup."; | ||
355 | } | 329 | } | ||
356 | 330 | | |||
357 | // setup udevMonitor | 331 | // setup udevMonitor | ||
358 | if (m_udevMonitor) { | 332 | if (m_udevMonitor) { | ||
359 | m_udevMonitor->filterSubsystemDevType("drm"); | 333 | m_udevMonitor->filterSubsystemDevType("drm"); | ||
Show All 17 Lines | 337 | connect(notifier, &QSocketNotifier::activated, this, | |||
377 | } | 351 | } | ||
378 | ); | 352 | ); | ||
379 | m_udevMonitor->enable(); | 353 | m_udevMonitor->enable(); | ||
380 | } | 354 | } | ||
381 | } | 355 | } | ||
382 | setReady(true); | 356 | setReady(true); | ||
383 | } | 357 | } | ||
384 | 358 | | |||
385 | void DrmBackend::updateOutputs() | 359 | bool DrmBackend::updateOutputs() | ||
386 | { | 360 | { | ||
387 | if (m_fd < 0) { | 361 | if (m_fd < 0) { | ||
388 | return; | 362 | return false; | ||
389 | } | 363 | } | ||
390 | 364 | | |||
391 | DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd)); | 365 | DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd)); | ||
392 | if (!resources) { | 366 | if (!resources) { | ||
393 | qCWarning(KWIN_DRM) << "drmModeGetResources failed"; | 367 | qCWarning(KWIN_DRM) << "drmModeGetResources failed"; | ||
394 | return; | 368 | return false; | ||
369 | } | ||||
370 | | ||||
371 | drmModeRes *res = resources.data(); | ||||
372 | auto oldConnectors = m_connectors; | ||||
373 | for (int i = 0; i < res->count_connectors; ++i) { | ||||
374 | const uint32_t currentConnector = res->connectors[i]; | ||||
375 | auto it = std::find_if(m_connectors.constBegin(), m_connectors.constEnd(), [currentConnector] (DrmConnector *c) { return c->id() == currentConnector; }); | ||||
376 | if (it == m_connectors.constEnd()) { | ||||
377 | auto c = new DrmConnector(currentConnector, m_fd); | ||||
378 | if (m_atomicModeSetting && !c->atomicInit()) { | ||||
379 | delete c; | ||||
380 | continue; | ||||
381 | } | ||||
382 | m_connectors << c; | ||||
383 | } else { | ||||
384 | oldConnectors.removeOne(*it); | ||||
385 | } | ||||
386 | } | ||||
387 | | ||||
388 | auto oldCrtcs = m_crtcs; | ||||
389 | for (int i = 0; i < res->count_crtcs; ++i) { | ||||
390 | const uint32_t currentCrtc = res->crtcs[i]; | ||||
391 | auto it = std::find_if(m_crtcs.constBegin(), m_crtcs.constEnd(), [currentCrtc] (DrmCrtc *c) { return c->id() == currentCrtc; }); | ||||
392 | if (it == m_crtcs.constEnd()) { | ||||
393 | auto c = new DrmCrtc(currentCrtc, this, i); | ||||
394 | if (m_atomicModeSetting && !c->atomicInit()) { | ||||
395 | delete c; | ||||
396 | continue; | ||||
397 | } | ||||
398 | m_crtcs << c; | ||||
399 | } else { | ||||
400 | oldCrtcs.removeOne(*it); | ||||
401 | } | ||||
402 | } | ||||
403 | | ||||
404 | for (auto c : qAsConst(oldConnectors)) { | ||||
405 | m_connectors.removeOne(c); | ||||
406 | } | ||||
407 | for (auto c : qAsConst(oldCrtcs)) { | ||||
408 | m_crtcs.removeOne(c); | ||||
395 | } | 409 | } | ||
396 | 410 | | |||
397 | QVector<DrmOutput*> connectedOutputs; | 411 | QVector<DrmOutput*> connectedOutputs; | ||
398 | QVector<DrmConnector*> pendingConnectors; | 412 | QVector<DrmConnector*> pendingConnectors; | ||
399 | 413 | | |||
400 | // split up connected connectors in already or not yet assigned ones | 414 | // split up connected connectors in already or not yet assigned ones | ||
401 | for (DrmConnector *con : qAsConst(m_connectors)) { | 415 | for (DrmConnector *con : qAsConst(m_connectors)) { | ||
402 | if (!con->isConnected()) { | 416 | if (!con->isConnected()) { | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | |||||
499 | std::sort(connectedOutputs.begin(), connectedOutputs.end(), [] (DrmOutput *a, DrmOutput *b) { return a->m_conn->id() < b->m_conn->id(); }); | 513 | std::sort(connectedOutputs.begin(), connectedOutputs.end(), [] (DrmOutput *a, DrmOutput *b) { return a->m_conn->id() < b->m_conn->id(); }); | ||
500 | m_outputs = connectedOutputs; | 514 | m_outputs = connectedOutputs; | ||
501 | m_enabledOutputs = connectedOutputs; | 515 | m_enabledOutputs = connectedOutputs; | ||
502 | readOutputsConfiguration(); | 516 | readOutputsConfiguration(); | ||
503 | updateOutputsEnabled(); | 517 | updateOutputsEnabled(); | ||
504 | if (!m_outputs.isEmpty()) { | 518 | if (!m_outputs.isEmpty()) { | ||
505 | emit screensQueried(); | 519 | emit screensQueried(); | ||
506 | } | 520 | } | ||
521 | | ||||
522 | qDeleteAll(oldConnectors); | ||||
523 | qDeleteAll(oldCrtcs); | ||||
524 | return true; | ||||
507 | } | 525 | } | ||
508 | 526 | | |||
509 | void DrmBackend::readOutputsConfiguration() | 527 | void DrmBackend::readOutputsConfiguration() | ||
510 | { | 528 | { | ||
511 | if (m_outputs.isEmpty()) { | 529 | if (m_outputs.isEmpty()) { | ||
512 | return; | 530 | return; | ||
513 | } | 531 | } | ||
514 | const QByteArray uuid = generateOutputConfigurationUuid(); | 532 | const QByteArray uuid = generateOutputConfigurationUuid(); | ||
▲ Show 20 Lines • Show All 289 Lines • Show Last 20 Lines |