From a9480f87902840388497ff85062e73381317626f Mon Sep 17 00:00:00 2001 From: Matt Hoosier Date: Wed, 27 May 2020 15:28:23 -0500 Subject: card: add constructor for pre-opened FD This is an escape hatch to let the user do whatever crazy thing he wants to obtain the DRM fd. This could be from a DRM lease, an FD passed across a Wayland protocol request, something calculated by manually walking across the set of DRI cards and selecting specific criteria, etc. --- kms++/src/card.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'kms++/src/card.cpp') diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp index 5b3d69e..062645a 100644 --- a/kms++/src/card.cpp +++ b/kms++/src/card.cpp @@ -148,6 +148,20 @@ Card::Card(const std::string& driver, uint32_t idx) setup(); } +Card::Card(int fd, bool take_ownership) +{ + if (take_ownership) { + m_fd = fd; + } else { + m_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); + + if (m_fd < 0) + throw invalid_argument(string(strerror(errno)) + " duplicating fd"); + } + + setup(); +} + void Card::setup() { drmVersionPtr ver = drmGetVersion(m_fd); -- cgit v1.2.3