diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/drm++/mode/mode.hpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/include/drm++/mode/mode.hpp b/include/drm++/mode/mode.hpp new file mode 100644 index 0000000..8df8845 --- /dev/null +++ b/include/drm++/mode/mode.hpp @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: MIT */ + +#pragma once + +/// +/// * DRM Resource +/// +/// ... +/// +/// * Notes to self +/// +/// - No encoder abstraction in atomic +/// - No subpixel due to inconsistent +/// - Might need to delete copy/move +/// - Raw mode as drm_mode_modeinfo +/// - Examine mode change behavior +/// + +#include "../helper/macros.hpp" +#include "../helper/types.hpp" + +#include <string> +#include <utility> +#include <vector> + +namespace drm::mode { + +enum class ConnectorType : u32; + +/// +/// Mode information +/// +struct ModeInfo { + /// Width and height in pixels + std::pair<u16, u16> resolution; + /// Refresh rate in Hz + double refreshRate; + /// Whether the mode is preferred (cannot be relied on) + bool preferred; + + /// Raw drm_mode_modeinfo struct + u8 raw[68]; +}; + +/// +/// CRTC object +/// +struct Crtc { + u32 id; +}; + +/// +/// Connector object +/// +struct Connector { + u32 id; + + /// Type of the connector + ConnectorType type; + /// Index of the connector per type (e.g. DP-3 or HDMI-A-1) + u32 typeIndex; + /// Supported modes of the connector (may change after failed commit) + std::vector<ModeInfo> modes; + /// Physical size of the display in millimeters if available + std::pair<u32, u32> physicalSize; +}; + +struct Plane { + u32 id; + + /// CRTC IDs the plane can be used with + std::vector<u32> crtcs; +}; + +/// +/// Modesetting resources +/// +/// @throws drm::ioctl::Exception on failure +/// +class Resources { +public: + /// + /// Query all modesetting resources + /// + /// @param fetchModes Whether to fetch connector modes (blocking). + /// + Resources(int fd, bool fetchModes = false); + + // Private access + GETTER(crtcs) + GETTER(connectors) + GETTER(planes) + + // Default operators and destructor + DEFAULT_OPERATORS(Resources) + ~Resources() noexcept = default; +private: + int m_fd; + + std::vector<Crtc> m_crtcs; + std::vector<Connector> m_connectors; + std::vector<Plane> m_planes; +}; + + +/// +/// Connector type +/// +enum class ConnectorType : u32 { + Unknown = 0, + VGA = 1, + DVII = 2, + DVID = 3, + DVIA = 4, + Composite = 5, + SVIDEO = 6, + LVDS = 7, + Component = 8, + NPinDIN = 9, + DisplayPort = 10, + HDMI_A = 11, + HDMI_B = 12, + TV = 13, + eDP = 14, + Virtual = 15, + DSI = 16, + DPI = 17, + Writeback = 18, + SPI = 19, + USB = 20 +}; + +/// +/// Convert a ConnectorType enum to a string representation +/// +std::string connectorTypeToString(ConnectorType type); + +} |
