aboutsummaryrefslogtreecommitdiff
path: root/src/wld/drm.c
diff options
context:
space:
mode:
authorJeff <jeff@i2p.rocks>2019-06-16 15:56:40 -0400
committerGitHub <noreply@github.com>2019-06-16 15:56:40 -0400
commit8015dab11ec76d5b6f18e23b4686d1e2dc233a42 (patch)
tree6529655e38f149e52a5b651803020c699292d557 /src/wld/drm.c
parentc5c548536c62f5b7281f43ab896c8daf927fcaee (diff)
parentba56eac2ab8869c9720d4ee252fb8618a1f535f3 (diff)
downloadwterm-8015dab11ec76d5b6f18e23b4686d1e2dc233a42.zip
wterm-8015dab11ec76d5b6f18e23b4686d1e2dc233a42.tar.gz
wterm-8015dab11ec76d5b6f18e23b4686d1e2dc233a42.tar.bz2
Merge pull request #13 from MichaelMackus/update-wld
Update wld
Diffstat (limited to 'src/wld/drm.c')
-rw-r--r--src/wld/drm.c108
1 files changed, 62 insertions, 46 deletions
diff --git a/src/wld/drm.c b/src/wld/drm.c
index f26fa0b..266f1ac 100644
--- a/src/wld/drm.c
+++ b/src/wld/drm.c
@@ -21,71 +21,87 @@
* SOFTWARE.
*/
-#include "wld/drm.h"
-#include "wld/drm-private.h"
+#include "drm.h"
+#include "drm-private.h"
#include <sys/sysmacros.h>
-const static struct drm_driver *drivers[] = {
+const static struct drm_driver * drivers[] = {
#if WITH_DRM_INTEL
&intel_drm_driver,
#endif
#if WITH_DRM_NOUVEAU
&nouveau_drm_driver,
#endif
- &dumb_drm_driver};
+ &dumb_drm_driver
+};
+
+static const struct drm_driver * find_driver(int fd)
+{
+ char path[64], id[32];
+ uint32_t vendor_id, device_id;
+ char * path_part;
+ struct stat st;
+ FILE * file;
+ uint32_t index;
+ int n;
+
+ if (fstat(fd, &st) == -1)
+ return NULL;
+
+ if (getenv("WLD_DRM_DUMB"))
+ goto dumb;
+
+ n = snprintf(path, sizeof(path), "/sys/dev/char/%u:%u/device/", major(st.st_rdev), minor(st.st_rdev));
+ if (n + 6 >= sizeof(path))
+ return NULL;
+ path_part = path + n;
+
+ strcpy(path_part, "vendor");
+ file = fopen(path, "r");
+ if (!file)
+ goto dumb;
+ fgets(id, sizeof id, file);
+ fclose(file);
+ vendor_id = strtoul(id, NULL, 0);
+
+ strcpy(path_part, "device");
+ file = fopen(path, "r");
+ if (!file)
+ goto dumb;
+ fgets(id, sizeof id, file);
+ fclose(file);
+ device_id = strtoul(id, NULL, 0);
+
+ for (index = 0; index < ARRAY_LENGTH(drivers); ++index)
+ {
+ DEBUG("Trying DRM driver `%s'\n", drivers[index]->name);
+ if (drivers[index]->device_supported(vendor_id, device_id))
+ return drivers[index];
+ }
+
+ DEBUG("No DRM driver supports device 0x%x:0x%x\n", vendor_id, device_id);
-static const struct drm_driver *find_driver(int fd) {
- char path[64], id[32];
- uint32_t vendor_id, device_id;
- char *path_part;
- struct stat st;
- FILE *file;
- uint32_t index;
-
- if (fstat(fd, &st) == -1)
return NULL;
- path_part = path + snprintf(path, sizeof path, "/sys/dev/char/%u:%u/device/",
- major(st.st_rdev), minor(st.st_rdev));
-
- strcpy(path_part, "vendor");
- file = fopen(path, "r");
- fgets(id, sizeof id, file);
- fclose(file);
- vendor_id = strtoul(id, NULL, 0);
-
- strcpy(path_part, "device");
- file = fopen(path, "r");
- fgets(id, sizeof id, file);
- fclose(file);
- device_id = strtoul(id, NULL, 0);
-
- if (getenv("WLD_DRM_DUMB"))
+dumb:
return &dumb_drm_driver;
-
- for (index = 0; index < ARRAY_LENGTH(drivers); ++index) {
- DEBUG("Trying DRM driver `%s'\n", drivers[index]->name);
- if (drivers[index]->device_supported(vendor_id, device_id))
- return drivers[index];
- }
-
- DEBUG("No DRM driver supports device 0x%x:0x%x\n", vendor_id, device_id);
-
- return NULL;
}
EXPORT
-struct wld_context *wld_drm_create_context(int fd) {
- const struct drm_driver *driver;
+struct wld_context * wld_drm_create_context(int fd)
+{
+ const struct drm_driver * driver;
- if (!(driver = find_driver(fd)))
- return NULL;
+ if (!(driver = find_driver(fd)))
+ return NULL;
- return driver->create_context(fd);
+ return driver->create_context(fd);
}
EXPORT
-bool wld_drm_is_dumb(struct wld_context *context) {
- return context->impl == dumb_context_impl;
+bool wld_drm_is_dumb(struct wld_context * context)
+{
+ return context->impl == dumb_context_impl;
}
+