summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2020-05-28 22:18:22 +0300
committerGitHub <noreply@github.com>2020-05-28 22:18:22 +0300
commitd9d5e44526a3b8065e4ae913032020d0bfd93103 (patch)
tree5b8a7e630944ef168de903afc33c7fbe20ec083d
parent852eedd94c0d519bb63ca989b9e13fa9c36f6b14 (diff)
parent554f3f0231c432dea740e56d6a51a15983c93310 (diff)
Merge pull request #56 from matthoosier-garmin/more-card-constructors
More card constructors
-rw-r--r--kms++/inc/kms++/card.h3
-rw-r--r--kms++/src/card.cpp24
2 files changed, 27 insertions, 0 deletions
diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
index e561ffc..5c1cf7c 100644
--- a/kms++/inc/kms++/card.h
+++ b/kms++/inc/kms++/card.h
@@ -24,8 +24,11 @@ class Card
{
friend class Framebuffer;
public:
+ static std::unique_ptr<Card> open_named_card(const std::string& name);
+
Card(const std::string& dev_path = "");
Card(const std::string& driver, uint32_t idx);
+ Card(int fd, bool take_ownership);
virtual ~Card();
Card(const Card& other) = delete;
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 5b3d69e..527aca6 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -104,6 +104,16 @@ static int open_device_by_driver(string name, uint32_t idx)
throw invalid_argument("Failed to find a DRM device " + name + ":" + to_string(idx));
}
+std::unique_ptr<Card> Card::open_named_card(const std::string& name)
+{
+ int fd = drmOpen(name.c_str(), 0);
+
+ if (fd < 0)
+ throw invalid_argument(string(strerror(errno)) + " opening card \"" + name + "\"");
+
+ return std::unique_ptr<Card>(new Card(fd, true));
+}
+
Card::Card(const std::string& dev_path)
{
const char* drv_p = getenv("KMSXX_DRIVER");
@@ -148,6 +158,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);