summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kms++/inc/kms++/card.h5
-rw-r--r--kms++/inc/kms++/omap/omapcard.h3
-rw-r--r--kms++/src/card.cpp37
-rw-r--r--kms++/src/omap/omapcard.cpp5
-rw-r--r--utils/kmsblank.cpp2
-rw-r--r--utils/kmsprint.cpp2
-rw-r--r--utils/kmstest.cpp2
-rw-r--r--utils/kmsview.cpp2
8 files changed, 29 insertions, 29 deletions
diff --git a/kms++/inc/kms++/card.h b/kms++/inc/kms++/card.h
index a2c27f8..099d5b5 100644
--- a/kms++/inc/kms++/card.h
+++ b/kms++/inc/kms++/card.h
@@ -14,10 +14,7 @@ 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& dev_path = "");
Card(const std::string& driver, uint32_t idx);
virtual ~Card();
diff --git a/kms++/inc/kms++/omap/omapcard.h b/kms++/inc/kms++/omap/omapcard.h
index 5c2f3a5..2f1f528 100644
--- a/kms++/inc/kms++/omap/omapcard.h
+++ b/kms++/inc/kms++/omap/omapcard.h
@@ -9,8 +9,7 @@ namespace kms
class OmapCard : public Card
{
public:
- OmapCard();
- OmapCard(const std::string& device);
+ OmapCard(const std::string& device = "");
virtual ~OmapCard();
struct omap_device* dev() const { return m_omap_dev; }
diff --git a/kms++/src/card.cpp b/kms++/src/card.cpp
index 85c693b..8de8b82 100644
--- a/kms++/src/card.cpp
+++ b/kms++/src/card.cpp
@@ -39,15 +39,29 @@ static vector<string> glob(const string& pattern)
return filenames;
}
-unique_ptr<Card> Card::open_modesetting_card()
+static int open_first_kms_device()
{
vector<string> paths = glob("/dev/dri/card*");
for (const string& path : paths) {
- unique_ptr<Card> card = unique_ptr<Card>(new Card(path));
+ int fd = open(path.c_str(), O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ throw invalid_argument(string(strerror(errno)) + " opening device " + path);
- if (card->has_kms())
- return card;
+ auto res = drmModeGetResources(fd);
+ if (!res) {
+ close(fd);
+ continue;
+ }
+
+ bool has_kms = res->count_crtcs > 0 && res->count_connectors > 0 && res->count_encoders > 0;
+
+ drmModeFreeResources(res);
+
+ if (has_kms)
+ return fd;
+
+ close(fd);
}
throw runtime_error("No modesetting DRM card found");
@@ -90,12 +104,14 @@ static int open_device_by_driver(string name, uint32_t idx)
throw invalid_argument("Failed to find a DRM device " + name + ":" + to_string(idx));
}
-Card::Card()
+Card::Card(const std::string& dev_path)
{
const char* drv_p = getenv("KMSXX_DRIVER");
const char* dev_p = getenv("KMSXX_DEVICE");
- if (dev_p) {
+ if (!dev_path.empty()) {
+ m_fd = open_device_by_path(dev_path);
+ } else if (dev_p) {
string dev(dev_p);
m_fd = open_device_by_path(dev);
} else if (drv_p) {
@@ -119,7 +135,7 @@ Card::Card()
m_fd = open_device_by_driver(name, num);
} else {
- m_fd = open_device_by_path("/dev/dri/card0");
+ m_fd = open_first_kms_device();
}
setup();
@@ -132,13 +148,6 @@ Card::Card(const std::string& driver, uint32_t idx)
setup();
}
-Card::Card(const std::string& dev_path)
-{
- m_fd = open_device_by_path(dev_path);
-
- setup();
-}
-
void Card::setup()
{
drmVersionPtr ver = drmGetVersion(m_fd);
diff --git a/kms++/src/omap/omapcard.cpp b/kms++/src/omap/omapcard.cpp
index e811b6d..5e21c75 100644
--- a/kms++/src/omap/omapcard.cpp
+++ b/kms++/src/omap/omapcard.cpp
@@ -9,11 +9,6 @@ using namespace std;
namespace kms
{
-OmapCard::OmapCard()
- : OmapCard("/dev/dri/card0")
-{
-
-}
OmapCard::OmapCard(const string& device)
: Card(device)
diff --git a/utils/kmsblank.cpp b/utils/kmsblank.cpp
index 0b51810..286c7f7 100644
--- a/utils/kmsblank.cpp
+++ b/utils/kmsblank.cpp
@@ -27,7 +27,7 @@ static void usage()
int main(int argc, char **argv)
{
- string dev_path = "/dev/dri/card0";
+ string dev_path;
vector<string> conn_strs;
uint32_t time = 0;
diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp
index 19cf8b7..9f550c7 100644
--- a/utils/kmsprint.cpp
+++ b/utils/kmsprint.cpp
@@ -497,7 +497,7 @@ static void usage()
int main(int argc, char **argv)
{
- string dev_path = "/dev/dri/card0";
+ string dev_path;
OptionSet optionset = {
Option("|device=", [&dev_path](string s)
diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp
index 37f9e0f..8144117 100644
--- a/utils/kmstest.cpp
+++ b/utils/kmstest.cpp
@@ -444,7 +444,7 @@ struct Arg
string arg;
};
-static string s_device_path = "/dev/dri/card0";
+static string s_device_path;
static vector<Arg> parse_cmdline(int argc, char **argv)
{
diff --git a/utils/kmsview.cpp b/utils/kmsview.cpp
index 04d005d..eea9dde 100644
--- a/utils/kmsview.cpp
+++ b/utils/kmsview.cpp
@@ -38,7 +38,7 @@ static void usage()
int main(int argc, char** argv)
{
uint32_t time = 0;
- string dev_path = "/dev/dri/card0";
+ string dev_path;
string conn_name;
OptionSet optionset = {