diff options
-rw-r--r-- | kms++/inc/kms++/card.h | 3 | ||||
-rw-r--r-- | kms++/src/card.cpp | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h index 72111f1..4b0d877 100644 --- a/kms++/inc/kms++/card.h +++ b/kms++/inc/kms++/card.h @@ -3,6 +3,7 @@ #include <cstdint> #include <vector> #include <map> +#include <memory> #include "decls.h" #include "pipeline.h" @@ -13,6 +14,8 @@ class Card { friend class Framebuffer; public: + static std::unique_ptr<Card> open_modesetting_card(); + Card(); Card(const std::string& dev_path); Card(const std::string& driver, uint32_t idx); diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp index 4632f22..04750af 100644 --- a/kms++/src/card.cpp +++ b/kms++/src/card.cpp @@ -7,6 +7,7 @@ #include <algorithm> #include <cerrno> #include <algorithm> +#include <sys/stat.h> #include <xf86drm.h> #include <xf86drmMode.h> @@ -18,6 +19,25 @@ using namespace std; namespace kms { +unique_ptr<Card> Card::open_modesetting_card() +{ + for (uint32_t i = 0; ; ++i) { + string path = "/dev/dri/card" + to_string(i); + + struct stat buffer; + if (stat(path.c_str(), &buffer)) + break; + + unique_ptr<Card> card = unique_ptr<Card>(new Card(path)); + + if (card->get_connectors().size() > 0 && + card->get_crtcs().size() > 0) + return card; + } + + throw runtime_error("No modesetting DRM card found"); +} + static int open_device_by_path(string path) { int fd = open(path.c_str(), O_RDWR | O_CLOEXEC); |