Loading...
Searching...
No Matches
DrmKmsDevice.hpp
Go to the documentation of this file.
1#pragma once
2
35#include <score_plugin_gfx_export.h>
36
37#include <cstdint>
38#include <memory>
39#include <string>
40#include <vector>
41
42namespace score::gfx::drm
43{
44
46{
47 std::string name;
48 std::uint32_t width{}, height{};
49 std::uint32_t refreshMilliHz{};
50 std::uint32_t clockKHz{};
51 bool interlaced{};
52 bool preferred{};
53};
54
56{
57 std::uint32_t id{};
58 std::string name;
59 bool connected{};
63 bool writeback{};
64 std::uint32_t mmWidth{}, mmHeight{};
65 std::vector<ModeInfo> modes;
66 std::vector<std::uint32_t> possibleCrtcs;
67};
68
72{
73 std::uint32_t fourcc{};
74 std::vector<std::uint64_t> modifiers;
75};
76
78{
79 std::uint32_t id{};
80 enum Type
81 {
82 Overlay,
83 Primary,
84 Cursor
85 } type{Overlay};
86 std::uint32_t possibleCrtcs{};
87 std::vector<PlaneFormat> formats;
88};
89
91{
92 std::uint32_t id{};
93 int index{};
94 bool active{};
95};
96
98{
99 std::string path;
100 std::string driver;
101 bool atomic{};
104 bool hasMaster{};
105 std::vector<ConnectorInfo> connectors;
106 std::vector<CrtcInfo> crtcs;
107 std::vector<PlaneInfo> planes;
108};
109
112{
113 std::uint32_t width{}, height{};
114 std::uint32_t fourcc{};
115 std::uint64_t modifier{};
116 int fd[4]{-1, -1, -1, -1};
117 std::uint32_t stride[4]{};
118 std::uint32_t offset[4]{};
119 std::uint32_t planeCount{1};
120};
121
124{
125 std::uint64_t sequence{};
126 std::uint64_t timestampNs{};
127 bool valid{};
128};
129
130class SCORE_PLUGIN_GFX_EXPORT KmsDevice
131{
132public:
133 KmsDevice();
134 ~KmsDevice();
135 KmsDevice(const KmsDevice&) = delete;
136 KmsDevice& operator=(const KmsDevice&) = delete;
137
141 bool open(const std::string& path);
142 void close();
143 bool isOpen() const noexcept;
144
146 const DeviceInfo& info() const noexcept;
147
149 static std::vector<DeviceInfo> enumerateDevices();
150
153 bool acquireMaster();
154 void releaseMaster();
155
160 {
161 std::uint32_t handle{};
162 std::uint32_t fbId{};
163 std::uint32_t stride{};
164 std::uint64_t size{};
165 void* map{};
166 };
167 bool createDumbBuffer(
168 std::uint32_t width, std::uint32_t height, std::uint32_t bpp,
169 DumbBuffer& out);
170 void destroyDumbBuffer(DumbBuffer& b);
171
176 std::uint32_t addFramebuffer(const FramebufferDesc& desc);
177 void removeFramebuffer(std::uint32_t fbId);
178
180 bool setMode(std::uint32_t connectorId, const ModeInfo& mode, std::uint32_t fbId);
181
184 bool pageFlip(std::uint32_t fbId, bool async = false);
185
190 std::uint32_t connectorId, const ModeInfo& mode, std::uint32_t fbId);
191
194 bool atomicFlip(std::uint32_t fbId, bool async = false);
195
201 std::uint32_t planeId, std::uint32_t fbId, int x, int y,
202 std::uint32_t width, std::uint32_t height);
203
215 std::uint32_t writebackConnectorId, std::uint32_t fbId,
216 bool includeCrtcState = true, bool allowModeset = true,
217 bool testOnly = false);
218
221 bool atomicReady() const noexcept;
222
225 FlipEvent waitFlip(int timeoutMs);
226
227 const std::string& lastError() const noexcept;
228
229 struct Impl;
230
231private:
232 std::unique_ptr<Impl> d;
233};
234
237SCORE_PLUGIN_GFX_EXPORT std::string modifierName(std::uint64_t modifier);
238
240SCORE_PLUGIN_GFX_EXPORT std::string fourccName(std::uint32_t fourcc);
241
242} // namespace score::gfx::drm
Definition DrmKmsDevice.hpp:131
bool atomicReady() const noexcept
bool pageFlip(std::uint32_t fbId, bool async=false)
bool writebackCapture(std::uint32_t writebackConnectorId, std::uint32_t fbId, bool includeCrtcState=true, bool allowModeset=true, bool testOnly=false)
bool atomicModeset(std::uint32_t connectorId, const ModeInfo &mode, std::uint32_t fbId)
bool setMode(std::uint32_t connectorId, const ModeInfo &mode, std::uint32_t fbId)
Light up connectorId with one of its modes, scanning out fbId.
std::uint32_t addFramebuffer(const FramebufferDesc &desc)
bool open(const std::string &path)
bool setOverlay(std::uint32_t planeId, std::uint32_t fbId, int x, int y, std::uint32_t width, std::uint32_t height)
bool atomicFlip(std::uint32_t fbId, bool async=false)
STL namespace.
Definition DrmKmsDevice.hpp:56
bool writeback
Definition DrmKmsDevice.hpp:63
std::string name
"HDMI-A-1", "DP-2", "Writeback-1"
Definition DrmKmsDevice.hpp:58
Definition DrmKmsDevice.hpp:91
Definition DrmKmsDevice.hpp:98
bool writebackConnectors
writeback connectors visible (readback)
Definition DrmKmsDevice.hpp:103
bool atomic
DRM_CLIENT_CAP_ATOMIC accepted.
Definition DrmKmsDevice.hpp:101
bool hasMaster
we hold master (else read-only)
Definition DrmKmsDevice.hpp:104
bool universalPlanes
overlay/cursor planes visible
Definition DrmKmsDevice.hpp:102
Result of one completed page flip, taken from the kernel's vblank event.
Definition DrmKmsDevice.hpp:124
std::uint64_t timestampNs
when the flip actually landed
Definition DrmKmsDevice.hpp:126
A framebuffer the kernel can scan out, built from one or more DMA-BUFs.
Definition DrmKmsDevice.hpp:112
Definition DrmKmsDevice.hpp:160
Definition DrmKmsDevice.hpp:46
std::uint32_t refreshMilliHz
60000 == 60.000 Hz
Definition DrmKmsDevice.hpp:49
Definition DrmKmsDevice.hpp:72
Definition DrmKmsDevice.hpp:78
std::uint32_t possibleCrtcs
bitmask of CRTC indices
Definition DrmKmsDevice.hpp:86