All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm 00/11] Random assortment of fixes and enhancements
@ 2015-01-23 16:08 Thierry Reding
  2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
                   ` (11 more replies)
  0 siblings, 12 replies; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

This is a stash of commits that I've been carrying for a couple months.
Laurent really wanted to have the connector name patch for modetest so
I thought I'd send them all out for review.

Thierry

Thierry Reding (11):
  libdrm: valgrind-clear a few more IOCTL arguments
  libdrm: Remove gratuitous blank lines
  libdrm: Make indentation consistent
  tests: Split helpers into library
  tests: Move name tables to libutil
  xf86drmMode.h: Use consistent padding
  xf86drmMode.h: Add DisplayPort MST encoder type
  tests: modetest: Accept connector names
  tests: Add libkms-test library
  tests: kms: Implement CRTC stealing test
  tests: kms: Implement universal planes test

 configure.ac                        |   2 +
 tests/Makefile.am                   |   2 +-
 tests/kms/Makefile.am               |  35 ++
 tests/kms/kms-steal-crtc.c          | 161 ++++++
 tests/kms/kms-universal-planes.c    | 358 ++++++++++++++
 tests/kms/libkms-test-crtc.c        |  47 ++
 tests/kms/libkms-test-device.c      | 218 ++++++++
 tests/kms/libkms-test-framebuffer.c | 157 ++++++
 tests/kms/libkms-test-plane.c       | 139 ++++++
 tests/kms/libkms-test-screen.c      |  92 ++++
 tests/kms/libkms-test.h             | 120 +++++
 tests/modeprint/Makefile.am         |   1 +
 tests/modeprint/modeprint.c         |   2 +-
 tests/modetest/Makefile.am          |   2 +
 tests/modetest/buffers.c            | 956 +-----------------------------------
 tests/modetest/buffers.h            |  12 +-
 tests/modetest/cursor.c             |   4 +-
 tests/modetest/modetest.c           | 207 +++++---
 tests/proptest/Makefile.am          |   4 +-
 tests/proptest/proptest.c           |  43 +-
 tests/util/Makefile.am              |  21 +
 tests/util/common.h                 |  33 ++
 tests/util/format.c                 | 119 +++++
 tests/util/format.h                 |  65 +++
 tests/util/kms.c                    | 122 +++++
 tests/util/kms.h                    |  33 ++
 tests/util/pattern.c                | 870 ++++++++++++++++++++++++++++++++
 tests/util/pattern.h                |  39 ++
 tests/vbltest/Makefile.am           |   1 +
 tests/vbltest/vbltest.c             |   2 +-
 xf86drmMode.c                       |  17 +-
 xf86drmMode.h                       |  17 +-
 32 files changed, 2805 insertions(+), 1096 deletions(-)
 create mode 100644 tests/kms/Makefile.am
 create mode 100644 tests/kms/kms-steal-crtc.c
 create mode 100644 tests/kms/kms-universal-planes.c
 create mode 100644 tests/kms/libkms-test-crtc.c
 create mode 100644 tests/kms/libkms-test-device.c
 create mode 100644 tests/kms/libkms-test-framebuffer.c
 create mode 100644 tests/kms/libkms-test-plane.c
 create mode 100644 tests/kms/libkms-test-screen.c
 create mode 100644 tests/kms/libkms-test.h
 create mode 100644 tests/util/Makefile.am
 create mode 100644 tests/util/common.h
 create mode 100644 tests/util/format.c
 create mode 100644 tests/util/format.h
 create mode 100644 tests/util/kms.c
 create mode 100644 tests/util/kms.h
 create mode 100644 tests/util/pattern.c
 create mode 100644 tests/util/pattern.h

-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:19   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Fixes a few complaints raised by valgrind when running the Tegra tests.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drmMode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index 60ce3699f3e3..f6e4416b88b5 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -282,6 +282,7 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
 	struct drm_mode_fb_cmd2 f;
 	int ret;
 
+	VG_CLEAR(f);
 	f.width  = width;
 	f.height = height;
 	f.pixel_format = pixel_format;
@@ -309,6 +310,7 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
 	struct drm_mode_fb_cmd info;
 	drmModeFBPtr r;
 
+	VG_CLEAR(info);
 	info.fb_id = buf;
 
 	if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
  2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:19   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Usage of blank lines can be a matter of taste, of course, but for these
we can surely all agree that they're not needed and inconsistent.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drmMode.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index f6e4416b88b5..7e228b3e7aa3 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -115,7 +115,6 @@ void drmModeFreeResources(drmModeResPtr ptr)
 	drmFree(ptr->connectors);
 	drmFree(ptr->encoders);
 	drmFree(ptr);
-
 }
 
 void drmModeFreeFB(drmModeFBPtr ptr)
@@ -133,7 +132,6 @@ void drmModeFreeCrtc(drmModeCrtcPtr ptr)
 		return;
 
 	drmFree(ptr);
-
 }
 
 void drmModeFreeConnector(drmModeConnectorPtr ptr)
@@ -146,7 +144,6 @@ void drmModeFreeConnector(drmModeConnectorPtr ptr)
 	drmFree(ptr->props);
 	drmFree(ptr->modes);
 	drmFree(ptr);
-
 }
 
 void drmModeFreeEncoder(drmModeEncoderPtr ptr)
@@ -301,8 +298,6 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t height,
 int drmModeRmFB(int fd, uint32_t bufferId)
 {
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
-
-
 }
 
 drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
@@ -342,7 +337,6 @@ int drmModeDirtyFB(int fd, uint32_t bufferId,
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_DIRTYFB, &dirty);
 }
 
-
 /*
  * Crtc functions
  */
@@ -379,7 +373,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
 	return r;
 }
 
-
 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
 		   drmModeModeInfoPtr mode)
@@ -594,7 +587,6 @@ int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_inf
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_DETACHMODE, &res);
 }
 
-
 drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
 {
 	struct drm_mode_get_property prop;
@@ -812,7 +804,6 @@ int drmCheckModesettingSupported(const char *busid)
 	return 0;
 #endif
 	return -ENOSYS;
-
 }
 
 int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
@@ -914,7 +905,6 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
 		    uint32_t crtc_w, uint32_t crtc_h,
 		    uint32_t src_x, uint32_t src_y,
 		    uint32_t src_w, uint32_t src_h)
-
 {
 	struct drm_mode_set_plane s;
 
@@ -934,7 +924,6 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id,
 	return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
 }
 
-
 drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
 {
 	struct drm_mode_get_plane ovr, counts;
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 03/11] libdrm: Make indentation consistent
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
  2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
  2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:20   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drmMode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index 7e228b3e7aa3..3d6b9cc307d1 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -250,7 +250,7 @@ err_allocs:
 }
 
 int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
-                 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
+		 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
 		 uint32_t *buf_id)
 {
 	struct drm_mode_fb_cmd f;
@@ -374,7 +374,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
 }
 
 int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
-                   uint32_t x, uint32_t y, uint32_t *connectors, int count,
+		   uint32_t x, uint32_t y, uint32_t *connectors, int count,
 		   drmModeModeInfoPtr mode)
 {
 	struct drm_mode_crtc crtc;
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 04/11] tests: Split helpers into library
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (2 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:24   ` Laurent Pinchart
                     ` (2 more replies)
  2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
                   ` (7 subsequent siblings)
  11 siblings, 3 replies; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Some of the helpers, such as the pattern drawing helpers or the format
lookup helpers, have potential to be reused. Move them into a separate
library to make it easier to share them.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 configure.ac                |   1 +
 tests/Makefile.am           |   2 +-
 tests/modeprint/Makefile.am |   1 +
 tests/modeprint/modeprint.c |   2 +-
 tests/modetest/Makefile.am  |   2 +
 tests/modetest/buffers.c    | 956 +-------------------------------------------
 tests/modetest/buffers.h    |  12 +-
 tests/modetest/cursor.c     |   4 +-
 tests/modetest/modetest.c   |  25 +-
 tests/proptest/proptest.c   |   3 +-
 tests/util/Makefile.am      |  19 +
 tests/util/common.h         |  33 ++
 tests/util/format.c         | 119 ++++++
 tests/util/format.h         |  65 +++
 tests/util/pattern.c        | 870 ++++++++++++++++++++++++++++++++++++++++
 tests/util/pattern.h        |  39 ++
 tests/vbltest/Makefile.am   |   1 +
 tests/vbltest/vbltest.c     |   2 +-
 18 files changed, 1177 insertions(+), 979 deletions(-)
 create mode 100644 tests/util/Makefile.am
 create mode 100644 tests/util/common.h
 create mode 100644 tests/util/format.c
 create mode 100644 tests/util/format.h
 create mode 100644 tests/util/pattern.c
 create mode 100644 tests/util/pattern.h

diff --git a/configure.ac b/configure.ac
index 8afee834508d..58411b79b682 100644
--- a/configure.ac
+++ b/configure.ac
@@ -441,6 +441,7 @@ AC_CONFIG_FILES([
 	tests/vbltest/Makefile
 	tests/exynos/Makefile
 	tests/tegra/Makefile
+	tests/util/Makefile
 	man/Makefile
 	libdrm.pc])
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e7ec4fa5ecff..310032732f6e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,7 @@ check_PROGRAMS = \
 	dristat \
 	drmstat
 
-SUBDIRS = modeprint proptest
+SUBDIRS = util modeprint proptest
 
 if HAVE_LIBKMS
 SUBDIRS += kmstest modetest
diff --git a/tests/modeprint/Makefile.am b/tests/modeprint/Makefile.am
index 6420ef336705..32a702ab0bdc 100644
--- a/tests/modeprint/Makefile.am
+++ b/tests/modeprint/Makefile.am
@@ -1,5 +1,6 @@
 AM_CFLAGS = \
 	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
 	-I$(top_srcdir)
 
 if HAVE_INSTALL_TESTS
diff --git a/tests/modeprint/modeprint.c b/tests/modeprint/modeprint.c
index 6f0d03905a46..8f9471023b52 100644
--- a/tests/modeprint/modeprint.c
+++ b/tests/modeprint/modeprint.c
@@ -41,7 +41,7 @@
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#include "util/common.h"
 
 int connectors;
 int full_props;
diff --git a/tests/modetest/Makefile.am b/tests/modetest/Makefile.am
index 93820fac7395..88fde2eb8345 100644
--- a/tests/modetest/Makefile.am
+++ b/tests/modetest/Makefile.am
@@ -4,6 +4,7 @@ AM_CFLAGS = $(filter-out -Wpointer-arith, $(WARN_CFLAGS))
 
 AM_CFLAGS += \
 	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
 	-I$(top_srcdir)
 
 if HAVE_INSTALL_TESTS
@@ -18,6 +19,7 @@ modetest_SOURCES = $(MODETEST_FILES)
 
 modetest_LDADD = \
 	$(top_builddir)/libdrm.la \
+	$(top_builddir)/tests/util/libutil.la \
 	-lpthread
 
 if HAVE_CAIRO
diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c
index e4e8149591ef..4db4e9a72124 100644
--- a/tests/modetest/buffers.c
+++ b/tests/modetest/buffers.c
@@ -49,8 +49,6 @@
 #include <cairo.h>
 #endif
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
 struct bo
 {
 	int fd;
@@ -62,956 +60,6 @@ struct bo
 };
 
 /* -----------------------------------------------------------------------------
- * Formats
- */
-
-struct color_component {
-	unsigned int length;
-	unsigned int offset;
-};
-
-struct rgb_info {
-	struct color_component red;
-	struct color_component green;
-	struct color_component blue;
-	struct color_component alpha;
-};
-
-enum yuv_order {
-	YUV_YCbCr = 1,
-	YUV_YCrCb = 2,
-	YUV_YC = 4,
-	YUV_CY = 8,
-};
-
-struct yuv_info {
-	enum yuv_order order;
-	unsigned int xsub;
-	unsigned int ysub;
-	unsigned int chroma_stride;
-};
-
-struct format_info {
-	unsigned int format;
-	const char *name;
-	const struct rgb_info rgb;
-	const struct yuv_info yuv;
-};
-
-#define MAKE_RGB_INFO(rl, ro, bl, bo, gl, go, al, ao) \
-	.rgb = { { (rl), (ro) }, { (bl), (bo) }, { (gl), (go) }, { (al), (ao) } }
-
-#define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \
-	.yuv = { (order), (xsub), (ysub), (chroma_stride) }
-
-static const struct format_info format_info[] = {
-	/* YUV packed */
-	{ DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) },
-	{ DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) },
-	{ DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) },
-	{ DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) },
-	/* YUV semi-planar */
-	{ DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) },
-	{ DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) },
-	{ DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) },
-	{ DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) },
-	/* YUV planar */
-	{ DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) },
-	{ DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) },
-	/* RGB16 */
-	{ DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) },
-	{ DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) },
-	{ DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) },
-	{ DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) },
-	{ DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) },
-	{ DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) },
-	{ DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) },
-	{ DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) },
-	{ DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) },
-	{ DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) },
-	{ DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) },
-	{ DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) },
-	{ DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) },
-	{ DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) },
-	{ DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) },
-	{ DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) },
-	/* RGB24 */
-	{ DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
-	{ DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
-	/* RGB32 */
-	{ DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
-	{ DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
-	{ DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
-	{ DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
-	{ DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) },
-	{ DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) },
-	{ DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) },
-	{ DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) },
-	{ DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) },
-	{ DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) },
-	{ DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) },
-	{ DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) },
-	{ DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) },
-	{ DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) },
-	{ DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) },
-};
-
-unsigned int format_fourcc(const char *name)
-{
-	unsigned int i;
-	for (i = 0; i < ARRAY_SIZE(format_info); i++) {
-		if (!strcmp(format_info[i].name, name))
-			return format_info[i].format;
-	}
-	return 0;
-}
-
-/* -----------------------------------------------------------------------------
- * Test patterns
- */
-
-struct color_rgb24 {
-	unsigned int value:24;
-} __attribute__((__packed__));
-
-struct color_yuv {
-	unsigned char y;
-	unsigned char u;
-	unsigned char v;
-};
-
-#define MAKE_YUV_601_Y(r, g, b) \
-	((( 66 * (r) + 129 * (g) +  25 * (b) + 128) >> 8) + 16)
-#define MAKE_YUV_601_U(r, g, b) \
-	(((-38 * (r) -  74 * (g) + 112 * (b) + 128) >> 8) + 128)
-#define MAKE_YUV_601_V(r, g, b) \
-	(((112 * (r) -  94 * (g) -  18 * (b) + 128) >> 8) + 128)
-
-#define MAKE_YUV_601(r, g, b) \
-	{ .y = MAKE_YUV_601_Y(r, g, b), \
-	  .u = MAKE_YUV_601_U(r, g, b), \
-	  .v = MAKE_YUV_601_V(r, g, b) }
-
-#define MAKE_RGBA(rgb, r, g, b, a) \
-	((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
-	 (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
-	 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
-	 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
-
-#define MAKE_RGB24(rgb, r, g, b) \
-	{ .value = MAKE_RGBA(rgb, r, g, b, 0) }
-
-static void
-fill_smpte_yuv_planar(const struct yuv_info *yuv,
-		      unsigned char *y_mem, unsigned char *u_mem,
-		      unsigned char *v_mem, unsigned int width,
-		      unsigned int height, unsigned int stride)
-{
-	const struct color_yuv colors_top[] = {
-		MAKE_YUV_601(191, 192, 192),	/* grey */
-		MAKE_YUV_601(192, 192, 0),	/* yellow */
-		MAKE_YUV_601(0, 192, 192),	/* cyan */
-		MAKE_YUV_601(0, 192, 0),	/* green */
-		MAKE_YUV_601(192, 0, 192),	/* magenta */
-		MAKE_YUV_601(192, 0, 0),	/* red */
-		MAKE_YUV_601(0, 0, 192),	/* blue */
-	};
-	const struct color_yuv colors_middle[] = {
-		MAKE_YUV_601(0, 0, 192),	/* blue */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(192, 0, 192),	/* magenta */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(0, 192, 192),	/* cyan */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(192, 192, 192),	/* grey */
-	};
-	const struct color_yuv colors_bottom[] = {
-		MAKE_YUV_601(0, 33, 76),	/* in-phase */
-		MAKE_YUV_601(255, 255, 255),	/* super white */
-		MAKE_YUV_601(50, 0, 106),	/* quadrature */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(9, 9, 9),		/* 3.5% */
-		MAKE_YUV_601(19, 19, 19),	/* 7.5% */
-		MAKE_YUV_601(29, 29, 29),	/* 11.5% */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-	};
-	unsigned int cs = yuv->chroma_stride;
-	unsigned int xsub = yuv->xsub;
-	unsigned int ysub = yuv->ysub;
-	unsigned int x;
-	unsigned int y;
-
-	/* Luma */
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			y_mem[x] = colors_top[x * 7 / width].y;
-		y_mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			y_mem[x] = colors_middle[x * 7 / width].y;
-		y_mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; ++x)
-			y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
-		for (; x < width * 6 / 7; ++x)
-			y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3
-						 / (width / 7) + 4].y;
-		for (; x < width; ++x)
-			y_mem[x] = colors_bottom[7].y;
-		y_mem += stride;
-	}
-
-	/* Chroma */
-	for (y = 0; y < height / ysub * 6 / 9; ++y) {
-		for (x = 0; x < width; x += xsub) {
-			u_mem[x*cs/xsub] = colors_top[x * 7 / width].u;
-			v_mem[x*cs/xsub] = colors_top[x * 7 / width].v;
-		}
-		u_mem += stride * cs / xsub;
-		v_mem += stride * cs / xsub;
-	}
-
-	for (; y < height / ysub * 7 / 9; ++y) {
-		for (x = 0; x < width; x += xsub) {
-			u_mem[x*cs/xsub] = colors_middle[x * 7 / width].u;
-			v_mem[x*cs/xsub] = colors_middle[x * 7 / width].v;
-		}
-		u_mem += stride * cs / xsub;
-		v_mem += stride * cs / xsub;
-	}
-
-	for (; y < height / ysub; ++y) {
-		for (x = 0; x < width * 5 / 7; x += xsub) {
-			u_mem[x*cs/xsub] =
-				colors_bottom[x * 4 / (width * 5 / 7)].u;
-			v_mem[x*cs/xsub] =
-				colors_bottom[x * 4 / (width * 5 / 7)].v;
-		}
-		for (; x < width * 6 / 7; x += xsub) {
-			u_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) *
-							 3 / (width / 7) + 4].u;
-			v_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) *
-							 3 / (width / 7) + 4].v;
-		}
-		for (; x < width; x += xsub) {
-			u_mem[x*cs/xsub] = colors_bottom[7].u;
-			v_mem[x*cs/xsub] = colors_bottom[7].v;
-		}
-		u_mem += stride * cs / xsub;
-		v_mem += stride * cs / xsub;
-	}
-}
-
-static void
-fill_smpte_yuv_packed(const struct yuv_info *yuv, unsigned char *mem,
-		      unsigned int width, unsigned int height,
-		      unsigned int stride)
-{
-	const struct color_yuv colors_top[] = {
-		MAKE_YUV_601(191, 192, 192),	/* grey */
-		MAKE_YUV_601(192, 192, 0),	/* yellow */
-		MAKE_YUV_601(0, 192, 192),	/* cyan */
-		MAKE_YUV_601(0, 192, 0),	/* green */
-		MAKE_YUV_601(192, 0, 192),	/* magenta */
-		MAKE_YUV_601(192, 0, 0),	/* red */
-		MAKE_YUV_601(0, 0, 192),	/* blue */
-	};
-	const struct color_yuv colors_middle[] = {
-		MAKE_YUV_601(0, 0, 192),	/* blue */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(192, 0, 192),	/* magenta */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(0, 192, 192),	/* cyan */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(192, 192, 192),	/* grey */
-	};
-	const struct color_yuv colors_bottom[] = {
-		MAKE_YUV_601(0, 33, 76),	/* in-phase */
-		MAKE_YUV_601(255, 255, 255),	/* super white */
-		MAKE_YUV_601(50, 0, 106),	/* quadrature */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-		MAKE_YUV_601(9, 9, 9),		/* 3.5% */
-		MAKE_YUV_601(19, 19, 19),	/* 7.5% */
-		MAKE_YUV_601(29, 29, 29),	/* 11.5% */
-		MAKE_YUV_601(19, 19, 19),	/* black */
-	};
-	unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
-	unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
-	unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
-	unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
-	unsigned int x;
-	unsigned int y;
-
-	/* Luma */
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			y_mem[2*x] = colors_top[x * 7 / width].y;
-		y_mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			y_mem[2*x] = colors_middle[x * 7 / width].y;
-		y_mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; ++x)
-			y_mem[2*x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
-		for (; x < width * 6 / 7; ++x)
-			y_mem[2*x] = colors_bottom[(x - width * 5 / 7) * 3
-						   / (width / 7) + 4].y;
-		for (; x < width; ++x)
-			y_mem[2*x] = colors_bottom[7].y;
-		y_mem += stride;
-	}
-
-	/* Chroma */
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; x += 2) {
-			c_mem[2*x+u] = colors_top[x * 7 / width].u;
-			c_mem[2*x+v] = colors_top[x * 7 / width].v;
-		}
-		c_mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; x += 2) {
-			c_mem[2*x+u] = colors_middle[x * 7 / width].u;
-			c_mem[2*x+v] = colors_middle[x * 7 / width].v;
-		}
-		c_mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; x += 2) {
-			c_mem[2*x+u] = colors_bottom[x * 4 / (width * 5 / 7)].u;
-			c_mem[2*x+v] = colors_bottom[x * 4 / (width * 5 / 7)].v;
-		}
-		for (; x < width * 6 / 7; x += 2) {
-			c_mem[2*x+u] = colors_bottom[(x - width * 5 / 7) *
-						     3 / (width / 7) + 4].u;
-			c_mem[2*x+v] = colors_bottom[(x - width * 5 / 7) *
-						     3 / (width / 7) + 4].v;
-		}
-		for (; x < width; x += 2) {
-			c_mem[2*x+u] = colors_bottom[7].u;
-			c_mem[2*x+v] = colors_bottom[7].v;
-		}
-		c_mem += stride;
-	}
-}
-
-static void
-fill_smpte_rgb16(const struct rgb_info *rgb, unsigned char *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const uint16_t colors_top[] = {
-		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
-		MAKE_RGBA(rgb, 192, 192, 0, 255),	/* yellow */
-		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
-		MAKE_RGBA(rgb, 0, 192, 0, 255),		/* green */
-		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
-		MAKE_RGBA(rgb, 192, 0, 0, 255),		/* red */
-		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
-	};
-	const uint16_t colors_middle[] = {
-		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
-	};
-	const uint16_t colors_bottom[] = {
-		MAKE_RGBA(rgb, 0, 33, 76, 255),		/* in-phase */
-		MAKE_RGBA(rgb, 255, 255, 255, 255),	/* super white */
-		MAKE_RGBA(rgb, 50, 0, 106, 255),	/* quadrature */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 9, 9, 9, 255),		/* 3.5% */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* 7.5% */
-		MAKE_RGBA(rgb, 29, 29, 29, 255),	/* 11.5% */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-	};
-	unsigned int x;
-	unsigned int y;
-
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((uint16_t *)mem)[x] = colors_top[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((uint16_t *)mem)[x] = colors_middle[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; ++x)
-			((uint16_t *)mem)[x] =
-				colors_bottom[x * 4 / (width * 5 / 7)];
-		for (; x < width * 6 / 7; ++x)
-			((uint16_t *)mem)[x] =
-				colors_bottom[(x - width * 5 / 7) * 3
-					      / (width / 7) + 4];
-		for (; x < width; ++x)
-			((uint16_t *)mem)[x] = colors_bottom[7];
-		mem += stride;
-	}
-}
-
-static void
-fill_smpte_rgb24(const struct rgb_info *rgb, void *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const struct color_rgb24 colors_top[] = {
-		MAKE_RGB24(rgb, 192, 192, 192),	/* grey */
-		MAKE_RGB24(rgb, 192, 192, 0),	/* yellow */
-		MAKE_RGB24(rgb, 0, 192, 192),	/* cyan */
-		MAKE_RGB24(rgb, 0, 192, 0),	/* green */
-		MAKE_RGB24(rgb, 192, 0, 192),	/* magenta */
-		MAKE_RGB24(rgb, 192, 0, 0),	/* red */
-		MAKE_RGB24(rgb, 0, 0, 192),	/* blue */
-	};
-	const struct color_rgb24 colors_middle[] = {
-		MAKE_RGB24(rgb, 0, 0, 192),	/* blue */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
-		MAKE_RGB24(rgb, 192, 0, 192),	/* magenta */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
-		MAKE_RGB24(rgb, 0, 192, 192),	/* cyan */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
-		MAKE_RGB24(rgb, 192, 192, 192),	/* grey */
-	};
-	const struct color_rgb24 colors_bottom[] = {
-		MAKE_RGB24(rgb, 0, 33, 76),	/* in-phase */
-		MAKE_RGB24(rgb, 255, 255, 255),	/* super white */
-		MAKE_RGB24(rgb, 50, 0, 106),	/* quadrature */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
-		MAKE_RGB24(rgb, 9, 9, 9),	/* 3.5% */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* 7.5% */
-		MAKE_RGB24(rgb, 29, 29, 29),	/* 11.5% */
-		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
-	};
-	unsigned int x;
-	unsigned int y;
-
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((struct color_rgb24 *)mem)[x] =
-				colors_top[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((struct color_rgb24 *)mem)[x] =
-				colors_middle[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; ++x)
-			((struct color_rgb24 *)mem)[x] =
-				colors_bottom[x * 4 / (width * 5 / 7)];
-		for (; x < width * 6 / 7; ++x)
-			((struct color_rgb24 *)mem)[x] =
-				colors_bottom[(x - width * 5 / 7) * 3
-					      / (width / 7) + 4];
-		for (; x < width; ++x)
-			((struct color_rgb24 *)mem)[x] = colors_bottom[7];
-		mem += stride;
-	}
-}
-
-static void
-fill_smpte_rgb32(const struct rgb_info *rgb, unsigned char *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const uint32_t colors_top[] = {
-		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
-		MAKE_RGBA(rgb, 192, 192, 0, 255),	/* yellow */
-		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
-		MAKE_RGBA(rgb, 0, 192, 0, 255),		/* green */
-		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
-		MAKE_RGBA(rgb, 192, 0, 0, 255),		/* red */
-		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
-	};
-	const uint32_t colors_middle[] = {
-		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
-	};
-	const uint32_t colors_bottom[] = {
-		MAKE_RGBA(rgb, 0, 33, 76, 255),		/* in-phase */
-		MAKE_RGBA(rgb, 255, 255, 255, 255),	/* super white */
-		MAKE_RGBA(rgb, 50, 0, 106, 255),	/* quadrature */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-		MAKE_RGBA(rgb, 9, 9, 9, 255),		/* 3.5% */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* 7.5% */
-		MAKE_RGBA(rgb, 29, 29, 29, 255),	/* 11.5% */
-		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
-	};
-	unsigned int x;
-	unsigned int y;
-
-	for (y = 0; y < height * 6 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((uint32_t *)mem)[x] = colors_top[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height * 7 / 9; ++y) {
-		for (x = 0; x < width; ++x)
-			((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
-		mem += stride;
-	}
-
-	for (; y < height; ++y) {
-		for (x = 0; x < width * 5 / 7; ++x)
-			((uint32_t *)mem)[x] =
-				colors_bottom[x * 4 / (width * 5 / 7)];
-		for (; x < width * 6 / 7; ++x)
-			((uint32_t *)mem)[x] =
-				colors_bottom[(x - width * 5 / 7) * 3
-					      / (width / 7) + 4];
-		for (; x < width; ++x)
-			((uint32_t *)mem)[x] = colors_bottom[7];
-		mem += stride;
-	}
-}
-
-static void
-fill_smpte(const struct format_info *info, void *planes[3], unsigned int width,
-	   unsigned int height, unsigned int stride)
-{
-	unsigned char *u, *v;
-
-	switch (info->format) {
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-		return fill_smpte_yuv_packed(&info->yuv, planes[0], width,
-					     height, stride);
-
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-		u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
-		v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
-		return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v,
-					     width, height, stride);
-
-	case DRM_FORMAT_YUV420:
-		return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1],
-					     planes[2], width, height, stride);
-
-	case DRM_FORMAT_YVU420:
-		return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2],
-					     planes[1], width, height, stride);
-
-	case DRM_FORMAT_ARGB4444:
-	case DRM_FORMAT_XRGB4444:
-	case DRM_FORMAT_ABGR4444:
-	case DRM_FORMAT_XBGR4444:
-	case DRM_FORMAT_RGBA4444:
-	case DRM_FORMAT_RGBX4444:
-	case DRM_FORMAT_BGRA4444:
-	case DRM_FORMAT_BGRX4444:
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRA5551:
-	case DRM_FORMAT_BGRX5551:
-		return fill_smpte_rgb16(&info->rgb, planes[0],
-					width, height, stride);
-
-	case DRM_FORMAT_BGR888:
-	case DRM_FORMAT_RGB888:
-		return fill_smpte_rgb24(&info->rgb, planes[0],
-					width, height, stride);
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRA8888:
-	case DRM_FORMAT_BGRX8888:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRA1010102:
-	case DRM_FORMAT_BGRX1010102:
-		return fill_smpte_rgb32(&info->rgb, planes[0],
-					width, height, stride);
-	}
-}
-
-/* swap these for big endian.. */
-#define RED   2
-#define GREEN 1
-#define BLUE  0
-
-static void
-make_pwetty(void *data, int width, int height, int stride, uint32_t format)
-{
-#ifdef HAVE_CAIRO
-	cairo_surface_t *surface;
-	cairo_t *cr;
-	int x, y;
-	cairo_format_t cairo_format;
-
-	/* we can ignore the order of R,G,B channels */
-	switch (format) {
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_ABGR8888:
-		cairo_format = CAIRO_FORMAT_ARGB32;
-		break;
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-		cairo_format = CAIRO_FORMAT_RGB16_565;
-		break;
-	default:
-		return;
-	}
-
-	surface = cairo_image_surface_create_for_data(data,
-						      cairo_format,
-						      width, height,
-						      stride);
-	cr = cairo_create(surface);
-	cairo_surface_destroy(surface);
-
-	cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
-	for (x = 0; x < width; x += 250)
-		for (y = 0; y < height; y += 250) {
-			char buf[64];
-
-			cairo_move_to(cr, x, y - 20);
-			cairo_line_to(cr, x, y + 20);
-			cairo_move_to(cr, x - 20, y);
-			cairo_line_to(cr, x + 20, y);
-			cairo_new_sub_path(cr);
-			cairo_arc(cr, x, y, 10, 0, M_PI * 2);
-			cairo_set_line_width(cr, 4);
-			cairo_set_source_rgb(cr, 0, 0, 0);
-			cairo_stroke_preserve(cr);
-			cairo_set_source_rgb(cr, 1, 1, 1);
-			cairo_set_line_width(cr, 2);
-			cairo_stroke(cr);
-
-			snprintf(buf, sizeof buf, "%d, %d", x, y);
-			cairo_move_to(cr, x + 20, y + 20);
-			cairo_text_path(cr, buf);
-			cairo_set_source_rgb(cr, 0, 0, 0);
-			cairo_stroke_preserve(cr);
-			cairo_set_source_rgb(cr, 1, 1, 1);
-			cairo_fill(cr);
-		}
-
-	cairo_destroy(cr);
-#endif
-}
-
-static void
-fill_tiles_yuv_planar(const struct format_info *info,
-		      unsigned char *y_mem, unsigned char *u_mem,
-		      unsigned char *v_mem, unsigned int width,
-		      unsigned int height, unsigned int stride)
-{
-	const struct yuv_info *yuv = &info->yuv;
-	unsigned int cs = yuv->chroma_stride;
-	unsigned int xsub = yuv->xsub;
-	unsigned int ysub = yuv->ysub;
-	unsigned int x;
-	unsigned int y;
-
-	for (y = 0; y < height; ++y) {
-		for (x = 0; x < width; ++x) {
-			div_t d = div(x+y, width);
-			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
-				       + 0x000a1120 * (d.rem >> 6);
-			struct color_yuv color =
-				MAKE_YUV_601((rgb32 >> 16) & 0xff,
-					     (rgb32 >> 8) & 0xff, rgb32 & 0xff);
-
-			y_mem[x] = color.y;
-			u_mem[x/xsub*cs] = color.u;
-			v_mem[x/xsub*cs] = color.v;
-		}
-
-		y_mem += stride;
-		if ((y + 1) % ysub == 0) {
-			u_mem += stride * cs / xsub;
-			v_mem += stride * cs / xsub;
-		}
-	}
-}
-
-static void
-fill_tiles_yuv_packed(const struct format_info *info, unsigned char *mem,
-		      unsigned int width, unsigned int height,
-		      unsigned int stride)
-{
-	const struct yuv_info *yuv = &info->yuv;
-	unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
-	unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
-	unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
-	unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
-	unsigned int x;
-	unsigned int y;
-
-	for (y = 0; y < height; ++y) {
-		for (x = 0; x < width; x += 2) {
-			div_t d = div(x+y, width);
-			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
-				       + 0x000a1120 * (d.rem >> 6);
-			struct color_yuv color =
-				MAKE_YUV_601((rgb32 >> 16) & 0xff,
-					     (rgb32 >> 8) & 0xff, rgb32 & 0xff);
-
-			y_mem[2*x] = color.y;
-			c_mem[2*x+u] = color.u;
-			y_mem[2*x+2] = color.y;
-			c_mem[2*x+v] = color.v;
-		}
-
-		y_mem += stride;
-		c_mem += stride;
-	}
-}
-
-static void
-fill_tiles_rgb16(const struct format_info *info, unsigned char *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const struct rgb_info *rgb = &info->rgb;
-	unsigned char *mem_base = mem;
-	unsigned int x, y;
-
-	for (y = 0; y < height; ++y) {
-		for (x = 0; x < width; ++x) {
-			div_t d = div(x+y, width);
-			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
-				       + 0x000a1120 * (d.rem >> 6);
-			uint16_t color =
-				MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
-					  (rgb32 >> 8) & 0xff, rgb32 & 0xff,
-					  255);
-
-			((uint16_t *)mem)[x] = color;
-		}
-		mem += stride;
-	}
-
-	make_pwetty(mem_base, width, height, stride, info->format);
-}
-
-static void
-fill_tiles_rgb24(const struct format_info *info, unsigned char *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const struct rgb_info *rgb = &info->rgb;
-	unsigned int x, y;
-
-	for (y = 0; y < height; ++y) {
-		for (x = 0; x < width; ++x) {
-			div_t d = div(x+y, width);
-			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
-				       + 0x000a1120 * (d.rem >> 6);
-			struct color_rgb24 color =
-				MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff,
-					   (rgb32 >> 8) & 0xff, rgb32 & 0xff);
-
-			((struct color_rgb24 *)mem)[x] = color;
-		}
-		mem += stride;
-	}
-}
-
-static void
-fill_tiles_rgb32(const struct format_info *info, unsigned char *mem,
-		 unsigned int width, unsigned int height, unsigned int stride)
-{
-	const struct rgb_info *rgb = &info->rgb;
-	unsigned char *mem_base = mem;
-	unsigned int x, y;
-
-	for (y = 0; y < height; ++y) {
-		for (x = 0; x < width; ++x) {
-			div_t d = div(x+y, width);
-			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
-				       + 0x000a1120 * (d.rem >> 6);
-			uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255;
-			uint32_t color =
-				MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
-					  (rgb32 >> 8) & 0xff, rgb32 & 0xff,
-					  alpha);
-
-			((uint32_t *)mem)[x] = color;
-		}
-		mem += stride;
-	}
-
-	make_pwetty(mem_base, width, height, stride, info->format);
-}
-
-static void
-fill_tiles(const struct format_info *info, void *planes[3], unsigned int width,
-	   unsigned int height, unsigned int stride)
-{
-	unsigned char *u, *v;
-
-	switch (info->format) {
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-		return fill_tiles_yuv_packed(info, planes[0],
-					     width, height, stride);
-
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-		u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
-		v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
-		return fill_tiles_yuv_planar(info, planes[0], u, v,
-					     width, height, stride);
-
-	case DRM_FORMAT_YUV420:
-		return fill_tiles_yuv_planar(info, planes[0], planes[1],
-					     planes[2], width, height, stride);
-
-	case DRM_FORMAT_YVU420:
-		return fill_tiles_yuv_planar(info, planes[0], planes[2],
-					     planes[1], width, height, stride);
-
-	case DRM_FORMAT_ARGB4444:
-	case DRM_FORMAT_XRGB4444:
-	case DRM_FORMAT_ABGR4444:
-	case DRM_FORMAT_XBGR4444:
-	case DRM_FORMAT_RGBA4444:
-	case DRM_FORMAT_RGBX4444:
-	case DRM_FORMAT_BGRA4444:
-	case DRM_FORMAT_BGRX4444:
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRA5551:
-	case DRM_FORMAT_BGRX5551:
-		return fill_tiles_rgb16(info, planes[0],
-					width, height, stride);
-
-	case DRM_FORMAT_BGR888:
-	case DRM_FORMAT_RGB888:
-		return fill_tiles_rgb24(info, planes[0],
-					width, height, stride);
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRA8888:
-	case DRM_FORMAT_BGRX8888:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRA1010102:
-	case DRM_FORMAT_BGRX1010102:
-		return fill_tiles_rgb32(info, planes[0],
-					width, height, stride);
-	}
-}
-
-static void
-fill_plain(const struct format_info *info, void *planes[3], unsigned int width,
-	   unsigned int height, unsigned int stride)
-{
-	memset(planes[0], 0x77, stride * height);
-}
-
-/*
- * fill_pattern - Fill a buffer with a test pattern
- * @format: Pixel format
- * @pattern: Test pattern
- * @buffer: Buffer memory
- * @width: Width in pixels
- * @height: Height in pixels
- * @stride: Line stride (pitch) in bytes
- *
- * Fill the buffer with the test pattern specified by the pattern parameter.
- * Supported formats vary depending on the selected pattern.
- */
-static void
-fill_pattern(unsigned int format, enum fill_pattern pattern, void *planes[3],
-	     unsigned int width, unsigned int height, unsigned int stride)
-{
-	const struct format_info *info = NULL;
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(format_info); ++i) {
-		if (format_info[i].format == format) {
-			info = &format_info[i];
-			break;
-		}
-	}
-
-	if (info == NULL)
-		return;
-
-	switch (pattern) {
-	case PATTERN_TILES:
-		return fill_tiles(info, planes, width, height, stride);
-
-	case PATTERN_SMPTE:
-		return fill_smpte(info, planes, width, height, stride);
-
-	case PATTERN_PLAIN:
-		return fill_plain(info, planes, width, height, stride);
-
-	default:
-		printf("Error: unsupported test pattern %u.\n", pattern);
-		break;
-	}
-}
-
-/* -----------------------------------------------------------------------------
  * Buffers management
  */
 
@@ -1086,7 +134,7 @@ struct bo *
 bo_create(int fd, unsigned int format,
 	  unsigned int width, unsigned int height,
 	  unsigned int handles[4], unsigned int pitches[4],
-	  unsigned int offsets[4], enum fill_pattern pattern)
+	  unsigned int offsets[4], enum util_fill_pattern pattern)
 {
 	unsigned int virtual_height;
 	struct bo *bo;
@@ -1278,7 +326,7 @@ bo_create(int fd, unsigned int format,
 		break;
 	}
 
-	fill_pattern(format, pattern, planes, width, height, pitches[0]);
+	util_fill_pattern(format, pattern, planes, width, height, pitches[0]);
 	bo_unmap(bo);
 
 	return bo;
diff --git a/tests/modetest/buffers.h b/tests/modetest/buffers.h
index ad73d0e4ba73..7f95396b4403 100644
--- a/tests/modetest/buffers.h
+++ b/tests/modetest/buffers.h
@@ -27,20 +27,14 @@
 #ifndef __BUFFERS_H__
 #define __BUFFERS_H__
 
-struct bo;
+#include "util/pattern.h"
 
-enum fill_pattern {
-	PATTERN_TILES = 0,
-	PATTERN_PLAIN = 1,
-	PATTERN_SMPTE = 2,
-};
+struct bo;
 
 struct bo *bo_create(int fd, unsigned int format,
 		   unsigned int width, unsigned int height,
 		   unsigned int handles[4], unsigned int pitches[4],
-		   unsigned int offsets[4], enum fill_pattern pattern);
+		   unsigned int offsets[4], enum util_fill_pattern pattern);
 void bo_destroy(struct bo *bo);
 
-unsigned int format_fourcc(const char *name);
-
 #endif
diff --git a/tests/modetest/cursor.c b/tests/modetest/cursor.c
index 62a50efb36e6..187054fe9556 100644
--- a/tests/modetest/cursor.c
+++ b/tests/modetest/cursor.c
@@ -40,11 +40,11 @@
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 
+#include "util/common.h"
+
 #include "buffers.h"
 #include "cursor.h"
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
 struct cursor {
 	int fd;
 	uint32_t bo_handle;
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index 4b9cf2f5b439..b610956adfcb 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -37,6 +37,7 @@
  * TODO: use cairo to write the mode info on the selected output once
  *       the mode has been programmed, along with possible test patterns.
  */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -58,6 +59,10 @@
 #include "xf86drmMode.h"
 #include "drm_fourcc.h"
 
+#include "util/common.h"
+#include "util/format.h"
+#include "util/pattern.h"
+
 #include "buffers.h"
 #include "cursor.h"
 
@@ -113,7 +118,6 @@ struct device {
 	} mode;
 };
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 static inline int64_t U642I64(uint64_t val)
 {
 	return (int64_t)*((int64_t *)&val);
@@ -1008,7 +1012,7 @@ static int set_plane(struct device *dev, struct plane_arg *p)
 		p->w, p->h, p->format_str, plane_id);
 
 	plane_bo = bo_create(dev->fd, p->fourcc, p->w, p->h, handles,
-			     pitches, offsets, PATTERN_TILES);
+			     pitches, offsets, UTIL_PATTERN_TILES);
 	if (plane_bo == NULL)
 		return -1;
 
@@ -1068,8 +1072,9 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
 			dev->mode.height = pipe->mode->vdisplay;
 	}
 
-	bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width, dev->mode.height,
-		       handles, pitches, offsets, PATTERN_SMPTE);
+	bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width,
+		       dev->mode.height, handles, pitches, offsets,
+		       UTIL_PATTERN_SMPTE);
 	if (bo == NULL)
 		return;
 
@@ -1138,7 +1143,7 @@ static void set_cursors(struct device *dev, struct pipe_arg *pipes, unsigned int
 	 * translucent alpha
 	 */
 	bo = bo_create(dev->fd, DRM_FORMAT_ARGB8888, cw, ch, handles, pitches,
-		       offsets, PATTERN_PLAIN);
+		       offsets, UTIL_PATTERN_PLAIN);
 	if (bo == NULL)
 		return;
 
@@ -1172,9 +1177,9 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned
 	unsigned int i;
 	int ret;
 
-	other_bo = bo_create(dev->fd, pipes[0].fourcc,
-			     dev->mode.width, dev->mode.height,
-			     handles, pitches, offsets, PATTERN_PLAIN);
+	other_bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width,
+			     dev->mode.height, handles, pitches, offsets,
+			     UTIL_PATTERN_PLAIN);
 	if (other_bo == NULL)
 		return;
 
@@ -1314,7 +1319,7 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg)
 		pipe->format_str[4] = '\0';
 	}
 
-	pipe->fourcc = format_fourcc(pipe->format_str);
+	pipe->fourcc = util_format_fourcc(pipe->format_str);
 	if (pipe->fourcc == 0)  {
 		fprintf(stderr, "unknown format %s\n", pipe->format_str);
 		return -1;
@@ -1369,7 +1374,7 @@ static int parse_plane(struct plane_arg *plane, const char *p)
 		strcpy(plane->format_str, "XR24");
 	}
 
-	plane->fourcc = format_fourcc(plane->format_str);
+	plane->fourcc = util_format_fourcc(plane->format_str);
 	if (plane->fourcc == 0) {
 		fprintf(stderr, "unknown format %s\n", plane->format_str);
 		return -EINVAL;
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
index 7618f63d2018..ee3fa408a310 100644
--- a/tests/proptest/proptest.c
+++ b/tests/proptest/proptest.c
@@ -35,7 +35,8 @@
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#include "util/common.h"
+
 static inline int64_t U642I64(uint64_t val)
 {
 	return (int64_t)*((int64_t *)&val);
diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am
new file mode 100644
index 000000000000..1a2519fbea89
--- /dev/null
+++ b/tests/util/Makefile.am
@@ -0,0 +1,19 @@
+noinst_LTLIBRARIES = \
+	libutil.la
+
+libutil_la_CPPFLAGS = \
+	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)
+
+libutil_la_CFLAGS = \
+	$(CAIRO_CFLAGS)
+
+libutil_la_SOURCES = \
+	common.h \
+	format.c \
+	format.h \
+	pattern.c \
+	pattern.h
+
+libutil_la_LIBADD = \
+	$(CAIRO_LIBS)
diff --git a/tests/util/common.h b/tests/util/common.h
new file mode 100644
index 000000000000..5d572c2dd003
--- /dev/null
+++ b/tests/util/common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef UTIL_COMMON_H
+#define UTIL_COMMON_H
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+#endif
+
+#endif /* UTIL_COMMON_H */
diff --git a/tests/util/format.c b/tests/util/format.c
new file mode 100644
index 000000000000..c365ceb3b9cd
--- /dev/null
+++ b/tests/util/format.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <drm_fourcc.h>
+
+#include "common.h"
+#include "format.h"
+
+#define MAKE_RGB_INFO(rl, ro, bl, bo, gl, go, al, ao) \
+	.rgb = { { (rl), (ro) }, { (bl), (bo) }, { (gl), (go) }, { (al), (ao) } }
+
+#define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \
+	.yuv = { (order), (xsub), (ysub), (chroma_stride) }
+
+static const struct util_format_info format_info[] = {
+	/* YUV packed */
+	{ DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) },
+	{ DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) },
+	{ DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) },
+	{ DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) },
+	/* YUV semi-planar */
+	{ DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) },
+	{ DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) },
+	{ DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) },
+	{ DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) },
+	/* YUV planar */
+	{ DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) },
+	{ DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) },
+	/* RGB16 */
+	{ DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) },
+	{ DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) },
+	{ DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) },
+	{ DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) },
+	{ DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) },
+	{ DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) },
+	{ DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) },
+	{ DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) },
+	{ DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) },
+	{ DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) },
+	{ DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) },
+	{ DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) },
+	{ DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) },
+	{ DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) },
+	{ DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) },
+	{ DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) },
+	{ DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) },
+	{ DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) },
+	/* RGB24 */
+	{ DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
+	{ DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
+	/* RGB32 */
+	{ DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
+	{ DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
+	{ DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
+	{ DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
+	{ DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
+	{ DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) },
+	{ DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) },
+	{ DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) },
+	{ DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) },
+	{ DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) },
+	{ DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) },
+	{ DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) },
+	{ DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) },
+	{ DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) },
+	{ DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) },
+	{ DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) },
+};
+
+uint32_t util_format_fourcc(const char *name)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(format_info); i++)
+		if (!strcmp(format_info[i].name, name))
+			return format_info[i].format;
+
+	return 0;
+}
+
+const struct util_format_info *util_format_info_find(uint32_t format)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(format_info); i++)
+		if (format_info[i].format == format)
+			return &format_info[i];
+
+	return NULL;
+}
diff --git a/tests/util/format.h b/tests/util/format.h
new file mode 100644
index 000000000000..2ce1c021fd78
--- /dev/null
+++ b/tests/util/format.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef UTIL_FORMAT_H
+#define UTIL_FORMAT_H
+
+struct util_color_component {
+	unsigned int length;
+	unsigned int offset;
+};
+
+struct util_rgb_info {
+	struct util_color_component red;
+	struct util_color_component green;
+	struct util_color_component blue;
+	struct util_color_component alpha;
+};
+
+enum util_yuv_order {
+	YUV_YCbCr = 1,
+	YUV_YCrCb = 2,
+	YUV_YC = 4,
+	YUV_CY = 8,
+};
+
+struct util_yuv_info {
+	enum util_yuv_order order;
+	unsigned int xsub;
+	unsigned int ysub;
+	unsigned int chroma_stride;
+};
+
+struct util_format_info {
+	uint32_t format;
+	const char *name;
+	const struct util_rgb_info rgb;
+	const struct util_yuv_info yuv;
+};
+
+uint32_t util_format_fourcc(const char *name);
+const struct util_format_info *util_format_info_find(uint32_t format);
+
+#endif /* UTIL_FORMAT_H */
diff --git a/tests/util/pattern.c b/tests/util/pattern.c
new file mode 100644
index 000000000000..82cc4a5a1eec
--- /dev/null
+++ b/tests/util/pattern.c
@@ -0,0 +1,870 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <drm_fourcc.h>
+
+#ifdef HAVE_CAIRO
+#include <cairo.h>
+#include <math.h>
+#endif
+
+#include "format.h"
+#include "pattern.h"
+
+struct color_rgb24 {
+	unsigned int value:24;
+} __attribute__((__packed__));
+
+struct color_yuv {
+	unsigned char y;
+	unsigned char u;
+	unsigned char v;
+};
+
+#define MAKE_YUV_601_Y(r, g, b) \
+	((( 66 * (r) + 129 * (g) +  25 * (b) + 128) >> 8) + 16)
+#define MAKE_YUV_601_U(r, g, b) \
+	(((-38 * (r) -  74 * (g) + 112 * (b) + 128) >> 8) + 128)
+#define MAKE_YUV_601_V(r, g, b) \
+	(((112 * (r) -  94 * (g) -  18 * (b) + 128) >> 8) + 128)
+
+#define MAKE_YUV_601(r, g, b) \
+	{ .y = MAKE_YUV_601_Y(r, g, b), \
+	  .u = MAKE_YUV_601_U(r, g, b), \
+	  .v = MAKE_YUV_601_V(r, g, b) }
+
+#define MAKE_RGBA(rgb, r, g, b, a) \
+	((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
+	 (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
+	 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
+	 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
+
+#define MAKE_RGB24(rgb, r, g, b) \
+	{ .value = MAKE_RGBA(rgb, r, g, b, 0) }
+
+static void fill_smpte_yuv_planar(const struct util_yuv_info *yuv,
+				  unsigned char *y_mem, unsigned char *u_mem,
+				  unsigned char *v_mem, unsigned int width,
+				  unsigned int height, unsigned int stride)
+{
+	const struct color_yuv colors_top[] = {
+		MAKE_YUV_601(191, 192, 192),	/* grey */
+		MAKE_YUV_601(192, 192, 0),	/* yellow */
+		MAKE_YUV_601(0, 192, 192),	/* cyan */
+		MAKE_YUV_601(0, 192, 0),	/* green */
+		MAKE_YUV_601(192, 0, 192),	/* magenta */
+		MAKE_YUV_601(192, 0, 0),	/* red */
+		MAKE_YUV_601(0, 0, 192),	/* blue */
+	};
+	const struct color_yuv colors_middle[] = {
+		MAKE_YUV_601(0, 0, 192),	/* blue */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(192, 0, 192),	/* magenta */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(0, 192, 192),	/* cyan */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(192, 192, 192),	/* grey */
+	};
+	const struct color_yuv colors_bottom[] = {
+		MAKE_YUV_601(0, 33, 76),	/* in-phase */
+		MAKE_YUV_601(255, 255, 255),	/* super white */
+		MAKE_YUV_601(50, 0, 106),	/* quadrature */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(9, 9, 9),		/* 3.5% */
+		MAKE_YUV_601(19, 19, 19),	/* 7.5% */
+		MAKE_YUV_601(29, 29, 29),	/* 11.5% */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+	};
+	unsigned int cs = yuv->chroma_stride;
+	unsigned int xsub = yuv->xsub;
+	unsigned int ysub = yuv->ysub;
+	unsigned int x;
+	unsigned int y;
+
+	/* Luma */
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			y_mem[x] = colors_top[x * 7 / width].y;
+		y_mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			y_mem[x] = colors_middle[x * 7 / width].y;
+		y_mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
+		for (; x < width * 6 / 7; ++x)
+			y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3
+						 / (width / 7) + 4].y;
+		for (; x < width; ++x)
+			y_mem[x] = colors_bottom[7].y;
+		y_mem += stride;
+	}
+
+	/* Chroma */
+	for (y = 0; y < height / ysub * 6 / 9; ++y) {
+		for (x = 0; x < width; x += xsub) {
+			u_mem[x*cs/xsub] = colors_top[x * 7 / width].u;
+			v_mem[x*cs/xsub] = colors_top[x * 7 / width].v;
+		}
+		u_mem += stride * cs / xsub;
+		v_mem += stride * cs / xsub;
+	}
+
+	for (; y < height / ysub * 7 / 9; ++y) {
+		for (x = 0; x < width; x += xsub) {
+			u_mem[x*cs/xsub] = colors_middle[x * 7 / width].u;
+			v_mem[x*cs/xsub] = colors_middle[x * 7 / width].v;
+		}
+		u_mem += stride * cs / xsub;
+		v_mem += stride * cs / xsub;
+	}
+
+	for (; y < height / ysub; ++y) {
+		for (x = 0; x < width * 5 / 7; x += xsub) {
+			u_mem[x*cs/xsub] =
+				colors_bottom[x * 4 / (width * 5 / 7)].u;
+			v_mem[x*cs/xsub] =
+				colors_bottom[x * 4 / (width * 5 / 7)].v;
+		}
+		for (; x < width * 6 / 7; x += xsub) {
+			u_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) *
+							 3 / (width / 7) + 4].u;
+			v_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) *
+							 3 / (width / 7) + 4].v;
+		}
+		for (; x < width; x += xsub) {
+			u_mem[x*cs/xsub] = colors_bottom[7].u;
+			v_mem[x*cs/xsub] = colors_bottom[7].v;
+		}
+		u_mem += stride * cs / xsub;
+		v_mem += stride * cs / xsub;
+	}
+}
+
+static void fill_smpte_yuv_packed(const struct util_yuv_info *yuv, void *mem,
+				  unsigned int width, unsigned int height,
+				  unsigned int stride)
+{
+	const struct color_yuv colors_top[] = {
+		MAKE_YUV_601(191, 192, 192),	/* grey */
+		MAKE_YUV_601(192, 192, 0),	/* yellow */
+		MAKE_YUV_601(0, 192, 192),	/* cyan */
+		MAKE_YUV_601(0, 192, 0),	/* green */
+		MAKE_YUV_601(192, 0, 192),	/* magenta */
+		MAKE_YUV_601(192, 0, 0),	/* red */
+		MAKE_YUV_601(0, 0, 192),	/* blue */
+	};
+	const struct color_yuv colors_middle[] = {
+		MAKE_YUV_601(0, 0, 192),	/* blue */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(192, 0, 192),	/* magenta */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(0, 192, 192),	/* cyan */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(192, 192, 192),	/* grey */
+	};
+	const struct color_yuv colors_bottom[] = {
+		MAKE_YUV_601(0, 33, 76),	/* in-phase */
+		MAKE_YUV_601(255, 255, 255),	/* super white */
+		MAKE_YUV_601(50, 0, 106),	/* quadrature */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+		MAKE_YUV_601(9, 9, 9),		/* 3.5% */
+		MAKE_YUV_601(19, 19, 19),	/* 7.5% */
+		MAKE_YUV_601(29, 29, 29),	/* 11.5% */
+		MAKE_YUV_601(19, 19, 19),	/* black */
+	};
+	unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
+	unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
+	unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
+	unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
+	unsigned int x;
+	unsigned int y;
+
+	/* Luma */
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			y_mem[2*x] = colors_top[x * 7 / width].y;
+		y_mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			y_mem[2*x] = colors_middle[x * 7 / width].y;
+		y_mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			y_mem[2*x] = colors_bottom[x * 4 / (width * 5 / 7)].y;
+		for (; x < width * 6 / 7; ++x)
+			y_mem[2*x] = colors_bottom[(x - width * 5 / 7) * 3
+						   / (width / 7) + 4].y;
+		for (; x < width; ++x)
+			y_mem[2*x] = colors_bottom[7].y;
+		y_mem += stride;
+	}
+
+	/* Chroma */
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; x += 2) {
+			c_mem[2*x+u] = colors_top[x * 7 / width].u;
+			c_mem[2*x+v] = colors_top[x * 7 / width].v;
+		}
+		c_mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; x += 2) {
+			c_mem[2*x+u] = colors_middle[x * 7 / width].u;
+			c_mem[2*x+v] = colors_middle[x * 7 / width].v;
+		}
+		c_mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; x += 2) {
+			c_mem[2*x+u] = colors_bottom[x * 4 / (width * 5 / 7)].u;
+			c_mem[2*x+v] = colors_bottom[x * 4 / (width * 5 / 7)].v;
+		}
+		for (; x < width * 6 / 7; x += 2) {
+			c_mem[2*x+u] = colors_bottom[(x - width * 5 / 7) *
+						     3 / (width / 7) + 4].u;
+			c_mem[2*x+v] = colors_bottom[(x - width * 5 / 7) *
+						     3 / (width / 7) + 4].v;
+		}
+		for (; x < width; x += 2) {
+			c_mem[2*x+u] = colors_bottom[7].u;
+			c_mem[2*x+v] = colors_bottom[7].v;
+		}
+		c_mem += stride;
+	}
+}
+
+static void fill_smpte_rgb16(const struct util_rgb_info *rgb, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const uint16_t colors_top[] = {
+		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
+		MAKE_RGBA(rgb, 192, 192, 0, 255),	/* yellow */
+		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
+		MAKE_RGBA(rgb, 0, 192, 0, 255),		/* green */
+		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
+		MAKE_RGBA(rgb, 192, 0, 0, 255),		/* red */
+		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
+	};
+	const uint16_t colors_middle[] = {
+		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
+	};
+	const uint16_t colors_bottom[] = {
+		MAKE_RGBA(rgb, 0, 33, 76, 255),		/* in-phase */
+		MAKE_RGBA(rgb, 255, 255, 255, 255),	/* super white */
+		MAKE_RGBA(rgb, 50, 0, 106, 255),	/* quadrature */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 9, 9, 9, 255),		/* 3.5% */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* 7.5% */
+		MAKE_RGBA(rgb, 29, 29, 29, 255),	/* 11.5% */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+	};
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint16_t *)mem)[x] = colors_top[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint16_t *)mem)[x] = colors_middle[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			((uint16_t *)mem)[x] =
+				colors_bottom[x * 4 / (width * 5 / 7)];
+		for (; x < width * 6 / 7; ++x)
+			((uint16_t *)mem)[x] =
+				colors_bottom[(x - width * 5 / 7) * 3
+					      / (width / 7) + 4];
+		for (; x < width; ++x)
+			((uint16_t *)mem)[x] = colors_bottom[7];
+		mem += stride;
+	}
+}
+
+static void fill_smpte_rgb24(const struct util_rgb_info *rgb, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const struct color_rgb24 colors_top[] = {
+		MAKE_RGB24(rgb, 192, 192, 192),	/* grey */
+		MAKE_RGB24(rgb, 192, 192, 0),	/* yellow */
+		MAKE_RGB24(rgb, 0, 192, 192),	/* cyan */
+		MAKE_RGB24(rgb, 0, 192, 0),	/* green */
+		MAKE_RGB24(rgb, 192, 0, 192),	/* magenta */
+		MAKE_RGB24(rgb, 192, 0, 0),	/* red */
+		MAKE_RGB24(rgb, 0, 0, 192),	/* blue */
+	};
+	const struct color_rgb24 colors_middle[] = {
+		MAKE_RGB24(rgb, 0, 0, 192),	/* blue */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
+		MAKE_RGB24(rgb, 192, 0, 192),	/* magenta */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
+		MAKE_RGB24(rgb, 0, 192, 192),	/* cyan */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
+		MAKE_RGB24(rgb, 192, 192, 192),	/* grey */
+	};
+	const struct color_rgb24 colors_bottom[] = {
+		MAKE_RGB24(rgb, 0, 33, 76),	/* in-phase */
+		MAKE_RGB24(rgb, 255, 255, 255),	/* super white */
+		MAKE_RGB24(rgb, 50, 0, 106),	/* quadrature */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
+		MAKE_RGB24(rgb, 9, 9, 9),	/* 3.5% */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* 7.5% */
+		MAKE_RGB24(rgb, 29, 29, 29),	/* 11.5% */
+		MAKE_RGB24(rgb, 19, 19, 19),	/* black */
+	};
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((struct color_rgb24 *)mem)[x] =
+				colors_top[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((struct color_rgb24 *)mem)[x] =
+				colors_middle[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			((struct color_rgb24 *)mem)[x] =
+				colors_bottom[x * 4 / (width * 5 / 7)];
+		for (; x < width * 6 / 7; ++x)
+			((struct color_rgb24 *)mem)[x] =
+				colors_bottom[(x - width * 5 / 7) * 3
+					      / (width / 7) + 4];
+		for (; x < width; ++x)
+			((struct color_rgb24 *)mem)[x] = colors_bottom[7];
+		mem += stride;
+	}
+}
+
+static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const uint32_t colors_top[] = {
+		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
+		MAKE_RGBA(rgb, 192, 192, 0, 255),	/* yellow */
+		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
+		MAKE_RGBA(rgb, 0, 192, 0, 255),		/* green */
+		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
+		MAKE_RGBA(rgb, 192, 0, 0, 255),		/* red */
+		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
+	};
+	const uint32_t colors_middle[] = {
+		MAKE_RGBA(rgb, 0, 0, 192, 255),		/* blue */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 192, 0, 192, 255),	/* magenta */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 0, 192, 192, 255),	/* cyan */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 192, 192, 192, 255),	/* grey */
+	};
+	const uint32_t colors_bottom[] = {
+		MAKE_RGBA(rgb, 0, 33, 76, 255),		/* in-phase */
+		MAKE_RGBA(rgb, 255, 255, 255, 255),	/* super white */
+		MAKE_RGBA(rgb, 50, 0, 106, 255),	/* quadrature */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+		MAKE_RGBA(rgb, 9, 9, 9, 255),		/* 3.5% */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* 7.5% */
+		MAKE_RGBA(rgb, 29, 29, 29, 255),	/* 11.5% */
+		MAKE_RGBA(rgb, 19, 19, 19, 255),	/* black */
+	};
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_top[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			((uint32_t *)mem)[x] =
+				colors_bottom[x * 4 / (width * 5 / 7)];
+		for (; x < width * 6 / 7; ++x)
+			((uint32_t *)mem)[x] =
+				colors_bottom[(x - width * 5 / 7) * 3
+					      / (width / 7) + 4];
+		for (; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_bottom[7];
+		mem += stride;
+	}
+}
+
+static void fill_smpte(const struct util_format_info *info, void *planes[3],
+		       unsigned int width, unsigned int height,
+		       unsigned int stride)
+{
+	unsigned char *u, *v;
+
+	switch (info->format) {
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+		return fill_smpte_yuv_packed(&info->yuv, planes[0], width,
+					     height, stride);
+
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+		u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
+		v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
+		return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v,
+					     width, height, stride);
+
+	case DRM_FORMAT_YUV420:
+		return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1],
+					     planes[2], width, height, stride);
+
+	case DRM_FORMAT_YVU420:
+		return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2],
+					     planes[1], width, height, stride);
+
+	case DRM_FORMAT_ARGB4444:
+	case DRM_FORMAT_XRGB4444:
+	case DRM_FORMAT_ABGR4444:
+	case DRM_FORMAT_XBGR4444:
+	case DRM_FORMAT_RGBA4444:
+	case DRM_FORMAT_RGBX4444:
+	case DRM_FORMAT_BGRA4444:
+	case DRM_FORMAT_BGRX4444:
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+	case DRM_FORMAT_ARGB1555:
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_ABGR1555:
+	case DRM_FORMAT_XBGR1555:
+	case DRM_FORMAT_RGBA5551:
+	case DRM_FORMAT_RGBX5551:
+	case DRM_FORMAT_BGRA5551:
+	case DRM_FORMAT_BGRX5551:
+		return fill_smpte_rgb16(&info->rgb, planes[0],
+					width, height, stride);
+
+	case DRM_FORMAT_BGR888:
+	case DRM_FORMAT_RGB888:
+		return fill_smpte_rgb24(&info->rgb, planes[0],
+					width, height, stride);
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ABGR8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_RGBA8888:
+	case DRM_FORMAT_RGBX8888:
+	case DRM_FORMAT_BGRA8888:
+	case DRM_FORMAT_BGRX8888:
+	case DRM_FORMAT_ARGB2101010:
+	case DRM_FORMAT_XRGB2101010:
+	case DRM_FORMAT_ABGR2101010:
+	case DRM_FORMAT_XBGR2101010:
+	case DRM_FORMAT_RGBA1010102:
+	case DRM_FORMAT_RGBX1010102:
+	case DRM_FORMAT_BGRA1010102:
+	case DRM_FORMAT_BGRX1010102:
+		return fill_smpte_rgb32(&info->rgb, planes[0],
+					width, height, stride);
+	}
+}
+
+/* swap these for big endian.. */
+#define RED   2
+#define GREEN 1
+#define BLUE  0
+
+static void make_pwetty(void *data, unsigned int width, unsigned int height,
+			unsigned int stride, uint32_t format)
+{
+#ifdef HAVE_CAIRO
+	cairo_surface_t *surface;
+	cairo_t *cr;
+	int x, y;
+	cairo_format_t cairo_format;
+
+	/* we can ignore the order of R,G,B channels */
+	switch (format) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_ABGR8888:
+		cairo_format = CAIRO_FORMAT_ARGB32;
+		break;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		cairo_format = CAIRO_FORMAT_RGB16_565;
+		break;
+	default:
+		return;
+	}
+
+	surface = cairo_image_surface_create_for_data(data,
+						      cairo_format,
+						      width, height,
+						      stride);
+	cr = cairo_create(surface);
+	cairo_surface_destroy(surface);
+
+	cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE);
+	for (x = 0; x < width; x += 250)
+		for (y = 0; y < height; y += 250) {
+			char buf[64];
+
+			cairo_move_to(cr, x, y - 20);
+			cairo_line_to(cr, x, y + 20);
+			cairo_move_to(cr, x - 20, y);
+			cairo_line_to(cr, x + 20, y);
+			cairo_new_sub_path(cr);
+			cairo_arc(cr, x, y, 10, 0, M_PI * 2);
+			cairo_set_line_width(cr, 4);
+			cairo_set_source_rgb(cr, 0, 0, 0);
+			cairo_stroke_preserve(cr);
+			cairo_set_source_rgb(cr, 1, 1, 1);
+			cairo_set_line_width(cr, 2);
+			cairo_stroke(cr);
+
+			snprintf(buf, sizeof buf, "%d, %d", x, y);
+			cairo_move_to(cr, x + 20, y + 20);
+			cairo_text_path(cr, buf);
+			cairo_set_source_rgb(cr, 0, 0, 0);
+			cairo_stroke_preserve(cr);
+			cairo_set_source_rgb(cr, 1, 1, 1);
+			cairo_fill(cr);
+		}
+
+	cairo_destroy(cr);
+#endif
+}
+
+static void fill_tiles_yuv_planar(const struct util_format_info *info,
+				  unsigned char *y_mem, unsigned char *u_mem,
+				  unsigned char *v_mem, unsigned int width,
+				  unsigned int height, unsigned int stride)
+{
+	const struct util_yuv_info *yuv = &info->yuv;
+	unsigned int cs = yuv->chroma_stride;
+	unsigned int xsub = yuv->xsub;
+	unsigned int ysub = yuv->ysub;
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; ++x) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
+				       + 0x000a1120 * (d.rem >> 6);
+			struct color_yuv color =
+				MAKE_YUV_601((rgb32 >> 16) & 0xff,
+					     (rgb32 >> 8) & 0xff, rgb32 & 0xff);
+
+			y_mem[x] = color.y;
+			u_mem[x/xsub*cs] = color.u;
+			v_mem[x/xsub*cs] = color.v;
+		}
+
+		y_mem += stride;
+		if ((y + 1) % ysub == 0) {
+			u_mem += stride * cs / xsub;
+			v_mem += stride * cs / xsub;
+		}
+	}
+}
+
+static void fill_tiles_yuv_packed(const struct util_format_info *info,
+				  void *mem, unsigned int width,
+				  unsigned int height, unsigned int stride)
+{
+	const struct util_yuv_info *yuv = &info->yuv;
+	unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1;
+	unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1;
+	unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0;
+	unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0;
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; x += 2) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
+				       + 0x000a1120 * (d.rem >> 6);
+			struct color_yuv color =
+				MAKE_YUV_601((rgb32 >> 16) & 0xff,
+					     (rgb32 >> 8) & 0xff, rgb32 & 0xff);
+
+			y_mem[2*x] = color.y;
+			c_mem[2*x+u] = color.u;
+			y_mem[2*x+2] = color.y;
+			c_mem[2*x+v] = color.v;
+		}
+
+		y_mem += stride;
+		c_mem += stride;
+	}
+}
+
+static void fill_tiles_rgb16(const struct util_format_info *info, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const struct util_rgb_info *rgb = &info->rgb;
+	void *mem_base = mem;
+	unsigned int x, y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; ++x) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
+				       + 0x000a1120 * (d.rem >> 6);
+			uint16_t color =
+				MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
+					  (rgb32 >> 8) & 0xff, rgb32 & 0xff,
+					  255);
+
+			((uint16_t *)mem)[x] = color;
+		}
+		mem += stride;
+	}
+
+	make_pwetty(mem_base, width, height, stride, info->format);
+}
+
+static void fill_tiles_rgb24(const struct util_format_info *info, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const struct util_rgb_info *rgb = &info->rgb;
+	unsigned int x, y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; ++x) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
+				       + 0x000a1120 * (d.rem >> 6);
+			struct color_rgb24 color =
+				MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff,
+					   (rgb32 >> 8) & 0xff, rgb32 & 0xff);
+
+			((struct color_rgb24 *)mem)[x] = color;
+		}
+		mem += stride;
+	}
+}
+
+static void fill_tiles_rgb32(const struct util_format_info *info, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const struct util_rgb_info *rgb = &info->rgb;
+	void *mem_base = mem;
+	unsigned int x, y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; ++x) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x00130502 * (d.quot >> 6)
+				       + 0x000a1120 * (d.rem >> 6);
+			uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255;
+			uint32_t color =
+				MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff,
+					  (rgb32 >> 8) & 0xff, rgb32 & 0xff,
+					  alpha);
+
+			((uint32_t *)mem)[x] = color;
+		}
+		mem += stride;
+	}
+
+	make_pwetty(mem_base, width, height, stride, info->format);
+}
+
+static void fill_tiles(const struct util_format_info *info, void *planes[3],
+		       unsigned int width, unsigned int height,
+		       unsigned int stride)
+{
+	unsigned char *u, *v;
+
+	switch (info->format) {
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+		return fill_tiles_yuv_packed(info, planes[0],
+					     width, height, stride);
+
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+		u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1;
+		v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1;
+		return fill_tiles_yuv_planar(info, planes[0], u, v,
+					     width, height, stride);
+
+	case DRM_FORMAT_YUV420:
+		return fill_tiles_yuv_planar(info, planes[0], planes[1],
+					     planes[2], width, height, stride);
+
+	case DRM_FORMAT_YVU420:
+		return fill_tiles_yuv_planar(info, planes[0], planes[2],
+					     planes[1], width, height, stride);
+
+	case DRM_FORMAT_ARGB4444:
+	case DRM_FORMAT_XRGB4444:
+	case DRM_FORMAT_ABGR4444:
+	case DRM_FORMAT_XBGR4444:
+	case DRM_FORMAT_RGBA4444:
+	case DRM_FORMAT_RGBX4444:
+	case DRM_FORMAT_BGRA4444:
+	case DRM_FORMAT_BGRX4444:
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+	case DRM_FORMAT_ARGB1555:
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_ABGR1555:
+	case DRM_FORMAT_XBGR1555:
+	case DRM_FORMAT_RGBA5551:
+	case DRM_FORMAT_RGBX5551:
+	case DRM_FORMAT_BGRA5551:
+	case DRM_FORMAT_BGRX5551:
+		return fill_tiles_rgb16(info, planes[0],
+					width, height, stride);
+
+	case DRM_FORMAT_BGR888:
+	case DRM_FORMAT_RGB888:
+		return fill_tiles_rgb24(info, planes[0],
+					width, height, stride);
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ABGR8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_RGBA8888:
+	case DRM_FORMAT_RGBX8888:
+	case DRM_FORMAT_BGRA8888:
+	case DRM_FORMAT_BGRX8888:
+	case DRM_FORMAT_ARGB2101010:
+	case DRM_FORMAT_XRGB2101010:
+	case DRM_FORMAT_ABGR2101010:
+	case DRM_FORMAT_XBGR2101010:
+	case DRM_FORMAT_RGBA1010102:
+	case DRM_FORMAT_RGBX1010102:
+	case DRM_FORMAT_BGRA1010102:
+	case DRM_FORMAT_BGRX1010102:
+		return fill_tiles_rgb32(info, planes[0],
+					width, height, stride);
+	}
+}
+
+static void fill_plain(const struct util_format_info *info, void *planes[3],
+		       unsigned int width, unsigned int height,
+		       unsigned int stride)
+{
+	memset(planes[0], 0x77, stride * height);
+}
+
+/*
+ * util_fill_pattern - Fill a buffer with a test pattern
+ * @format: Pixel format
+ * @pattern: Test pattern
+ * @planes: Array of buffers
+ * @width: Width in pixels
+ * @height: Height in pixels
+ * @stride: Line stride (pitch) in bytes
+ *
+ * Fill the buffers with the test pattern specified by the pattern parameter.
+ * Supported formats vary depending on the selected pattern.
+ */
+void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern,
+		       void *planes[3], unsigned int width,
+		       unsigned int height, unsigned int stride)
+{
+	const struct util_format_info *info;
+
+	info = util_format_info_find(format);
+	if (info == NULL)
+		return;
+
+	switch (pattern) {
+	case UTIL_PATTERN_TILES:
+		return fill_tiles(info, planes, width, height, stride);
+
+	case UTIL_PATTERN_SMPTE:
+		return fill_smpte(info, planes, width, height, stride);
+
+	case UTIL_PATTERN_PLAIN:
+		return fill_plain(info, planes, width, height, stride);
+
+	default:
+		printf("Error: unsupported test pattern %u.\n", pattern);
+		break;
+	}
+}
diff --git a/tests/util/pattern.h b/tests/util/pattern.h
new file mode 100644
index 000000000000..d5c4260cc6ed
--- /dev/null
+++ b/tests/util/pattern.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef UTIL_PATTERN_H
+#define UTIL_PATTERN_H
+
+enum util_fill_pattern {
+	UTIL_PATTERN_TILES,
+	UTIL_PATTERN_PLAIN,
+	UTIL_PATTERN_SMPTE,
+};
+
+void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern,
+		       void *planes[3], unsigned int width,
+		       unsigned int height, unsigned int stride);
+
+#endif /* UTIL_PATTERN_H */
diff --git a/tests/vbltest/Makefile.am b/tests/vbltest/Makefile.am
index 34a35e7d17dc..c014ea8c7253 100644
--- a/tests/vbltest/Makefile.am
+++ b/tests/vbltest/Makefile.am
@@ -1,5 +1,6 @@
 AM_CFLAGS = \
 	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
 	-I$(top_srcdir)
 if HAVE_INSTALL_TESTS
 bin_PROGRAMS = \
diff --git a/tests/vbltest/vbltest.c b/tests/vbltest/vbltest.c
index cdc1ef6b3364..7e5e0962deaf 100644
--- a/tests/vbltest/vbltest.c
+++ b/tests/vbltest/vbltest.c
@@ -54,7 +54,7 @@
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#include "util/common.h"
 
 extern char *optarg;
 extern int optind, opterr, optopt;
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 05/11] tests: Move name tables to libutil
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (3 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:24   ` Laurent Pinchart
  2015-01-29 15:28   ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
  2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
                   ` (6 subsequent siblings)
  11 siblings, 2 replies; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

These tables are duplicated in several places, so move them into libutil
so that they can be shared.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/modetest/modetest.c  |  50 ++-----------------
 tests/proptest/Makefile.am |   4 +-
 tests/proptest/proptest.c  |  40 +--------------
 tests/util/Makefile.am     |   2 +
 tests/util/kms.c           | 122 +++++++++++++++++++++++++++++++++++++++++++++
 tests/util/kms.h           |  33 ++++++++++++
 6 files changed, 165 insertions(+), 86 deletions(-)
 create mode 100644 tests/util/kms.c
 create mode 100644 tests/util/kms.h

diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index b610956adfcb..d5fd99ebe1fd 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -61,6 +61,7 @@
 
 #include "util/common.h"
 #include "util/format.h"
+#include "util/kms.h"
 #include "util/pattern.h"
 
 #include "buffers.h"
@@ -123,11 +124,6 @@ static inline int64_t U642I64(uint64_t val)
 	return (int64_t)*((int64_t *)&val);
 }
 
-struct type_name {
-	int type;
-	const char *name;
-};
-
 #define type_name_fn(res) \
 const char * res##_str(int type) {			\
 	unsigned int i;					\
@@ -138,44 +134,6 @@ const char * res##_str(int type) {			\
 	return "(invalid)";				\
 }
 
-struct type_name encoder_type_names[] = {
-	{ DRM_MODE_ENCODER_NONE, "none" },
-	{ DRM_MODE_ENCODER_DAC, "DAC" },
-	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
-	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
-	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
-};
-
-static type_name_fn(encoder_type)
-
-struct type_name connector_status_names[] = {
-	{ DRM_MODE_CONNECTED, "connected" },
-	{ DRM_MODE_DISCONNECTED, "disconnected" },
-	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
-};
-
-static type_name_fn(connector_status)
-
-struct type_name connector_type_names[] = {
-	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
-	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
-	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
-	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
-	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
-	{ DRM_MODE_CONNECTOR_Composite, "composite" },
-	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
-	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
-	{ DRM_MODE_CONNECTOR_Component, "component" },
-	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
-	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
-	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
-	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
-	{ DRM_MODE_CONNECTOR_TV, "TV" },
-	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
-};
-
-static type_name_fn(connector_type)
-
 #define bit_name_fn(res)					\
 const char * res##_str(int type) {				\
 	unsigned int i;						\
@@ -235,7 +193,7 @@ static void dump_encoders(struct device *dev)
 		printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",
 		       encoder->encoder_id,
 		       encoder->crtc_id,
-		       encoder_type_str(encoder->encoder_type),
+		       util_lookup_encoder_type_name(encoder->encoder_type),
 		       encoder->possible_crtcs,
 		       encoder->possible_clones);
 	}
@@ -379,8 +337,8 @@ static void dump_connectors(struct device *dev)
 		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t",
 		       connector->connector_id,
 		       connector->encoder_id,
-		       connector_status_str(connector->connection),
-		       connector_type_str(connector->connector_type),
+		       util_lookup_connector_status_name(connector->connection),
+		       util_lookup_connector_type_name(connector->connector_type),
 		       connector->mmWidth, connector->mmHeight,
 		       connector->count_modes);
 
diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am
index f81a3c00846b..c615489b9a92 100644
--- a/tests/proptest/Makefile.am
+++ b/tests/proptest/Makefile.am
@@ -1,5 +1,6 @@
 AM_CFLAGS = \
 	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
 	-I$(top_srcdir)
 
 noinst_PROGRAMS = \
@@ -8,4 +9,5 @@ noinst_PROGRAMS = \
 proptest_SOURCES = \
 	proptest.c
 proptest_LDADD = \
-	$(top_builddir)/libdrm.la
+	$(top_builddir)/libdrm.la \
+	$(top_builddir)/tests/util/libutil.la
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
index ee3fa408a310..b442d583d528 100644
--- a/tests/proptest/proptest.c
+++ b/tests/proptest/proptest.c
@@ -45,44 +45,6 @@ static inline int64_t U642I64(uint64_t val)
 int fd;
 drmModeResPtr res = NULL;
 
-const char *connector_type_str(uint32_t type)
-{
-	switch (type) {
-	case DRM_MODE_CONNECTOR_Unknown:
-		return "Unknown";
-	case DRM_MODE_CONNECTOR_VGA:
-		return "VGA";
-	case DRM_MODE_CONNECTOR_DVII:
-		return "DVI-I";
-	case DRM_MODE_CONNECTOR_DVID:
-		return "DVI-D";
-	case DRM_MODE_CONNECTOR_DVIA:
-		return "DVI-A";
-	case DRM_MODE_CONNECTOR_Composite:
-		return "Composite";
-	case DRM_MODE_CONNECTOR_SVIDEO:
-		return "SVIDEO";
-	case DRM_MODE_CONNECTOR_LVDS:
-		return "LVDS";
-	case DRM_MODE_CONNECTOR_Component:
-		return "Component";
-	case DRM_MODE_CONNECTOR_9PinDIN:
-		return "9PinDin";
-	case DRM_MODE_CONNECTOR_DisplayPort:
-		return "DisplayPort";
-	case DRM_MODE_CONNECTOR_HDMIA:
-		return "HDMI-A";
-	case DRM_MODE_CONNECTOR_HDMIB:
-		return "HDMI-B";
-	case DRM_MODE_CONNECTOR_TV:
-		return "TV";
-	case DRM_MODE_CONNECTOR_eDP:
-		return "eDP";
-	default:
-		return "Invalid";
-	}
-}
-
 /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */
 static void
 dump_blob(uint32_t blob_id)
@@ -226,7 +188,7 @@ static void listConnectorProperties(void)
 		}
 
 		printf("Connector %u (%s-%u)\n", c->connector_id,
-		       connector_type_str(c->connector_type),
+		       util_lookup_connector_type_name(c->connector_type),
 		       c->connector_type_id);
 
 		listObjectProperties(c->connector_id,
diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am
index 1a2519fbea89..c00574484867 100644
--- a/tests/util/Makefile.am
+++ b/tests/util/Makefile.am
@@ -12,6 +12,8 @@ libutil_la_SOURCES = \
 	common.h \
 	format.c \
 	format.h \
+	kms.c \
+	kms.h \
 	pattern.c \
 	pattern.h
 
diff --git a/tests/util/kms.c b/tests/util/kms.c
new file mode 100644
index 000000000000..a271ca047c4e
--- /dev/null
+++ b/tests/util/kms.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/*
+ * This fairly simple test program dumps output in a similar format to the
+ * "xrandr" tool everyone knows & loves.  It's necessarily slightly different
+ * since the kernel separates outputs into encoder and connector structures,
+ * each with their own unique ID.  The program also allows test testing of the
+ * memory management and mode setting APIs by allowing the user to specify a
+ * connector and mode to use for mode setting.  If all works as expected, a
+ * blue background should be painted on the monitor attached to the specified
+ * connector after the selected mode is set.
+ *
+ * TODO: use cairo to write the mode info on the selected output once
+ *       the mode has been programmed, along with possible test patterns.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "xf86drmMode.h"
+
+#include "common.h"
+
+struct type_name {
+	unsigned int type;
+	const char *name;
+};
+
+static const char *util_lookup_type_name(unsigned int type,
+					 const struct type_name *table,
+					 unsigned int count)
+{
+	unsigned int i;
+
+	for (i = 0; i < count; i++)
+		if (table[i].type == type)
+			return table[i].name;
+
+	return NULL;
+}
+
+static const struct type_name encoder_type_names[] = {
+	{ DRM_MODE_ENCODER_NONE, "none" },
+	{ DRM_MODE_ENCODER_DAC, "DAC" },
+	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
+	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
+	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
+	{ DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
+	{ DRM_MODE_ENCODER_DSI, "DSI" },
+	{ DRM_MODE_ENCODER_DPMST, "DisplayPort MST" },
+};
+
+const char *util_lookup_encoder_type_name(unsigned int type)
+{
+	return util_lookup_type_name(type, encoder_type_names,
+				     ARRAY_SIZE(encoder_type_names));
+}
+
+static const struct type_name connector_status_names[] = {
+	{ DRM_MODE_CONNECTED, "connected" },
+	{ DRM_MODE_DISCONNECTED, "disconnected" },
+	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
+};
+
+const char *util_lookup_connector_status_name(unsigned int status)
+{
+	return util_lookup_type_name(status, connector_status_names,
+				     ARRAY_SIZE(connector_status_names));
+}
+
+static const struct type_name connector_type_names[] = {
+	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
+	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
+	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
+	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
+	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
+	{ DRM_MODE_CONNECTOR_Composite, "composite" },
+	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
+	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
+	{ DRM_MODE_CONNECTOR_Component, "component" },
+	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
+	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
+	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
+	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
+	{ DRM_MODE_CONNECTOR_TV, "TV" },
+	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
+	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
+	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
+};
+
+const char *util_lookup_connector_type_name(unsigned int type)
+{
+	return util_lookup_type_name(type, connector_type_names,
+				     ARRAY_SIZE(connector_type_names));
+}
diff --git a/tests/util/kms.h b/tests/util/kms.h
new file mode 100644
index 000000000000..fa9ab69983ac
--- /dev/null
+++ b/tests/util/kms.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2008 Tungsten Graphics
+ *   Jakob Bornecrantz <jakob@tungstengraphics.com>
+ * Copyright 2008 Intel Corporation
+ *   Jesse Barnes <jesse.barnes@intel.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef UTIL_KMS_H
+#define UTIL_KMS_H
+
+const char *util_lookup_encoder_type_name(unsigned int type);
+const char *util_lookup_connector_status_name(unsigned int type);
+const char *util_lookup_connector_type_name(unsigned int type);
+
+#endif /* UTIL_KMS_H */
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (4 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:26   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drmMode.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/xf86drmMode.h b/xf86drmMode.h
index 856a6bb0f569..e70c16d437f4 100644
--- a/xf86drmMode.h
+++ b/xf86drmMode.h
@@ -123,13 +123,13 @@ extern "C" {
 #define DRM_MODE_DITHERING_OFF  0
 #define DRM_MODE_DITHERING_ON   1
 
-#define DRM_MODE_ENCODER_NONE   0
-#define DRM_MODE_ENCODER_DAC    1
-#define DRM_MODE_ENCODER_TMDS   2
-#define DRM_MODE_ENCODER_LVDS   3
-#define DRM_MODE_ENCODER_TVDAC  4
+#define DRM_MODE_ENCODER_NONE    0
+#define DRM_MODE_ENCODER_DAC     1
+#define DRM_MODE_ENCODER_TMDS    2
+#define DRM_MODE_ENCODER_LVDS    3
+#define DRM_MODE_ENCODER_TVDAC   4
 #define DRM_MODE_ENCODER_VIRTUAL 5
-#define DRM_MODE_ENCODER_DSI	6
+#define DRM_MODE_ENCODER_DSI     6
 
 #define DRM_MODE_SUBCONNECTOR_Automatic 0
 #define DRM_MODE_SUBCONNECTOR_Unknown   0
@@ -153,8 +153,8 @@ extern "C" {
 #define DRM_MODE_CONNECTOR_DisplayPort  10
 #define DRM_MODE_CONNECTOR_HDMIA        11
 #define DRM_MODE_CONNECTOR_HDMIB        12
-#define DRM_MODE_CONNECTOR_TV		13
-#define DRM_MODE_CONNECTOR_eDP		14
+#define DRM_MODE_CONNECTOR_TV           13
+#define DRM_MODE_CONNECTOR_eDP          14
 #define DRM_MODE_CONNECTOR_VIRTUAL      15
 #define DRM_MODE_CONNECTOR_DSI          16
 
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (5 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:40   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

This brings xf86drmMode.h in sync with include/drm/drm_mode.h.
Eventually we really should only have a single set of definitions rather
than duplicating this in two files.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 xf86drmMode.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xf86drmMode.h b/xf86drmMode.h
index e70c16d437f4..70f14a1ae506 100644
--- a/xf86drmMode.h
+++ b/xf86drmMode.h
@@ -130,6 +130,7 @@ extern "C" {
 #define DRM_MODE_ENCODER_TVDAC   4
 #define DRM_MODE_ENCODER_VIRTUAL 5
 #define DRM_MODE_ENCODER_DSI     6
+#define DRM_MODE_ENCODER_DPMST   7
 
 #define DRM_MODE_SUBCONNECTOR_Automatic 0
 #define DRM_MODE_SUBCONNECTOR_Unknown   0
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 08/11] tests: modetest: Accept connector names
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (6 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-24 23:56   ` Laurent Pinchart
  2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

Allow connector names to be used in the specification of the -s option.
This requires storing the string passed on the command-line so that it
can later be resolved to a connector ID (after the DRM device has been
opened).

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/modetest/modetest.c | 134 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 123 insertions(+), 11 deletions(-)

diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index d5fd99ebe1fd..a7cc94f8938c 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -82,6 +82,7 @@ struct connector {
 	drmModeConnector *connector;
 	drmModeObjectProperties *props;
 	drmModePropertyRes **props_info;
+	char *name;
 };
 
 struct fb {
@@ -327,7 +328,7 @@ static void dump_connectors(struct device *dev)
 	int i, j;
 
 	printf("Connectors:\n");
-	printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
+	printf("id\tencoder\tstatus\t\tname\t\tsize (mm)\tmodes\tencoders\n");
 	for (i = 0; i < dev->resources->res->count_connectors; i++) {
 		struct connector *_connector = &dev->resources->connectors[i];
 		drmModeConnector *connector = _connector->connector;
@@ -338,7 +339,7 @@ static void dump_connectors(struct device *dev)
 		       connector->connector_id,
 		       connector->encoder_id,
 		       util_lookup_connector_status_name(connector->connection),
-		       util_lookup_connector_type_name(connector->connector_type),
+		       _connector->name,
 		       connector->mmWidth, connector->mmHeight,
 		       connector->count_modes);
 
@@ -464,12 +465,13 @@ static void dump_planes(struct device *dev)
 
 static void free_resources(struct resources *res)
 {
+	int i;
+
 	if (!res)
 		return;
 
 #define free_resource(_res, __res, type, Type)					\
 	do {									\
-		int i;								\
 		if (!(_res)->type##s)						\
 			break;							\
 		for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) {	\
@@ -482,7 +484,6 @@ static void free_resources(struct resources *res)
 
 #define free_properties(_res, __res, type)					\
 	do {									\
-		int i;								\
 		for (i = 0; i < (int)(_res)->__res->count_##type##s; ++i) {	\
 			drmModeFreeObjectProperties(res->type##s[i].props);	\
 			free(res->type##s[i].props_info);			\
@@ -494,6 +495,10 @@ static void free_resources(struct resources *res)
 
 		free_resource(res, res, crtc, Crtc);
 		free_resource(res, res, encoder, Encoder);
+
+		for (i = 0; i < res->res->count_connectors; i++)
+			free(res->connectors[i].name);
+
 		free_resource(res, res, connector, Connector);
 		free_resource(res, res, fb, FB);
 
@@ -511,6 +516,47 @@ static void free_resources(struct resources *res)
 	free(res);
 }
 
+static unsigned int get_connector_index(struct resources *res, uint32_t type)
+{
+	unsigned int index = 0;
+	int i;
+
+	for (i = 0; i < res->res->count_connectors; i++)
+		if (res->connectors[i].connector->connector_type == type)
+			index++;
+
+	return index - 1;
+}
+
+static unsigned int get_order(unsigned int value)
+{
+	unsigned int order = 0;
+
+	do {
+		value /= 10;
+		order++;
+	} while (value > 0);
+
+	return order - 1;
+}
+
+static void connector_set_name(struct connector *connector,
+			       struct resources *res)
+{
+	uint32_t type = connector->connector->connector_type;
+	const char *type_name;
+	unsigned int index;
+	int len;
+
+	type_name = util_lookup_connector_type_name(type);
+	index = get_connector_index(res, type);
+	len = strlen(type_name) + get_order(index) + 2;
+
+	connector->name = malloc(len + 1);
+	if (connector->name)
+		snprintf(connector->name, len + 1, "%s-%u", type_name,  index);
+}
+
 static struct resources *get_resources(struct device *dev)
 {
 	struct resources *res;
@@ -562,6 +608,12 @@ static struct resources *get_resources(struct device *dev)
 	get_resource(res, res, connector, Connector);
 	get_resource(res, res, fb, FB);
 
+	for (i = 0; i < res->res->count_connectors; i++) {
+		struct connector *connector = &res->connectors[i];
+
+		connector_set_name(connector, res);
+	}
+
 #define get_properties(_res, __res, type, Type)					\
 	do {									\
 		int i;								\
@@ -630,6 +682,21 @@ static int get_crtc_index(struct device *dev, uint32_t id)
 	return -1;
 }
 
+static drmModeConnector *get_connector_by_name(struct device *dev, const char *name)
+{
+	struct connector *connector;
+	int i;
+
+	for (i = 0; i < dev->resources->res->count_connectors; i++) {
+		connector = &dev->resources->connectors[i];
+
+		if (strcmp(connector->name, name) == 0)
+			return connector->connector;
+	}
+
+	return NULL;
+}
+
 static drmModeConnector *get_connector_by_id(struct device *dev, uint32_t id)
 {
 	drmModeConnector *connector;
@@ -670,6 +737,7 @@ static drmModeEncoder *get_encoder_by_id(struct device *dev, uint32_t id)
  * can bind it with a free crtc.
  */
 struct pipe_arg {
+	const char **cons;
 	uint32_t *con_ids;
 	unsigned int num_cons;
 	uint32_t crtc_id;
@@ -784,8 +852,8 @@ static int pipe_find_crtc_and_mode(struct device *dev, struct pipe_arg *pipe)
 					   pipe->mode_str, pipe->vrefresh);
 		if (mode == NULL) {
 			fprintf(stderr,
-				"failed to find mode \"%s\" for connector %u\n",
-				pipe->mode_str, pipe->con_ids[i]);
+				"failed to find mode \"%s\" for connector %s\n",
+				pipe->mode_str, pipe->cons[i]);
 			return -EINVAL;
 		}
 	}
@@ -1054,7 +1122,7 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
 		printf("setting mode %s-%dHz@%s on connectors ",
 		       pipe->mode_str, pipe->mode->vrefresh, pipe->format_str);
 		for (j = 0; j < pipe->num_cons; ++j)
-			printf("%u, ", pipe->con_ids[j]);
+			printf("%s, ", pipe->cons[j]);
 		printf("crtc %d\n", pipe->crtc->crtc->crtc_id);
 
 		ret = drmModeSetCrtc(dev->fd, pipe->crtc->crtc->crtc_id, fb_id,
@@ -1230,18 +1298,28 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg)
 
 	/* Count the number of connectors and allocate them. */
 	pipe->num_cons = 1;
-	for (p = arg; isdigit(*p) || *p == ','; ++p) {
+	for (p = arg; *p && *p != ':' && *p != '@'; ++p) {
 		if (*p == ',')
 			pipe->num_cons++;
 	}
 
-	pipe->con_ids = malloc(pipe->num_cons * sizeof *pipe->con_ids);
+	pipe->cons = malloc(pipe->num_cons * sizeof(*pipe->cons));
+	if (pipe->cons == NULL)
+		return -1;
+
+	pipe->con_ids = malloc(pipe->num_cons * sizeof(*pipe->con_ids));
 	if (pipe->con_ids == NULL)
 		return -1;
 
 	/* Parse the connectors. */
 	for (i = 0, p = arg; i < pipe->num_cons; ++i, p = endp + 1) {
-		pipe->con_ids[i] = strtoul(p, &endp, 10);
+		endp = strpbrk(p, ",@:");
+
+		if (endp)
+			pipe->cons[i] = strndup(p, endp - p);
+		else
+			pipe->cons[i] = strdup(p);
+
 		if (*endp != ',')
 			break;
 	}
@@ -1405,6 +1483,32 @@ static int cursor_supported(void)
 	return 1;
 }
 
+static int pipe_resolve_connectors(struct pipe_arg *pipe, struct device *dev)
+{
+	drmModeConnector *connector;
+	unsigned int i;
+	uint32_t id;
+	char *endp;
+
+	for (i = 0; i < pipe->num_cons; i++) {
+		id = strtoul(pipe->cons[i], &endp, 10);
+		if (endp == pipe->cons[i]) {
+			connector = get_connector_by_name(dev, pipe->cons[i]);
+			if (!connector) {
+				fprintf(stderr, "no connector named %s\n",
+					pipe->cons[i]);
+				return -ENODEV;
+			}
+
+			id = connector->connector_id;
+		}
+
+		pipe->con_ids[i] = id;
+	}
+
+	return 0;
+}
+
 static char optstr[] = "cdD:efM:P:ps:Cvw:";
 
 int main(int argc, char **argv)
@@ -1420,7 +1524,7 @@ int main(int argc, char **argv)
 	char *device = NULL;
 	char *module = NULL;
 	unsigned int i;
-	int count = 0, plane_count = 0;
+	unsigned int count = 0, plane_count = 0;
 	unsigned int prop_count = 0;
 	struct pipe_arg *pipe_args = NULL;
 	struct plane_arg *plane_args = NULL;
@@ -1559,6 +1663,14 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
+	for (i = 0; i < count; i++) {
+		if (pipe_resolve_connectors(&pipe_args[i], &dev) < 0) {
+			free_resources(dev.resources);
+			drmClose(dev.fd);
+			return 1;
+		}
+	}
+
 #define dump_resource(dev, res) if (res) dump_##res(dev)
 
 	dump_resource(&dev, encoders);
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 09/11] tests: Add libkms-test library
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (7 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-29 15:30   ` [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution Emil Velikov
  2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
                   ` (2 subsequent siblings)
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

This library contains abstractions for KMS that help remove the need for
a lot of boilerplate in KMS test programs.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 configure.ac                        |   1 +
 tests/Makefile.am                   |   2 +-
 tests/kms/Makefile.am               |  19 ++++
 tests/kms/libkms-test-crtc.c        |  47 ++++++++
 tests/kms/libkms-test-device.c      | 218 ++++++++++++++++++++++++++++++++++++
 tests/kms/libkms-test-framebuffer.c | 157 ++++++++++++++++++++++++++
 tests/kms/libkms-test-plane.c       | 139 +++++++++++++++++++++++
 tests/kms/libkms-test-screen.c      |  92 +++++++++++++++
 tests/kms/libkms-test.h             | 120 ++++++++++++++++++++
 9 files changed, 794 insertions(+), 1 deletion(-)
 create mode 100644 tests/kms/Makefile.am
 create mode 100644 tests/kms/libkms-test-crtc.c
 create mode 100644 tests/kms/libkms-test-device.c
 create mode 100644 tests/kms/libkms-test-framebuffer.c
 create mode 100644 tests/kms/libkms-test-plane.c
 create mode 100644 tests/kms/libkms-test-screen.c
 create mode 100644 tests/kms/libkms-test.h

diff --git a/configure.ac b/configure.ac
index 58411b79b682..0a6c414bf9eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -435,6 +435,7 @@ AC_CONFIG_FILES([
 	tests/Makefile
 	tests/modeprint/Makefile
 	tests/modetest/Makefile
+	tests/kms/Makefile
 	tests/kmstest/Makefile
 	tests/proptest/Makefile
 	tests/radeon/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 310032732f6e..e14cc3d24a22 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,7 @@ check_PROGRAMS = \
 	dristat \
 	drmstat
 
-SUBDIRS = util modeprint proptest
+SUBDIRS = util kms modeprint proptest
 
 if HAVE_LIBKMS
 SUBDIRS += kmstest modetest
diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
new file mode 100644
index 000000000000..c84bae05d869
--- /dev/null
+++ b/tests/kms/Makefile.am
@@ -0,0 +1,19 @@
+AM_CPPFLAGS = \
+	-I$(top_srcdir)/include/drm \
+	-I$(top_srcdir)/tests \
+	-I$(top_srcdir)
+
+AM_CFLAGS = \
+	$(WARN_CFLAGS)
+
+noinst_LTLIBRARIES = libkms-test.la
+
+libkms_test_la_SOURCES = \
+	libkms-test-crtc.c \
+	libkms-test-device.c \
+	libkms-test-framebuffer.c \
+	libkms-test-plane.c \
+	libkms-test-screen.c
+
+libkms_test_la_LIBADD = \
+	$(top_builddir)/libdrm.la
diff --git a/tests/kms/libkms-test-crtc.c b/tests/kms/libkms-test-crtc.c
new file mode 100644
index 000000000000..3adb4903919f
--- /dev/null
+++ b/tests/kms/libkms-test-crtc.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "libkms-test.h"
+
+struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id)
+{
+	struct kms_crtc *crtc;
+
+	crtc = calloc(1, sizeof(*crtc));
+	if (!crtc)
+		return NULL;
+
+	crtc->device = device;
+	crtc->id = id;
+
+	return crtc;
+}
+
+void kms_crtc_free(struct kms_crtc *crtc)
+{
+	free(crtc);
+}
diff --git a/tests/kms/libkms-test-device.c b/tests/kms/libkms-test-device.c
new file mode 100644
index 000000000000..53c7349b89ab
--- /dev/null
+++ b/tests/kms/libkms-test-device.c
@@ -0,0 +1,218 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "util/common.h"
+#include "libkms-test.h"
+
+static const char *const connector_names[] = {
+	"Unknown",
+	"VGA",
+	"DVI-I",
+	"DVI-D",
+	"DVI-A",
+	"Composite",
+	"SVIDEO",
+	"LVDS",
+	"Component",
+	"9PinDIN",
+	"DisplayPort",
+	"HDMI-A",
+	"HDMI-B",
+	"TV",
+	"eDP",
+	"Virtual",
+	"DSI",
+};
+
+static void kms_device_probe_screens(struct kms_device *device)
+{
+	unsigned int counts[ARRAY_SIZE(connector_names)];
+	struct kms_screen *screen;
+	drmModeRes *res;
+	int i;
+
+	memset(counts, 0, sizeof(counts));
+
+	res = drmModeGetResources(device->fd);
+	if (!res)
+		return;
+
+	device->screens = calloc(res->count_connectors, sizeof(screen));
+	if (!device->screens)
+		return;
+
+	for (i = 0; i < res->count_connectors; i++) {
+		unsigned int *count;
+		const char *type;
+		int len;
+
+		screen = kms_screen_create(device, res->connectors[i]);
+		if (!screen)
+			continue;
+
+		/* assign a unique name to this screen */
+		type = connector_names[screen->type];
+		count = &counts[screen->type];
+
+		len = snprintf(NULL, 0, "%s-%u", type, *count);
+
+		screen->name = malloc(len + 1);
+		if (!screen->name) {
+			free(screen);
+			continue;
+		}
+
+		snprintf(screen->name, len + 1, "%s-%u", type, *count);
+		(*count)++;
+
+		device->screens[i] = screen;
+		device->num_screens++;
+	}
+
+	drmModeFreeResources(res);
+}
+
+static void kms_device_probe_crtcs(struct kms_device *device)
+{
+	struct kms_crtc *crtc;
+	drmModeRes *res;
+	int i;
+
+	res = drmModeGetResources(device->fd);
+	if (!res)
+		return;
+
+	device->crtcs = calloc(res->count_crtcs, sizeof(crtc));
+	if (!device->crtcs)
+		return;
+
+	for (i = 0; i < res->count_crtcs; i++) {
+		crtc = kms_crtc_create(device, res->crtcs[i]);
+		if (!crtc)
+			continue;
+
+		device->crtcs[i] = crtc;
+		device->num_crtcs++;
+	}
+
+	drmModeFreeResources(res);
+}
+
+static void kms_device_probe_planes(struct kms_device *device)
+{
+	struct kms_plane *plane;
+	drmModePlaneRes *res;
+	unsigned int i;
+
+	res = drmModeGetPlaneResources(device->fd);
+	if (!res)
+		return;
+
+	device->planes = calloc(res->count_planes, sizeof(plane));
+	if (!device->planes)
+		return;
+
+	for (i = 0; i < res->count_planes; i++) {
+		plane = kms_plane_create(device, res->planes[i]);
+		if (!plane)
+			continue;
+
+		device->planes[i] = plane;
+		device->num_planes++;
+	}
+
+	drmModeFreePlaneResources(res);
+}
+
+static void kms_device_probe(struct kms_device *device)
+{
+	kms_device_probe_screens(device);
+	kms_device_probe_crtcs(device);
+	kms_device_probe_planes(device);
+}
+
+struct kms_device *kms_device_open(int fd)
+{
+	struct kms_device *device;
+
+	device = calloc(1, sizeof(*device));
+	if (!device)
+		return NULL;
+
+	device->fd = fd;
+
+	kms_device_probe(device);
+
+	return device;
+}
+
+void kms_device_close(struct kms_device *device)
+{
+	unsigned int i;
+
+	for (i = 0; i < device->num_planes; i++)
+		kms_plane_free(device->planes[i]);
+
+	free(device->planes);
+
+	for (i = 0; i < device->num_crtcs; i++)
+		kms_crtc_free(device->crtcs[i]);
+
+	free(device->crtcs);
+
+	for (i = 0; i < device->num_screens; i++)
+		kms_screen_free(device->screens[i]);
+
+	free(device->screens);
+
+	if (device->fd >= 0)
+		close(device->fd);
+
+	free(device);
+}
+
+struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device,
+						uint32_t type,
+						unsigned int index)
+{
+	unsigned int i;
+
+	for (i = 0; i < device->num_planes; i++) {
+		if (device->planes[i]->type == type) {
+			if (index == 0)
+				return device->planes[i];
+
+			index--;
+		}
+	}
+
+	return NULL;
+}
diff --git a/tests/kms/libkms-test-framebuffer.c b/tests/kms/libkms-test-framebuffer.c
new file mode 100644
index 000000000000..c9e5ad3c250d
--- /dev/null
+++ b/tests/kms/libkms-test-framebuffer.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include <sys/mman.h>
+
+#include <drm_fourcc.h>
+
+#include "xf86drm.h"
+
+#include "libkms-test.h"
+
+struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device,
+					       unsigned int width,
+					       unsigned int height,
+					       uint32_t format)
+{
+	uint32_t handles[4], pitches[4], offsets[4];
+	struct drm_mode_create_dumb args;
+	struct kms_framebuffer *fb;
+	int err;
+
+	fb = calloc(1, sizeof(*fb));
+	if (!fb)
+		return NULL;
+
+	fb->device = device;
+	fb->width = width;
+	fb->height = height;
+	fb->format = format;
+
+	memset(&args, 0, sizeof(args));
+	args.width = width;
+	args.height = height;
+
+	switch (format) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_RGBA8888:
+		args.bpp = 32;
+		break;
+
+	default:
+		free(fb);
+		return NULL;
+	}
+
+	err = drmIoctl(device->fd, DRM_IOCTL_MODE_CREATE_DUMB, &args);
+	if (err < 0) {
+		free(fb);
+		return NULL;
+	}
+
+	fb->handle = args.handle;
+	fb->pitch = args.pitch;
+	fb->size = args.size;
+
+	handles[0] = fb->handle;
+	pitches[0] = fb->pitch;
+	offsets[0] = 0;
+
+	err = drmModeAddFB2(device->fd, width, height, format, handles,
+			    pitches, offsets, &fb->id, 0);
+	if (err < 0) {
+		kms_framebuffer_free(fb);
+		return NULL;
+	}
+
+	return fb;
+}
+
+void kms_framebuffer_free(struct kms_framebuffer *fb)
+{
+	struct kms_device *device = fb->device;
+	struct drm_mode_destroy_dumb args;
+	int err;
+
+	if (fb->id) {
+		err = drmModeRmFB(device->fd, fb->id);
+		if (err < 0) {
+			/* not much we can do now */
+		}
+	}
+
+	memset(&args, 0, sizeof(args));
+	args.handle = fb->handle;
+
+	err = drmIoctl(device->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &args);
+	if (err < 0) {
+		/* not much we can do now */
+	}
+
+	free(fb);
+}
+
+int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp)
+{
+	struct kms_device *device = fb->device;
+	struct drm_mode_map_dumb args;
+	void *ptr;
+	int err;
+
+	if (fb->ptr) {
+		*ptrp = fb->ptr;
+		return 0;
+	}
+
+	memset(&args, 0, sizeof(args));
+	args.handle = fb->handle;
+
+	err = drmIoctl(device->fd, DRM_IOCTL_MODE_MAP_DUMB, &args);
+	if (err < 0)
+		return -errno;
+
+	ptr = mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED,
+		   device->fd, args.offset);
+	if (ptr == MAP_FAILED)
+		return -errno;
+
+	*ptrp = fb->ptr = ptr;
+
+	return 0;
+}
+
+void kms_framebuffer_unmap(struct kms_framebuffer *fb)
+{
+	if (fb->ptr) {
+		munmap(fb->ptr, fb->size);
+		fb->ptr = NULL;
+	}
+}
diff --git a/tests/kms/libkms-test-plane.c b/tests/kms/libkms-test-plane.c
new file mode 100644
index 000000000000..8eb78af1dcc7
--- /dev/null
+++ b/tests/kms/libkms-test-plane.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "libkms-test.h"
+
+static int kms_plane_probe(struct kms_plane *plane)
+{
+	struct kms_device *device = plane->device;
+	drmModeObjectPropertiesPtr props;
+	drmModePlane *p;
+	unsigned int i;
+
+	p = drmModeGetPlane(device->fd, plane->id);
+	if (!p)
+		return -ENODEV;
+
+	/* TODO: allow dynamic assignment to CRTCs */
+	if (p->crtc_id == 0) {
+		for (i = 0; i < device->num_crtcs; i++) {
+			if (p->possible_crtcs & (1 << i)) {
+				p->crtc_id = device->crtcs[i]->id;
+				break;
+			}
+		}
+	}
+
+	for (i = 0; i < device->num_crtcs; i++) {
+		if (device->crtcs[i]->id == p->crtc_id) {
+			plane->crtc = device->crtcs[i];
+			break;
+		}
+	}
+
+	plane->formats = calloc(p->count_formats, sizeof(uint32_t));
+	if (!plane->formats)
+		return -ENOMEM;
+
+	for (i = 0; i < p->count_formats; i++)
+		plane->formats[i] = p->formats[i];
+
+	plane->num_formats = p->count_formats;
+
+	drmModeFreePlane(p);
+
+	props = drmModeObjectGetProperties(device->fd, plane->id,
+					   DRM_MODE_OBJECT_PLANE);
+	if (!props)
+		return -ENODEV;
+
+	for (i = 0; i < props->count_props; i++) {
+		drmModePropertyPtr prop;
+
+		prop = drmModeGetProperty(device->fd, props->props[i]);
+		if (prop) {
+			if (strcmp(prop->name, "type") == 0)
+				plane->type = props->prop_values[i];
+
+			drmModeFreeProperty(prop);
+		}
+	}
+
+	drmModeFreeObjectProperties(props);
+
+	return 0;
+}
+
+struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id)
+{
+	struct kms_plane *plane;
+
+	plane = calloc(1, sizeof(*plane));
+	if (!plane)
+		return NULL;
+
+	plane->device = device;
+	plane->id = id;
+
+	kms_plane_probe(plane);
+
+	return plane;
+}
+
+void kms_plane_free(struct kms_plane *plane)
+{
+	free(plane);
+}
+
+int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb,
+		  unsigned int x, unsigned int y)
+{
+	struct kms_device *device = plane->device;
+	int err;
+
+	err = drmModeSetPlane(device->fd, plane->id, plane->crtc->id, fb->id,
+			      0, x, y, fb->width, fb->height, 0 << 16,
+			      0 << 16, fb->width << 16, fb->height << 16);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
+
+bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format)
+{
+	unsigned int i;
+
+	for (i = 0; i < plane->num_formats; i++)
+		if (plane->formats[i] == format)
+			return true;
+
+	return false;
+}
diff --git a/tests/kms/libkms-test-screen.c b/tests/kms/libkms-test-screen.c
new file mode 100644
index 000000000000..336902228090
--- /dev/null
+++ b/tests/kms/libkms-test-screen.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "libkms-test.h"
+
+static void kms_screen_probe(struct kms_screen *screen)
+{
+	struct kms_device *device = screen->device;
+	drmModeConnector *con;
+
+	con = drmModeGetConnector(device->fd, screen->id);
+	if (!con)
+		return;
+
+	screen->type = con->connector_type;
+
+	if (con->connection == DRM_MODE_CONNECTED)
+		screen->connected = true;
+	else
+		screen->connected = false;
+
+	memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo));
+	screen->width = screen->mode.hdisplay;
+	screen->height = screen->mode.vdisplay;
+
+	drmModeFreeConnector(con);
+}
+
+struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id)
+{
+	struct kms_screen *screen;
+
+	screen = calloc(1, sizeof(*screen));
+	if (!screen)
+		return NULL;
+
+	screen->device = device;
+	screen->id = id;
+
+	kms_screen_probe(screen);
+
+	return screen;
+}
+
+void kms_screen_free(struct kms_screen *screen)
+{
+	if (screen)
+		free(screen->name);
+
+	free(screen);
+}
+
+int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
+		   struct kms_framebuffer *fb)
+{
+	struct kms_device *device = screen->device;
+	int err;
+
+	err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id,
+			     1, &screen->mode);
+	if (err < 0)
+		return -errno;
+
+	return 0;
+}
diff --git a/tests/kms/libkms-test.h b/tests/kms/libkms-test.h
new file mode 100644
index 000000000000..7b1d02e9aa0a
--- /dev/null
+++ b/tests/kms/libkms-test.h
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef LIBKMS_TEST_H
+#define LIBKMS_TEST_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include <xf86drmMode.h>
+
+struct kms_device {
+	int fd;
+
+	struct kms_screen **screens;
+	unsigned int num_screens;
+
+	struct kms_crtc **crtcs;
+	unsigned int num_crtcs;
+
+	struct kms_plane **planes;
+	unsigned int num_planes;
+};
+
+struct kms_device *kms_device_open(int fd);
+void kms_device_close(struct kms_device *device);
+
+struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device,
+						uint32_t type,
+						unsigned int index);
+
+struct kms_crtc {
+	struct kms_device *device;
+	uint32_t id;
+};
+
+struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id);
+void kms_crtc_free(struct kms_crtc *crtc);
+
+struct kms_framebuffer {
+	struct kms_device *device;
+
+	unsigned int width;
+	unsigned int height;
+	unsigned int pitch;
+	uint32_t format;
+	size_t size;
+
+	uint32_t handle;
+	uint32_t id;
+
+	void *ptr;
+};
+
+struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device,
+					       unsigned int width,
+					       unsigned int height,
+					       uint32_t format);
+void kms_framebuffer_free(struct kms_framebuffer *fb);
+int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp);
+void kms_framebuffer_unmap(struct kms_framebuffer *fb);
+
+struct kms_screen {
+	struct kms_device *device;
+	bool connected;
+	uint32_t type;
+	uint32_t id;
+
+	unsigned int width;
+	unsigned int height;
+	char *name;
+
+	drmModeModeInfo mode;
+};
+
+struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id);
+void kms_screen_free(struct kms_screen *screen);
+
+int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc,
+		   struct kms_framebuffer *fb);
+
+struct kms_plane {
+	struct kms_device *device;
+	struct kms_crtc *crtc;
+	unsigned int type;
+	uint32_t id;
+
+	uint32_t *formats;
+	unsigned int num_formats;
+};
+
+struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id);
+void kms_plane_free(struct kms_plane *plane);
+
+int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb,
+		  unsigned int x, unsigned int y);
+bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format);
+
+#endif
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (8 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-29 15:30   ` [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo Emil Velikov
  2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
  2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

This test program sets a mode and framebuffer on a connector and cycles
through all CRTCs, moving the connector to each of them in turn. This is
useful to verify that CRTC stealing is properly handled in the DRM core
and drivers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/kms/Makefile.am      |  11 ++++
 tests/kms/kms-steal-crtc.c | 161 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 172 insertions(+)
 create mode 100644 tests/kms/kms-steal-crtc.c

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index c84bae05d869..10584c8930a4 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -17,3 +17,14 @@ libkms_test_la_SOURCES = \
 
 libkms_test_la_LIBADD = \
 	$(top_builddir)/libdrm.la
+
+if HAVE_INSTALL_TESTS
+bin_PROGRAMS = \
+	kms-steal-crtc
+else
+noinst_PROGRAMS = \
+	kms-steal-crtc
+endif
+
+kms_steal_crtc_SOURCES = kms-steal-crtc.c
+kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la
diff --git a/tests/kms/kms-steal-crtc.c b/tests/kms/kms-steal-crtc.c
new file mode 100644
index 000000000000..2f7f327edc16
--- /dev/null
+++ b/tests/kms/kms-steal-crtc.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drm_fourcc.h>
+
+#include "util/pattern.h"
+#include "libkms-test.h"
+
+static void signal_handler(int signum)
+{
+}
+
+int main(int argc, char *argv[])
+{
+	struct kms_framebuffer *fb;
+	struct kms_screen *screen;
+	struct kms_device *device;
+	unsigned int index = 0;
+	struct sigaction sa;
+	int fd, err;
+	void *ptr;
+
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s DEVICE\n", argv[0]);
+		return 1;
+	}
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = signal_handler;
+
+	err = sigaction(SIGINT, &sa, NULL);
+	if (err < 0) {
+		fprintf(stderr, "sigaction() failed: %m\n");
+		return 1;
+	}
+
+	fd = open(argv[1], O_RDWR);
+	if (fd < 0) {
+		fprintf(stderr, "open() failed: %m\n");
+		return 1;
+	}
+
+	device = kms_device_open(fd);
+	if (!device) {
+		fprintf(stderr, "kms_device_open() failed: %m\n");
+		return 1;
+	}
+
+	if (device->num_screens < 1) {
+		fprintf(stderr, "no screens found\n");
+		kms_device_close(device);
+		close(fd);
+		return 1;
+	}
+
+	/* TODO: allow command-line to override */
+	screen = device->screens[0];
+
+	printf("Using screen %s, resolution %ux%u\n", screen->name,
+	       screen->width, screen->height);
+
+	fb = kms_framebuffer_create(device, screen->width, screen->height,
+				    DRM_FORMAT_XRGB8888);
+	if (!fb) {
+		fprintf(stderr, "kms_framebuffer_create() failed\n");
+		return 1;
+	}
+
+	err = kms_framebuffer_map(fb, &ptr);
+	if (err < 0) {
+		fprintf(stderr, "kms_framebuffer_map() failed: %d\n", err);
+		return 1;
+	}
+
+	util_fill_pattern(fb->format, UTIL_PATTERN_SMPTE, &ptr, fb->width,
+			  fb->height, fb->pitch);
+
+	kms_framebuffer_unmap(fb);
+
+	err = kms_screen_set(screen, device->crtcs[index++], fb);
+	if (err < 0) {
+		fprintf(stderr, "kms_screen_set() failed: %d\n", err);
+		return 1;
+	}
+
+	while (true) {
+		int nfds = STDIN_FILENO + 1;
+		struct timeval timeout;
+		fd_set fds;
+
+		memset(&timeout, 0, sizeof(timeout));
+		timeout.tv_sec = 5;
+		timeout.tv_usec = 0;
+
+		FD_ZERO(&fds);
+		FD_SET(STDIN_FILENO, &fds);
+
+		err = select(nfds, &fds, NULL, NULL, &timeout);
+		if (err < 0) {
+			if (errno == EINTR)
+				break;
+
+			fprintf(stderr, "select() failed: %d\n", errno);
+			break;
+		}
+
+		if (err > 0) {
+			if (FD_ISSET(STDIN_FILENO, &fds))
+				break;
+		}
+
+		/* switch CRTC */
+		if (index >= device->num_crtcs)
+			index = 0;
+
+		err = kms_screen_set(screen, device->crtcs[index], fb);
+		if (err < 0) {
+			fprintf(stderr, "kms_screen_set() failed: %d\n", err);
+			break;
+		}
+
+		index++;
+	}
+
+	kms_framebuffer_free(fb);
+	kms_device_close(device);
+	close(fd);
+
+	return 0;
+}
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH libdrm 11/11] tests: kms: Implement universal planes test
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (9 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
@ 2015-01-23 16:08 ` Thierry Reding
  2015-01-29 15:31   ` [PATCH 11.1/11] SQUASH: kms-universal-planes: link against cairo Emil Velikov
  2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov
  11 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-23 16:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Laurent Pinchart

From: Thierry Reding <treding@nvidia.com>

This small program allows universal planes to be tested. Currently this
isn't very flexible because it allows only the first plane of a given
type to be tested on the first CRTC. However it should be simple to
extend this with some additional command-line arguments.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/kms/Makefile.am            |   9 +-
 tests/kms/kms-universal-planes.c | 358 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 365 insertions(+), 2 deletions(-)
 create mode 100644 tests/kms/kms-universal-planes.c

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index 10584c8930a4..e9589221e489 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -20,11 +20,16 @@ libkms_test_la_LIBADD = \
 
 if HAVE_INSTALL_TESTS
 bin_PROGRAMS = \
-	kms-steal-crtc
+	kms-steal-crtc \
+	kms-universal-planes
 else
 noinst_PROGRAMS = \
-	kms-steal-crtc
+	kms-steal-crtc \
+	kms-universal-planes
 endif
 
 kms_steal_crtc_SOURCES = kms-steal-crtc.c
 kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la
+
+kms_universal_planes_SOURCES = kms-universal-planes.c
+kms_universal_planes_LDADD = libkms-test.la
diff --git a/tests/kms/kms-universal-planes.c b/tests/kms/kms-universal-planes.c
new file mode 100644
index 000000000000..9151231ff860
--- /dev/null
+++ b/tests/kms/kms-universal-planes.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright © 2014 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drm_fourcc.h>
+#include "xf86drm.h"
+
+#include "util/common.h"
+#include "libkms-test.h"
+
+static const uint32_t formats[] = {
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_XBGR8888,
+	DRM_FORMAT_RGBA8888,
+};
+
+static uint32_t choose_format(struct kms_plane *plane)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(formats); i++)
+		if (kms_plane_supports_format(plane, formats[i]))
+			return formats[i];
+
+	return 0;
+}
+
+static void prepare_framebuffer(struct kms_framebuffer *fb, bool invert)
+{
+	const unsigned int block_size = 16;
+	uint32_t colors[2];
+	unsigned int i, j;
+	uint32_t *buf;
+	void *ptr;
+	int err;
+
+	switch (fb->format) {
+	case DRM_FORMAT_XRGB8888:
+		printf("using XRGB8888 format\n");
+		           /* XXRRGGBB */
+		colors[0] = 0xffff0000;
+		colors[1] = 0xff0000ff;
+		break;
+
+	case DRM_FORMAT_XBGR8888:
+		printf("using XBGR8888 format\n");
+		           /* XXBBGGRR */
+		colors[0] = 0xff0000ff;
+		colors[1] = 0xffff0000;
+		break;
+
+	case DRM_FORMAT_RGBA8888:
+		printf("using RGBA8888 format\n");
+		           /* RRGGBBAA */
+		colors[0] = 0xff0000ff;
+		colors[1] = 0x0000ffff;
+		break;
+
+	default:
+		colors[0] = 0xffffffff;
+		colors[1] = 0xffffffff;
+		break;
+	}
+
+	err = kms_framebuffer_map(fb, &ptr);
+	if (err < 0) {
+		fprintf(stderr, "kms_framebuffer_map() failed: %s\n",
+			strerror(-err));
+		return;
+	}
+
+	buf = ptr;
+
+	for (j = 0; j < fb->height; j++) {
+		for (i = 0; i < fb->width; i++) {
+			unsigned int color = (j / block_size) ^
+					     (i / block_size);
+
+			if (invert)
+				color ^= color;
+
+			*buf++ = colors[color & 1];
+		}
+	}
+
+	kms_framebuffer_unmap(fb);
+}
+
+int main(int argc, char *argv[])
+{
+	static const char opts[] = "chopv";
+	static struct option options[] = {
+		{ "cursor", 0, 0, 'c' },
+		{ "help", 0, 0, 'h' },
+		{ "overlay", 0, 0, 'o' },
+		{ "primary", 0, 0, 'p' },
+		{ "verbose", 0, 0, 'v' },
+		{ 0, 0, 0, 0 },
+	};
+	struct kms_framebuffer *cursor = NULL;
+	struct kms_framebuffer *root = NULL;
+	struct kms_framebuffer *fb = NULL;
+	struct kms_device *device;
+	bool use_overlay = false;
+	bool use_primary = false;
+	struct kms_plane *plane;
+	bool use_cursor = false;
+	bool verbose = false;
+	unsigned int i;
+	int opt, idx;
+	int fd, err;
+
+	while ((opt = getopt_long(argc, argv, opts, options, &idx)) != -1) {
+		switch (opt) {
+		case 'c':
+			use_cursor = true;
+			break;
+
+		case 'h':
+			break;
+
+		case 'o':
+			use_overlay = true;
+			break;
+
+		case 'p':
+			use_primary = true;
+			break;
+
+		case 'v':
+			verbose = true;
+			break;
+
+		default:
+			printf("unknown option \"%c\"\n", opt);
+			return 1;
+		}
+	}
+
+	if (optind >= argc) {
+		fprintf(stderr, "usage: %s [options] DEVICE\n", argv[0]);
+		return 1;
+	}
+
+	fd = open(argv[optind], O_RDWR);
+	if (fd < 0) {
+		fprintf(stderr, "open() failed: %m\n");
+		return 1;
+	}
+
+	err = drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+	if (err < 0) {
+		fprintf(stderr, "drmSetClientCap() failed: %d\n", err);
+		return 1;
+	}
+
+	device = kms_device_open(fd);
+	if (!device)
+		return 1;
+
+	if (verbose) {
+		printf("Screens: %u\n", device->num_screens);
+
+		for (i = 0; i < device->num_screens; i++) {
+			struct kms_screen *screen = device->screens[i];
+			const char *status = "disconnected";
+
+			if (screen->connected)
+				status = "connected";
+
+			printf("  %u: %x\n", i, screen->id);
+			printf("    Status: %s\n", status);
+			printf("    Name: %s\n", screen->name);
+			printf("    Resolution: %ux%u\n", screen->width,
+			       screen->height);
+		}
+
+		printf("Planes: %u\n", device->num_planes);
+
+		for (i = 0; i < device->num_planes; i++) {
+			struct kms_plane *plane = device->planes[i];
+			const char *type = NULL;
+
+			switch (plane->type) {
+			case DRM_PLANE_TYPE_OVERLAY:
+				type = "overlay";
+				break;
+
+			case DRM_PLANE_TYPE_PRIMARY:
+				type = "primary";
+				break;
+
+			case DRM_PLANE_TYPE_CURSOR:
+				type = "cursor";
+				break;
+			}
+
+			printf("  %u: %p\n", i, plane);
+			printf("    ID: %x\n", plane->id);
+			printf("    CRTC: %x\n", plane->crtc->id);
+			printf("    Type: %x (%s)\n", plane->type, type);
+		}
+	}
+
+	if (use_cursor) {
+		unsigned int x, y;
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_CURSOR,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no cursor plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		cursor = kms_framebuffer_create(device, 32, 32, format);
+		if (!cursor) {
+			fprintf(stderr, "failed to create cursor buffer\n");
+			return 1;
+		}
+
+		prepare_framebuffer(cursor, false);
+
+		x = (device->screens[0]->width - cursor->width) / 2;
+		y = (device->screens[0]->height - cursor->height) / 2;
+
+		kms_plane_set(plane, cursor, x, y);
+	}
+
+	if (use_overlay) {
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_OVERLAY,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no overlay plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		fb = kms_framebuffer_create(device, 320, 240, format);
+		if (!fb)
+			return 1;
+
+		prepare_framebuffer(fb, false);
+
+		kms_plane_set(plane, fb, 0, 0);
+	}
+
+	if (use_primary) {
+		unsigned int x, y;
+		uint32_t format;
+
+		plane = kms_device_find_plane_by_type(device,
+						      DRM_PLANE_TYPE_PRIMARY,
+						      0);
+		if (!plane) {
+			fprintf(stderr, "no primary plane found\n");
+			return 1;
+		}
+
+		format = choose_format(plane);
+		if (!format) {
+			fprintf(stderr, "no matching format found\n");
+			return 1;
+		}
+
+		root = kms_framebuffer_create(device, 640, 480, format);
+		if (!root)
+			return 1;
+
+		prepare_framebuffer(root, true);
+
+		x = (device->screens[0]->width - root->width) / 2;
+		y = (device->screens[0]->height - root->height) / 2;
+
+		kms_plane_set(plane, root, x, y);
+	}
+
+	while (1) {
+		struct timeval timeout = { 1, 0 };
+		fd_set fds;
+
+		FD_ZERO(&fds);
+		FD_SET(STDIN_FILENO, &fds);
+
+		err = select(STDIN_FILENO + 1, &fds, NULL, NULL, &timeout);
+		if (err < 0) {
+			fprintf(stderr, "select() failed: %m\n");
+			break;
+		}
+
+		/* timeout */
+		if (err == 0)
+			continue;
+
+		if (FD_ISSET(STDIN_FILENO, &fds))
+			break;
+	}
+
+	if (cursor)
+		kms_framebuffer_free(cursor);
+
+	if (root)
+		kms_framebuffer_free(root);
+
+	if (fb)
+		kms_framebuffer_free(fb);
+
+	kms_device_close(device);
+	close(fd);
+
+	return 0;
+}
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments
  2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
@ 2015-01-24 23:19   ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:19 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:14 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Fixes a few complaints raised by valgrind when running the Tegra tests.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

I agree that a fix is needed, and that this patch matches the rest of the 
code, so

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

However, shouldn't structures be memset to 0 unconditionally, especially 
considering the recent discussion regarding reserved fields that should be 
initialized to default values by userspace ? This can be fixed by a separate 
patch.

> ---
>  xf86drmMode.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/xf86drmMode.c b/xf86drmMode.c
> index 60ce3699f3e3..f6e4416b88b5 100644
> --- a/xf86drmMode.c
> +++ b/xf86drmMode.c
> @@ -282,6 +282,7 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t
> height, struct drm_mode_fb_cmd2 f;
>  	int ret;
> 
> +	VG_CLEAR(f);
>  	f.width  = width;
>  	f.height = height;
>  	f.pixel_format = pixel_format;
> @@ -309,6 +310,7 @@ drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
>  	struct drm_mode_fb_cmd info;
>  	drmModeFBPtr r;
> 
> +	VG_CLEAR(info);
>  	info.fb_id = buf;
> 
>  	if (drmIoctl(fd, DRM_IOCTL_MODE_GETFB, &info))

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines
  2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
@ 2015-01-24 23:19   ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:19 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:15 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Usage of blank lines can be a matter of taste, of course, but for these
> we can surely all agree that they're not needed and inconsistent.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  xf86drmMode.c | 11 -----------
>  1 file changed, 11 deletions(-)
> 
> diff --git a/xf86drmMode.c b/xf86drmMode.c
> index f6e4416b88b5..7e228b3e7aa3 100644
> --- a/xf86drmMode.c
> +++ b/xf86drmMode.c
> @@ -115,7 +115,6 @@ void drmModeFreeResources(drmModeResPtr ptr)
>  	drmFree(ptr->connectors);
>  	drmFree(ptr->encoders);
>  	drmFree(ptr);
> -
>  }
> 
>  void drmModeFreeFB(drmModeFBPtr ptr)
> @@ -133,7 +132,6 @@ void drmModeFreeCrtc(drmModeCrtcPtr ptr)
>  		return;
> 
>  	drmFree(ptr);
> -
>  }
> 
>  void drmModeFreeConnector(drmModeConnectorPtr ptr)
> @@ -146,7 +144,6 @@ void drmModeFreeConnector(drmModeConnectorPtr ptr)
>  	drmFree(ptr->props);
>  	drmFree(ptr->modes);
>  	drmFree(ptr);
> -
>  }
> 
>  void drmModeFreeEncoder(drmModeEncoderPtr ptr)
> @@ -301,8 +298,6 @@ int drmModeAddFB2(int fd, uint32_t width, uint32_t
> height, int drmModeRmFB(int fd, uint32_t bufferId)
>  {
>  	return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId);
> -
> -
>  }
> 
>  drmModeFBPtr drmModeGetFB(int fd, uint32_t buf)
> @@ -342,7 +337,6 @@ int drmModeDirtyFB(int fd, uint32_t bufferId,
>  	return DRM_IOCTL(fd, DRM_IOCTL_MODE_DIRTYFB, &dirty);
>  }
> 
> -
>  /*
>   * Crtc functions
>   */
> @@ -379,7 +373,6 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
>  	return r;
>  }
> 
> -
>  int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
>                     uint32_t x, uint32_t y, uint32_t *connectors, int count,
> drmModeModeInfoPtr mode)
> @@ -594,7 +587,6 @@ int drmModeDetachMode(int fd, uint32_t connector_id,
> drmModeModeInfoPtr mode_inf return DRM_IOCTL(fd, DRM_IOCTL_MODE_DETACHMODE,
> &res);
>  }
> 
> -
>  drmModePropertyPtr drmModeGetProperty(int fd, uint32_t property_id)
>  {
>  	struct drm_mode_get_property prop;
> @@ -812,7 +804,6 @@ int drmCheckModesettingSupported(const char *busid)
>  	return 0;
>  #endif
>  	return -ENOSYS;
> -
>  }
> 
>  int drmModeCrtcGetGamma(int fd, uint32_t crtc_id, uint32_t size,
> @@ -914,7 +905,6 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t
> crtc_id, uint32_t crtc_w, uint32_t crtc_h,
>  		    uint32_t src_x, uint32_t src_y,
>  		    uint32_t src_w, uint32_t src_h)
> -
>  {
>  	struct drm_mode_set_plane s;
> 
> @@ -934,7 +924,6 @@ int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t
> crtc_id, return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s);
>  }
> 
> -
>  drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id)
>  {
>  	struct drm_mode_get_plane ovr, counts;

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 03/11] libdrm: Make indentation consistent
  2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
@ 2015-01-24 23:20   ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:20 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:16 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  xf86drmMode.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xf86drmMode.c b/xf86drmMode.c
> index 7e228b3e7aa3..3d6b9cc307d1 100644
> --- a/xf86drmMode.c
> +++ b/xf86drmMode.c
> @@ -250,7 +250,7 @@ err_allocs:
>  }
> 
>  int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t depth,
> -                 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
> +		 uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
>  		 uint32_t *buf_id)
>  {
>  	struct drm_mode_fb_cmd f;
> @@ -374,7 +374,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
>  }
> 
>  int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
> -                   uint32_t x, uint32_t y, uint32_t *connectors, int count,
> +		   uint32_t x, uint32_t y, uint32_t *connectors, int count,
>  		   drmModeModeInfoPtr mode)
>  {
>  	struct drm_mode_crtc crtc;

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 04/11] tests: Split helpers into library
  2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
@ 2015-01-24 23:24   ` Laurent Pinchart
  2015-01-29 15:27   ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
  2015-01-29 15:27   ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
  2 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:24 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

On Friday 23 January 2015 17:08:17 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Some of the helpers, such as the pattern drawing helpers or the format
> lookup helpers, have potential to be reused. Move them into a separate
> library to make it easier to share them.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  configure.ac                |   1 +
>  tests/Makefile.am           |   2 +-
>  tests/modeprint/Makefile.am |   1 +
>  tests/modeprint/modeprint.c |   2 +-
>  tests/modetest/Makefile.am  |   2 +
>  tests/modetest/buffers.c    | 956 +----------------------------------------
>  tests/modetest/buffers.h    |  12 +-
>  tests/modetest/cursor.c     |   4 +-
>  tests/modetest/modetest.c   |  25 +-
>  tests/proptest/proptest.c   |   3 +-
>  tests/util/Makefile.am      |  19 +
>  tests/util/common.h         |  33 ++
>  tests/util/format.c         | 119 ++++++
>  tests/util/format.h         |  65 +++
>  tests/util/pattern.c        | 870 ++++++++++++++++++++++++++++++++++++++++
>  tests/util/pattern.h        |  39 ++
>  tests/vbltest/Makefile.am   |   1 +
>  tests/vbltest/vbltest.c     |   2 +-
>  18 files changed, 1177 insertions(+), 979 deletions(-)
>  create mode 100644 tests/util/Makefile.am
>  create mode 100644 tests/util/common.h
>  create mode 100644 tests/util/format.c
>  create mode 100644 tests/util/format.h
>  create mode 100644 tests/util/pattern.c
>  create mode 100644 tests/util/pattern.h

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 05/11] tests: Move name tables to libutil
  2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
@ 2015-01-24 23:24   ` Laurent Pinchart
  2015-01-29 15:28   ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
  1 sibling, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:24 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:18 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> These tables are duplicated in several places, so move them into libutil
> so that they can be shared.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  tests/modetest/modetest.c  |  50 ++-----------------
>  tests/proptest/Makefile.am |   4 +-
>  tests/proptest/proptest.c  |  40 +--------------
>  tests/util/Makefile.am     |   2 +
>  tests/util/kms.c           | 122 ++++++++++++++++++++++++++++++++++++++++++
>  tests/util/kms.h           |  33 ++++++++++++
>  6 files changed, 165 insertions(+), 86 deletions(-)
>  create mode 100644 tests/util/kms.c
>  create mode 100644 tests/util/kms.h
> 
> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> index b610956adfcb..d5fd99ebe1fd 100644
> --- a/tests/modetest/modetest.c
> +++ b/tests/modetest/modetest.c
> @@ -61,6 +61,7 @@
> 
>  #include "util/common.h"
>  #include "util/format.h"
> +#include "util/kms.h"
>  #include "util/pattern.h"
> 
>  #include "buffers.h"
> @@ -123,11 +124,6 @@ static inline int64_t U642I64(uint64_t val)
>  	return (int64_t)*((int64_t *)&val);
>  }
> 
> -struct type_name {
> -	int type;
> -	const char *name;
> -};
> -
>  #define type_name_fn(res) \
>  const char * res##_str(int type) {			\
>  	unsigned int i;					\
> @@ -138,44 +134,6 @@ const char * res##_str(int type) {			\
>  	return "(invalid)";				\
>  }
> 
> -struct type_name encoder_type_names[] = {
> -	{ DRM_MODE_ENCODER_NONE, "none" },
> -	{ DRM_MODE_ENCODER_DAC, "DAC" },
> -	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
> -	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
> -	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
> -};
> -
> -static type_name_fn(encoder_type)
> -
> -struct type_name connector_status_names[] = {
> -	{ DRM_MODE_CONNECTED, "connected" },
> -	{ DRM_MODE_DISCONNECTED, "disconnected" },
> -	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> -};
> -
> -static type_name_fn(connector_status)
> -
> -struct type_name connector_type_names[] = {
> -	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
> -	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
> -	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> -	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
> -	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
> -	{ DRM_MODE_CONNECTOR_Composite, "composite" },
> -	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
> -	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
> -	{ DRM_MODE_CONNECTOR_Component, "component" },
> -	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
> -	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
> -	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
> -	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
> -	{ DRM_MODE_CONNECTOR_TV, "TV" },
> -	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
> -};
> -
> -static type_name_fn(connector_type)
> -
>  #define bit_name_fn(res)					\
>  const char * res##_str(int type) {				\
>  	unsigned int i;						\
> @@ -235,7 +193,7 @@ static void dump_encoders(struct device *dev)
>  		printf("%d\t%d\t%s\t0x%08x\t0x%08x\n",
>  		       encoder->encoder_id,
>  		       encoder->crtc_id,
> -		       encoder_type_str(encoder->encoder_type),
> +		       util_lookup_encoder_type_name(encoder->encoder_type),
>  		       encoder->possible_crtcs,
>  		       encoder->possible_clones);
>  	}
> @@ -379,8 +337,8 @@ static void dump_connectors(struct device *dev)
>  		printf("%d\t%d\t%s\t%s\t%dx%d\t\t%d\t",
>  		       connector->connector_id,
>  		       connector->encoder_id,
> -		       connector_status_str(connector->connection),
> -		       connector_type_str(connector->connector_type),
> +		       util_lookup_connector_status_name(connector->connection),
> +		       util_lookup_connector_type_name(connector->connector_type),
>  		       connector->mmWidth, connector->mmHeight,
>  		       connector->count_modes);
> 
> diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am
> index f81a3c00846b..c615489b9a92 100644
> --- a/tests/proptest/Makefile.am
> +++ b/tests/proptest/Makefile.am
> @@ -1,5 +1,6 @@
>  AM_CFLAGS = \
>  	-I$(top_srcdir)/include/drm \
> +	-I$(top_srcdir)/tests \
>  	-I$(top_srcdir)
> 
>  noinst_PROGRAMS = \
> @@ -8,4 +9,5 @@ noinst_PROGRAMS = \
>  proptest_SOURCES = \
>  	proptest.c
>  proptest_LDADD = \
> -	$(top_builddir)/libdrm.la
> +	$(top_builddir)/libdrm.la \
> +	$(top_builddir)/tests/util/libutil.la
> diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
> index ee3fa408a310..b442d583d528 100644
> --- a/tests/proptest/proptest.c
> +++ b/tests/proptest/proptest.c
> @@ -45,44 +45,6 @@ static inline int64_t U642I64(uint64_t val)
>  int fd;
>  drmModeResPtr res = NULL;
> 
> -const char *connector_type_str(uint32_t type)
> -{
> -	switch (type) {
> -	case DRM_MODE_CONNECTOR_Unknown:
> -		return "Unknown";
> -	case DRM_MODE_CONNECTOR_VGA:
> -		return "VGA";
> -	case DRM_MODE_CONNECTOR_DVII:
> -		return "DVI-I";
> -	case DRM_MODE_CONNECTOR_DVID:
> -		return "DVI-D";
> -	case DRM_MODE_CONNECTOR_DVIA:
> -		return "DVI-A";
> -	case DRM_MODE_CONNECTOR_Composite:
> -		return "Composite";
> -	case DRM_MODE_CONNECTOR_SVIDEO:
> -		return "SVIDEO";
> -	case DRM_MODE_CONNECTOR_LVDS:
> -		return "LVDS";
> -	case DRM_MODE_CONNECTOR_Component:
> -		return "Component";
> -	case DRM_MODE_CONNECTOR_9PinDIN:
> -		return "9PinDin";
> -	case DRM_MODE_CONNECTOR_DisplayPort:
> -		return "DisplayPort";
> -	case DRM_MODE_CONNECTOR_HDMIA:
> -		return "HDMI-A";
> -	case DRM_MODE_CONNECTOR_HDMIB:
> -		return "HDMI-B";
> -	case DRM_MODE_CONNECTOR_TV:
> -		return "TV";
> -	case DRM_MODE_CONNECTOR_eDP:
> -		return "eDP";
> -	default:
> -		return "Invalid";
> -	}
> -}
> -
>  /* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c
> */ static void
>  dump_blob(uint32_t blob_id)
> @@ -226,7 +188,7 @@ static void listConnectorProperties(void)
>  		}
> 
>  		printf("Connector %u (%s-%u)\n", c->connector_id,
> -		       connector_type_str(c->connector_type),
> +		       util_lookup_connector_type_name(c->connector_type),
>  		       c->connector_type_id);
> 
>  		listObjectProperties(c->connector_id,
> diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am
> index 1a2519fbea89..c00574484867 100644
> --- a/tests/util/Makefile.am
> +++ b/tests/util/Makefile.am
> @@ -12,6 +12,8 @@ libutil_la_SOURCES = \
>  	common.h \
>  	format.c \
>  	format.h \
> +	kms.c \
> +	kms.h \
>  	pattern.c \
>  	pattern.h
> 
> diff --git a/tests/util/kms.c b/tests/util/kms.c
> new file mode 100644
> index 000000000000..a271ca047c4e
> --- /dev/null
> +++ b/tests/util/kms.c
> @@ -0,0 +1,122 @@
> +/*
> + * Copyright 2008 Tungsten Graphics
> + *   Jakob Bornecrantz <jakob@tungstengraphics.com>
> + * Copyright 2008 Intel Corporation
> + *   Jesse Barnes <jesse.barnes@intel.com>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> "Software"), + * to deal in the Software without restriction, including
> without limitation + * the rights to use, copy, modify, merge, publish,
> distribute, sublicense, + * and/or sell copies of the Software, and to
> permit persons to whom the + * Software is furnished to do so, subject to
> the following conditions: + *
> + * The above copyright notice and this permission notice shall be included
> in + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE
> SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE.
> + */
> +
> +/*
> + * This fairly simple test program dumps output in a similar format to the
> + * "xrandr" tool everyone knows & loves.  It's necessarily slightly
> different + * since the kernel separates outputs into encoder and connector
> structures, + * each with their own unique ID.  The program also allows
> test testing of the + * memory management and mode setting APIs by allowing
> the user to specify a + * connector and mode to use for mode setting.  If
> all works as expected, a + * blue background should be painted on the
> monitor attached to the specified + * connector after the selected mode is
> set.
> + *
> + * TODO: use cairo to write the mode info on the selected output once
> + *       the mode has been programmed, along with possible test patterns.
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <stdint.h>
> +#include <stdlib.h>
> +
> +#include "xf86drmMode.h"
> +
> +#include "common.h"
> +
> +struct type_name {
> +	unsigned int type;
> +	const char *name;
> +};
> +
> +static const char *util_lookup_type_name(unsigned int type,
> +					 const struct type_name *table,
> +					 unsigned int count)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < count; i++)
> +		if (table[i].type == type)
> +			return table[i].name;
> +
> +	return NULL;
> +}
> +
> +static const struct type_name encoder_type_names[] = {
> +	{ DRM_MODE_ENCODER_NONE, "none" },
> +	{ DRM_MODE_ENCODER_DAC, "DAC" },
> +	{ DRM_MODE_ENCODER_TMDS, "TMDS" },
> +	{ DRM_MODE_ENCODER_LVDS, "LVDS" },
> +	{ DRM_MODE_ENCODER_TVDAC, "TVDAC" },
> +	{ DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
> +	{ DRM_MODE_ENCODER_DSI, "DSI" },
> +	{ DRM_MODE_ENCODER_DPMST, "DisplayPort MST" },
> +};
> +
> +const char *util_lookup_encoder_type_name(unsigned int type)
> +{
> +	return util_lookup_type_name(type, encoder_type_names,
> +				     ARRAY_SIZE(encoder_type_names));
> +}
> +
> +static const struct type_name connector_status_names[] = {
> +	{ DRM_MODE_CONNECTED, "connected" },
> +	{ DRM_MODE_DISCONNECTED, "disconnected" },
> +	{ DRM_MODE_UNKNOWNCONNECTION, "unknown" },
> +};
> +
> +const char *util_lookup_connector_status_name(unsigned int status)
> +{
> +	return util_lookup_type_name(status, connector_status_names,
> +				     ARRAY_SIZE(connector_status_names));
> +}
> +
> +static const struct type_name connector_type_names[] = {
> +	{ DRM_MODE_CONNECTOR_Unknown, "unknown" },
> +	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
> +	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
> +	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
> +	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
> +	{ DRM_MODE_CONNECTOR_Composite, "composite" },
> +	{ DRM_MODE_CONNECTOR_SVIDEO, "s-video" },
> +	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
> +	{ DRM_MODE_CONNECTOR_Component, "component" },
> +	{ DRM_MODE_CONNECTOR_9PinDIN, "9-pin DIN" },
> +	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
> +	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
> +	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
> +	{ DRM_MODE_CONNECTOR_TV, "TV" },
> +	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
> +	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
> +	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
> +};
> +
> +const char *util_lookup_connector_type_name(unsigned int type)
> +{
> +	return util_lookup_type_name(type, connector_type_names,
> +				     ARRAY_SIZE(connector_type_names));
> +}
> diff --git a/tests/util/kms.h b/tests/util/kms.h
> new file mode 100644
> index 000000000000..fa9ab69983ac
> --- /dev/null
> +++ b/tests/util/kms.h
> @@ -0,0 +1,33 @@
> +/*
> + * Copyright 2008 Tungsten Graphics
> + *   Jakob Bornecrantz <jakob@tungstengraphics.com>
> + * Copyright 2008 Intel Corporation
> + *   Jesse Barnes <jesse.barnes@intel.com>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> "Software"), + * to deal in the Software without restriction, including
> without limitation + * the rights to use, copy, modify, merge, publish,
> distribute, sublicense, + * and/or sell copies of the Software, and to
> permit persons to whom the + * Software is furnished to do so, subject to
> the following conditions: + *
> + * The above copyright notice and this permission notice shall be included
> in + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE
> SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE.
> + */
> +
> +#ifndef UTIL_KMS_H
> +#define UTIL_KMS_H
> +
> +const char *util_lookup_encoder_type_name(unsigned int type);
> +const char *util_lookup_connector_status_name(unsigned int type);
> +const char *util_lookup_connector_type_name(unsigned int type);
> +
> +#endif /* UTIL_KMS_H */

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding
  2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
@ 2015-01-24 23:26   ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:26 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:19 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  xf86drmMode.h | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/xf86drmMode.h b/xf86drmMode.h
> index 856a6bb0f569..e70c16d437f4 100644
> --- a/xf86drmMode.h
> +++ b/xf86drmMode.h
> @@ -123,13 +123,13 @@ extern "C" {
>  #define DRM_MODE_DITHERING_OFF  0
>  #define DRM_MODE_DITHERING_ON   1
> 
> -#define DRM_MODE_ENCODER_NONE   0
> -#define DRM_MODE_ENCODER_DAC    1
> -#define DRM_MODE_ENCODER_TMDS   2
> -#define DRM_MODE_ENCODER_LVDS   3
> -#define DRM_MODE_ENCODER_TVDAC  4
> +#define DRM_MODE_ENCODER_NONE    0
> +#define DRM_MODE_ENCODER_DAC     1
> +#define DRM_MODE_ENCODER_TMDS    2
> +#define DRM_MODE_ENCODER_LVDS    3
> +#define DRM_MODE_ENCODER_TVDAC   4
>  #define DRM_MODE_ENCODER_VIRTUAL 5
> -#define DRM_MODE_ENCODER_DSI	6
> +#define DRM_MODE_ENCODER_DSI     6

Nitpicking here, I would have aligned everything on the same column for every 
block of #define's, but that's up to you.

> 
>  #define DRM_MODE_SUBCONNECTOR_Automatic 0
>  #define DRM_MODE_SUBCONNECTOR_Unknown   0
> @@ -153,8 +153,8 @@ extern "C" {
>  #define DRM_MODE_CONNECTOR_DisplayPort  10
>  #define DRM_MODE_CONNECTOR_HDMIA        11
>  #define DRM_MODE_CONNECTOR_HDMIB        12
> -#define DRM_MODE_CONNECTOR_TV		13
> -#define DRM_MODE_CONNECTOR_eDP		14
> +#define DRM_MODE_CONNECTOR_TV           13
> +#define DRM_MODE_CONNECTOR_eDP          14
>  #define DRM_MODE_CONNECTOR_VIRTUAL      15
>  #define DRM_MODE_CONNECTOR_DSI          16

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type
  2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
@ 2015-01-24 23:40   ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:40 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:20 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> This brings xf86drmMode.h in sync with include/drm/drm_mode.h.
> Eventually we really should only have a single set of definitions rather
> than duplicating this in two files.

The purpose of these duplicate definitions is to avoid application build 
breakages when compiled against an old drm.h header that doesn't include 
drm_modes.h. Given that drm_modes.h has been introduced in 2.6.39 more than 6 
years ago, wouldn't it be time to drop this ?

If we need to support old distributions (such as RHEL 5 for instance) shipping 
kernel headers older than 2.6.39, do we still need to keep the definitions in 
sync with newer kernel headers ? Build breakages would only occur when 
compiling an application that makes use of the new definitions against old 
kernel headers. If the distribution is stuck on <2.6.39 I doubt it will ship 
applications using recent DRM features.

> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  xf86drmMode.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/xf86drmMode.h b/xf86drmMode.h
> index e70c16d437f4..70f14a1ae506 100644
> --- a/xf86drmMode.h
> +++ b/xf86drmMode.h
> @@ -130,6 +130,7 @@ extern "C" {
>  #define DRM_MODE_ENCODER_TVDAC   4
>  #define DRM_MODE_ENCODER_VIRTUAL 5
>  #define DRM_MODE_ENCODER_DSI     6
> +#define DRM_MODE_ENCODER_DPMST   7
> 
>  #define DRM_MODE_SUBCONNECTOR_Automatic 0
>  #define DRM_MODE_SUBCONNECTOR_Unknown   0

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 08/11] tests: modetest: Accept connector names
  2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
@ 2015-01-24 23:56   ` Laurent Pinchart
  2015-01-26 10:14     ` Thierry Reding
  0 siblings, 1 reply; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-24 23:56 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

Thank you for the patch.

On Friday 23 January 2015 17:08:21 Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Allow connector names to be used in the specification of the -s option.
> This requires storing the string passed on the command-line so that it
> can later be resolved to a connector ID (after the DRM device has been
> opened).
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  tests/modetest/modetest.c | 134 +++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 123 insertions(+), 11 deletions(-)
> 
> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> index d5fd99ebe1fd..a7cc94f8938c 100644
> --- a/tests/modetest/modetest.c
> +++ b/tests/modetest/modetest.c

[snip]

> @@ -327,7 +328,7 @@ static void dump_connectors(struct device *dev)
>  	int i, j;
> 
>  	printf("Connectors:\n");
> -	printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
> +	printf("id\tencoder\tstatus\t\tname\t\tsize (mm)\tmodes\tencoders\n");
>  	for (i = 0; i < dev->resources->res->count_connectors; i++) {
>  		struct connector *_connector = &dev->resources->connectors[i];
>  		drmModeConnector *connector = _connector->connector;
> @@ -338,7 +339,7 @@ static void dump_connectors(struct device *dev)
>  		       connector->connector_id,
>  		       connector->encoder_id,
>  		       util_lookup_connector_status_name(connector->connection),
> -		       util_lookup_connector_type_name(connector->connector_type),
> +		       _connector->name,
>  		       connector->mmWidth, connector->mmHeight,
>  		       connector->count_modes);

As this is a low-level test tool I believe it would be useful to print both 
the name and the ID. Maybe something like "name (id)" ?

[snip]

> @@ -511,6 +516,47 @@ static void free_resources(struct resources *res)
>  	free(res);
>  }
> 
> +static unsigned int get_connector_index(struct resources *res, uint32_t
> type)
> +{
> +	unsigned int index = 0;
> +	int i;
> +
> +	for (i = 0; i < res->res->count_connectors; i++)
> +		if (res->connectors[i].connector->connector_type == type)
> +			index++;
> +
> +	return index - 1;
> +}
> +
> +static unsigned int get_order(unsigned int value)
> +{
> +	unsigned int order = 0;
> +
> +	do {
> +		value /= 10;
> +		order++;
> +	} while (value > 0);
> +
> +	return order - 1;
> +}
> +
> +static void connector_set_name(struct connector *connector,
> +			       struct resources *res)
> +{
> +	uint32_t type = connector->connector->connector_type;
> +	const char *type_name;
> +	unsigned int index;
> +	int len;
> +
> +	type_name = util_lookup_connector_type_name(type);
> +	index = get_connector_index(res, type);

The kernel's connector name is created using connector_type_id, not the 
connector index. Shouldn't we do the same here ?

> +	len = strlen(type_name) + get_order(index) + 2;

This looks like an over-optimization to me, can't you just add 9 to account 
for the largest possible index ? Or, even better, use asprintf ? The function 
is a GNU extension but is available on BSD according to its manpage.

> +	connector->name = malloc(len + 1);
> +	if (connector->name)
> +		snprintf(connector->name, len + 1, "%s-%u", type_name,  index);
> +}
> +
>  static struct resources *get_resources(struct device *dev)
>  {
>  	struct resources *res;

[snip]

> @@ -1405,6 +1483,32 @@ static int cursor_supported(void)
>  	return 1;
>  }
> 
> +static int pipe_resolve_connectors(struct pipe_arg *pipe, struct device
> *dev)
> +{
> +	drmModeConnector *connector;
> +	unsigned int i;
> +	uint32_t id;
> +	char *endp;
> +
> +	for (i = 0; i < pipe->num_cons; i++) {
> +		id = strtoul(pipe->cons[i], &endp, 10);
> +		if (endp == pipe->cons[i]) {

This won't have the expected behaviour for 9-pin DIN connectors, as the name 
starts with a digit. You should instead test for *endp == '\0'.

> +			connector = get_connector_by_name(dev, pipe->cons[i]);
> +			if (!connector) {
> +				fprintf(stderr, "no connector named %s\n",
> +					pipe->cons[i]);
> +				return -ENODEV;
> +			}
> +
> +			id = connector->connector_id;
> +		}
> +
> +		pipe->con_ids[i] = id;
> +	}
> +
> +	return 0;
> +}

Could update the help text in usage() to reflect the new usage ?

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 08/11] tests: modetest: Accept connector names
  2015-01-24 23:56   ` Laurent Pinchart
@ 2015-01-26 10:14     ` Thierry Reding
  2015-01-26 10:24       ` Laurent Pinchart
  0 siblings, 1 reply; 29+ messages in thread
From: Thierry Reding @ 2015-01-26 10:14 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 5417 bytes --]

On Sun, Jan 25, 2015 at 01:56:51AM +0200, Laurent Pinchart wrote:
> Hi Thierry,
> 
> Thank you for the patch.
> 
> On Friday 23 January 2015 17:08:21 Thierry Reding wrote:
> > From: Thierry Reding <treding@nvidia.com>
> > 
> > Allow connector names to be used in the specification of the -s option.
> > This requires storing the string passed on the command-line so that it
> > can later be resolved to a connector ID (after the DRM device has been
> > opened).
> > 
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> >  tests/modetest/modetest.c | 134 +++++++++++++++++++++++++++++++++++++++----
> >  1 file changed, 123 insertions(+), 11 deletions(-)
> > 
> > diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> > index d5fd99ebe1fd..a7cc94f8938c 100644
> > --- a/tests/modetest/modetest.c
> > +++ b/tests/modetest/modetest.c
> 
> [snip]
> 
> > @@ -327,7 +328,7 @@ static void dump_connectors(struct device *dev)
> >  	int i, j;
> > 
> >  	printf("Connectors:\n");
> > -	printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
> > +	printf("id\tencoder\tstatus\t\tname\t\tsize (mm)\tmodes\tencoders\n");
> >  	for (i = 0; i < dev->resources->res->count_connectors; i++) {
> >  		struct connector *_connector = &dev->resources->connectors[i];
> >  		drmModeConnector *connector = _connector->connector;
> > @@ -338,7 +339,7 @@ static void dump_connectors(struct device *dev)
> >  		       connector->connector_id,
> >  		       connector->encoder_id,
> >  		       util_lookup_connector_status_name(connector->connection),
> > -		       util_lookup_connector_type_name(connector->connector_type),
> > +		       _connector->name,
> >  		       connector->mmWidth, connector->mmHeight,
> >  		       connector->count_modes);
> 
> As this is a low-level test tool I believe it would be useful to print both 
> the name and the ID. Maybe something like "name (id)" ?

The ID is already printed in the very first column.

> > @@ -511,6 +516,47 @@ static void free_resources(struct resources *res)
> >  	free(res);
> >  }
> > 
> > +static unsigned int get_connector_index(struct resources *res, uint32_t
> > type)
> > +{
> > +	unsigned int index = 0;
> > +	int i;
> > +
> > +	for (i = 0; i < res->res->count_connectors; i++)
> > +		if (res->connectors[i].connector->connector_type == type)
> > +			index++;
> > +
> > +	return index - 1;
> > +}
> > +
> > +static unsigned int get_order(unsigned int value)
> > +{
> > +	unsigned int order = 0;
> > +
> > +	do {
> > +		value /= 10;
> > +		order++;
> > +	} while (value > 0);
> > +
> > +	return order - 1;
> > +}
> > +
> > +static void connector_set_name(struct connector *connector,
> > +			       struct resources *res)
> > +{
> > +	uint32_t type = connector->connector->connector_type;
> > +	const char *type_name;
> > +	unsigned int index;
> > +	int len;
> > +
> > +	type_name = util_lookup_connector_type_name(type);
> > +	index = get_connector_index(res, type);
> 
> The kernel's connector name is created using connector_type_id, not the 
> connector index. Shouldn't we do the same here ?

The idea was to mirror what X was doing so that people familiar with the
xrandr tool would feel right at home. Note that the index here is by
type, not global. So you'd end up with something like this:

	HDMI-A-1
	HDMI-A-2
	LVDS-1

I think that's what most people would find to be the least surprising.
Using the connector_type_id would again introduce the potential to get
no-deterministic names (dependent on driver probe ordering in case of
multiple cards).

That said I now realize that this actually starts numbering connectors
at 0, so get_connector_index() should probably return index rather than
index - 1 to be consistent with what X does.

> > +	len = strlen(type_name) + get_order(index) + 2;
> 
> This looks like an over-optimization to me, can't you just add 9 to account 
> for the largest possible index ? Or, even better, use asprintf ? The function 
> is a GNU extension but is available on BSD according to its manpage.

Always using 9 characters would be wasting 8 bytes per connector for
something like 99% of the systems. I had thought about using asprintf
but decided not to use it because it isn't always available and it is
pretty simple to compute the actual length.

> > +static int pipe_resolve_connectors(struct pipe_arg *pipe, struct device
> > *dev)
> > +{
> > +	drmModeConnector *connector;
> > +	unsigned int i;
> > +	uint32_t id;
> > +	char *endp;
> > +
> > +	for (i = 0; i < pipe->num_cons; i++) {
> > +		id = strtoul(pipe->cons[i], &endp, 10);
> > +		if (endp == pipe->cons[i]) {
> 
> This won't have the expected behaviour for 9-pin DIN connectors, as the name 
> starts with a digit. You should instead test for *endp == '\0'.

Good catch. I've changed this check to:

	if (*endp != '\0') {
		... look up by name ...
	}

> > +			connector = get_connector_by_name(dev, pipe->cons[i]);
> > +			if (!connector) {
> > +				fprintf(stderr, "no connector named %s\n",
> > +					pipe->cons[i]);
> > +				return -ENODEV;
> > +			}
> > +
> > +			id = connector->connector_id;
> > +		}
> > +
> > +		pipe->con_ids[i] = id;
> > +	}
> > +
> > +	return 0;
> > +}
> 
> Could update the help text in usage() to reflect the new usage ?

Done.

Thierry

[-- Attachment #1.2: Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 08/11] tests: modetest: Accept connector names
  2015-01-26 10:14     ` Thierry Reding
@ 2015-01-26 10:24       ` Laurent Pinchart
  0 siblings, 0 replies; 29+ messages in thread
From: Laurent Pinchart @ 2015-01-26 10:24 UTC (permalink / raw)
  To: Thierry Reding; +Cc: dri-devel

Hi Thierry,

On Monday 26 January 2015 11:14:32 Thierry Reding wrote:
> On Sun, Jan 25, 2015 at 01:56:51AM +0200, Laurent Pinchart wrote:
> > On Friday 23 January 2015 17:08:21 Thierry Reding wrote:
> >> From: Thierry Reding <treding@nvidia.com>
> >> 
> >> Allow connector names to be used in the specification of the -s option.
> >> This requires storing the string passed on the command-line so that it
> >> can later be resolved to a connector ID (after the DRM device has been
> >> opened).
> >> 
> >> Signed-off-by: Thierry Reding <treding@nvidia.com>
> >> ---
> >> 
> >>  tests/modetest/modetest.c | 134 +++++++++++++++++++++++++++++++++++----
> >>  1 file changed, 123 insertions(+), 11 deletions(-)
> >> 
> >> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> >> index d5fd99ebe1fd..a7cc94f8938c 100644
> >> --- a/tests/modetest/modetest.c
> >> +++ b/tests/modetest/modetest.c
> > 
> > [snip]
> > 
> >> @@ -327,7 +328,7 @@ static void dump_connectors(struct device *dev)
> >> 
> >>  	int i, j;
> >>  	
> >>  	printf("Connectors:\n");
> >> 
> >> -	printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
> >> +	printf("id\tencoder\tstatus\t\tname\t\tsize
> >> (mm)\tmodes\tencoders\n");
> >> 
> >>  	for (i = 0; i < dev->resources->res->count_connectors; i++) {
> >>  	
> >>  		struct connector *_connector = &dev->resources->connectors[i];
> >>  		drmModeConnector *connector = _connector->connector;
> >> 
> >> @@ -338,7 +339,7 @@ static void dump_connectors(struct device *dev)
> >> 
> >>  		       connector->connector_id,
> >>  		       connector->encoder_id,
> >>  		       util_lookup_connector_status_name(connector->connection),
> >> 
> >> -		       util_lookup_connector_type_name(connector->
> >> connector_type),
> >> +		       _connector->name,
> >> 
> >>  		       connector->mmWidth, connector->mmHeight,
> >>  		       connector->count_modes);
> > 
> > As this is a low-level test tool I believe it would be useful to print
> > both the name and the ID. Maybe something like "name (id)" ?
> 
> The ID is already printed in the very first column.

My bad.

> >> @@ -511,6 +516,47 @@ static void free_resources(struct resources *res)
> >>  	free(res);
> >>  }
> >> 
> >> +static unsigned int get_connector_index(struct resources *res, uint32_t
> >> type)
> >> +{
> >> +	unsigned int index = 0;
> >> +	int i;
> >> +
> >> +	for (i = 0; i < res->res->count_connectors; i++)
> >> +		if (res->connectors[i].connector->connector_type == type)
> >> +			index++;
> >> +
> >> +	return index - 1;
> >> +}
> >> +
> >> +static unsigned int get_order(unsigned int value)
> >> +{
> >> +	unsigned int order = 0;
> >> +
> >> +	do {
> >> +		value /= 10;
> >> +		order++;
> >> +	} while (value > 0);
> >> +
> >> +	return order - 1;
> >> +}
> >> +
> >> +static void connector_set_name(struct connector *connector,
> >> +			       struct resources *res)
> >> +{
> >> +	uint32_t type = connector->connector->connector_type;
> >> +	const char *type_name;
> >> +	unsigned int index;
> >> +	int len;
> >> +
> >> +	type_name = util_lookup_connector_type_name(type);
> >> +	index = get_connector_index(res, type);
> > 
> > The kernel's connector name is created using connector_type_id, not the
> > connector index. Shouldn't we do the same here ?
> 
> The idea was to mirror what X was doing so that people familiar with the
> xrandr tool would feel right at home. Note that the index here is by
> type, not global. So you'd end up with something like this:
> 
> 	HDMI-A-1
> 	HDMI-A-2
> 	LVDS-1
> 
> I think that's what most people would find to be the least surprising.
> Using the connector_type_id would again introduce the potential to get
> no-deterministic names (dependent on driver probe ordering in case of
> multiple cards).

Isn't the index dependent on probe ordering as well ?

> That said I now realize that this actually starts numbering connectors
> at 0, so get_connector_index() should probably return index rather than
> index - 1 to be consistent with what X does.

Yes, I think that's a good idea.

> >> +	len = strlen(type_name) + get_order(index) + 2;
> > 
> > This looks like an over-optimization to me, can't you just add 9 to
> > account for the largest possible index ? Or, even better, use asprintf ?
> > The function is a GNU extension but is available on BSD according to its
> > manpage.
>
> Always using 9 characters would be wasting 8 bytes per connector for
> something like 99% of the systems.

We're talking about 8 bytes per connector for a test tool. With no more than a 
dozen of connectors. Right ? :-)

> I had thought about using asprintf but decided not to use it because it
> isn't always available and it is pretty simple to compute the actual length.

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH 04.1/11] SQUASH: tests: misc cleanups
  2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
  2015-01-24 23:24   ` Laurent Pinchart
@ 2015-01-29 15:27   ` Emil Velikov
  2015-01-29 15:27   ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
  2 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:27 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Cairo
 - Add cflags only when needed (tests/util).
 - Leave the link against cairo for the final object, not the static
library.
 - Use Makefile.sources for the sources list.
 - Drop unused includes

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/modetest/Makefile.am  |  1 -
 tests/modetest/buffers.c    |  5 -----
 tests/util/Makefile.am      | 12 +++---------
 tests/util/Makefile.sources |  6 ++++++
 4 files changed, 9 insertions(+), 15 deletions(-)
 create mode 100644 tests/util/Makefile.sources

diff --git a/tests/modetest/Makefile.am b/tests/modetest/Makefile.am
index 88fde2e..40dad3e 100644
--- a/tests/modetest/Makefile.am
+++ b/tests/modetest/Makefile.am
@@ -23,7 +23,6 @@ modetest_LDADD = \
 	-lpthread
 
 if HAVE_CAIRO
-AM_CFLAGS += $(CAIRO_CFLAGS)
 modetest_LDADD += $(CAIRO_LIBS)
 endif
 
diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c
index 4db4e9a..2db538c 100644
--- a/tests/modetest/buffers.c
+++ b/tests/modetest/buffers.c
@@ -44,11 +44,6 @@
 
 #include "buffers.h"
 
-#ifdef HAVE_CAIRO
-#include <math.h>
-#include <cairo.h>
-#endif
-
 struct bo
 {
 	int fd;
diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am
index 1a2519f..f8e0b17 100644
--- a/tests/util/Makefile.am
+++ b/tests/util/Makefile.am
@@ -1,3 +1,5 @@
+include Makefile.sources
+
 noinst_LTLIBRARIES = \
 	libutil.la
 
@@ -8,12 +10,4 @@ libutil_la_CPPFLAGS = \
 libutil_la_CFLAGS = \
 	$(CAIRO_CFLAGS)
 
-libutil_la_SOURCES = \
-	common.h \
-	format.c \
-	format.h \
-	pattern.c \
-	pattern.h
-
-libutil_la_LIBADD = \
-	$(CAIRO_LIBS)
+libutil_la_SOURCES = $(UTIL_FILES)
diff --git a/tests/util/Makefile.sources b/tests/util/Makefile.sources
new file mode 100644
index 0000000..e91fa72
--- /dev/null
+++ b/tests/util/Makefile.sources
@@ -0,0 +1,6 @@
+UTIL_FILES := \
+	common.h \
+	format.c \
+	format.h \
+	pattern.c \
+	pattern.h
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 04.2/11] SQUASH: util: add android build
  2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
  2015-01-24 23:24   ` Laurent Pinchart
  2015-01-29 15:27   ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
@ 2015-01-29 15:27   ` Emil Velikov
  2 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:27 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 Android.mk                |  1 +
 CleanSpec.mk              |  1 +
 tests/modetest/Android.mk |  5 ++++-
 tests/util/Android.mk     | 13 +++++++++++++
 4 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 tests/util/Android.mk

diff --git a/Android.mk b/Android.mk
index 6f76113..af5f7a9 100644
--- a/Android.mk
+++ b/Android.mk
@@ -57,6 +57,7 @@ SUBDIRS := \
 	nouveau \
 	radeon \
 	libkms \
+	tests/util \
 	tests/modetest
 
 mkfiles := $(patsubst %,$(LIBDRM_TOP)/%/Android.mk,$(SUBDIRS))
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 8e23cd2..28a11db 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -1,3 +1,4 @@
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/libdrm)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/freedreno)
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libdrm_*intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libdrm_*intermediates)
diff --git a/tests/modetest/Android.mk b/tests/modetest/Android.mk
index aee3564..6cf10dc 100644
--- a/tests/modetest/Android.mk
+++ b/tests/modetest/Android.mk
@@ -7,8 +7,11 @@ LOCAL_SRC_FILES := $(MODETEST_FILES)
 
 LOCAL_MODULE := modetest
 
-LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/libdrm
+LOCAL_C_INCLUDES += \
+	$(TARGET_OUT_HEADERS)/libdrm \
+	$(LIBDRM_TOP)/tests
 
 LOCAL_SHARED_LIBRARIES := libdrm
+LOCAL_STATIC_LIBRARIES := libdrm_util
 
 include $(BUILD_EXECUTABLE)
diff --git a/tests/util/Android.mk b/tests/util/Android.mk
new file mode 100644
index 0000000..4dc1cce
--- /dev/null
+++ b/tests/util/Android.mk
@@ -0,0 +1,13 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+include $(LOCAL_PATH)/Makefile.sources
+
+LOCAL_SRC_FILES := $(UTIL_FILES)
+
+LOCAL_MODULE := libdrm_util
+
+LOCAL_C_INCLUDES += \
+	$(TARGET_OUT_HEADERS)/libdrm
+
+include $(BUILD_STATIC_LIBRARY)
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources
  2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
  2015-01-24 23:24   ` Laurent Pinchart
@ 2015-01-29 15:28   ` Emil Velikov
  1 sibling, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:28 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/util/Makefile.sources | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/util/Makefile.sources b/tests/util/Makefile.sources
index e91fa72..e5f8511 100644
--- a/tests/util/Makefile.sources
+++ b/tests/util/Makefile.sources
@@ -2,5 +2,7 @@ UTIL_FILES := \
 	common.h \
 	format.c \
 	format.h \
+	kms.c \
+	kms.h \
 	pattern.c \
 	pattern.h
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution
  2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
@ 2015-01-29 15:30   ` Emil Velikov
  0 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:30 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/kms/Makefile.am | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index c84bae0..764a00d 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -8,6 +8,9 @@ AM_CFLAGS = \
 
 noinst_LTLIBRARIES = libkms-test.la
 
+noinst_HEADERS = \
+	libkms-test.h
+
 libkms_test_la_SOURCES = \
 	libkms-test-crtc.c \
 	libkms-test-device.c \
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo
  2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
@ 2015-01-29 15:30   ` Emil Velikov
  0 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:30 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/kms/Makefile.am | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index 0e1b4ef..d033934 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -29,5 +29,11 @@ noinst_PROGRAMS = \
 	kms-steal-crtc
 endif
 
+TEST_LIBS = libkms-test.la
+
+if HAVE_CAIRO
+TEST_LIBS += $(CAIRO_LIBS)
+endif
+
 kms_steal_crtc_SOURCES = kms-steal-crtc.c
-kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la
+kms_steal_crtc_LDADD = ../util/libutil.la $(TEST_LIBS)
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 11.1/11] SQUASH: kms-universal-planes: link against cairo
  2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
@ 2015-01-29 15:31   ` Emil Velikov
  0 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:31 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/kms/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index 3b37e3e..fe7dd98 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -41,4 +41,4 @@ kms_steal_crtc_SOURCES = kms-steal-crtc.c
 kms_steal_crtc_LDADD = ../util/libutil.la $(TEST_LIBS)
 
 kms_universal_planes_SOURCES = kms-universal-planes.c
-kms_universal_planes_LDADD = libkms-test.la
+kms_universal_planes_LDADD = $(TEST_LIBS)
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH libdrm 00/11] Random assortment of fixes and enhancements
  2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
                   ` (10 preceding siblings ...)
  2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
@ 2015-01-29 15:36 ` Emil Velikov
  11 siblings, 0 replies; 29+ messages in thread
From: Emil Velikov @ 2015-01-29 15:36 UTC (permalink / raw)
  To: Thierry Reding, dri-devel; +Cc: emil.l.velikov, Laurent Pinchart

On 23/01/15 16:08, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> This is a stash of commits that I've been carrying for a couple months.
> Laurent really wanted to have the connector name patch for modetest so
> I thought I'd send them all out for review.
> 
Hi Thierry,

As mentioned earlier I've noticed a couple of small bits while checking
out the Android build. Hope you don't mind my somewhat pedantic nit-picking.

The whole series can be found at

https://github.com/evelikov/libdrm/tree/for-tagr

-Emil

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2015-01-29 15:36 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
2015-01-24 23:20   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:27   ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
2015-01-29 15:27   ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:28   ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
2015-01-24 23:26   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
2015-01-24 23:40   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
2015-01-24 23:56   ` Laurent Pinchart
2015-01-26 10:14     ` Thierry Reding
2015-01-26 10:24       ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
2015-01-29 15:30   ` [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
2015-01-29 15:30   ` [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
2015-01-29 15:31   ` [PATCH 11.1/11] SQUASH: kms-universal-planes: link against cairo Emil Velikov
2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.