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