Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-libdrm: Commit

external/libdrm


Commit MetaInfo

Revision4ee3818ff172776e96f29213e66e98c2735704c6 (tree)
Time2019-10-18 03:11:23
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterMauro Rossi

Log Message

xf86drm: add drmOpenByFB

The new function looks up the DRM device with specified type
associated with the specified framebuffer and opens it.

Signed-off-by: Chih-Wei Huang <cwhuang@linux.org.tw>

Change Summary

Incremental Difference

--- a/xf86drm.c
+++ b/xf86drm.c
@@ -773,6 +773,48 @@ drm_public int drmOpenRender(int minor)
773773 }
774774
775775 /**
776+ * Open the DRM device with specified type of specified framebuffer.
777+ *
778+ * Looks up the associated DRM device with specified type of the
779+ * specified framebuffer and opens it.
780+ *
781+ * \param fb the index of framebuffer.
782+ * \param type the device node type to open, PRIMARY, CONTROL or RENDER
783+ *
784+ * \return a file descriptor on success, or a negative value on error.
785+ *
786+ */
787+drm_public int drmOpenByFB(int fb, int type)
788+{
789+#ifdef __linux__
790+ DIR *sysdir;
791+ struct dirent *ent;
792+ char buf[64];
793+ const char *name = drmGetMinorName(type);
794+ int fd = -1, len = strlen(name);
795+
796+ snprintf(buf, sizeof(buf), "/sys/class/graphics/fb%d/device/drm", fb);
797+ sysdir = opendir(buf);
798+ if (!sysdir)
799+ return -errno;
800+
801+ while ((ent = readdir(sysdir))) {
802+ if (!strncmp(ent->d_name, name, len)) {
803+ snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, ent->d_name);
804+ fd = open(buf, O_RDWR | O_CLOEXEC, 0);
805+ break;
806+ }
807+ }
808+
809+ closedir(sysdir);
810+ return fd;
811+#else
812+#warning "Missing implementation of drmOpenByFB"
813+ return -EINVAL;
814+#endif
815+}
816+
817+/**
776818 * Free the version information returned by drmGetVersion().
777819 *
778820 * \param v pointer to the version information.
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -582,6 +582,7 @@ extern int drmOpenWithType(const char *name, const char *busid,
582582
583583 extern int drmOpenControl(int minor);
584584 extern int drmOpenRender(int minor);
585+extern int drmOpenByFB(int fb, int type);
585586 extern int drmClose(int fd);
586587 extern drmVersionPtr drmGetVersion(int fd);
587588 extern drmVersionPtr drmGetLibVersion(int fd);
Show on old repository browser