external/libdrm
Révision | aa8425da5a098b45f1480954cbdc3469c07ece1f (tree) |
---|---|
l'heure | 2019-01-14 01:06:59 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
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>
@@ -790,6 +790,48 @@ drm_public int drmOpenRender(int minor) | ||
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
793 | + * Open the DRM device with specified type of specified framebuffer. | |
794 | + * | |
795 | + * Looks up the associated DRM device with specified type of the | |
796 | + * specified framebuffer and opens it. | |
797 | + * | |
798 | + * \param fb the index of framebuffer. | |
799 | + * \param type the device node type to open, PRIMARY, CONTROL or RENDER | |
800 | + * | |
801 | + * \return a file descriptor on success, or a negative value on error. | |
802 | + * | |
803 | + */ | |
804 | +drm_public int drmOpenByFB(int fb, int type) | |
805 | +{ | |
806 | +#ifdef __linux__ | |
807 | + DIR *sysdir; | |
808 | + struct dirent *ent; | |
809 | + char buf[64]; | |
810 | + const char *name = drmGetMinorName(type); | |
811 | + int fd = -1, len = strlen(name); | |
812 | + | |
813 | + snprintf(buf, sizeof(buf), "/sys/class/graphics/fb%d/device/drm", fb); | |
814 | + sysdir = opendir(buf); | |
815 | + if (!sysdir) | |
816 | + return -errno; | |
817 | + | |
818 | + while ((ent = readdir(sysdir))) { | |
819 | + if (!strncmp(ent->d_name, name, len)) { | |
820 | + snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, ent->d_name); | |
821 | + fd = open(buf, O_RDWR | O_CLOEXEC, 0); | |
822 | + break; | |
823 | + } | |
824 | + } | |
825 | + | |
826 | + closedir(sysdir); | |
827 | + return fd; | |
828 | +#else | |
829 | +#warning "Missing implementation of drmOpenByFB" | |
830 | + return -EINVAL; | |
831 | +#endif | |
832 | +} | |
833 | + | |
834 | +/** | |
793 | 835 | * Free the version information returned by drmGetVersion(). |
794 | 836 | * |
795 | 837 | * \param v pointer to the version information. |
@@ -570,6 +570,7 @@ extern int drmOpenWithType(const char *name, const char *busid, | ||
570 | 570 | |
571 | 571 | extern int drmOpenControl(int minor); |
572 | 572 | extern int drmOpenRender(int minor); |
573 | +extern int drmOpenByFB(int fb, int type); | |
573 | 574 | extern int drmClose(int fd); |
574 | 575 | extern drmVersionPtr drmGetVersion(int fd); |
575 | 576 | extern drmVersionPtr drmGetLibVersion(int fd); |