|
3 | 3 |
|
4 | 4 | #include "content_client_qt.h"
|
5 | 5 |
|
| 6 | +#include "compositor/compositor.h" |
| 7 | + |
6 | 8 | #include "base/command_line.h"
|
7 | 9 | #include "base/files/file_util.h"
|
8 | 10 | #include "base/json/json_string_value_serializer.h"
|
|
29 | 31 | #include <QLibraryInfo>
|
30 | 32 | #include <QString>
|
31 | 33 | #include <QSysInfo>
|
32 |
| - |
| 34 | +#include <QThread> |
33 | 35 |
|
34 | 36 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS)
|
35 | 37 | #include "media/cdm/cdm_paths.h" // nogncheck
|
@@ -485,4 +487,104 @@ blink::OriginTrialPolicy *ContentClientQt::GetOriginTrialPolicy()
|
485 | 487 | return origin_trial_policy_.get();
|
486 | 488 | }
|
487 | 489 |
|
| 490 | +void ContentClientQt::SetGpuInfo(const gpu::GPUInfo &gpu_info) |
| 491 | +{ |
| 492 | + if (Q_LIKELY(!lcWebEngineCompositor().isDebugEnabled())) |
| 493 | + return; |
| 494 | + |
| 495 | + base::CommandLine *commandLine = base::CommandLine::ForCurrentProcess(); |
| 496 | + const bool isBrowserProcess = !commandLine->HasSwitch(switches::kProcessType); |
| 497 | + const bool isMainThread = QThread::currentThread() == qApp->thread(); |
| 498 | + |
| 499 | + // Limit this to the main thread of the browser process for now. |
| 500 | + if (!isBrowserProcess || !isMainThread) |
| 501 | + return; |
| 502 | + |
| 503 | + if (!gpu_info.IsInitialized()) { |
| 504 | + // This is probably not an issue but suspicious. |
| 505 | + qCDebug(lcWebEngineCompositor, "Failed to initialize GPUInfo."); |
| 506 | + return; |
| 507 | + } |
| 508 | + |
| 509 | + const gpu::GPUInfo::GPUDevice &primary = gpu_info.gpu; |
| 510 | + |
| 511 | + // Do not print the info again if the device hasn't been changed. |
| 512 | + // Change of the device is unexpected: we don't support or implement fallback yet. |
| 513 | + // It is suspicious if the info is logged twice. |
| 514 | + if (m_gpuInfo && m_gpuInfo->gpu.device_string == primary.device_string) |
| 515 | + return; |
| 516 | + m_gpuInfo = gpu_info; |
| 517 | + |
| 518 | + auto deviceToString = [](const gpu::GPUInfo::GPUDevice &device) -> QString { |
| 519 | + if (device.vendor_id == 0x0) |
| 520 | + return "Disabled"_L1; |
| 521 | + |
| 522 | + QString log; |
| 523 | + |
| 524 | + // TODO: Factor vendor translation out from QtWebEngineCore::GPUInfo. |
| 525 | + // Only name the most commmon desktop GPU hardware vendors for now. |
| 526 | + switch (device.vendor_id) { |
| 527 | + case 0x1002: |
| 528 | + log += "AMD"_L1; |
| 529 | + break; |
| 530 | + case 0x10DE: |
| 531 | + log += "Nvidia"_L1; |
| 532 | + break; |
| 533 | + case 0x8086: |
| 534 | + log += "Intel"_L1; |
| 535 | + break; |
| 536 | + default: |
| 537 | + log += "vendor id: 0x"_L1 + QString::number(device.vendor_id, 16); |
| 538 | + } |
| 539 | + |
| 540 | + log += ", device id: 0x"_L1 + QString::number(device.device_id, 16); |
| 541 | + |
| 542 | + if (!device.driver_vendor.empty()) { |
| 543 | + log += ", driver: "_L1 + QLatin1StringView(device.driver_vendor) + u' ' |
| 544 | + + QLatin1StringView(device.driver_version); |
| 545 | + } |
| 546 | + log += ", system device id: 0x"_L1 + QString::number(device.system_device_id, 16); |
| 547 | + |
| 548 | + log += ", preference: "_L1; |
| 549 | + switch (device.gpu_preference) { |
| 550 | + case gl::GpuPreference::kNone: |
| 551 | + log += "None"_L1; |
| 552 | + break; |
| 553 | + case gl::GpuPreference::kDefault: |
| 554 | + log += "Default"_L1; |
| 555 | + break; |
| 556 | + case gl::GpuPreference::kLowPower: |
| 557 | + log += "LowPower"_L1; |
| 558 | + break; |
| 559 | + case gl::GpuPreference::kHighPerformance: |
| 560 | + log += "HighPerformance"_L1; |
| 561 | + break; |
| 562 | + } |
| 563 | + |
| 564 | + log += ", active: "_L1 + (device.active ? "yes"_L1 : "no"_L1); |
| 565 | + return log; |
| 566 | + }; |
| 567 | + |
| 568 | + QString log; |
| 569 | + if (gpu_info.gl_vendor.empty() || gpu_info.gl_vendor == "Disabled") { |
| 570 | + log += "ANGLE is disabled:\n"_L1; |
| 571 | + log += " GL Renderer: "_L1 + QLatin1StringView(gpu_info.gl_renderer) + u'\n'; |
| 572 | + log += " Software Renderer: "_L1 + (primary.IsSoftwareRenderer() ? "yes"_L1 : "no"_L1) |
| 573 | + + u'\n'; |
| 574 | + log += " Primary GPU: "_L1 + deviceToString(primary) + u'\n'; |
| 575 | + } else { |
| 576 | + log += QLatin1StringView(gpu_info.display_type) + " display is initialized:\n"_L1; |
| 577 | + log += " GL Renderer: "_L1 + QLatin1StringView(gpu_info.gl_renderer) + u'\n'; |
| 578 | + log += " "_L1 + QString::number(gpu_info.GpuCount()) + " GPU(s) detected:\n"_L1; |
| 579 | + log += " "_L1 + deviceToString(primary) + u'\n'; |
| 580 | + for (auto &secondary : gpu_info.secondary_gpus) |
| 581 | + log += " "_L1 + deviceToString(secondary) + u'\n'; |
| 582 | + |
| 583 | + log += " NVIDIA Optimus: "_L1 + (gpu_info.optimus ? "enabled"_L1 : "disabled"_L1) + u'\n'; |
| 584 | + log += " AMD Switchable: "_L1 + (gpu_info.amd_switchable ? "enabled"_L1 : "disabled"_L1); |
| 585 | + } |
| 586 | + |
| 587 | + qCDebug(lcWebEngineCompositor, "%ls", qUtf16Printable(log)); |
| 588 | +} |
| 589 | + |
488 | 590 | } // namespace QtWebEngineCore
|
0 commit comments