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