| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "gpuinfo.h" |
| 5 | |
| 6 | #include <algorithm> |
| 7 | #include <iterator> |
| 8 | #include <utility> |
| 9 | |
| 10 | GPUInfo::GPUInfo(Vendor vendor, int index, IGPUInfo::Path &&path) noexcept |
| 11 | : vendor_(vendor) |
| 12 | , index_(index) |
| 13 | , path_(std::move(path)) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | Vendor GPUInfo::vendor() const |
| 18 | { |
| 19 | return vendor_; |
| 20 | } |
| 21 | |
| 22 | int GPUInfo::index() const |
| 23 | { |
| 24 | return index_; |
| 25 | } |
| 26 | |
| 27 | IGPUInfo::Path const &GPUInfo::path() const |
| 28 | { |
| 29 | return path_; |
| 30 | } |
| 31 | |
| 32 | std::vector<std::string> GPUInfo::keys() const |
| 33 | { |
| 34 | std::vector<std::string> keys; |
| 35 | keys.reserve(info_.size()); |
| 36 | |
| 37 | auto const keySelector = [](auto const &pair) { return pair.first; }; |
| 38 | std::transform(info_.cbegin(), info_.cend(), std::back_inserter(keys), |
| 39 | keySelector); |
| 40 | |
| 41 | return keys; |
| 42 | } |
| 43 | |
| 44 | std::string GPUInfo::info(std::string_view key) const |
| 45 | { |
| 46 | auto const dataIt = info_.find(std::string(key)); |
| 47 | if (dataIt != info_.cend()) |
| 48 | return dataIt->second; |
| 49 | |
| 50 | return std::string{}; |
| 51 | } |
| 52 | |
| 53 | bool GPUInfo::hasCapability(std::string_view name) const |
| 54 | { |
| 55 | return capabilities_.count(std::string(name)) > 0; |
| 56 | } |
| 57 | |
| 58 | void GPUInfo::initialize( |
| 59 | std::vector<std::unique_ptr<IGPUInfo::IProvider>> const &providers, |
| 60 | IHWIDTranslator const &hwidTranslator) |
| 61 | { |
| 62 | for (auto const &provider : providers) { |
| 63 | auto infos = provider->provideInfo(vendor_, index_, path_, hwidTranslator); |
| 64 | for (auto &info : infos) |
| 65 | info_.emplace(std::move(info)); |
| 66 | |
| 67 | auto capabilities = provider->provideCapabilities(vendor_, index_, path_); |
| 68 | for (auto &capability : capabilities) |
| 69 | capabilities_.emplace(std::move(capability)); |
| 70 | } |
| 71 | } |