aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-03-10 22:51:41 +0100
committerdec05eba <dec05eba@protonmail.com>2024-03-10 23:15:57 +0100
commit877465a702adae8b320b7c6ea8c3c0f2795eb2d0 (patch)
treea35b450be1cace04aa8e838e356c2bc206dee0a0 /src/utils.c
parent1690381bb211ab9de103b9709b9e957f2bd4f09b (diff)
Use dri card matching current egl context
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c78
1 files changed, 45 insertions, 33 deletions
diff --git a/src/utils.c b/src/utils.c
index c342f6e..45e58a6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -370,47 +370,59 @@ bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info) {
return supported;
}
-bool gsr_get_valid_card_path(char *output) {
- for(int i = 0; i < 10; ++i) {
- drmVersion *ver = NULL;
- drmModePlaneResPtr planes = NULL;
- bool found_screen_card = false;
+static bool try_card_has_valid_plane(const char *card_path) {
+ drmVersion *ver = NULL;
+ drmModePlaneResPtr planes = NULL;
+ bool found_screen_card = false;
- sprintf(output, DRM_DEV_NAME, DRM_DIR_NAME, i);
- int fd = open(output, O_RDONLY);
- if(fd == -1)
- continue;
+ int fd = open(card_path, O_RDONLY);
+ if(fd == -1)
+ return false;
- ver = drmGetVersion(fd);
- if(!ver || strstr(ver->name, "nouveau"))
- goto next;
+ ver = drmGetVersion(fd);
+ if(!ver || strstr(ver->name, "nouveau"))
+ goto next;
- drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+ drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
- planes = drmModeGetPlaneResources(fd);
- if(!planes)
- goto next;
+ planes = drmModeGetPlaneResources(fd);
+ if(!planes)
+ goto next;
- for(uint32_t j = 0; j < planes->count_planes; ++j) {
- drmModePlanePtr plane = drmModeGetPlane(fd, planes->planes[j]);
- if(!plane)
- continue;
-
- if(plane->fb_id)
- found_screen_card = true;
+ for(uint32_t j = 0; j < planes->count_planes; ++j) {
+ drmModePlanePtr plane = drmModeGetPlane(fd, planes->planes[j]);
+ if(!plane)
+ continue;
- drmModeFreePlane(plane);
- if(found_screen_card)
- break;
- }
+ if(plane->fb_id)
+ found_screen_card = true;
- next:
- if(planes)
- drmModeFreePlaneResources(planes);
- if(ver)
- drmFreeVersion(ver);
- close(fd);
+ drmModeFreePlane(plane);
if(found_screen_card)
+ break;
+ }
+
+ next:
+ if(planes)
+ drmModeFreePlaneResources(planes);
+ if(ver)
+ drmFreeVersion(ver);
+ close(fd);
+ if(found_screen_card)
+ return true;
+
+ return false;
+}
+
+bool gsr_get_valid_card_path(gsr_egl *egl, char *output) {
+ if(egl->dri_card_path) {
+ strncpy(output, egl->dri_card_path, 128);
+ return try_card_has_valid_plane(output);
+ }
+
+ for(int i = 0; i < 10; ++i) {
+ snprintf(output, 128, DRM_DEV_NAME, DRM_DIR_NAME, i);
+ if(try_card_has_valid_plane(output))
return true;
}
return false;