aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-04-18 23:41:33 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-04-18 23:41:33 +0200
commit08d400b59c6871cefc58fa4cfb5de70a78db4065 (patch)
treec286f8e5a7eed320ef0eb8d6a240040c5ed16cc6
parent42725d5720ed74ee5664c12d4b9c19885374233b (diff)
downloaddrminfo-08d400b59c6871cefc58fa4cfb5de70a78db4065.tar.gz
drm format probe
-rw-r--r--drminfo.c47
-rw-r--r--drmtools.c50
-rw-r--r--drmtools.h1
3 files changed, 98 insertions, 0 deletions
diff --git a/drminfo.c b/drminfo.c
index 97ab8da..2020ddb 100644
--- a/drminfo.c
+++ b/drminfo.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
@@ -8,6 +9,7 @@
#include <getopt.h>
#include <sys/ioctl.h>
+#include <drm/drm_fourcc.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@@ -99,6 +101,51 @@ static void drm_info(int devnr)
drmModeFreeConnector(conn);
fprintf(stdout, "\n");
}
+
+ fprintf(stdout, "legacy formats\n");
+ drm_probe_format(fd, 32, 24, 0, true);
+ drm_probe_format(fd, 32, 30, 0, true);
+ drm_probe_format(fd, 24, 24, 0, true);
+ drm_probe_format(fd, 16, 16, 0, true);
+ drm_probe_format(fd, 16, 15, 0, true);
+ fprintf(stdout, "\n");
+
+ fprintf(stdout, "fourcc formats\n");
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_XRGB8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_XBGR8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_RGBX8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_BGRX8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_ARGB8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_ABGR8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_RGBA8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_BGRA8888, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_XRGB2101010, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_XBGR2101010, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_RGBX1010102, true);
+ drm_probe_format(fd, 32, 0, DRM_FORMAT_BGRX1010102, true);
+
+ drm_probe_format(fd, 24, 0, DRM_FORMAT_RGB888, true);
+ drm_probe_format(fd, 24, 0, DRM_FORMAT_BGR888, true);
+
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_XRGB4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_XBGR4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_RGBX4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_BGRX4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_ARGB4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_ABGR4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_RGBA4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_BGRA4444, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_XRGB1555, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_XBGR1555, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_RGBX5551, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_BGRX5551, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_ARGB1555, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_ABGR1555, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_RGBA5551, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_BGRA5551, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_RGB565, true);
+ drm_probe_format(fd, 16, 0, DRM_FORMAT_BGR565, true);
+ fprintf(stdout, "\n");
}
/* ------------------------------------------------------------------ */
diff --git a/drmtools.c b/drmtools.c
index 8ff054b..042b8d6 100644
--- a/drmtools.c
+++ b/drmtools.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
@@ -92,3 +93,52 @@ void drm_conn_name(drmModeConnector *conn, char *dest, int dlen)
/* ------------------------------------------------------------------ */
+bool drm_probe_format(int fd, uint32_t bpp, uint32_t depth, uint32_t fourcc, bool print)
+{
+ struct drm_mode_create_dumb cd;
+ struct drm_mode_destroy_dumb dd;
+ uint32_t zero = 0;
+ uint32_t fb_id = 0;
+ bool result = false;
+ int rc;
+
+ /* create dumb buffer */
+ memset(&cd, 0, sizeof(cd));
+ cd.width = 64;
+ cd.height = 64;
+ cd.bpp = bpp;
+ rc = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &cd);
+ if (rc < 0)
+ goto done;
+
+ /* create framebuffer */
+ if (fourcc) {
+ rc = drmModeAddFB2(fd, cd.width, cd.height, fourcc,
+ &cd.handle, &cd.pitch, &zero,
+ &fb_id, 0);
+ if (rc == 0 && print)
+ printf(" bpp %d, fourcc %c%c%c%c\n", cd.bpp,
+ (fourcc >> 0) & 0xff,
+ (fourcc >> 8) & 0xff,
+ (fourcc >> 16) & 0xff,
+ (fourcc >> 24) & 0xff);
+ } else if (depth) {
+ rc = drmModeAddFB(fd, cd.width, cd.height, depth, cd.bpp,
+ cd.pitch, cd.handle, &fb_id);
+ if (rc == 0 && print)
+ printf(" bpp %d, depth %d\n", cd.bpp, depth);
+ } else {
+ rc = -1;
+ }
+
+ if (rc == 0) {
+ /* worked, yay! */
+ result = true;
+ drmModeRmFB(fd, fb_id);
+ }
+ dd.handle = cd.handle;
+ drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dd);
+
+done:
+ return result;
+}
diff --git a/drmtools.h b/drmtools.h
index ed43544..9560261 100644
--- a/drmtools.h
+++ b/drmtools.h
@@ -2,3 +2,4 @@ const char *drm_connector_type_name(int nr);
const char *drm_connector_mode_name(int nr);
const char *drm_encoder_type_name(int nr);
void drm_conn_name(drmModeConnector *conn, char *dest, int dlen);
+bool drm_probe_format(int fd, uint32_t bpp, uint32_t depth, uint32_t fourcc, bool print);