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