From: Thierry Reding <treding@xxxxxxxxxx> 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@xxxxxxxxxx> --- 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@xxxxxxxxxxxxxxxxxxxx> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@xxxxxxxxx> + * + * 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@xxxxxxxxxxxxxxxxxxxx> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@xxxxxxxxx> + * + * 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@xxxxxxxxxxxxxxxxxxxx> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@xxxxxxxxx> + * + * 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@xxxxxxxxxxxxxxxxxxxx> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@xxxxxxxxx> + * + * 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@xxxxxxxxxxxxxxxxxxxx> + * Copyright 2008 Intel Corporation + * Jesse Barnes <jesse.barnes@xxxxxxxxx> + * + * 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@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel