From 6b539536349378d54d4b46b9375ae573f34d6e43 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 12 Mar 2014 03:29:24 +0100 Subject: crtc and connector count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blueshift_drm_c.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/src/blueshift_drm_c.c b/src/blueshift_drm_c.c index b00660d..d143ddc 100644 --- a/src/blueshift_drm_c.c +++ b/src/blueshift_drm_c.c @@ -20,12 +20,29 @@ #include #include #include +#include #include +#ifndef O_CLOEXEC + #define O_CLOEXEC 02000000 +#endif + +/* Requires video group */ #include #include -/* Requires video group */ + + +/** + * File descriptor for the DRM connection + */ +static int drm_fd; + +/** + * DRM mode resources + */ +static drmModeRes* drm_res = NULL; + /** @@ -52,13 +69,89 @@ int blueshift_drm_card_count() } +/** + * Open connection to a graphics card + * + * @param card The index of the graphics card + * @return Zero on success + */ +int blueshift_drm_open(int card) +{ + long maxlen = strlen(DRM_DIR_NAME) + strlen(DRM_DEV_NAME) + 10; + char* pathname = alloca(maxlen * sizeof(char)); + + sprintf(pathname, DRM_DEV_NAME, DRM_DIR_NAME, card); + + drm_fd = open(pathname, O_RDWR | O_CLOEXEC); + if (drm_fd < 0) + { + perror("open"); + return 1; + } + + return 0; +} + + +/** + * Close connection to the graphics card + */ +void blueshift_drm_close() +{ + drmModeFreeResources(drm_res); + close(drm_fd); +} + + +/** + * Update the resource, required after `blueshift_drm_open` + */ +void blueshift_drm_update() +{ + if (drm_res) + drmModeFreeResources(drm_res); + + drm_res = drmModeGetResources(drm_fd); +} + + +/** + * Return the number of CRTC:s on the opened card + * + * @return The number of CRTC:s on the opened card + */ +int blueshift_drm_crtc_count() +{ + return drm_res->count_crtcs; +} + + +/** + * Return the number of connectors on the opened card + * + * @return The number of connectors on the opened card + */ +int blueshift_drm_connector_count() +{ + return drm_res->count_connectors; +} + + + int main(int argc, char** argv) { (void) argc; (void) argv; - printf("%li\n", blueshift_drm_card_count()); + printf("Card count: %i\n", blueshift_drm_card_count()); + + blueshift_drm_open(0); + blueshift_drm_update(); + printf("CRTC count: %i\n", blueshift_drm_crtc_count()); + printf("Connector count: %i\n", blueshift_drm_connector_count()); + + blueshift_drm_close(); return 0; } -- cgit v1.2.3-70-g09d2