1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2020 Collabora, Ltd. 3bf215546Sopenharmony_ci * Author: Antonio Caggiano <antonio.caggiano@collabora.com> 4bf215546Sopenharmony_ci * Author: Rohan Garg <rohan.garg@collabora.com> 5bf215546Sopenharmony_ci * Author: Robert Beckett <bob.beckett@collabora.com> 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT 8bf215546Sopenharmony_ci */ 9bf215546Sopenharmony_ci 10bf215546Sopenharmony_ci#pragma once 11bf215546Sopenharmony_ci 12bf215546Sopenharmony_ci#include <optional> 13bf215546Sopenharmony_ci#include <string> 14bf215546Sopenharmony_ci#include <vector> 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_cinamespace pps 17bf215546Sopenharmony_ci{ 18bf215546Sopenharmony_ci/// @brief Helper class for a DRM device 19bf215546Sopenharmony_ciclass DrmDevice 20bf215546Sopenharmony_ci{ 21bf215546Sopenharmony_ci public: 22bf215546Sopenharmony_ci /// @return The number of DRM devices available in the system 23bf215546Sopenharmony_ci static uint32_t device_count(); 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci /// @return All DRM devices available in the system 26bf215546Sopenharmony_ci static std::vector<DrmDevice> create_all(); 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci /// @return A DRM device selected by its number in the system, nullopt otherwise 29bf215546Sopenharmony_ci static std::optional<DrmDevice> create(int32_t gpu_num); 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci /// @brief Prefer calling create instead of default constructor 32bf215546Sopenharmony_ci DrmDevice() = default; 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci // Allow move 35bf215546Sopenharmony_ci DrmDevice(DrmDevice &&); 36bf215546Sopenharmony_ci DrmDevice &operator=(DrmDevice &&); 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci // Forbid copy 39bf215546Sopenharmony_ci DrmDevice(const DrmDevice &) = delete; 40bf215546Sopenharmony_ci DrmDevice &operator=(const DrmDevice &) = delete; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci ~DrmDevice(); 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci /// @return Whether a device has a valid name 45bf215546Sopenharmony_ci operator bool() const; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci /// File descriptor of the device opened in read/write mode 48bf215546Sopenharmony_ci int fd = -1; 49bf215546Sopenharmony_ci int32_t gpu_num = -1; 50bf215546Sopenharmony_ci std::string name = ""; 51bf215546Sopenharmony_ci}; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci} // namespace pps 54