diff options
author | Thierry Reding | 2015-12-09 11:37:39 -0600 |
---|---|---|
committer | Emil Velikov | 2015-12-18 11:43:40 -0600 |
commit | 1ec3c44bdd38051d870f64d0b2cc7dbd59760386 (patch) | |
tree | 16736bbd48e66bee6592f10a8ec358d57d51e141 | |
parent | 15d90ef3504128a276923db840af1410ca255647 (diff) | |
download | external-libdrm-1ec3c44bdd38051d870f64d0b2cc7dbd59760386.tar.gz external-libdrm-1ec3c44bdd38051d870f64d0b2cc7dbd59760386.tar.xz external-libdrm-1ec3c44bdd38051d870f64d0b2cc7dbd59760386.zip |
tests: Split helpers into library
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.
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r-- | CleanSpec.mk | 1 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/modeprint/Makefile.am | 1 | ||||
-rw-r--r-- | tests/modeprint/modeprint.c | 2 | ||||
-rw-r--r-- | tests/modetest/Android.mk | 1 | ||||
-rw-r--r-- | tests/modetest/Makefile.am | 8 | ||||
-rw-r--r-- | tests/modetest/buffers.c | 961 | ||||
-rw-r--r-- | tests/modetest/buffers.h | 12 | ||||
-rw-r--r-- | tests/modetest/cursor.c | 4 | ||||
-rw-r--r-- | tests/modetest/modetest.c | 25 | ||||
-rw-r--r-- | tests/proptest/Makefile.am | 4 | ||||
-rw-r--r-- | tests/proptest/proptest.c | 3 | ||||
-rw-r--r-- | tests/util/Android.mk | 39 | ||||
-rw-r--r-- | tests/util/Makefile.am | 13 | ||||
-rw-r--r-- | tests/util/Makefile.sources | 6 | ||||
-rw-r--r-- | tests/util/common.h | 33 | ||||
-rw-r--r-- | tests/util/format.c | 120 | ||||
-rw-r--r-- | tests/util/format.h | 65 | ||||
-rw-r--r-- | tests/util/pattern.c | 870 | ||||
-rw-r--r-- | tests/util/pattern.h | 39 | ||||
-rw-r--r-- | tests/vbltest/Makefile.am | 1 | ||||
-rw-r--r-- | tests/vbltest/vbltest.c | 2 |
23 files changed, 1223 insertions, 990 deletions
diff --git a/CleanSpec.mk b/CleanSpec.mk index 8e23cd25..28a11db4 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk | |||
@@ -1,3 +1,4 @@ | |||
1 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/libdrm) | 1 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/libdrm) |
2 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/freedreno) | 2 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/include/freedreno) |
3 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libdrm_*intermediates) | 3 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libdrm_*intermediates) |
4 | $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libdrm_*intermediates) | ||
diff --git a/configure.ac b/configure.ac index b929d36a..ca6cbf4e 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -507,6 +507,7 @@ AC_CONFIG_FILES([ | |||
507 | tests/exynos/Makefile | 507 | tests/exynos/Makefile |
508 | tests/tegra/Makefile | 508 | tests/tegra/Makefile |
509 | tests/nouveau/Makefile | 509 | tests/nouveau/Makefile |
510 | tests/util/Makefile | ||
510 | man/Makefile | 511 | man/Makefile |
511 | libdrm.pc]) | 512 | libdrm.pc]) |
512 | AC_OUTPUT | 513 | AC_OUTPUT |
diff --git a/tests/Makefile.am b/tests/Makefile.am index c53f4af6..7ffc076f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -1,4 +1,4 @@ | |||
1 | SUBDIRS = modeprint proptest modetest vbltest | 1 | SUBDIRS = util modeprint proptest modetest vbltest |
2 | 2 | ||
3 | if HAVE_LIBKMS | 3 | if HAVE_LIBKMS |
4 | SUBDIRS += kmstest | 4 | SUBDIRS += kmstest |
diff --git a/tests/modeprint/Makefile.am b/tests/modeprint/Makefile.am index 895805fd..601dbc96 100644 --- a/tests/modeprint/Makefile.am +++ b/tests/modeprint/Makefile.am | |||
@@ -1,6 +1,7 @@ | |||
1 | AM_CFLAGS = \ | 1 | AM_CFLAGS = \ |
2 | $(WARN_CFLAGS)\ | 2 | $(WARN_CFLAGS)\ |
3 | -I$(top_srcdir)/include/drm \ | 3 | -I$(top_srcdir)/include/drm \ |
4 | -I$(top_srcdir)/tests \ | ||
4 | -I$(top_srcdir) | 5 | -I$(top_srcdir) |
5 | 6 | ||
6 | if HAVE_INSTALL_TESTS | 7 | if HAVE_INSTALL_TESTS |
diff --git a/tests/modeprint/modeprint.c b/tests/modeprint/modeprint.c index 5e953f71..0d854103 100644 --- a/tests/modeprint/modeprint.c +++ b/tests/modeprint/modeprint.c | |||
@@ -41,7 +41,7 @@ | |||
41 | #include "xf86drm.h" | 41 | #include "xf86drm.h" |
42 | #include "xf86drmMode.h" | 42 | #include "xf86drmMode.h" |
43 | 43 | ||
44 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) | 44 | #include "util/common.h" |
45 | 45 | ||
46 | int current; | 46 | int current; |
47 | int connectors; | 47 | int connectors; |
diff --git a/tests/modetest/Android.mk b/tests/modetest/Android.mk index 0fdfe685..e616558f 100644 --- a/tests/modetest/Android.mk +++ b/tests/modetest/Android.mk | |||
@@ -8,5 +8,6 @@ LOCAL_SRC_FILES := $(MODETEST_FILES) | |||
8 | LOCAL_MODULE := modetest | 8 | LOCAL_MODULE := modetest |
9 | 9 | ||
10 | LOCAL_SHARED_LIBRARIES := libdrm | 10 | LOCAL_SHARED_LIBRARIES := libdrm |
11 | LOCAL_STATIC_LIBRARIES := libdrm_util | ||
11 | 12 | ||
12 | include $(BUILD_EXECUTABLE) | 13 | include $(BUILD_EXECUTABLE) |
diff --git a/tests/modetest/Makefile.am b/tests/modetest/Makefile.am index 93820fac..25ce372f 100644 --- a/tests/modetest/Makefile.am +++ b/tests/modetest/Makefile.am | |||
@@ -4,6 +4,7 @@ AM_CFLAGS = $(filter-out -Wpointer-arith, $(WARN_CFLAGS)) | |||
4 | 4 | ||
5 | AM_CFLAGS += \ | 5 | AM_CFLAGS += \ |
6 | -I$(top_srcdir)/include/drm \ | 6 | -I$(top_srcdir)/include/drm \ |
7 | -I$(top_srcdir)/tests \ | ||
7 | -I$(top_srcdir) | 8 | -I$(top_srcdir) |
8 | 9 | ||
9 | if HAVE_INSTALL_TESTS | 10 | if HAVE_INSTALL_TESTS |
@@ -18,11 +19,8 @@ modetest_SOURCES = $(MODETEST_FILES) | |||
18 | 19 | ||
19 | modetest_LDADD = \ | 20 | modetest_LDADD = \ |
20 | $(top_builddir)/libdrm.la \ | 21 | $(top_builddir)/libdrm.la \ |
22 | $(top_builddir)/tests/util/libutil.la \ | ||
23 | $(CAIRO_LIBS) \ | ||
21 | -lpthread | 24 | -lpthread |
22 | 25 | ||
23 | if HAVE_CAIRO | ||
24 | AM_CFLAGS += $(CAIRO_CFLAGS) | ||
25 | modetest_LDADD += $(CAIRO_LIBS) | ||
26 | endif | ||
27 | |||
28 | EXTRA_DIST = Android.mk | 26 | EXTRA_DIST = Android.mk |
diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c index ebb14ef8..4fd310b9 100644 --- a/tests/modetest/buffers.c +++ b/tests/modetest/buffers.c | |||
@@ -44,13 +44,6 @@ | |||
44 | 44 | ||
45 | #include "buffers.h" | 45 | #include "buffers.h" |
46 | 46 | ||
47 | #ifdef HAVE_CAIRO | ||
48 | #include <math.h> | ||
49 | #include <cairo.h> | ||
50 | #endif | ||
51 | |||
52 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
53 | |||
54 | struct bo | 47 | struct bo |
55 | { | 48 | { |
56 | int fd; | 49 | int fd; |
@@ -62,956 +55,6 @@ struct bo | |||
62 | }; | 55 | }; |
63 | 56 | ||
64 | /* ----------------------------------------------------------------------------- | 57 | /* ----------------------------------------------------------------------------- |
65 | * Formats | ||
66 | */ | ||
67 | |||
68 | struct color_component { | ||
69 | unsigned int length; | ||
70 | unsigned int offset; | ||
71 | }; | ||
72 | |||
73 | struct rgb_info { | ||
74 | struct color_component red; | ||
75 | struct color_component green; | ||
76 | struct color_component blue; | ||
77 | struct color_component alpha; | ||
78 | }; | ||
79 | |||
80 | enum yuv_order { | ||
81 | YUV_YCbCr = 1, | ||
82 | YUV_YCrCb = 2, | ||
83 | YUV_YC = 4, | ||
84 | YUV_CY = 8, | ||
85 | }; | ||
86 | |||
87 | struct yuv_info { | ||
88 | enum yuv_order order; | ||
89 | unsigned int xsub; | ||
90 | unsigned int ysub; | ||
91 | unsigned int chroma_stride; | ||
92 | }; | ||
93 | |||
94 | struct format_info { | ||
95 | unsigned int format; | ||
96 | const char *name; | ||
97 | const struct rgb_info rgb; | ||
98 | const struct yuv_info yuv; | ||
99 | }; | ||
100 | |||
101 | #define MAKE_RGB_INFO(rl, ro, gl, go, bl, bo, al, ao) \ | ||
102 | .rgb = { { (rl), (ro) }, { (gl), (go) }, { (bl), (bo) }, { (al), (ao) } } | ||
103 | |||
104 | #define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \ | ||
105 | .yuv = { (order), (xsub), (ysub), (chroma_stride) } | ||
106 | |||
107 | static const struct format_info format_info[] = { | ||
108 | /* YUV packed */ | ||
109 | { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) }, | ||
110 | { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) }, | ||
111 | { DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) }, | ||
112 | { DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) }, | ||
113 | /* YUV semi-planar */ | ||
114 | { DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) }, | ||
115 | { DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) }, | ||
116 | { DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) }, | ||
117 | { DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) }, | ||
118 | /* YUV planar */ | ||
119 | { DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) }, | ||
120 | { DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) }, | ||
121 | /* RGB16 */ | ||
122 | { DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) }, | ||
123 | { DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) }, | ||
124 | { DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) }, | ||
125 | { DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) }, | ||
126 | { DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) }, | ||
127 | { DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) }, | ||
128 | { DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) }, | ||
129 | { DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) }, | ||
130 | { DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) }, | ||
131 | { DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) }, | ||
132 | { DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) }, | ||
133 | { DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) }, | ||
134 | { DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) }, | ||
135 | { DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) }, | ||
136 | { DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) }, | ||
137 | { DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) }, | ||
138 | { DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) }, | ||
139 | { DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) }, | ||
140 | /* RGB24 */ | ||
141 | { DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, | ||
142 | { DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, | ||
143 | /* RGB32 */ | ||
144 | { DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) }, | ||
145 | { DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, | ||
146 | { DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) }, | ||
147 | { DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, | ||
148 | { DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) }, | ||
149 | { DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) }, | ||
150 | { DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) }, | ||
151 | { DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) }, | ||
152 | { DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) }, | ||
153 | { DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) }, | ||
154 | { DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) }, | ||
155 | { DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) }, | ||
156 | { DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) }, | ||
157 | { DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) }, | ||
158 | { DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) }, | ||
159 | { DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) }, | ||
160 | }; | ||
161 | |||
162 | unsigned int format_fourcc(const char *name) | ||
163 | { | ||
164 | unsigned int i; | ||
165 | for (i = 0; i < ARRAY_SIZE(format_info); i++) { | ||
166 | if (!strcmp(format_info[i].name, name)) | ||
167 | return format_info[i].format; | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | /* ----------------------------------------------------------------------------- | ||
173 | * Test patterns | ||
174 | */ | ||
175 | |||
176 | struct color_rgb24 { | ||
177 | unsigned int value:24; | ||
178 | } __attribute__((__packed__)); | ||
179 | |||
180 | struct color_yuv { | ||
181 | unsigned char y; | ||
182 | unsigned char u; | ||
183 | unsigned char v; | ||
184 | }; | ||
185 | |||
186 | #define MAKE_YUV_601_Y(r, g, b) \ | ||
187 | ((( 66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16) | ||
188 | #define MAKE_YUV_601_U(r, g, b) \ | ||
189 | (((-38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128) | ||
190 | #define MAKE_YUV_601_V(r, g, b) \ | ||
191 | (((112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128) | ||
192 | |||
193 | #define MAKE_YUV_601(r, g, b) \ | ||
194 | { .y = MAKE_YUV_601_Y(r, g, b), \ | ||
195 | .u = MAKE_YUV_601_U(r, g, b), \ | ||
196 | .v = MAKE_YUV_601_V(r, g, b) } | ||
197 | |||
198 | #define MAKE_RGBA(rgb, r, g, b, a) \ | ||
199 | ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \ | ||
200 | (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \ | ||
201 | (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \ | ||
202 | (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset)) | ||
203 | |||
204 | #define MAKE_RGB24(rgb, r, g, b) \ | ||
205 | { .value = MAKE_RGBA(rgb, r, g, b, 0) } | ||
206 | |||
207 | static void | ||
208 | fill_smpte_yuv_planar(const struct yuv_info *yuv, | ||
209 | unsigned char *y_mem, unsigned char *u_mem, | ||
210 | unsigned char *v_mem, unsigned int width, | ||
211 | unsigned int height, unsigned int stride) | ||
212 | { | ||
213 | const struct color_yuv colors_top[] = { | ||
214 | MAKE_YUV_601(191, 192, 192), /* grey */ | ||
215 | MAKE_YUV_601(192, 192, 0), /* yellow */ | ||
216 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
217 | MAKE_YUV_601(0, 192, 0), /* green */ | ||
218 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
219 | MAKE_YUV_601(192, 0, 0), /* red */ | ||
220 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
221 | }; | ||
222 | const struct color_yuv colors_middle[] = { | ||
223 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
224 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
225 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
226 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
227 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
228 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
229 | MAKE_YUV_601(192, 192, 192), /* grey */ | ||
230 | }; | ||
231 | const struct color_yuv colors_bottom[] = { | ||
232 | MAKE_YUV_601(0, 33, 76), /* in-phase */ | ||
233 | MAKE_YUV_601(255, 255, 255), /* super white */ | ||
234 | MAKE_YUV_601(50, 0, 106), /* quadrature */ | ||
235 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
236 | MAKE_YUV_601(9, 9, 9), /* 3.5% */ | ||
237 | MAKE_YUV_601(19, 19, 19), /* 7.5% */ | ||
238 | MAKE_YUV_601(29, 29, 29), /* 11.5% */ | ||
239 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
240 | }; | ||
241 | unsigned int cs = yuv->chroma_stride; | ||
242 | unsigned int xsub = yuv->xsub; | ||
243 | unsigned int ysub = yuv->ysub; | ||
244 | unsigned int x; | ||
245 | unsigned int y; | ||
246 | |||
247 | /* Luma */ | ||
248 | for (y = 0; y < height * 6 / 9; ++y) { | ||
249 | for (x = 0; x < width; ++x) | ||
250 | y_mem[x] = colors_top[x * 7 / width].y; | ||
251 | y_mem += stride; | ||
252 | } | ||
253 | |||
254 | for (; y < height * 7 / 9; ++y) { | ||
255 | for (x = 0; x < width; ++x) | ||
256 | y_mem[x] = colors_middle[x * 7 / width].y; | ||
257 | y_mem += stride; | ||
258 | } | ||
259 | |||
260 | for (; y < height; ++y) { | ||
261 | for (x = 0; x < width * 5 / 7; ++x) | ||
262 | y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y; | ||
263 | for (; x < width * 6 / 7; ++x) | ||
264 | y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3 | ||
265 | / (width / 7) + 4].y; | ||
266 | for (; x < width; ++x) | ||
267 | y_mem[x] = colors_bottom[7].y; | ||
268 | y_mem += stride; | ||
269 | } | ||
270 | |||
271 | /* Chroma */ | ||
272 | for (y = 0; y < height / ysub * 6 / 9; ++y) { | ||
273 | for (x = 0; x < width; x += xsub) { | ||
274 | u_mem[x*cs/xsub] = colors_top[x * 7 / width].u; | ||
275 | v_mem[x*cs/xsub] = colors_top[x * 7 / width].v; | ||
276 | } | ||
277 | u_mem += stride * cs / xsub; | ||
278 | v_mem += stride * cs / xsub; | ||
279 | } | ||
280 | |||
281 | for (; y < height / ysub * 7 / 9; ++y) { | ||
282 | for (x = 0; x < width; x += xsub) { | ||
283 | u_mem[x*cs/xsub] = colors_middle[x * 7 / width].u; | ||
284 | v_mem[x*cs/xsub] = colors_middle[x * 7 / width].v; | ||
285 | } | ||
286 | u_mem += stride * cs / xsub; | ||
287 | v_mem += stride * cs / xsub; | ||
288 | } | ||
289 | |||
290 | for (; y < height / ysub; ++y) { | ||
291 | for (x = 0; x < width * 5 / 7; x += xsub) { | ||
292 | u_mem[x*cs/xsub] = | ||
293 | colors_bottom[x * 4 / (width * 5 / 7)].u; | ||
294 | v_mem[x*cs/xsub] = | ||
295 | colors_bottom[x * 4 / (width * 5 / 7)].v; | ||
296 | } | ||
297 | for (; x < width * 6 / 7; x += xsub) { | ||
298 | u_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * | ||
299 | 3 / (width / 7) + 4].u; | ||
300 | v_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * | ||
301 | 3 / (width / 7) + 4].v; | ||
302 | } | ||
303 | for (; x < width; x += xsub) { | ||
304 | u_mem[x*cs/xsub] = colors_bottom[7].u; | ||
305 | v_mem[x*cs/xsub] = colors_bottom[7].v; | ||
306 | } | ||
307 | u_mem += stride * cs / xsub; | ||
308 | v_mem += stride * cs / xsub; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | static void | ||
313 | fill_smpte_yuv_packed(const struct yuv_info *yuv, unsigned char *mem, | ||
314 | unsigned int width, unsigned int height, | ||
315 | unsigned int stride) | ||
316 | { | ||
317 | const struct color_yuv colors_top[] = { | ||
318 | MAKE_YUV_601(191, 192, 192), /* grey */ | ||
319 | MAKE_YUV_601(192, 192, 0), /* yellow */ | ||
320 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
321 | MAKE_YUV_601(0, 192, 0), /* green */ | ||
322 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
323 | MAKE_YUV_601(192, 0, 0), /* red */ | ||
324 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
325 | }; | ||
326 | const struct color_yuv colors_middle[] = { | ||
327 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
328 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
329 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
330 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
331 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
332 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
333 | MAKE_YUV_601(192, 192, 192), /* grey */ | ||
334 | }; | ||
335 | const struct color_yuv colors_bottom[] = { | ||
336 | MAKE_YUV_601(0, 33, 76), /* in-phase */ | ||
337 | MAKE_YUV_601(255, 255, 255), /* super white */ | ||
338 | MAKE_YUV_601(50, 0, 106), /* quadrature */ | ||
339 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
340 | MAKE_YUV_601(9, 9, 9), /* 3.5% */ | ||
341 | MAKE_YUV_601(19, 19, 19), /* 7.5% */ | ||
342 | MAKE_YUV_601(29, 29, 29), /* 11.5% */ | ||
343 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
344 | }; | ||
345 | unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; | ||
346 | unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; | ||
347 | unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; | ||
348 | unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; | ||
349 | unsigned int x; | ||
350 | unsigned int y; | ||
351 | |||
352 | /* Luma */ | ||
353 | for (y = 0; y < height * 6 / 9; ++y) { | ||
354 | for (x = 0; x < width; ++x) | ||
355 | y_mem[2*x] = colors_top[x * 7 / width].y; | ||
356 | y_mem += stride; | ||
357 | } | ||
358 | |||
359 | for (; y < height * 7 / 9; ++y) { | ||
360 | for (x = 0; x < width; ++x) | ||
361 | y_mem[2*x] = colors_middle[x * 7 / width].y; | ||
362 | y_mem += stride; | ||
363 | } | ||
364 | |||
365 | for (; y < height; ++y) { | ||
366 | for (x = 0; x < width * 5 / 7; ++x) | ||
367 | y_mem[2*x] = colors_bottom[x * 4 / (width * 5 / 7)].y; | ||
368 | for (; x < width * 6 / 7; ++x) | ||
369 | y_mem[2*x] = colors_bottom[(x - width * 5 / 7) * 3 | ||
370 | / (width / 7) + 4].y; | ||
371 | for (; x < width; ++x) | ||
372 | y_mem[2*x] = colors_bottom[7].y; | ||
373 | y_mem += stride; | ||
374 | } | ||
375 | |||
376 | /* Chroma */ | ||
377 | for (y = 0; y < height * 6 / 9; ++y) { | ||
378 | for (x = 0; x < width; x += 2) { | ||
379 | c_mem[2*x+u] = colors_top[x * 7 / width].u; | ||
380 | c_mem[2*x+v] = colors_top[x * 7 / width].v; | ||
381 | } | ||
382 | c_mem += stride; | ||
383 | } | ||
384 | |||
385 | for (; y < height * 7 / 9; ++y) { | ||
386 | for (x = 0; x < width; x += 2) { | ||
387 | c_mem[2*x+u] = colors_middle[x * 7 / width].u; | ||
388 | c_mem[2*x+v] = colors_middle[x * 7 / width].v; | ||
389 | } | ||
390 | c_mem += stride; | ||
391 | } | ||
392 | |||
393 | for (; y < height; ++y) { | ||
394 | for (x = 0; x < width * 5 / 7; x += 2) { | ||
395 | c_mem[2*x+u] = colors_bottom[x * 4 / (width * 5 / 7)].u; | ||
396 | c_mem[2*x+v] = colors_bottom[x * 4 / (width * 5 / 7)].v; | ||
397 | } | ||
398 | for (; x < width * 6 / 7; x += 2) { | ||
399 | c_mem[2*x+u] = colors_bottom[(x - width * 5 / 7) * | ||
400 | 3 / (width / 7) + 4].u; | ||
401 | c_mem[2*x+v] = colors_bottom[(x - width * 5 / 7) * | ||
402 | 3 / (width / 7) + 4].v; | ||
403 | } | ||
404 | for (; x < width; x += 2) { | ||
405 | c_mem[2*x+u] = colors_bottom[7].u; | ||
406 | c_mem[2*x+v] = colors_bottom[7].v; | ||
407 | } | ||
408 | c_mem += stride; | ||
409 | } | ||
410 | } | ||
411 | |||
412 | static void | ||
413 | fill_smpte_rgb16(const struct rgb_info *rgb, unsigned char *mem, | ||
414 | unsigned int width, unsigned int height, unsigned int stride) | ||
415 | { | ||
416 | const uint16_t colors_top[] = { | ||
417 | MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ | ||
418 | MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ | ||
419 | MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ | ||
420 | MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ | ||
421 | MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ | ||
422 | MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ | ||
423 | MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ | ||
424 | }; | ||
425 | const uint16_t colors_middle[] = { | ||
426 | MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ | ||
427 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
428 | MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ | ||
429 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
430 | MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ | ||
431 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
432 | MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ | ||
433 | }; | ||
434 | const uint16_t colors_bottom[] = { | ||
435 | MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ | ||
436 | MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ | ||
437 | MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ | ||
438 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
439 | MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ | ||
440 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ | ||
441 | MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ | ||
442 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
443 | }; | ||
444 | unsigned int x; | ||
445 | unsigned int y; | ||
446 | |||
447 | for (y = 0; y < height * 6 / 9; ++y) { | ||
448 | for (x = 0; x < width; ++x) | ||
449 | ((uint16_t *)mem)[x] = colors_top[x * 7 / width]; | ||
450 | mem += stride; | ||
451 | } | ||
452 | |||
453 | for (; y < height * 7 / 9; ++y) { | ||
454 | for (x = 0; x < width; ++x) | ||
455 | ((uint16_t *)mem)[x] = colors_middle[x * 7 / width]; | ||
456 | mem += stride; | ||
457 | } | ||
458 | |||
459 | for (; y < height; ++y) { | ||
460 | for (x = 0; x < width * 5 / 7; ++x) | ||
461 | ((uint16_t *)mem)[x] = | ||
462 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
463 | for (; x < width * 6 / 7; ++x) | ||
464 | ((uint16_t *)mem)[x] = | ||
465 | colors_bottom[(x - width * 5 / 7) * 3 | ||
466 | / (width / 7) + 4]; | ||
467 | for (; x < width; ++x) | ||
468 | ((uint16_t *)mem)[x] = colors_bottom[7]; | ||
469 | mem += stride; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | static void | ||
474 | fill_smpte_rgb24(const struct rgb_info *rgb, void *mem, | ||
475 | unsigned int width, unsigned int height, unsigned int stride) | ||
476 | { | ||
477 | const struct color_rgb24 colors_top[] = { | ||
478 | MAKE_RGB24(rgb, 192, 192, 192), /* grey */ | ||
479 | MAKE_RGB24(rgb, 192, 192, 0), /* yellow */ | ||
480 | MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ | ||
481 | MAKE_RGB24(rgb, 0, 192, 0), /* green */ | ||
482 | MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ | ||
483 | MAKE_RGB24(rgb, 192, 0, 0), /* red */ | ||
484 | MAKE_RGB24(rgb, 0, 0, 192), /* blue */ | ||
485 | }; | ||
486 | const struct color_rgb24 colors_middle[] = { | ||
487 | MAKE_RGB24(rgb, 0, 0, 192), /* blue */ | ||
488 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
489 | MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ | ||
490 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
491 | MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ | ||
492 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
493 | MAKE_RGB24(rgb, 192, 192, 192), /* grey */ | ||
494 | }; | ||
495 | const struct color_rgb24 colors_bottom[] = { | ||
496 | MAKE_RGB24(rgb, 0, 33, 76), /* in-phase */ | ||
497 | MAKE_RGB24(rgb, 255, 255, 255), /* super white */ | ||
498 | MAKE_RGB24(rgb, 50, 0, 106), /* quadrature */ | ||
499 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
500 | MAKE_RGB24(rgb, 9, 9, 9), /* 3.5% */ | ||
501 | MAKE_RGB24(rgb, 19, 19, 19), /* 7.5% */ | ||
502 | MAKE_RGB24(rgb, 29, 29, 29), /* 11.5% */ | ||
503 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
504 | }; | ||
505 | unsigned int x; | ||
506 | unsigned int y; | ||
507 | |||
508 | for (y = 0; y < height * 6 / 9; ++y) { | ||
509 | for (x = 0; x < width; ++x) | ||
510 | ((struct color_rgb24 *)mem)[x] = | ||
511 | colors_top[x * 7 / width]; | ||
512 | mem += stride; | ||
513 | } | ||
514 | |||
515 | for (; y < height * 7 / 9; ++y) { | ||
516 | for (x = 0; x < width; ++x) | ||
517 | ((struct color_rgb24 *)mem)[x] = | ||
518 | colors_middle[x * 7 / width]; | ||
519 | mem += stride; | ||
520 | } | ||
521 | |||
522 | for (; y < height; ++y) { | ||
523 | for (x = 0; x < width * 5 / 7; ++x) | ||
524 | ((struct color_rgb24 *)mem)[x] = | ||
525 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
526 | for (; x < width * 6 / 7; ++x) | ||
527 | ((struct color_rgb24 *)mem)[x] = | ||
528 | colors_bottom[(x - width * 5 / 7) * 3 | ||
529 | / (width / 7) + 4]; | ||
530 | for (; x < width; ++x) | ||
531 | ((struct color_rgb24 *)mem)[x] = colors_bottom[7]; | ||
532 | mem += stride; | ||
533 | } | ||
534 | } | ||
535 | |||
536 | static void | ||
537 | fill_smpte_rgb32(const struct rgb_info *rgb, unsigned char *mem, | ||
538 | unsigned int width, unsigned int height, unsigned int stride) | ||
539 | { | ||
540 | const uint32_t colors_top[] = { | ||
541 | MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ | ||
542 | MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ | ||
543 | MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ | ||
544 | MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ | ||
545 | MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ | ||
546 | MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ | ||
547 | MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ | ||
548 | }; | ||
549 | const uint32_t colors_middle[] = { | ||
550 | MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ | ||
551 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
552 | MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ | ||
553 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
554 | MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ | ||
555 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
556 | MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ | ||
557 | }; | ||
558 | const uint32_t colors_bottom[] = { | ||
559 | MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ | ||
560 | MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ | ||
561 | MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ | ||
562 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
563 | MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ | ||
564 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ | ||
565 | MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ | ||
566 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
567 | }; | ||
568 | unsigned int x; | ||
569 | unsigned int y; | ||
570 | |||
571 | for (y = 0; y < height * 6 / 9; ++y) { | ||
572 | for (x = 0; x < width; ++x) | ||
573 | ((uint32_t *)mem)[x] = colors_top[x * 7 / width]; | ||
574 | mem += stride; | ||
575 | } | ||
576 | |||
577 | for (; y < height * 7 / 9; ++y) { | ||
578 | for (x = 0; x < width; ++x) | ||
579 | ((uint32_t *)mem)[x] = colors_middle[x * 7 / width]; | ||
580 | mem += stride; | ||
581 | } | ||
582 | |||
583 | for (; y < height; ++y) { | ||
584 | for (x = 0; x < width * 5 / 7; ++x) | ||
585 | ((uint32_t *)mem)[x] = | ||
586 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
587 | for (; x < width * 6 / 7; ++x) | ||
588 | ((uint32_t *)mem)[x] = | ||
589 | colors_bottom[(x - width * 5 / 7) * 3 | ||
590 | / (width / 7) + 4]; | ||
591 | for (; x < width; ++x) | ||
592 | ((uint32_t *)mem)[x] = colors_bottom[7]; | ||
593 | mem += stride; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | static void | ||
598 | fill_smpte(const struct format_info *info, void *planes[3], unsigned int width, | ||
599 | unsigned int height, unsigned int stride) | ||
600 | { | ||
601 | unsigned char *u, *v; | ||
602 | |||
603 | switch (info->format) { | ||
604 | case DRM_FORMAT_UYVY: | ||
605 | case DRM_FORMAT_VYUY: | ||
606 | case DRM_FORMAT_YUYV: | ||
607 | case DRM_FORMAT_YVYU: | ||
608 | return fill_smpte_yuv_packed(&info->yuv, planes[0], width, | ||
609 | height, stride); | ||
610 | |||
611 | case DRM_FORMAT_NV12: | ||
612 | case DRM_FORMAT_NV21: | ||
613 | case DRM_FORMAT_NV16: | ||
614 | case DRM_FORMAT_NV61: | ||
615 | u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; | ||
616 | v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; | ||
617 | return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v, | ||
618 | width, height, stride); | ||
619 | |||
620 | case DRM_FORMAT_YUV420: | ||
621 | return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1], | ||
622 | planes[2], width, height, stride); | ||
623 | |||
624 | case DRM_FORMAT_YVU420: | ||
625 | return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2], | ||
626 | planes[1], width, height, stride); | ||
627 | |||
628 | case DRM_FORMAT_ARGB4444: | ||
629 | case DRM_FORMAT_XRGB4444: | ||
630 | case DRM_FORMAT_ABGR4444: | ||
631 | case DRM_FORMAT_XBGR4444: | ||
632 | case DRM_FORMAT_RGBA4444: | ||
633 | case DRM_FORMAT_RGBX4444: | ||
634 | case DRM_FORMAT_BGRA4444: | ||
635 | case DRM_FORMAT_BGRX4444: | ||
636 | case DRM_FORMAT_RGB565: | ||
637 | case DRM_FORMAT_BGR565: | ||
638 | case DRM_FORMAT_ARGB1555: | ||
639 | case DRM_FORMAT_XRGB1555: | ||
640 | case DRM_FORMAT_ABGR1555: | ||
641 | case DRM_FORMAT_XBGR1555: | ||
642 | case DRM_FORMAT_RGBA5551: | ||
643 | case DRM_FORMAT_RGBX5551: | ||
644 | case DRM_FORMAT_BGRA5551: | ||
645 | case DRM_FORMAT_BGRX5551: | ||
646 | return fill_smpte_rgb16(&info->rgb, planes[0], | ||
647 | width, height, stride); | ||
648 | |||
649 | case DRM_FORMAT_BGR888: | ||
650 | case DRM_FORMAT_RGB888: | ||
651 | return fill_smpte_rgb24(&info->rgb, planes[0], | ||
652 | width, height, stride); | ||
653 | case DRM_FORMAT_ARGB8888: | ||
654 | case DRM_FORMAT_XRGB8888: | ||
655 | case DRM_FORMAT_ABGR8888: | ||
656 | case DRM_FORMAT_XBGR8888: | ||
657 | case DRM_FORMAT_RGBA8888: | ||
658 | case DRM_FORMAT_RGBX8888: | ||
659 | case DRM_FORMAT_BGRA8888: | ||
660 | case DRM_FORMAT_BGRX8888: | ||
661 | case DRM_FORMAT_ARGB2101010: | ||
662 | case DRM_FORMAT_XRGB2101010: | ||
663 | case DRM_FORMAT_ABGR2101010: | ||
664 | case DRM_FORMAT_XBGR2101010: | ||
665 | case DRM_FORMAT_RGBA1010102: | ||
666 | case DRM_FORMAT_RGBX1010102: | ||
667 | case DRM_FORMAT_BGRA1010102: | ||
668 | case DRM_FORMAT_BGRX1010102: | ||
669 | return fill_smpte_rgb32(&info->rgb, planes[0], | ||
670 | width, height, stride); | ||
671 | } | ||
672 | } | ||
673 | |||
674 | /* swap these for big endian.. */ | ||
675 | #define RED 2 | ||
676 | #define GREEN 1 | ||
677 | #define BLUE 0 | ||
678 | |||
679 | static void | ||
680 | make_pwetty(void *data, int width, int height, int stride, uint32_t format) | ||
681 | { | ||
682 | #ifdef HAVE_CAIRO | ||
683 | cairo_surface_t *surface; | ||
684 | cairo_t *cr; | ||
685 | int x, y; | ||
686 | cairo_format_t cairo_format; | ||
687 | |||
688 | /* we can ignore the order of R,G,B channels */ | ||
689 | switch (format) { | ||
690 | case DRM_FORMAT_XRGB8888: | ||
691 | case DRM_FORMAT_ARGB8888: | ||
692 | case DRM_FORMAT_XBGR8888: | ||
693 | case DRM_FORMAT_ABGR8888: | ||
694 | cairo_format = CAIRO_FORMAT_ARGB32; | ||
695 | break; | ||
696 | case DRM_FORMAT_RGB565: | ||
697 | case DRM_FORMAT_BGR565: | ||
698 | cairo_format = CAIRO_FORMAT_RGB16_565; | ||
699 | break; | ||
700 | default: | ||
701 | return; | ||
702 | } | ||
703 | |||
704 | surface = cairo_image_surface_create_for_data(data, | ||
705 | cairo_format, | ||
706 | width, height, | ||
707 | stride); | ||
708 | cr = cairo_create(surface); | ||
709 | cairo_surface_destroy(surface); | ||
710 | |||
711 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); | ||
712 | for (x = 0; x < width; x += 250) | ||
713 | for (y = 0; y < height; y += 250) { | ||
714 | char buf[64]; | ||
715 | |||
716 | cairo_move_to(cr, x, y - 20); | ||
717 | cairo_line_to(cr, x, y + 20); | ||
718 | cairo_move_to(cr, x - 20, y); | ||
719 | cairo_line_to(cr, x + 20, y); | ||
720 | cairo_new_sub_path(cr); | ||
721 | cairo_arc(cr, x, y, 10, 0, M_PI * 2); | ||
722 | cairo_set_line_width(cr, 4); | ||
723 | cairo_set_source_rgb(cr, 0, 0, 0); | ||
724 | cairo_stroke_preserve(cr); | ||
725 | cairo_set_source_rgb(cr, 1, 1, 1); | ||
726 | cairo_set_line_width(cr, 2); | ||
727 | cairo_stroke(cr); | ||
728 | |||
729 | snprintf(buf, sizeof buf, "%d, %d", x, y); | ||
730 | cairo_move_to(cr, x + 20, y + 20); | ||
731 | cairo_text_path(cr, buf); | ||
732 | cairo_set_source_rgb(cr, 0, 0, 0); | ||
733 | cairo_stroke_preserve(cr); | ||
734 | cairo_set_source_rgb(cr, 1, 1, 1); | ||
735 | cairo_fill(cr); | ||
736 | } | ||
737 | |||
738 | cairo_destroy(cr); | ||
739 | #endif | ||
740 | } | ||
741 | |||
742 | static void | ||
743 | fill_tiles_yuv_planar(const struct format_info *info, | ||
744 | unsigned char *y_mem, unsigned char *u_mem, | ||
745 | unsigned char *v_mem, unsigned int width, | ||
746 | unsigned int height, unsigned int stride) | ||
747 | { | ||
748 | const struct yuv_info *yuv = &info->yuv; | ||
749 | unsigned int cs = yuv->chroma_stride; | ||
750 | unsigned int xsub = yuv->xsub; | ||
751 | unsigned int ysub = yuv->ysub; | ||
752 | unsigned int x; | ||
753 | unsigned int y; | ||
754 | |||
755 | for (y = 0; y < height; ++y) { | ||
756 | for (x = 0; x < width; ++x) { | ||
757 | div_t d = div(x+y, width); | ||
758 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
759 | + 0x000a1120 * (d.rem >> 6); | ||
760 | struct color_yuv color = | ||
761 | MAKE_YUV_601((rgb32 >> 16) & 0xff, | ||
762 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
763 | |||
764 | y_mem[x] = color.y; | ||
765 | u_mem[x/xsub*cs] = color.u; | ||
766 | v_mem[x/xsub*cs] = color.v; | ||
767 | } | ||
768 | |||
769 | y_mem += stride; | ||
770 | if ((y + 1) % ysub == 0) { | ||
771 | u_mem += stride * cs / xsub; | ||
772 | v_mem += stride * cs / xsub; | ||
773 | } | ||
774 | } | ||
775 | } | ||
776 | |||
777 | static void | ||
778 | fill_tiles_yuv_packed(const struct format_info *info, unsigned char *mem, | ||
779 | unsigned int width, unsigned int height, | ||
780 | unsigned int stride) | ||
781 | { | ||
782 | const struct yuv_info *yuv = &info->yuv; | ||
783 | unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; | ||
784 | unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; | ||
785 | unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; | ||
786 | unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; | ||
787 | unsigned int x; | ||
788 | unsigned int y; | ||
789 | |||
790 | for (y = 0; y < height; ++y) { | ||
791 | for (x = 0; x < width; x += 2) { | ||
792 | div_t d = div(x+y, width); | ||
793 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
794 | + 0x000a1120 * (d.rem >> 6); | ||
795 | struct color_yuv color = | ||
796 | MAKE_YUV_601((rgb32 >> 16) & 0xff, | ||
797 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
798 | |||
799 | y_mem[2*x] = color.y; | ||
800 | c_mem[2*x+u] = color.u; | ||
801 | y_mem[2*x+2] = color.y; | ||
802 | c_mem[2*x+v] = color.v; | ||
803 | } | ||
804 | |||
805 | y_mem += stride; | ||
806 | c_mem += stride; | ||
807 | } | ||
808 | } | ||
809 | |||
810 | static void | ||
811 | fill_tiles_rgb16(const struct format_info *info, unsigned char *mem, | ||
812 | unsigned int width, unsigned int height, unsigned int stride) | ||
813 | { | ||
814 | const struct rgb_info *rgb = &info->rgb; | ||
815 | unsigned char *mem_base = mem; | ||
816 | unsigned int x, y; | ||
817 | |||
818 | for (y = 0; y < height; ++y) { | ||
819 | for (x = 0; x < width; ++x) { | ||
820 | div_t d = div(x+y, width); | ||
821 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
822 | + 0x000a1120 * (d.rem >> 6); | ||
823 | uint16_t color = | ||
824 | MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, | ||
825 | (rgb32 >> 8) & 0xff, rgb32 & 0xff, | ||
826 | 255); | ||
827 | |||
828 | ((uint16_t *)mem)[x] = color; | ||
829 | } | ||
830 | mem += stride; | ||
831 | } | ||
832 | |||
833 | make_pwetty(mem_base, width, height, stride, info->format); | ||
834 | } | ||
835 | |||
836 | static void | ||
837 | fill_tiles_rgb24(const struct format_info *info, unsigned char *mem, | ||
838 | unsigned int width, unsigned int height, unsigned int stride) | ||
839 | { | ||
840 | const struct rgb_info *rgb = &info->rgb; | ||
841 | unsigned int x, y; | ||
842 | |||
843 | for (y = 0; y < height; ++y) { | ||
844 | for (x = 0; x < width; ++x) { | ||
845 | div_t d = div(x+y, width); | ||
846 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
847 | + 0x000a1120 * (d.rem >> 6); | ||
848 | struct color_rgb24 color = | ||
849 | MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff, | ||
850 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
851 | |||
852 | ((struct color_rgb24 *)mem)[x] = color; | ||
853 | } | ||
854 | mem += stride; | ||
855 | } | ||
856 | } | ||
857 | |||
858 | static void | ||
859 | fill_tiles_rgb32(const struct format_info *info, unsigned char *mem, | ||
860 | unsigned int width, unsigned int height, unsigned int stride) | ||
861 | { | ||
862 | const struct rgb_info *rgb = &info->rgb; | ||
863 | unsigned char *mem_base = mem; | ||
864 | unsigned int x, y; | ||
865 | |||
866 | for (y = 0; y < height; ++y) { | ||
867 | for (x = 0; x < width; ++x) { | ||
868 | div_t d = div(x+y, width); | ||
869 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
870 | + 0x000a1120 * (d.rem >> 6); | ||
871 | uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255; | ||
872 | uint32_t color = | ||
873 | MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, | ||
874 | (rgb32 >> 8) & 0xff, rgb32 & 0xff, | ||
875 | alpha); | ||
876 | |||
877 | ((uint32_t *)mem)[x] = color; | ||
878 | } | ||
879 | mem += stride; | ||
880 | } | ||
881 | |||
882 | make_pwetty(mem_base, width, height, stride, info->format); | ||
883 | } | ||
884 | |||
885 | static void | ||
886 | fill_tiles(const struct format_info *info, void *planes[3], unsigned int width, | ||
887 | unsigned int height, unsigned int stride) | ||
888 | { | ||
889 | unsigned char *u, *v; | ||
890 | |||
891 | switch (info->format) { | ||
892 | case DRM_FORMAT_UYVY: | ||
893 | case DRM_FORMAT_VYUY: | ||
894 | case DRM_FORMAT_YUYV: | ||
895 | case DRM_FORMAT_YVYU: | ||
896 | return fill_tiles_yuv_packed(info, planes[0], | ||
897 | width, height, stride); | ||
898 | |||
899 | case DRM_FORMAT_NV12: | ||
900 | case DRM_FORMAT_NV21: | ||
901 | case DRM_FORMAT_NV16: | ||
902 | case DRM_FORMAT_NV61: | ||
903 | u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; | ||
904 | v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; | ||
905 | return fill_tiles_yuv_planar(info, planes[0], u, v, | ||
906 | width, height, stride); | ||
907 | |||
908 | case DRM_FORMAT_YUV420: | ||
909 | return fill_tiles_yuv_planar(info, planes[0], planes[1], | ||
910 | planes[2], width, height, stride); | ||
911 | |||
912 | case DRM_FORMAT_YVU420: | ||
913 | return fill_tiles_yuv_planar(info, planes[0], planes[2], | ||
914 | planes[1], width, height, stride); | ||
915 | |||
916 | case DRM_FORMAT_ARGB4444: | ||
917 | case DRM_FORMAT_XRGB4444: | ||
918 | case DRM_FORMAT_ABGR4444: | ||
919 | case DRM_FORMAT_XBGR4444: | ||
920 | case DRM_FORMAT_RGBA4444: | ||
921 | case DRM_FORMAT_RGBX4444: | ||
922 | case DRM_FORMAT_BGRA4444: | ||
923 | case DRM_FORMAT_BGRX4444: | ||
924 | case DRM_FORMAT_RGB565: | ||
925 | case DRM_FORMAT_BGR565: | ||
926 | case DRM_FORMAT_ARGB1555: | ||
927 | case DRM_FORMAT_XRGB1555: | ||
928 | case DRM_FORMAT_ABGR1555: | ||
929 | case DRM_FORMAT_XBGR1555: | ||
930 | case DRM_FORMAT_RGBA5551: | ||
931 | case DRM_FORMAT_RGBX5551: | ||
932 | case DRM_FORMAT_BGRA5551: | ||
933 | case DRM_FORMAT_BGRX5551: | ||
934 | return fill_tiles_rgb16(info, planes[0], | ||
935 | width, height, stride); | ||
936 | |||
937 | case DRM_FORMAT_BGR888: | ||
938 | case DRM_FORMAT_RGB888: | ||
939 | return fill_tiles_rgb24(info, planes[0], | ||
940 | width, height, stride); | ||
941 | case DRM_FORMAT_ARGB8888: | ||
942 | case DRM_FORMAT_XRGB8888: | ||
943 | case DRM_FORMAT_ABGR8888: | ||
944 | case DRM_FORMAT_XBGR8888: | ||
945 | case DRM_FORMAT_RGBA8888: | ||
946 | case DRM_FORMAT_RGBX8888: | ||
947 | case DRM_FORMAT_BGRA8888: | ||
948 | case DRM_FORMAT_BGRX8888: | ||
949 | case DRM_FORMAT_ARGB2101010: | ||
950 | case DRM_FORMAT_XRGB2101010: | ||
951 | case DRM_FORMAT_ABGR2101010: | ||
952 | case DRM_FORMAT_XBGR2101010: | ||
953 | case DRM_FORMAT_RGBA1010102: | ||
954 | case DRM_FORMAT_RGBX1010102: | ||
955 | case DRM_FORMAT_BGRA1010102: | ||
956 | case DRM_FORMAT_BGRX1010102: | ||
957 | return fill_tiles_rgb32(info, planes[0], | ||
958 | width, height, stride); | ||
959 | } | ||
960 | } | ||
961 | |||
962 | static void | ||
963 | fill_plain(const struct format_info *info, void *planes[3], unsigned int width, | ||
964 | unsigned int height, unsigned int stride) | ||
965 | { | ||
966 | memset(planes[0], 0x77, stride * height); | ||
967 | } | ||
968 | |||
969 | /* | ||
970 | * fill_pattern - Fill a buffer with a test pattern | ||
971 | * @format: Pixel format | ||
972 | * @pattern: Test pattern | ||
973 | * @buffer: Buffer memory | ||
974 | * @width: Width in pixels | ||
975 | * @height: Height in pixels | ||
976 | * @stride: Line stride (pitch) in bytes | ||
977 | * | ||
978 | * Fill the buffer with the test pattern specified by the pattern parameter. | ||
979 | * Supported formats vary depending on the selected pattern. | ||
980 | */ | ||
981 | static void | ||
982 | fill_pattern(unsigned int format, enum fill_pattern pattern, void *planes[3], | ||
983 | unsigned int width, unsigned int height, unsigned int stride) | ||
984 | { | ||
985 | const struct format_info *info = NULL; | ||
986 | unsigned int i; | ||
987 | |||
988 | for (i = 0; i < ARRAY_SIZE(format_info); ++i) { | ||
989 | if (format_info[i].format == format) { | ||
990 | info = &format_info[i]; | ||
991 | break; | ||
992 | } | ||
993 | } | ||
994 | |||
995 | if (info == NULL) | ||
996 | return; | ||
997 | |||
998 | switch (pattern) { | ||
999 | case PATTERN_TILES: | ||
1000 | return fill_tiles(info, planes, width, height, stride); | ||
1001 | |||
1002 | case PATTERN_SMPTE: | ||
1003 | return fill_smpte(info, planes, width, height, stride); | ||
1004 | |||
1005 | case PATTERN_PLAIN: | ||
1006 | return fill_plain(info, planes, width, height, stride); | ||
1007 | |||
1008 | default: | ||
1009 | printf("Error: unsupported test pattern %u.\n", pattern); | ||
1010 | break; | ||
1011 | } | ||
1012 | } | ||
1013 | |||
1014 | /* ----------------------------------------------------------------------------- | ||
1015 | * Buffers management | 58 | * Buffers management |
1016 | */ | 59 | */ |
1017 | 60 | ||
@@ -1086,7 +129,7 @@ struct bo * | |||
1086 | bo_create(int fd, unsigned int format, | 129 | bo_create(int fd, unsigned int format, |
1087 | unsigned int width, unsigned int height, | 130 | unsigned int width, unsigned int height, |
1088 | unsigned int handles[4], unsigned int pitches[4], | 131 | unsigned int handles[4], unsigned int pitches[4], |
1089 | unsigned int offsets[4], enum fill_pattern pattern) | 132 | unsigned int offsets[4], enum util_fill_pattern pattern) |
1090 | { | 133 | { |
1091 | unsigned int virtual_height; | 134 | unsigned int virtual_height; |
1092 | struct bo *bo; | 135 | struct bo *bo; |
@@ -1280,7 +323,7 @@ bo_create(int fd, unsigned int format, | |||
1280 | break; | 323 | break; |
1281 | } | 324 | } |
1282 | 325 | ||
1283 | fill_pattern(format, pattern, planes, width, height, pitches[0]); | 326 | util_fill_pattern(format, pattern, planes, width, height, pitches[0]); |
1284 | bo_unmap(bo); | 327 | bo_unmap(bo); |
1285 | 328 | ||
1286 | return bo; | 329 | return bo; |
diff --git a/tests/modetest/buffers.h b/tests/modetest/buffers.h index ad73d0e4..7f95396b 100644 --- a/tests/modetest/buffers.h +++ b/tests/modetest/buffers.h | |||
@@ -27,20 +27,14 @@ | |||
27 | #ifndef __BUFFERS_H__ | 27 | #ifndef __BUFFERS_H__ |
28 | #define __BUFFERS_H__ | 28 | #define __BUFFERS_H__ |
29 | 29 | ||
30 | struct bo; | 30 | #include "util/pattern.h" |
31 | 31 | ||
32 | enum fill_pattern { | 32 | struct bo; |
33 | PATTERN_TILES = 0, | ||
34 | PATTERN_PLAIN = 1, | ||
35 | PATTERN_SMPTE = 2, | ||
36 | }; | ||
37 | 33 | ||
38 | struct bo *bo_create(int fd, unsigned int format, | 34 | struct bo *bo_create(int fd, unsigned int format, |
39 | unsigned int width, unsigned int height, | 35 | unsigned int width, unsigned int height, |
40 | unsigned int handles[4], unsigned int pitches[4], | 36 | unsigned int handles[4], unsigned int pitches[4], |
41 | unsigned int offsets[4], enum fill_pattern pattern); | 37 | unsigned int offsets[4], enum util_fill_pattern pattern); |
42 | void bo_destroy(struct bo *bo); | 38 | void bo_destroy(struct bo *bo); |
43 | 39 | ||
44 | unsigned int format_fourcc(const char *name); | ||
45 | |||
46 | #endif | 40 | #endif |
diff --git a/tests/modetest/cursor.c b/tests/modetest/cursor.c index d8a19bd2..6de82a4a 100644 --- a/tests/modetest/cursor.c +++ b/tests/modetest/cursor.c | |||
@@ -40,11 +40,11 @@ | |||
40 | #include "xf86drm.h" | 40 | #include "xf86drm.h" |
41 | #include "xf86drmMode.h" | 41 | #include "xf86drmMode.h" |
42 | 42 | ||
43 | #include "util/common.h" | ||
44 | |||
43 | #include "buffers.h" | 45 | #include "buffers.h" |
44 | #include "cursor.h" | 46 | #include "cursor.h" |
45 | 47 | ||
46 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
47 | |||
48 | struct cursor { | 48 | struct cursor { |
49 | int fd; | 49 | int fd; |
50 | uint32_t bo_handle; | 50 | uint32_t bo_handle; |
diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 3b01918d..361c6da9 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c | |||
@@ -37,6 +37,7 @@ | |||
37 | * TODO: use cairo to write the mode info on the selected output once | 37 | * TODO: use cairo to write the mode info on the selected output once |
38 | * the mode has been programmed, along with possible test patterns. | 38 | * the mode has been programmed, along with possible test patterns. |
39 | */ | 39 | */ |
40 | |||
40 | #ifdef HAVE_CONFIG_H | 41 | #ifdef HAVE_CONFIG_H |
41 | #include "config.h" | 42 | #include "config.h" |
42 | #endif | 43 | #endif |
@@ -59,6 +60,10 @@ | |||
59 | #include "xf86drmMode.h" | 60 | #include "xf86drmMode.h" |
60 | #include "drm_fourcc.h" | 61 | #include "drm_fourcc.h" |
61 | 62 | ||
63 | #include "util/common.h" | ||
64 | #include "util/format.h" | ||
65 | #include "util/pattern.h" | ||
66 | |||
62 | #include "buffers.h" | 67 | #include "buffers.h" |
63 | #include "cursor.h" | 68 | #include "cursor.h" |
64 | 69 | ||
@@ -116,7 +121,6 @@ struct device { | |||
116 | } mode; | 121 | } mode; |
117 | }; | 122 | }; |
118 | 123 | ||
119 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
120 | static inline int64_t U642I64(uint64_t val) | 124 | static inline int64_t U642I64(uint64_t val) |
121 | { | 125 | { |
122 | return (int64_t)*((int64_t *)&val); | 126 | return (int64_t)*((int64_t *)&val); |
@@ -1047,7 +1051,7 @@ static int set_plane(struct device *dev, struct plane_arg *p) | |||
1047 | p->w, p->h, p->format_str, plane_id); | 1051 | p->w, p->h, p->format_str, plane_id); |
1048 | 1052 | ||
1049 | plane_bo = bo_create(dev->fd, p->fourcc, p->w, p->h, handles, | 1053 | plane_bo = bo_create(dev->fd, p->fourcc, p->w, p->h, handles, |
1050 | pitches, offsets, PATTERN_TILES); | 1054 | pitches, offsets, UTIL_PATTERN_TILES); |
1051 | if (plane_bo == NULL) | 1055 | if (plane_bo == NULL) |
1052 | return -1; | 1056 | return -1; |
1053 | 1057 | ||
@@ -1123,8 +1127,9 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co | |||
1123 | dev->mode.height = pipe->mode->vdisplay; | 1127 | dev->mode.height = pipe->mode->vdisplay; |
1124 | } | 1128 | } |
1125 | 1129 | ||
1126 | bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width, dev->mode.height, | 1130 | bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width, |
1127 | handles, pitches, offsets, PATTERN_SMPTE); | 1131 | dev->mode.height, handles, pitches, offsets, |
1132 | UTIL_PATTERN_SMPTE); | ||
1128 | if (bo == NULL) | 1133 | if (bo == NULL) |
1129 | return; | 1134 | return; |
1130 | 1135 | ||
@@ -1202,7 +1207,7 @@ static void set_cursors(struct device *dev, struct pipe_arg *pipes, unsigned int | |||
1202 | * translucent alpha | 1207 | * translucent alpha |
1203 | */ | 1208 | */ |
1204 | bo = bo_create(dev->fd, DRM_FORMAT_ARGB8888, cw, ch, handles, pitches, | 1209 | bo = bo_create(dev->fd, DRM_FORMAT_ARGB8888, cw, ch, handles, pitches, |
1205 | offsets, PATTERN_PLAIN); | 1210 | offsets, UTIL_PATTERN_PLAIN); |
1206 | if (bo == NULL) | 1211 | if (bo == NULL) |
1207 | return; | 1212 | return; |
1208 | 1213 | ||
@@ -1241,9 +1246,9 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned | |||
1241 | unsigned int i; | 1246 | unsigned int i; |
1242 | int ret; | 1247 | int ret; |
1243 | 1248 | ||
1244 | other_bo = bo_create(dev->fd, pipes[0].fourcc, | 1249 | other_bo = bo_create(dev->fd, pipes[0].fourcc, dev->mode.width, |
1245 | dev->mode.width, dev->mode.height, | 1250 | dev->mode.height, handles, pitches, offsets, |
1246 | handles, pitches, offsets, PATTERN_PLAIN); | 1251 | UTIL_PATTERN_PLAIN); |
1247 | if (other_bo == NULL) | 1252 | if (other_bo == NULL) |
1248 | return; | 1253 | return; |
1249 | 1254 | ||
@@ -1391,7 +1396,7 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg) | |||
1391 | pipe->format_str[4] = '\0'; | 1396 | pipe->format_str[4] = '\0'; |
1392 | } | 1397 | } |
1393 | 1398 | ||
1394 | pipe->fourcc = format_fourcc(pipe->format_str); | 1399 | pipe->fourcc = util_format_fourcc(pipe->format_str); |
1395 | if (pipe->fourcc == 0) { | 1400 | if (pipe->fourcc == 0) { |
1396 | fprintf(stderr, "unknown format %s\n", pipe->format_str); | 1401 | fprintf(stderr, "unknown format %s\n", pipe->format_str); |
1397 | return -1; | 1402 | return -1; |
@@ -1444,7 +1449,7 @@ static int parse_plane(struct plane_arg *plane, const char *p) | |||
1444 | strcpy(plane->format_str, "XR24"); | 1449 | strcpy(plane->format_str, "XR24"); |
1445 | } | 1450 | } |
1446 | 1451 | ||
1447 | plane->fourcc = format_fourcc(plane->format_str); | 1452 | plane->fourcc = util_format_fourcc(plane->format_str); |
1448 | if (plane->fourcc == 0) { | 1453 | if (plane->fourcc == 0) { |
1449 | fprintf(stderr, "unknown format %s\n", plane->format_str); | 1454 | fprintf(stderr, "unknown format %s\n", plane->format_str); |
1450 | return -EINVAL; | 1455 | return -EINVAL; |
diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am index 0594e02e..14288206 100644 --- a/tests/proptest/Makefile.am +++ b/tests/proptest/Makefile.am | |||
@@ -1,6 +1,7 @@ | |||
1 | AM_CFLAGS = \ | 1 | AM_CFLAGS = \ |
2 | $(WARN_CFLAGS)\ | 2 | $(WARN_CFLAGS)\ |
3 | -I$(top_srcdir)/include/drm \ | 3 | -I$(top_srcdir)/include/drm \ |
4 | -I$(top_srcdir)/tests \ | ||
4 | -I$(top_srcdir) | 5 | -I$(top_srcdir) |
5 | 6 | ||
6 | if HAVE_INSTALL_TESTS | 7 | if HAVE_INSTALL_TESTS |
@@ -14,4 +15,5 @@ endif | |||
14 | proptest_SOURCES = \ | 15 | proptest_SOURCES = \ |
15 | proptest.c | 16 | proptest.c |
16 | proptest_LDADD = \ | 17 | proptest_LDADD = \ |
17 | $(top_builddir)/libdrm.la | 18 | $(top_builddir)/libdrm.la \ |
19 | $(top_builddir)/tests/util/libutil.la | ||
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c index b9296bdb..b6e00cfc 100644 --- a/tests/proptest/proptest.c +++ b/tests/proptest/proptest.c | |||
@@ -35,7 +35,8 @@ | |||
35 | #include "xf86drm.h" | 35 | #include "xf86drm.h" |
36 | #include "xf86drmMode.h" | 36 | #include "xf86drmMode.h" |
37 | 37 | ||
38 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | 38 | #include "util/common.h" |
39 | |||
39 | static inline int64_t U642I64(uint64_t val) | 40 | static inline int64_t U642I64(uint64_t val) |
40 | { | 41 | { |
41 | return (int64_t)*((int64_t *)&val); | 42 | return (int64_t)*((int64_t *)&val); |
diff --git a/tests/util/Android.mk b/tests/util/Android.mk new file mode 100644 index 00000000..73bc6805 --- /dev/null +++ b/tests/util/Android.mk | |||
@@ -0,0 +1,39 @@ | |||
1 | # | ||
2 | # Copyright © 2015 NVIDIA Corporation | ||
3 | # | ||
4 | # Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | # copy of this software and associated documentation files (the "Software"), | ||
6 | # to deal in the Software without restriction, including without limitation | ||
7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | # and/or sell copies of the Software, and to permit persons to whom the | ||
9 | # Software is furnished to do so, subject to the following conditions: | ||
10 | # | ||
11 | # The above copyright notice and this permission notice (including the next | ||
12 | # paragraph) shall be included in all copies or substantial portions of the | ||
13 | # Software. | ||
14 | # | ||
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
18 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
21 | # IN THE SOFTWARE. | ||
22 | # | ||
23 | |||
24 | LOCAL_PATH := $(call my-dir) | ||
25 | |||
26 | include $(CLEAR_VARS) | ||
27 | include $(LOCAL_PATH)/Makefile.sources | ||
28 | |||
29 | LOCAL_MODULE := libdrm_util | ||
30 | LOCAL_MODULE_TAGS := optional | ||
31 | |||
32 | LOCAL_SHARED_LIBRARIES := libdrm | ||
33 | |||
34 | LOCAL_SRC_FILES := $(UTIL_FILES) | ||
35 | |||
36 | # avoid name clashes by requiring users to include util/*.h | ||
37 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(dir $(LOCAL_PATH)) | ||
38 | |||
39 | include $(BUILD_STATIC_LIBRARY) | ||
diff --git a/tests/util/Makefile.am b/tests/util/Makefile.am new file mode 100644 index 00000000..f8e0b171 --- /dev/null +++ b/tests/util/Makefile.am | |||
@@ -0,0 +1,13 @@ | |||
1 | include Makefile.sources | ||
2 | |||
3 | noinst_LTLIBRARIES = \ | ||
4 | libutil.la | ||
5 | |||
6 | libutil_la_CPPFLAGS = \ | ||
7 | -I$(top_srcdir)/include/drm \ | ||
8 | -I$(top_srcdir) | ||
9 | |||
10 | libutil_la_CFLAGS = \ | ||
11 | $(CAIRO_CFLAGS) | ||
12 | |||
13 | libutil_la_SOURCES = $(UTIL_FILES) | ||
diff --git a/tests/util/Makefile.sources b/tests/util/Makefile.sources new file mode 100644 index 00000000..e91fa722 --- /dev/null +++ b/tests/util/Makefile.sources | |||
@@ -0,0 +1,6 @@ | |||
1 | UTIL_FILES := \ | ||
2 | common.h \ | ||
3 | format.c \ | ||
4 | format.h \ | ||
5 | pattern.c \ | ||
6 | pattern.h | ||
diff --git a/tests/util/common.h b/tests/util/common.h new file mode 100644 index 00000000..5d572c2d --- /dev/null +++ b/tests/util/common.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Tungsten Graphics | ||
3 | * Jakob Bornecrantz <jakob@tungstengraphics.com> | ||
4 | * Copyright 2008 Intel Corporation | ||
5 | * Jesse Barnes <jesse.barnes@intel.com> | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
23 | * IN THE SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #ifndef UTIL_COMMON_H | ||
27 | #define UTIL_COMMON_H | ||
28 | |||
29 | #ifndef ARRAY_SIZE | ||
30 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
31 | #endif | ||
32 | |||
33 | #endif /* UTIL_COMMON_H */ | ||
diff --git a/tests/util/format.c b/tests/util/format.c new file mode 100644 index 00000000..043cfe7f --- /dev/null +++ b/tests/util/format.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Tungsten Graphics | ||
3 | * Jakob Bornecrantz <jakob@tungstengraphics.com> | ||
4 | * Copyright 2008 Intel Corporation | ||
5 | * Jesse Barnes <jesse.barnes@intel.com> | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
23 | * IN THE SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #ifdef HAVE_CONFIG_H | ||
27 | #include "config.h" | ||
28 | #endif | ||
29 | |||
30 | #include <stdint.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | |||
34 | #include <drm_fourcc.h> | ||
35 | |||
36 | #include "common.h" | ||
37 | #include "format.h" | ||
38 | |||
39 | #define MAKE_RGB_INFO(rl, ro, gl, go, bl, bo, al, ao) \ | ||
40 | .rgb = { { (rl), (ro) }, { (gl), (go) }, { (bl), (bo) }, { (al), (ao) } } | ||
41 | |||
42 | #define MAKE_YUV_INFO(order, xsub, ysub, chroma_stride) \ | ||
43 | .yuv = { (order), (xsub), (ysub), (chroma_stride) } | ||
44 | |||
45 | static const struct util_format_info format_info[] = { | ||
46 | /* YUV packed */ | ||
47 | { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) }, | ||
48 | { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) }, | ||
49 | { DRM_FORMAT_YUYV, "YUYV", MAKE_YUV_INFO(YUV_YCbCr | YUV_YC, 2, 2, 2) }, | ||
50 | { DRM_FORMAT_YVYU, "YVYU", MAKE_YUV_INFO(YUV_YCrCb | YUV_YC, 2, 2, 2) }, | ||
51 | /* YUV semi-planar */ | ||
52 | { DRM_FORMAT_NV12, "NV12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 2) }, | ||
53 | { DRM_FORMAT_NV21, "NV21", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 2) }, | ||
54 | { DRM_FORMAT_NV16, "NV16", MAKE_YUV_INFO(YUV_YCbCr, 2, 1, 2) }, | ||
55 | { DRM_FORMAT_NV61, "NV61", MAKE_YUV_INFO(YUV_YCrCb, 2, 1, 2) }, | ||
56 | /* YUV planar */ | ||
57 | { DRM_FORMAT_YUV420, "YU12", MAKE_YUV_INFO(YUV_YCbCr, 2, 2, 1) }, | ||
58 | { DRM_FORMAT_YVU420, "YV12", MAKE_YUV_INFO(YUV_YCrCb, 2, 2, 1) }, | ||
59 | /* RGB16 */ | ||
60 | { DRM_FORMAT_ARGB4444, "AR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 4, 12) }, | ||
61 | { DRM_FORMAT_XRGB4444, "XR12", MAKE_RGB_INFO(4, 8, 4, 4, 4, 0, 0, 0) }, | ||
62 | { DRM_FORMAT_ABGR4444, "AB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 4, 12) }, | ||
63 | { DRM_FORMAT_XBGR4444, "XB12", MAKE_RGB_INFO(4, 0, 4, 4, 4, 8, 0, 0) }, | ||
64 | { DRM_FORMAT_RGBA4444, "RA12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 4, 0) }, | ||
65 | { DRM_FORMAT_RGBX4444, "RX12", MAKE_RGB_INFO(4, 12, 4, 8, 4, 4, 0, 0) }, | ||
66 | { DRM_FORMAT_BGRA4444, "BA12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 4, 0) }, | ||
67 | { DRM_FORMAT_BGRX4444, "BX12", MAKE_RGB_INFO(4, 4, 4, 8, 4, 12, 0, 0) }, | ||
68 | { DRM_FORMAT_ARGB1555, "AR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 1, 15) }, | ||
69 | { DRM_FORMAT_XRGB1555, "XR15", MAKE_RGB_INFO(5, 10, 5, 5, 5, 0, 0, 0) }, | ||
70 | { DRM_FORMAT_ABGR1555, "AB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 1, 15) }, | ||
71 | { DRM_FORMAT_XBGR1555, "XB15", MAKE_RGB_INFO(5, 0, 5, 5, 5, 10, 0, 0) }, | ||
72 | { DRM_FORMAT_RGBA5551, "RA15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 1, 0) }, | ||
73 | { DRM_FORMAT_RGBX5551, "RX15", MAKE_RGB_INFO(5, 11, 5, 6, 5, 1, 0, 0) }, | ||
74 | { DRM_FORMAT_BGRA5551, "BA15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 1, 0) }, | ||
75 | { DRM_FORMAT_BGRX5551, "BX15", MAKE_RGB_INFO(5, 1, 5, 6, 5, 11, 0, 0) }, | ||
76 | { DRM_FORMAT_RGB565, "RG16", MAKE_RGB_INFO(5, 11, 6, 5, 5, 0, 0, 0) }, | ||
77 | { DRM_FORMAT_BGR565, "BG16", MAKE_RGB_INFO(5, 0, 6, 5, 5, 11, 0, 0) }, | ||
78 | /* RGB24 */ | ||
79 | { DRM_FORMAT_BGR888, "BG24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, | ||
80 | { DRM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, | ||
81 | /* RGB32 */ | ||
82 | { DRM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) }, | ||
83 | { DRM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) }, | ||
84 | { DRM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) }, | ||
85 | { DRM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) }, | ||
86 | { DRM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) }, | ||
87 | { DRM_FORMAT_RGBX8888, "RX24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 0, 0) }, | ||
88 | { DRM_FORMAT_BGRA8888, "BA24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 8, 0) }, | ||
89 | { DRM_FORMAT_BGRX8888, "BX24", MAKE_RGB_INFO(8, 8, 8, 16, 8, 24, 0, 0) }, | ||
90 | { DRM_FORMAT_ARGB2101010, "AR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 2, 30) }, | ||
91 | { DRM_FORMAT_XRGB2101010, "XR30", MAKE_RGB_INFO(10, 20, 10, 10, 10, 0, 0, 0) }, | ||
92 | { DRM_FORMAT_ABGR2101010, "AB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 2, 30) }, | ||
93 | { DRM_FORMAT_XBGR2101010, "XB30", MAKE_RGB_INFO(10, 0, 10, 10, 10, 20, 0, 0) }, | ||
94 | { DRM_FORMAT_RGBA1010102, "RA30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 2, 0) }, | ||
95 | { DRM_FORMAT_RGBX1010102, "RX30", MAKE_RGB_INFO(10, 22, 10, 12, 10, 2, 0, 0) }, | ||
96 | { DRM_FORMAT_BGRA1010102, "BA30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 2, 0) }, | ||
97 | { DRM_FORMAT_BGRX1010102, "BX30", MAKE_RGB_INFO(10, 2, 10, 12, 10, 22, 0, 0) }, | ||
98 | }; | ||
99 | |||
100 | uint32_t util_format_fourcc(const char *name) | ||
101 | { | ||
102 | unsigned int i; | ||
103 | |||
104 | for (i = 0; i < ARRAY_SIZE(format_info); i++) | ||
105 | if (!strcmp(format_info[i].name, name)) | ||
106 | return format_info[i].format; | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | const struct util_format_info *util_format_info_find(uint32_t format) | ||
112 | { | ||
113 | unsigned int i; | ||
114 | |||
115 | for (i = 0; i < ARRAY_SIZE(format_info); i++) | ||
116 | if (format_info[i].format == format) | ||
117 | return &format_info[i]; | ||
118 | |||
119 | return NULL; | ||
120 | } | ||
diff --git a/tests/util/format.h b/tests/util/format.h new file mode 100644 index 00000000..2ce1c021 --- /dev/null +++ b/tests/util/format.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Tungsten Graphics | ||
3 | * Jakob Bornecrantz <jakob@tungstengraphics.com> | ||
4 | * Copyright 2008 Intel Corporation | ||
5 | * Jesse Barnes <jesse.barnes@intel.com> | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
23 | * IN THE SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #ifndef UTIL_FORMAT_H | ||
27 | #define UTIL_FORMAT_H | ||
28 | |||
29 | struct util_color_component { | ||
30 | unsigned int length; | ||
31 | unsigned int offset; | ||
32 | }; | ||
33 | |||
34 | struct util_rgb_info { | ||
35 | struct util_color_component red; | ||
36 | struct util_color_component green; | ||
37 | struct util_color_component blue; | ||
38 | struct util_color_component alpha; | ||
39 | }; | ||
40 | |||
41 | enum util_yuv_order { | ||
42 | YUV_YCbCr = 1, | ||
43 | YUV_YCrCb = 2, | ||
44 | YUV_YC = 4, | ||
45 | YUV_CY = 8, | ||
46 | }; | ||
47 | |||
48 | struct util_yuv_info { | ||
49 | enum util_yuv_order order; | ||
50 | unsigned int xsub; | ||
51 | unsigned int ysub; | ||
52 | unsigned int chroma_stride; | ||
53 | }; | ||
54 | |||
55 | struct util_format_info { | ||
56 | uint32_t format; | ||
57 | const char *name; | ||
58 | const struct util_rgb_info rgb; | ||
59 | const struct util_yuv_info yuv; | ||
60 | }; | ||
61 | |||
62 | uint32_t util_format_fourcc(const char *name); | ||
63 | const struct util_format_info *util_format_info_find(uint32_t format); | ||
64 | |||
65 | #endif /* UTIL_FORMAT_H */ | ||
diff --git a/tests/util/pattern.c b/tests/util/pattern.c new file mode 100644 index 00000000..00b08a8c --- /dev/null +++ b/tests/util/pattern.c | |||
@@ -0,0 +1,870 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Tungsten Graphics | ||
3 | * Jakob Bornecrantz <jakob@tungstengraphics.com> | ||
4 | * Copyright 2008 Intel Corporation | ||
5 | * Jesse Barnes <jesse.barnes@intel.com> | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
23 | * IN THE SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #ifdef HAVE_CONFIG_H | ||
27 | #include "config.h" | ||
28 | #endif | ||
29 | |||
30 | #include <stdint.h> | ||
31 | #include <stdio.h> | ||
32 | #include <stdlib.h> | ||
33 | #include <string.h> | ||
34 | |||
35 | #include <drm_fourcc.h> | ||
36 | |||
37 | #ifdef HAVE_CAIRO | ||
38 | #include <cairo.h> | ||
39 | #include <math.h> | ||
40 | #endif | ||
41 | |||
42 | #include "format.h" | ||
43 | #include "pattern.h" | ||
44 | |||
45 | struct color_rgb24 { | ||
46 | unsigned int value:24; | ||
47 | } __attribute__((__packed__)); | ||
48 | |||
49 | struct color_yuv { | ||
50 | unsigned char y; | ||
51 | unsigned char u; | ||
52 | unsigned char v; | ||
53 | }; | ||
54 | |||
55 | #define MAKE_YUV_601_Y(r, g, b) \ | ||
56 | ((( 66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16) | ||
57 | #define MAKE_YUV_601_U(r, g, b) \ | ||
58 | (((-38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128) | ||
59 | #define MAKE_YUV_601_V(r, g, b) \ | ||
60 | (((112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128) | ||
61 | |||
62 | #define MAKE_YUV_601(r, g, b) \ | ||
63 | { .y = MAKE_YUV_601_Y(r, g, b), \ | ||
64 | .u = MAKE_YUV_601_U(r, g, b), \ | ||
65 | .v = MAKE_YUV_601_V(r, g, b) } | ||
66 | |||
67 | #define MAKE_RGBA(rgb, r, g, b, a) \ | ||
68 | ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \ | ||
69 | (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \ | ||
70 | (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \ | ||
71 | (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset)) | ||
72 | |||
73 | #define MAKE_RGB24(rgb, r, g, b) \ | ||
74 | { .value = MAKE_RGBA(rgb, r, g, b, 0) } | ||
75 | |||
76 | static void fill_smpte_yuv_planar(const struct util_yuv_info *yuv, | ||
77 | unsigned char *y_mem, unsigned char *u_mem, | ||
78 | unsigned char *v_mem, unsigned int width, | ||
79 | unsigned int height, unsigned int stride) | ||
80 | { | ||
81 | const struct color_yuv colors_top[] = { | ||
82 | MAKE_YUV_601(191, 192, 192), /* grey */ | ||
83 | MAKE_YUV_601(192, 192, 0), /* yellow */ | ||
84 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
85 | MAKE_YUV_601(0, 192, 0), /* green */ | ||
86 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
87 | MAKE_YUV_601(192, 0, 0), /* red */ | ||
88 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
89 | }; | ||
90 | const struct color_yuv colors_middle[] = { | ||
91 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
92 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
93 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
94 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
95 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
96 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
97 | MAKE_YUV_601(192, 192, 192), /* grey */ | ||
98 | }; | ||
99 | const struct color_yuv colors_bottom[] = { | ||
100 | MAKE_YUV_601(0, 33, 76), /* in-phase */ | ||
101 | MAKE_YUV_601(255, 255, 255), /* super white */ | ||
102 | MAKE_YUV_601(50, 0, 106), /* quadrature */ | ||
103 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
104 | MAKE_YUV_601(9, 9, 9), /* 3.5% */ | ||
105 | MAKE_YUV_601(19, 19, 19), /* 7.5% */ | ||
106 | MAKE_YUV_601(29, 29, 29), /* 11.5% */ | ||
107 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
108 | }; | ||
109 | unsigned int cs = yuv->chroma_stride; | ||
110 | unsigned int xsub = yuv->xsub; | ||
111 | unsigned int ysub = yuv->ysub; | ||
112 | unsigned int x; | ||
113 | unsigned int y; | ||
114 | |||
115 | /* Luma */ | ||
116 | for (y = 0; y < height * 6 / 9; ++y) { | ||
117 | for (x = 0; x < width; ++x) | ||
118 | y_mem[x] = colors_top[x * 7 / width].y; | ||
119 | y_mem += stride; | ||
120 | } | ||
121 | |||
122 | for (; y < height * 7 / 9; ++y) { | ||
123 | for (x = 0; x < width; ++x) | ||
124 | y_mem[x] = colors_middle[x * 7 / width].y; | ||
125 | y_mem += stride; | ||
126 | } | ||
127 | |||
128 | for (; y < height; ++y) { | ||
129 | for (x = 0; x < width * 5 / 7; ++x) | ||
130 | y_mem[x] = colors_bottom[x * 4 / (width * 5 / 7)].y; | ||
131 | for (; x < width * 6 / 7; ++x) | ||
132 | y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3 | ||
133 | / (width / 7) + 4].y; | ||
134 | for (; x < width; ++x) | ||
135 | y_mem[x] = colors_bottom[7].y; | ||
136 | y_mem += stride; | ||
137 | } | ||
138 | |||
139 | /* Chroma */ | ||
140 | for (y = 0; y < height / ysub * 6 / 9; ++y) { | ||
141 | for (x = 0; x < width; x += xsub) { | ||
142 | u_mem[x*cs/xsub] = colors_top[x * 7 / width].u; | ||
143 | v_mem[x*cs/xsub] = colors_top[x * 7 / width].v; | ||
144 | } | ||
145 | u_mem += stride * cs / xsub; | ||
146 | v_mem += stride * cs / xsub; | ||
147 | } | ||
148 | |||
149 | for (; y < height / ysub * 7 / 9; ++y) { | ||
150 | for (x = 0; x < width; x += xsub) { | ||
151 | u_mem[x*cs/xsub] = colors_middle[x * 7 / width].u; | ||
152 | v_mem[x*cs/xsub] = colors_middle[x * 7 / width].v; | ||
153 | } | ||
154 | u_mem += stride * cs / xsub; | ||
155 | v_mem += stride * cs / xsub; | ||
156 | } | ||
157 | |||
158 | for (; y < height / ysub; ++y) { | ||
159 | for (x = 0; x < width * 5 / 7; x += xsub) { | ||
160 | u_mem[x*cs/xsub] = | ||
161 | colors_bottom[x * 4 / (width * 5 / 7)].u; | ||
162 | v_mem[x*cs/xsub] = | ||
163 | colors_bottom[x * 4 / (width * 5 / 7)].v; | ||
164 | } | ||
165 | for (; x < width * 6 / 7; x += xsub) { | ||
166 | u_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * | ||
167 | 3 / (width / 7) + 4].u; | ||
168 | v_mem[x*cs/xsub] = colors_bottom[(x - width * 5 / 7) * | ||
169 | 3 / (width / 7) + 4].v; | ||
170 | } | ||
171 | for (; x < width; x += xsub) { | ||
172 | u_mem[x*cs/xsub] = colors_bottom[7].u; | ||
173 | v_mem[x*cs/xsub] = colors_bottom[7].v; | ||
174 | } | ||
175 | u_mem += stride * cs / xsub; | ||
176 | v_mem += stride * cs / xsub; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | static void fill_smpte_yuv_packed(const struct util_yuv_info *yuv, void *mem, | ||
181 | unsigned int width, unsigned int height, | ||
182 | unsigned int stride) | ||
183 | { | ||
184 | const struct color_yuv colors_top[] = { | ||
185 | MAKE_YUV_601(191, 192, 192), /* grey */ | ||
186 | MAKE_YUV_601(192, 192, 0), /* yellow */ | ||
187 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
188 | MAKE_YUV_601(0, 192, 0), /* green */ | ||
189 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
190 | MAKE_YUV_601(192, 0, 0), /* red */ | ||
191 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
192 | }; | ||
193 | const struct color_yuv colors_middle[] = { | ||
194 | MAKE_YUV_601(0, 0, 192), /* blue */ | ||
195 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
196 | MAKE_YUV_601(192, 0, 192), /* magenta */ | ||
197 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
198 | MAKE_YUV_601(0, 192, 192), /* cyan */ | ||
199 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
200 | MAKE_YUV_601(192, 192, 192), /* grey */ | ||
201 | }; | ||
202 | const struct color_yuv colors_bottom[] = { | ||
203 | MAKE_YUV_601(0, 33, 76), /* in-phase */ | ||
204 | MAKE_YUV_601(255, 255, 255), /* super white */ | ||
205 | MAKE_YUV_601(50, 0, 106), /* quadrature */ | ||
206 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
207 | MAKE_YUV_601(9, 9, 9), /* 3.5% */ | ||
208 | MAKE_YUV_601(19, 19, 19), /* 7.5% */ | ||
209 | MAKE_YUV_601(29, 29, 29), /* 11.5% */ | ||
210 | MAKE_YUV_601(19, 19, 19), /* black */ | ||
211 | }; | ||
212 | unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; | ||
213 | unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; | ||
214 | unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; | ||
215 | unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; | ||
216 | unsigned int x; | ||
217 | unsigned int y; | ||
218 | |||
219 | /* Luma */ | ||
220 | for (y = 0; y < height * 6 / 9; ++y) { | ||
221 | for (x = 0; x < width; ++x) | ||
222 | y_mem[2*x] = colors_top[x * 7 / width].y; | ||
223 | y_mem += stride; | ||
224 | } | ||
225 | |||
226 | for (; y < height * 7 / 9; ++y) { | ||
227 | for (x = 0; x < width; ++x) | ||
228 | y_mem[2*x] = colors_middle[x * 7 / width].y; | ||
229 | y_mem += stride; | ||
230 | } | ||
231 | |||
232 | for (; y < height; ++y) { | ||
233 | for (x = 0; x < width * 5 / 7; ++x) | ||
234 | y_mem[2*x] = colors_bottom[x * 4 / (width * 5 / 7)].y; | ||
235 | for (; x < width * 6 / 7; ++x) | ||
236 | y_mem[2*x] = colors_bottom[(x - width * 5 / 7) * 3 | ||
237 | / (width / 7) + 4].y; | ||
238 | for (; x < width; ++x) | ||
239 | y_mem[2*x] = colors_bottom[7].y; | ||
240 | y_mem += stride; | ||
241 | } | ||
242 | |||
243 | /* Chroma */ | ||
244 | for (y = 0; y < height * 6 / 9; ++y) { | ||
245 | for (x = 0; x < width; x += 2) { | ||
246 | c_mem[2*x+u] = colors_top[x * 7 / width].u; | ||
247 | c_mem[2*x+v] = colors_top[x * 7 / width].v; | ||
248 | } | ||
249 | c_mem += stride; | ||
250 | } | ||
251 | |||
252 | for (; y < height * 7 / 9; ++y) { | ||
253 | for (x = 0; x < width; x += 2) { | ||
254 | c_mem[2*x+u] = colors_middle[x * 7 / width].u; | ||
255 | c_mem[2*x+v] = colors_middle[x * 7 / width].v; | ||
256 | } | ||
257 | c_mem += stride; | ||
258 | } | ||
259 | |||
260 | for (; y < height; ++y) { | ||
261 | for (x = 0; x < width * 5 / 7; x += 2) { | ||
262 | c_mem[2*x+u] = colors_bottom[x * 4 / (width * 5 / 7)].u; | ||
263 | c_mem[2*x+v] = colors_bottom[x * 4 / (width * 5 / 7)].v; | ||
264 | } | ||
265 | for (; x < width * 6 / 7; x += 2) { | ||
266 | c_mem[2*x+u] = colors_bottom[(x - width * 5 / 7) * | ||
267 | 3 / (width / 7) + 4].u; | ||
268 | c_mem[2*x+v] = colors_bottom[(x - width * 5 / 7) * | ||
269 | 3 / (width / 7) + 4].v; | ||
270 | } | ||
271 | for (; x < width; x += 2) { | ||
272 | c_mem[2*x+u] = colors_bottom[7].u; | ||
273 | c_mem[2*x+v] = colors_bottom[7].v; | ||
274 | } | ||
275 | c_mem += stride; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | static void fill_smpte_rgb16(const struct util_rgb_info *rgb, void *mem, | ||
280 | unsigned int width, unsigned int height, | ||
281 | unsigned int stride) | ||
282 | { | ||
283 | const uint16_t colors_top[] = { | ||
284 | MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ | ||
285 | MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ | ||
286 | MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ | ||
287 | MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ | ||
288 | MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ | ||
289 | MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ | ||
290 | MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ | ||
291 | }; | ||
292 | const uint16_t colors_middle[] = { | ||
293 | MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ | ||
294 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
295 | MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ | ||
296 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
297 | MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ | ||
298 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
299 | MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ | ||
300 | }; | ||
301 | const uint16_t colors_bottom[] = { | ||
302 | MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ | ||
303 | MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ | ||
304 | MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ | ||
305 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
306 | MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ | ||
307 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ | ||
308 | MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ | ||
309 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
310 | }; | ||
311 | unsigned int x; | ||
312 | unsigned int y; | ||
313 | |||
314 | for (y = 0; y < height * 6 / 9; ++y) { | ||
315 | for (x = 0; x < width; ++x) | ||
316 | ((uint16_t *)mem)[x] = colors_top[x * 7 / width]; | ||
317 | mem += stride; | ||
318 | } | ||
319 | |||
320 | for (; y < height * 7 / 9; ++y) { | ||
321 | for (x = 0; x < width; ++x) | ||
322 | ((uint16_t *)mem)[x] = colors_middle[x * 7 / width]; | ||
323 | mem += stride; | ||
324 | } | ||
325 | |||
326 | for (; y < height; ++y) { | ||
327 | for (x = 0; x < width * 5 / 7; ++x) | ||
328 | ((uint16_t *)mem)[x] = | ||
329 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
330 | for (; x < width * 6 / 7; ++x) | ||
331 | ((uint16_t *)mem)[x] = | ||
332 | colors_bottom[(x - width * 5 / 7) * 3 | ||
333 | / (width / 7) + 4]; | ||
334 | for (; x < width; ++x) | ||
335 | ((uint16_t *)mem)[x] = colors_bottom[7]; | ||
336 | mem += stride; | ||
337 | } | ||
338 | } | ||
339 | |||
340 | static void fill_smpte_rgb24(const struct util_rgb_info *rgb, void *mem, | ||
341 | unsigned int width, unsigned int height, | ||
342 | unsigned int stride) | ||
343 | { | ||
344 | const struct color_rgb24 colors_top[] = { | ||
345 | MAKE_RGB24(rgb, 192, 192, 192), /* grey */ | ||
346 | MAKE_RGB24(rgb, 192, 192, 0), /* yellow */ | ||
347 | MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ | ||
348 | MAKE_RGB24(rgb, 0, 192, 0), /* green */ | ||
349 | MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ | ||
350 | MAKE_RGB24(rgb, 192, 0, 0), /* red */ | ||
351 | MAKE_RGB24(rgb, 0, 0, 192), /* blue */ | ||
352 | }; | ||
353 | const struct color_rgb24 colors_middle[] = { | ||
354 | MAKE_RGB24(rgb, 0, 0, 192), /* blue */ | ||
355 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
356 | MAKE_RGB24(rgb, 192, 0, 192), /* magenta */ | ||
357 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
358 | MAKE_RGB24(rgb, 0, 192, 192), /* cyan */ | ||
359 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
360 | MAKE_RGB24(rgb, 192, 192, 192), /* grey */ | ||
361 | }; | ||
362 | const struct color_rgb24 colors_bottom[] = { | ||
363 | MAKE_RGB24(rgb, 0, 33, 76), /* in-phase */ | ||
364 | MAKE_RGB24(rgb, 255, 255, 255), /* super white */ | ||
365 | MAKE_RGB24(rgb, 50, 0, 106), /* quadrature */ | ||
366 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
367 | MAKE_RGB24(rgb, 9, 9, 9), /* 3.5% */ | ||
368 | MAKE_RGB24(rgb, 19, 19, 19), /* 7.5% */ | ||
369 | MAKE_RGB24(rgb, 29, 29, 29), /* 11.5% */ | ||
370 | MAKE_RGB24(rgb, 19, 19, 19), /* black */ | ||
371 | }; | ||
372 | unsigned int x; | ||
373 | unsigned int y; | ||
374 | |||
375 | for (y = 0; y < height * 6 / 9; ++y) { | ||
376 | for (x = 0; x < width; ++x) | ||
377 | ((struct color_rgb24 *)mem)[x] = | ||
378 | colors_top[x * 7 / width]; | ||
379 | mem += stride; | ||
380 | } | ||
381 | |||
382 | for (; y < height * 7 / 9; ++y) { | ||
383 | for (x = 0; x < width; ++x) | ||
384 | ((struct color_rgb24 *)mem)[x] = | ||
385 | colors_middle[x * 7 / width]; | ||
386 | mem += stride; | ||
387 | } | ||
388 | |||
389 | for (; y < height; ++y) { | ||
390 | for (x = 0; x < width * 5 / 7; ++x) | ||
391 | ((struct color_rgb24 *)mem)[x] = | ||
392 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
393 | for (; x < width * 6 / 7; ++x) | ||
394 | ((struct color_rgb24 *)mem)[x] = | ||
395 | colors_bottom[(x - width * 5 / 7) * 3 | ||
396 | / (width / 7) + 4]; | ||
397 | for (; x < width; ++x) | ||
398 | ((struct color_rgb24 *)mem)[x] = colors_bottom[7]; | ||
399 | mem += stride; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem, | ||
404 | unsigned int width, unsigned int height, | ||
405 | unsigned int stride) | ||
406 | { | ||
407 | const uint32_t colors_top[] = { | ||
408 | MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ | ||
409 | MAKE_RGBA(rgb, 192, 192, 0, 255), /* yellow */ | ||
410 | MAKE_RGBA(rgb, 0, 192, 192, 255), /* cyan */ | ||
411 | MAKE_RGBA(rgb, 0, 192, 0, 255), /* green */ | ||
412 | MAKE_RGBA(rgb, 192, 0, 192, 255), /* magenta */ | ||
413 | MAKE_RGBA(rgb, 192, 0, 0, 255), /* red */ | ||
414 | MAKE_RGBA(rgb, 0, 0, 192, 255), /* blue */ | ||
415 | }; | ||
416 | const uint32_t colors_middle[] = { | ||
417 | MAKE_RGBA(rgb, 0, 0, 192, 127), /* blue */ | ||
418 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
419 | MAKE_RGBA(rgb, 192, 0, 192, 127), /* magenta */ | ||
420 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
421 | MAKE_RGBA(rgb, 0, 192, 192, 127), /* cyan */ | ||
422 | MAKE_RGBA(rgb, 19, 19, 19, 127), /* black */ | ||
423 | MAKE_RGBA(rgb, 192, 192, 192, 127), /* grey */ | ||
424 | }; | ||
425 | const uint32_t colors_bottom[] = { | ||
426 | MAKE_RGBA(rgb, 0, 33, 76, 255), /* in-phase */ | ||
427 | MAKE_RGBA(rgb, 255, 255, 255, 255), /* super white */ | ||
428 | MAKE_RGBA(rgb, 50, 0, 106, 255), /* quadrature */ | ||
429 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
430 | MAKE_RGBA(rgb, 9, 9, 9, 255), /* 3.5% */ | ||
431 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* 7.5% */ | ||
432 | MAKE_RGBA(rgb, 29, 29, 29, 255), /* 11.5% */ | ||
433 | MAKE_RGBA(rgb, 19, 19, 19, 255), /* black */ | ||
434 | }; | ||
435 | unsigned int x; | ||
436 | unsigned int y; | ||
437 | |||
438 | for (y = 0; y < height * 6 / 9; ++y) { | ||
439 | for (x = 0; x < width; ++x) | ||
440 | ((uint32_t *)mem)[x] = colors_top[x * 7 / width]; | ||
441 | mem += stride; | ||
442 | } | ||
443 | |||
444 | for (; y < height * 7 / 9; ++y) { | ||
445 | for (x = 0; x < width; ++x) | ||
446 | ((uint32_t *)mem)[x] = colors_middle[x * 7 / width]; | ||
447 | mem += stride; | ||
448 | } | ||
449 | |||
450 | for (; y < height; ++y) { | ||
451 | for (x = 0; x < width * 5 / 7; ++x) | ||
452 | ((uint32_t *)mem)[x] = | ||
453 | colors_bottom[x * 4 / (width * 5 / 7)]; | ||
454 | for (; x < width * 6 / 7; ++x) | ||
455 | ((uint32_t *)mem)[x] = | ||
456 | colors_bottom[(x - width * 5 / 7) * 3 | ||
457 | / (width / 7) + 4]; | ||
458 | for (; x < width; ++x) | ||
459 | ((uint32_t *)mem)[x] = colors_bottom[7]; | ||
460 | mem += stride; | ||
461 | } | ||
462 | } | ||
463 | |||
464 | static void fill_smpte(const struct util_format_info *info, void *planes[3], | ||
465 | unsigned int width, unsigned int height, | ||
466 | unsigned int stride) | ||
467 | { | ||
468 | unsigned char *u, *v; | ||
469 | |||
470 | switch (info->format) { | ||
471 | case DRM_FORMAT_UYVY: | ||
472 | case DRM_FORMAT_VYUY: | ||
473 | case DRM_FORMAT_YUYV: | ||
474 | case DRM_FORMAT_YVYU: | ||
475 | return fill_smpte_yuv_packed(&info->yuv, planes[0], width, | ||
476 | height, stride); | ||
477 | |||
478 | case DRM_FORMAT_NV12: | ||
479 | case DRM_FORMAT_NV21: | ||
480 | case DRM_FORMAT_NV16: | ||
481 | case DRM_FORMAT_NV61: | ||
482 | u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; | ||
483 | v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; | ||
484 | return fill_smpte_yuv_planar(&info->yuv, planes[0], u, v, | ||
485 | width, height, stride); | ||
486 | |||
487 | case DRM_FORMAT_YUV420: | ||
488 | return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[1], | ||
489 | planes[2], width, height, stride); | ||
490 | |||
491 | case DRM_FORMAT_YVU420: | ||
492 | return fill_smpte_yuv_planar(&info->yuv, planes[0], planes[2], | ||
493 | planes[1], width, height, stride); | ||
494 | |||
495 | case DRM_FORMAT_ARGB4444: | ||
496 | case DRM_FORMAT_XRGB4444: | ||
497 | case DRM_FORMAT_ABGR4444: | ||
498 | case DRM_FORMAT_XBGR4444: | ||
499 | case DRM_FORMAT_RGBA4444: | ||
500 | case DRM_FORMAT_RGBX4444: | ||
501 | case DRM_FORMAT_BGRA4444: | ||
502 | case DRM_FORMAT_BGRX4444: | ||
503 | case DRM_FORMAT_RGB565: | ||
504 | case DRM_FORMAT_BGR565: | ||
505 | case DRM_FORMAT_ARGB1555: | ||
506 | case DRM_FORMAT_XRGB1555: | ||
507 | case DRM_FORMAT_ABGR1555: | ||
508 | case DRM_FORMAT_XBGR1555: | ||
509 | case DRM_FORMAT_RGBA5551: | ||
510 | case DRM_FORMAT_RGBX5551: | ||
511 | case DRM_FORMAT_BGRA5551: | ||
512 | case DRM_FORMAT_BGRX5551: | ||
513 | return fill_smpte_rgb16(&info->rgb, planes[0], | ||
514 | width, height, stride); | ||
515 | |||
516 | case DRM_FORMAT_BGR888: | ||
517 | case DRM_FORMAT_RGB888: | ||
518 | return fill_smpte_rgb24(&info->rgb, planes[0], | ||
519 | width, height, stride); | ||
520 | case DRM_FORMAT_ARGB8888: | ||
521 | case DRM_FORMAT_XRGB8888: | ||
522 | case DRM_FORMAT_ABGR8888: | ||
523 | case DRM_FORMAT_XBGR8888: | ||
524 | case DRM_FORMAT_RGBA8888: | ||
525 | case DRM_FORMAT_RGBX8888: | ||
526 | case DRM_FORMAT_BGRA8888: | ||
527 | case DRM_FORMAT_BGRX8888: | ||
528 | case DRM_FORMAT_ARGB2101010: | ||
529 | case DRM_FORMAT_XRGB2101010: | ||
530 | case DRM_FORMAT_ABGR2101010: | ||
531 | case DRM_FORMAT_XBGR2101010: | ||
532 | case DRM_FORMAT_RGBA1010102: | ||
533 | case DRM_FORMAT_RGBX1010102: | ||
534 | case DRM_FORMAT_BGRA1010102: | ||
535 | case DRM_FORMAT_BGRX1010102: | ||
536 | return fill_smpte_rgb32(&info->rgb, planes[0], | ||
537 | width, height, stride); | ||
538 | } | ||
539 | } | ||
540 | |||
541 | /* swap these for big endian.. */ | ||
542 | #define RED 2 | ||
543 | #define GREEN 1 | ||
544 | #define BLUE 0 | ||
545 | |||
546 | static void make_pwetty(void *data, unsigned int width, unsigned int height, | ||
547 | unsigned int stride, uint32_t format) | ||
548 | { | ||
549 | #ifdef HAVE_CAIRO | ||
550 | cairo_surface_t *surface; | ||
551 | cairo_t *cr; | ||
552 | int x, y; | ||
553 | cairo_format_t cairo_format; | ||
554 | |||
555 | /* we can ignore the order of R,G,B channels */ | ||
556 | switch (format) { | ||
557 | case DRM_FORMAT_XRGB8888: | ||
558 | case DRM_FORMAT_ARGB8888: | ||
559 | case DRM_FORMAT_XBGR8888: | ||
560 | case DRM_FORMAT_ABGR8888: | ||
561 | cairo_format = CAIRO_FORMAT_ARGB32; | ||
562 | break; | ||
563 | case DRM_FORMAT_RGB565: | ||
564 | case DRM_FORMAT_BGR565: | ||
565 | cairo_format = CAIRO_FORMAT_RGB16_565; | ||
566 | break; | ||
567 | default: | ||
568 | return; | ||
569 | } | ||
570 | |||
571 | surface = cairo_image_surface_create_for_data(data, | ||
572 | cairo_format, | ||
573 | width, height, | ||
574 | stride); | ||
575 | cr = cairo_create(surface); | ||
576 | cairo_surface_destroy(surface); | ||
577 | |||
578 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_SQUARE); | ||
579 | for (x = 0; x < width; x += 250) | ||
580 | for (y = 0; y < height; y += 250) { | ||
581 | char buf[64]; | ||
582 | |||
583 | cairo_move_to(cr, x, y - 20); | ||
584 | cairo_line_to(cr, x, y + 20); | ||
585 | cairo_move_to(cr, x - 20, y); | ||
586 | cairo_line_to(cr, x + 20, y); | ||
587 | cairo_new_sub_path(cr); | ||
588 | cairo_arc(cr, x, y, 10, 0, M_PI * 2); | ||
589 | cairo_set_line_width(cr, 4); | ||
590 | cairo_set_source_rgb(cr, 0, 0, 0); | ||
591 | cairo_stroke_preserve(cr); | ||
592 | cairo_set_source_rgb(cr, 1, 1, 1); | ||
593 | cairo_set_line_width(cr, 2); | ||
594 | cairo_stroke(cr); | ||
595 | |||
596 | snprintf(buf, sizeof buf, "%d, %d", x, y); | ||
597 | cairo_move_to(cr, x + 20, y + 20); | ||
598 | cairo_text_path(cr, buf); | ||
599 | cairo_set_source_rgb(cr, 0, 0, 0); | ||
600 | cairo_stroke_preserve(cr); | ||
601 | cairo_set_source_rgb(cr, 1, 1, 1); | ||
602 | cairo_fill(cr); | ||
603 | } | ||
604 | |||
605 | cairo_destroy(cr); | ||
606 | #endif | ||
607 | } | ||
608 | |||
609 | static void fill_tiles_yuv_planar(const struct util_format_info *info, | ||
610 | unsigned char *y_mem, unsigned char *u_mem, | ||
611 | unsigned char *v_mem, unsigned int width, | ||
612 | unsigned int height, unsigned int stride) | ||
613 | { | ||
614 | const struct util_yuv_info *yuv = &info->yuv; | ||
615 | unsigned int cs = yuv->chroma_stride; | ||
616 | unsigned int xsub = yuv->xsub; | ||
617 | unsigned int ysub = yuv->ysub; | ||
618 | unsigned int x; | ||
619 | unsigned int y; | ||
620 | |||
621 | for (y = 0; y < height; ++y) { | ||
622 | for (x = 0; x < width; ++x) { | ||
623 | div_t d = div(x+y, width); | ||
624 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
625 | + 0x000a1120 * (d.rem >> 6); | ||
626 | struct color_yuv color = | ||
627 | MAKE_YUV_601((rgb32 >> 16) & 0xff, | ||
628 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
629 | |||
630 | y_mem[x] = color.y; | ||
631 | u_mem[x/xsub*cs] = color.u; | ||
632 | v_mem[x/xsub*cs] = color.v; | ||
633 | } | ||
634 | |||
635 | y_mem += stride; | ||
636 | if ((y + 1) % ysub == 0) { | ||
637 | u_mem += stride * cs / xsub; | ||
638 | v_mem += stride * cs / xsub; | ||
639 | } | ||
640 | } | ||
641 | } | ||
642 | |||
643 | static void fill_tiles_yuv_packed(const struct util_format_info *info, | ||
644 | void *mem, unsigned int width, | ||
645 | unsigned int height, unsigned int stride) | ||
646 | { | ||
647 | const struct util_yuv_info *yuv = &info->yuv; | ||
648 | unsigned char *y_mem = (yuv->order & YUV_YC) ? mem : mem + 1; | ||
649 | unsigned char *c_mem = (yuv->order & YUV_CY) ? mem : mem + 1; | ||
650 | unsigned int u = (yuv->order & YUV_YCrCb) ? 2 : 0; | ||
651 | unsigned int v = (yuv->order & YUV_YCbCr) ? 2 : 0; | ||
652 | unsigned int x; | ||
653 | unsigned int y; | ||
654 | |||
655 | for (y = 0; y < height; ++y) { | ||
656 | for (x = 0; x < width; x += 2) { | ||
657 | div_t d = div(x+y, width); | ||
658 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
659 | + 0x000a1120 * (d.rem >> 6); | ||
660 | struct color_yuv color = | ||
661 | MAKE_YUV_601((rgb32 >> 16) & 0xff, | ||
662 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
663 | |||
664 | y_mem[2*x] = color.y; | ||
665 | c_mem[2*x+u] = color.u; | ||
666 | y_mem[2*x+2] = color.y; | ||
667 | c_mem[2*x+v] = color.v; | ||
668 | } | ||
669 | |||
670 | y_mem += stride; | ||
671 | c_mem += stride; | ||
672 | } | ||
673 | } | ||
674 | |||
675 | static void fill_tiles_rgb16(const struct util_format_info *info, void *mem, | ||
676 | unsigned int width, unsigned int height, | ||
677 | unsigned int stride) | ||
678 | { | ||
679 | const struct util_rgb_info *rgb = &info->rgb; | ||
680 | void *mem_base = mem; | ||
681 | unsigned int x, y; | ||
682 | |||
683 | for (y = 0; y < height; ++y) { | ||
684 | for (x = 0; x < width; ++x) { | ||
685 | div_t d = div(x+y, width); | ||
686 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
687 | + 0x000a1120 * (d.rem >> 6); | ||
688 | uint16_t color = | ||
689 | MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, | ||
690 | (rgb32 >> 8) & 0xff, rgb32 & 0xff, | ||
691 | 255); | ||
692 | |||
693 | ((uint16_t *)mem)[x] = color; | ||
694 | } | ||
695 | mem += stride; | ||
696 | } | ||
697 | |||
698 | make_pwetty(mem_base, width, height, stride, info->format); | ||
699 | } | ||
700 | |||
701 | static void fill_tiles_rgb24(const struct util_format_info *info, void *mem, | ||
702 | unsigned int width, unsigned int height, | ||
703 | unsigned int stride) | ||
704 | { | ||
705 | const struct util_rgb_info *rgb = &info->rgb; | ||
706 | unsigned int x, y; | ||
707 | |||
708 | for (y = 0; y < height; ++y) { | ||
709 | for (x = 0; x < width; ++x) { | ||
710 | div_t d = div(x+y, width); | ||
711 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
712 | + 0x000a1120 * (d.rem >> 6); | ||
713 | struct color_rgb24 color = | ||
714 | MAKE_RGB24(rgb, (rgb32 >> 16) & 0xff, | ||
715 | (rgb32 >> 8) & 0xff, rgb32 & 0xff); | ||
716 | |||
717 | ((struct color_rgb24 *)mem)[x] = color; | ||
718 | } | ||
719 | mem += stride; | ||
720 | } | ||
721 | } | ||
722 | |||
723 | static void fill_tiles_rgb32(const struct util_format_info *info, void *mem, | ||
724 | unsigned int width, unsigned int height, | ||
725 | unsigned int stride) | ||
726 | { | ||
727 | const struct util_rgb_info *rgb = &info->rgb; | ||
728 | void *mem_base = mem; | ||
729 | unsigned int x, y; | ||
730 | |||
731 | for (y = 0; y < height; ++y) { | ||
732 | for (x = 0; x < width; ++x) { | ||
733 | div_t d = div(x+y, width); | ||
734 | uint32_t rgb32 = 0x00130502 * (d.quot >> 6) | ||
735 | + 0x000a1120 * (d.rem >> 6); | ||
736 | uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255; | ||
737 | uint32_t color = | ||
738 | MAKE_RGBA(rgb, (rgb32 >> 16) & 0xff, | ||
739 | (rgb32 >> 8) & 0xff, rgb32 & 0xff, | ||
740 | alpha); | ||
741 | |||
742 | ((uint32_t *)mem)[x] = color; | ||
743 | } | ||
744 | mem += stride; | ||
745 | } | ||
746 | |||
747 | make_pwetty(mem_base, width, height, stride, info->format); | ||
748 | } | ||
749 | |||
750 | static void fill_tiles(const struct util_format_info *info, void *planes[3], | ||
751 | unsigned int width, unsigned int height, | ||
752 | unsigned int stride) | ||
753 | { | ||
754 | unsigned char *u, *v; | ||
755 | |||
756 | switch (info->format) { | ||
757 | case DRM_FORMAT_UYVY: | ||
758 | case DRM_FORMAT_VYUY: | ||
759 | case DRM_FORMAT_YUYV: | ||
760 | case DRM_FORMAT_YVYU: | ||
761 | return fill_tiles_yuv_packed(info, planes[0], | ||
762 | width, height, stride); | ||
763 | |||
764 | case DRM_FORMAT_NV12: | ||
765 | case DRM_FORMAT_NV21: | ||
766 | case DRM_FORMAT_NV16: | ||
767 | case DRM_FORMAT_NV61: | ||
768 | u = info->yuv.order & YUV_YCbCr ? planes[1] : planes[1] + 1; | ||
769 | v = info->yuv.order & YUV_YCrCb ? planes[1] : planes[1] + 1; | ||
770 | return fill_tiles_yuv_planar(info, planes[0], u, v, | ||
771 | width, height, stride); | ||
772 | |||
773 | case DRM_FORMAT_YUV420: | ||
774 | return fill_tiles_yuv_planar(info, planes[0], planes[1], | ||
775 | planes[2], width, height, stride); | ||
776 | |||
777 | case DRM_FORMAT_YVU420: | ||
778 | return fill_tiles_yuv_planar(info, planes[0], planes[2], | ||
779 | planes[1], width, height, stride); | ||
780 | |||
781 | case DRM_FORMAT_ARGB4444: | ||
782 | case DRM_FORMAT_XRGB4444: | ||
783 | case DRM_FORMAT_ABGR4444: | ||
784 | case DRM_FORMAT_XBGR4444: | ||
785 | case DRM_FORMAT_RGBA4444: | ||
786 | case DRM_FORMAT_RGBX4444: | ||
787 | case DRM_FORMAT_BGRA4444: | ||
788 | case DRM_FORMAT_BGRX4444: | ||
789 | case DRM_FORMAT_RGB565: | ||
790 | case DRM_FORMAT_BGR565: | ||
791 | case DRM_FORMAT_ARGB1555: | ||
792 | case DRM_FORMAT_XRGB1555: | ||
793 | case DRM_FORMAT_ABGR1555: | ||
794 | case DRM_FORMAT_XBGR1555: | ||
795 | case DRM_FORMAT_RGBA5551: | ||
796 | case DRM_FORMAT_RGBX5551: | ||
797 | case DRM_FORMAT_BGRA5551: | ||
798 | case DRM_FORMAT_BGRX5551: | ||
799 | return fill_tiles_rgb16(info, planes[0], | ||
800 | width, height, stride); | ||
801 | |||
802 | case DRM_FORMAT_BGR888: | ||
803 | case DRM_FORMAT_RGB888: | ||
804 | return fill_tiles_rgb24(info, planes[0], | ||
805 | width, height, stride); | ||
806 | case DRM_FORMAT_ARGB8888: | ||
807 | case DRM_FORMAT_XRGB8888: | ||
808 | case DRM_FORMAT_ABGR8888: | ||
809 | case DRM_FORMAT_XBGR8888: | ||
810 | case DRM_FORMAT_RGBA8888: | ||
811 | case DRM_FORMAT_RGBX8888: | ||
812 | case DRM_FORMAT_BGRA8888: | ||
813 | case DRM_FORMAT_BGRX8888: | ||
814 | case DRM_FORMAT_ARGB2101010: | ||
815 | case DRM_FORMAT_XRGB2101010: | ||
816 | case DRM_FORMAT_ABGR2101010: | ||
817 | case DRM_FORMAT_XBGR2101010: | ||
818 | case DRM_FORMAT_RGBA1010102: | ||
819 | case DRM_FORMAT_RGBX1010102: | ||
820 | case DRM_FORMAT_BGRA1010102: | ||
821 | case DRM_FORMAT_BGRX1010102: | ||
822 | return fill_tiles_rgb32(info, planes[0], | ||
823 | width, height, stride); | ||
824 | } | ||
825 | } | ||
826 | |||
827 | static void fill_plain(const struct util_format_info *info, void *planes[3], | ||
828 | unsigned int width, unsigned int height, | ||
829 | unsigned int stride) | ||
830 | { | ||
831 | memset(planes[0], 0x77, stride * height); | ||
832 | } | ||
833 | |||
834 | /* | ||
835 | * util_fill_pattern - Fill a buffer with a test pattern | ||
836 | * @format: Pixel format | ||
837 | * @pattern: Test pattern | ||
838 | * @planes: Array of buffers | ||
839 | * @width: Width in pixels | ||
840 | * @height: Height in pixels | ||
841 | * @stride: Line stride (pitch) in bytes | ||
842 | * | ||
843 | * Fill the buffers with the test pattern specified by the pattern parameter. | ||
844 | * Supported formats vary depending on the selected pattern. | ||
845 | */ | ||
846 | void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, | ||
847 | void *planes[3], unsigned int width, | ||
848 | unsigned int height, unsigned int stride) | ||
849 | { | ||
850 | const struct util_format_info *info; | ||
851 | |||
852 | info = util_format_info_find(format); | ||
853 | if (info == NULL) | ||
854 | return; | ||
855 | |||
856 | switch (pattern) { | ||
857 | case UTIL_PATTERN_TILES: | ||
858 | return fill_tiles(info, planes, width, height, stride); | ||
859 | |||
860 | case UTIL_PATTERN_SMPTE: | ||
861 | return fill_smpte(info, planes, width, height, stride); | ||
862 | |||
863 | case UTIL_PATTERN_PLAIN: | ||
864 | return fill_plain(info, planes, width, height, stride); | ||
865 | |||
866 | default: | ||
867 | printf("Error: unsupported test pattern %u.\n", pattern); | ||
868 | break; | ||
869 | } | ||
870 | } | ||
diff --git a/tests/util/pattern.h b/tests/util/pattern.h new file mode 100644 index 00000000..d5c4260c --- /dev/null +++ b/tests/util/pattern.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Copyright 2008 Tungsten Graphics | ||
3 | * Jakob Bornecrantz <jakob@tungstengraphics.com> | ||
4 | * Copyright 2008 Intel Corporation | ||
5 | * Jesse Barnes <jesse.barnes@intel.com> | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
8 | * copy of this software and associated documentation files (the "Software"), | ||
9 | * to deal in the Software without restriction, including without limitation | ||
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
11 | * and/or sell copies of the Software, and to permit persons to whom the | ||
12 | * Software is furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
23 | * IN THE SOFTWARE. | ||
24 | */ | ||
25 | |||
26 | #ifndef UTIL_PATTERN_H | ||
27 | #define UTIL_PATTERN_H | ||
28 | |||
29 | enum util_fill_pattern { | ||
30 | UTIL_PATTERN_TILES, | ||
31 | UTIL_PATTERN_PLAIN, | ||
32 | UTIL_PATTERN_SMPTE, | ||
33 | }; | ||
34 | |||
35 | void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, | ||
36 | void *planes[3], unsigned int width, | ||
37 | unsigned int height, unsigned int stride); | ||
38 | |||
39 | #endif /* UTIL_PATTERN_H */ | ||
diff --git a/tests/vbltest/Makefile.am b/tests/vbltest/Makefile.am index 4d87887a..182e3b6d 100644 --- a/tests/vbltest/Makefile.am +++ b/tests/vbltest/Makefile.am | |||
@@ -1,6 +1,7 @@ | |||
1 | AM_CFLAGS = \ | 1 | AM_CFLAGS = \ |
2 | $(WARN_CFLAGS)\ | 2 | $(WARN_CFLAGS)\ |
3 | -I$(top_srcdir)/include/drm \ | 3 | -I$(top_srcdir)/include/drm \ |
4 | -I$(top_srcdir)/tests \ | ||
4 | -I$(top_srcdir) | 5 | -I$(top_srcdir) |
5 | 6 | ||
6 | if HAVE_INSTALL_TESTS | 7 | if HAVE_INSTALL_TESTS |
diff --git a/tests/vbltest/vbltest.c b/tests/vbltest/vbltest.c index e27f45c1..de93e770 100644 --- a/tests/vbltest/vbltest.c +++ b/tests/vbltest/vbltest.c | |||
@@ -54,7 +54,7 @@ | |||
54 | #include "xf86drm.h" | 54 | #include "xf86drm.h" |
55 | #include "xf86drmMode.h" | 55 | #include "xf86drmMode.h" |
56 | 56 | ||
57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | 57 | #include "util/common.h" |
58 | 58 | ||
59 | extern char *optarg; | 59 | extern char *optarg; |
60 | extern int optind, opterr, optopt; | 60 | extern int optind, opterr, optopt; |