plane_test: support P010

This CL adds P010 to plane_test to simplify testing this format.
Needs another CL for minigbm.

BUG=b:183760490
TEST=on volteer:
  /usr/bin/plane_test -f P010
  /usr/bin/plane_test --format NV12 --size 600x400 -p --format P010 --size 200x200 -d 200,200
work as expected.

Cq-Depend: chromium:2808788
Change-Id: I40817388180476ed702c1530c9e583d4e9ee6cb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/drm-tests/+/2808787
Tested-by: Miguel Casas <mcasas@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
diff --git a/bsdrm/src/draw.c b/bsdrm/src/draw.c
index de9e2e1..f911e58 100644
--- a/bsdrm/src/draw.c
+++ b/bsdrm/src/draw.c
@@ -78,7 +78,7 @@
 	    PIXEL_FORMAT_AND_NAME(NV12),
 	    3,
 	    {
-		{ { 0.2567890625f, 0.50412890625f, 0.09790625f }, 16.0f, 1, 1, 1, 0, 0 },
+		{ { 0.2567890625f, 0.50412890625f, 0.09790625f },       16.0f, 1, 1, 1, 0, 0 },
 		{ { -0.14822265625f, -0.2909921875f, 0.43921484375f }, 128.0f, 2, 2, 2, 1, 0 },
 		{ { 0.43921484375f, -0.3677890625f, -0.07142578125f }, 128.0f, 2, 2, 2, 1, 1 },
 	    },
@@ -146,6 +146,15 @@
 		{ { -0.14822265625f, -0.2909921875f, 0.43921484375f }, 128.0f, 2, 2, 1, 2, 0 },
 	    },
 	},
+	{
+	    PIXEL_FORMAT_AND_NAME(P010),
+	    3,
+	    {
+		{ { 0.2567890625f, 0.50412890625f, 0.09790625f },       16.0f, 1, 1, 2, 0, 0 },
+		{ { -0.14822265625f, -0.2909921875f, 0.43921484375f }, 128.0f, 2, 2, 4, 1, 0 },
+		{ { 0.43921484375f, -0.3677890625f, -0.07142578125f }, 128.0f, 2, 2, 4, 1, 2 },
+	    },
+	},
 };
 
 struct draw_plane {
@@ -201,8 +210,9 @@
 {
 	uint8_t *ptr, *converted_colors[MAX_COMPONENTS];
 	struct draw_plane planes[GBM_MAX_PLANES];
-	uint32_t height = data->h = gbm_bo_get_height(bo);
-	uint32_t width = data->w = gbm_bo_get_width(bo);
+	const uint32_t height = data->h = gbm_bo_get_height(bo);
+	const uint32_t width = data->w = gbm_bo_get_width(bo);
+	const uint32_t bytes_per_pixel = gbm_bo_get_bpp(bo);
 
 	size_t num_planes = mmap_planes(mapper, bo, planes);
 	if (num_planes == 0) {
@@ -236,22 +246,27 @@
 	for (size_t comp_index = 0; comp_index < format->component_count; comp_index++) {
 		const struct draw_format_component *comp = &format->components[comp_index];
 		struct draw_plane *plane = &planes[comp->plane_index];
+
 		for (uint32_t y = 0; y < height / comp->vertical_subsample_rate; y++) {
 			rows[comp_index] = plane->ptr + comp->plane_offset + plane->row_stride * y;
+
 			for (uint32_t x = 0; x < width / comp->horizontal_subsample_rate; x++) {
 				offset = color = samples = 0;
+
 				for (uint32_t j = 0; j < comp->vertical_subsample_rate; j++) {
 					offset = (y * comp->vertical_subsample_rate + j) * width +
 						 x * comp->horizontal_subsample_rate;
-					for (uint32_t i = 0; i < comp->horizontal_subsample_rate;
-					     i++) {
+					for (uint32_t i = 0; i < comp->horizontal_subsample_rate; i++) {
 						color += converted_colors[comp_index][offset];
 						samples++;
 						offset++;
 					}
 				}
-
-				*(rows[comp_index] + x * comp->byte_skip) = color / samples;
+				uint8_t* const byte_address = rows[comp_index] + x * comp->byte_skip;
+				if (bytes_per_pixel != 2u)
+					*byte_address = color / samples;
+				else // This is for P010 and similar high-bit depth YUV formats.
+					*(uint16_t *)byte_address = (color / samples) << 8;
 			}
 		}
 	}
diff --git a/plane_test.c b/plane_test.c
index 06ccedf..94e8522 100644
--- a/plane_test.c
+++ b/plane_test.c
@@ -483,11 +483,12 @@
 		printf("Creating buffer %ux%u %s\n", tp->bo_w, tp->bo_h,
 		       bs_get_format_name(tp->format));
 		tp->bo = gbm_bo_create(gbm, tp->bo_w, tp->bo_h, bs_get_pixel_format(tp->format),
-				       GBM_BO_USE_SCANOUT | GBM_BO_USE_SW_WRITE_RARELY);
+				       GBM_BO_USE_SCANOUT);
 		if (!tp->bo) {
 			bs_debug_error("failed to create buffer object");
 			return 1;
 		}
+		printf("Bytes per pixel: %d\n", gbm_bo_get_bpp(tp->bo));
 
 		tp->fb_id = bs_drm_fb_create_gbm(tp->bo);
 		if (!tp->fb_id) {