diff options
author | Benjamin Gaignard | 2016-02-05 08:02:51 -0600 |
---|---|---|
committer | Sean Paul | 2016-02-16 12:49:04 -0600 |
commit | 5ba2bf74d75d9753f9aec1e83798070e78918109 (patch) | |
tree | 243c84522c070c00c9d3e0879f467b607d910dc0 | |
parent | cfe84dc58885ca7b75ec113f95b1c7b6873381b5 (diff) | |
download | external-libdrm-5ba2bf74d75d9753f9aec1e83798070e78918109.tar.gz external-libdrm-5ba2bf74d75d9753f9aec1e83798070e78918109.tar.xz external-libdrm-5ba2bf74d75d9753f9aec1e83798070e78918109.zip |
atomictest: add NV12 support
Make atomictest support NV12 format.
Conversion from RGB to YUV is done in software using the same matrix
than for modetest.
Remove bbp parameter from create_sp_bo because it is link to plane format.
Change-Id: I2f844b24d11fca65310668522bca4427c2c5e4ef
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
-rw-r--r-- | tests/planetest/atomictest.c | 3 | ||||
-rw-r--r-- | tests/planetest/bo.c | 69 | ||||
-rw-r--r-- | tests/planetest/bo.h | 2 | ||||
-rw-r--r-- | tests/planetest/dev.c | 3 | ||||
-rw-r--r-- | tests/planetest/planetest.c | 2 |
5 files changed, 69 insertions, 10 deletions
diff --git a/tests/planetest/atomictest.c b/tests/planetest/atomictest.c index 6df3f16d..5fec911a 100644 --- a/tests/planetest/atomictest.c +++ b/tests/planetest/atomictest.c | |||
@@ -91,8 +91,7 @@ int main(int argc, char *argv[]) | |||
91 | goto out; | 91 | goto out; |
92 | } | 92 | } |
93 | 93 | ||
94 | plane[i]->bo = create_sp_bo(dev, plane_w, plane_h, 16, 32, | 94 | plane[i]->bo = create_sp_bo(dev, plane_w, plane_h, 16, plane[i]->format, 0); |
95 | plane[i]->format, 0); | ||
96 | if (!plane[i]->bo) { | 95 | if (!plane[i]->bo) { |
97 | printf("failed to create plane bo\n"); | 96 | printf("failed to create plane bo\n"); |
98 | goto out; | 97 | goto out; |
diff --git a/tests/planetest/bo.c b/tests/planetest/bo.c index 9a718280..d4b82c66 100644 --- a/tests/planetest/bo.c +++ b/tests/planetest/bo.c | |||
@@ -13,9 +13,46 @@ | |||
13 | #include "bo.h" | 13 | #include "bo.h" |
14 | #include "dev.h" | 14 | #include "dev.h" |
15 | 15 | ||
16 | #define MAKE_YUV_601_Y(r, g, b) \ | ||
17 | ((( 66 * (r) + 129 * (g) + 25 * (b) + 128) >> 8) + 16) | ||
18 | #define MAKE_YUV_601_U(r, g, b) \ | ||
19 | (((-38 * (r) - 74 * (g) + 112 * (b) + 128) >> 8) + 128) | ||
20 | #define MAKE_YUV_601_V(r, g, b) \ | ||
21 | (((112 * (r) - 94 * (g) - 18 * (b) + 128) >> 8) + 128) | ||
22 | |||
23 | static void draw_rect_yuv(struct sp_bo *bo, uint32_t x, uint32_t y, uint32_t width, | ||
24 | uint32_t height, uint8_t a, uint8_t r, uint8_t g, uint8_t b) | ||
25 | { | ||
26 | uint32_t i, j, xmax = x + width, ymax = y + height; | ||
27 | |||
28 | if (xmax > bo->width) | ||
29 | xmax = bo->width; | ||
30 | if (ymax > bo->height) | ||
31 | ymax = bo->height; | ||
32 | |||
33 | for (i = y; i < ymax; i++) { | ||
34 | uint8_t *luma = bo->map_addr + i * bo->pitch; | ||
35 | |||
36 | for (j = x; j < xmax; j++) | ||
37 | luma[j] = MAKE_YUV_601_Y(r, g, b); | ||
38 | } | ||
39 | |||
40 | for (i = y; i < ymax / 2; i++) { | ||
41 | uint8_t *chroma = bo->map_addr + (i + height) * bo->pitch; | ||
42 | |||
43 | for (j = x; j < xmax / 2; j++) { | ||
44 | chroma[j*2] = MAKE_YUV_601_U(r, g, b); | ||
45 | chroma[j*2 + 1] = MAKE_YUV_601_V(r, g, b); | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
16 | void fill_bo(struct sp_bo *bo, uint8_t a, uint8_t r, uint8_t g, uint8_t b) | 50 | void fill_bo(struct sp_bo *bo, uint8_t a, uint8_t r, uint8_t g, uint8_t b) |
17 | { | 51 | { |
18 | draw_rect(bo, 0, 0, bo->width, bo->height, a, r, g, b); | 52 | if (bo->format == DRM_FORMAT_NV12) |
53 | draw_rect_yuv(bo, 0, 0, bo->width, bo->height, a, r, g, b); | ||
54 | else | ||
55 | draw_rect(bo, 0, 0, bo->width, bo->height, a, r, g, b); | ||
19 | } | 56 | } |
20 | 57 | ||
21 | void draw_rect(struct sp_bo *bo, uint32_t x, uint32_t y, uint32_t width, | 58 | void draw_rect(struct sp_bo *bo, uint32_t x, uint32_t y, uint32_t width, |
@@ -59,6 +96,11 @@ static int add_fb_sp_bo(struct sp_bo *bo, uint32_t format) | |||
59 | handles[0] = bo->handle; | 96 | handles[0] = bo->handle; |
60 | pitches[0] = bo->pitch; | 97 | pitches[0] = bo->pitch; |
61 | offsets[0] = 0; | 98 | offsets[0] = 0; |
99 | if (bo->format == DRM_FORMAT_NV12) { | ||
100 | handles[1] = bo->handle; | ||
101 | pitches[1] = pitches[0]; | ||
102 | offsets[1] = pitches[0] * bo->height; | ||
103 | } | ||
62 | 104 | ||
63 | ret = drmModeAddFB2(bo->dev->fd, bo->width, bo->height, | 105 | ret = drmModeAddFB2(bo->dev->fd, bo->width, bo->height, |
64 | format, handles, pitches, offsets, | 106 | format, handles, pitches, offsets, |
@@ -94,8 +136,21 @@ static int map_sp_bo(struct sp_bo *bo) | |||
94 | return 0; | 136 | return 0; |
95 | } | 137 | } |
96 | 138 | ||
139 | static int format_to_bpp(uint32_t format) | ||
140 | { | ||
141 | switch (format) { | ||
142 | case DRM_FORMAT_NV12: | ||
143 | return 8; | ||
144 | case DRM_FORMAT_ARGB8888: | ||
145 | case DRM_FORMAT_XRGB8888: | ||
146 | case DRM_FORMAT_RGBA8888: | ||
147 | default: | ||
148 | return 32; | ||
149 | } | ||
150 | } | ||
151 | |||
97 | struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, | 152 | struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, |
98 | uint32_t depth, uint32_t bpp, uint32_t format, uint32_t flags) | 153 | uint32_t depth, uint32_t format, uint32_t flags) |
99 | { | 154 | { |
100 | int ret; | 155 | int ret; |
101 | struct drm_mode_create_dumb cd; | 156 | struct drm_mode_create_dumb cd; |
@@ -105,9 +160,13 @@ struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, | |||
105 | if (!bo) | 160 | if (!bo) |
106 | return NULL; | 161 | return NULL; |
107 | 162 | ||
108 | cd.height = height; | 163 | if (format == DRM_FORMAT_NV12) |
164 | cd.height = height * 3 / 2; | ||
165 | else | ||
166 | cd.height = height; | ||
167 | |||
109 | cd.width = width; | 168 | cd.width = width; |
110 | cd.bpp = bpp; | 169 | cd.bpp = format_to_bpp(format); |
111 | cd.flags = flags; | 170 | cd.flags = flags; |
112 | 171 | ||
113 | ret = drmIoctl(dev->fd, DRM_IOCTL_MODE_CREATE_DUMB, &cd); | 172 | ret = drmIoctl(dev->fd, DRM_IOCTL_MODE_CREATE_DUMB, &cd); |
@@ -120,7 +179,7 @@ struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, | |||
120 | bo->width = width; | 179 | bo->width = width; |
121 | bo->height = height; | 180 | bo->height = height; |
122 | bo->depth = depth; | 181 | bo->depth = depth; |
123 | bo->bpp = bpp; | 182 | bo->bpp = format_to_bpp(format); |
124 | bo->format = format; | 183 | bo->format = format; |
125 | bo->flags = flags; | 184 | bo->flags = flags; |
126 | 185 | ||
diff --git a/tests/planetest/bo.h b/tests/planetest/bo.h index 4c5ddf81..7471e126 100644 --- a/tests/planetest/bo.h +++ b/tests/planetest/bo.h | |||
@@ -23,7 +23,7 @@ struct sp_bo { | |||
23 | }; | 23 | }; |
24 | 24 | ||
25 | struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, | 25 | struct sp_bo *create_sp_bo(struct sp_dev *dev, uint32_t width, uint32_t height, |
26 | uint32_t depth, uint32_t bpp, uint32_t format, uint32_t flags); | 26 | uint32_t depth, uint32_t format, uint32_t flags); |
27 | 27 | ||
28 | void fill_bo(struct sp_bo *bo, uint8_t a, uint8_t r, uint8_t g, uint8_t b); | 28 | void fill_bo(struct sp_bo *bo, uint8_t a, uint8_t r, uint8_t g, uint8_t b); |
29 | void draw_rect(struct sp_bo *bo, uint32_t x, uint32_t y, uint32_t width, | 29 | void draw_rect(struct sp_bo *bo, uint32_t x, uint32_t y, uint32_t width, |
diff --git a/tests/planetest/dev.c b/tests/planetest/dev.c index c8277df3..bd0968c6 100644 --- a/tests/planetest/dev.c +++ b/tests/planetest/dev.c | |||
@@ -93,7 +93,8 @@ static int get_supported_format(struct sp_plane *plane, uint32_t *format) | |||
93 | for (i = 0; i < plane->plane->count_formats; i++) { | 93 | for (i = 0; i < plane->plane->count_formats; i++) { |
94 | if (plane->plane->formats[i] == DRM_FORMAT_XRGB8888 || | 94 | if (plane->plane->formats[i] == DRM_FORMAT_XRGB8888 || |
95 | plane->plane->formats[i] == DRM_FORMAT_ARGB8888 || | 95 | plane->plane->formats[i] == DRM_FORMAT_ARGB8888 || |
96 | plane->plane->formats[i] == DRM_FORMAT_RGBA8888) { | 96 | plane->plane->formats[i] == DRM_FORMAT_RGBA8888 || |
97 | plane->plane->formats[i] == DRM_FORMAT_NV12) { | ||
97 | *format = plane->plane->formats[i]; | 98 | *format = plane->plane->formats[i]; |
98 | return 0; | 99 | return 0; |
99 | } | 100 | } |
diff --git a/tests/planetest/planetest.c b/tests/planetest/planetest.c index 7fcfca68..5e187c99 100644 --- a/tests/planetest/planetest.c +++ b/tests/planetest/planetest.c | |||
@@ -79,7 +79,7 @@ int main(int argc, char *argv[]) | |||
79 | goto out; | 79 | goto out; |
80 | } | 80 | } |
81 | 81 | ||
82 | plane[i]->bo = create_sp_bo(dev, plane_w, plane_h, 16, 32, | 82 | plane[i]->bo = create_sp_bo(dev, plane_w, plane_h, 16, |
83 | plane[i]->format, 0); | 83 | plane[i]->format, 0); |
84 | if (!plane[i]->bo) { | 84 | if (!plane[i]->bo) { |
85 | printf("failed to create plane bo\n"); | 85 | printf("failed to create plane bo\n"); |