minigbm: rockchip: enable NV12 for Android

For NV12 buffers to work on Android, we need to use the same
logic that we use in gralloc_drm_rockchip.  Otherwise, video
playback doesn't work in the container.

BUG=chromium:616275
TEST=Play Youtube app.  Also ran plane_test (which defaults to NV12).
CQ-DEPEND=CL:392547

Change-Id: I8dbd989f2638c99200866f8191450c71114bdbe5
Reviewed-on: https://chromium-review.googlesource.com/392548
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/rockchip.c b/rockchip.c
index e551099..c2b055e 100644
--- a/rockchip.c
+++ b/rockchip.c
@@ -26,17 +26,24 @@
 	struct drm_rockchip_gem_create gem_create;
 
 	if (format == DRV_FORMAT_NV12) {
-		width = ALIGN(width, 4);
-		height = ALIGN(height, 4);
-	}
+		uint32_t w_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16);
+		uint32_t h_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16);
 
-	drv_bo_from_format(bo, width, height, format);
+		uint32_t aligned_width = w_mbs * 16;
+		uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2);
+
+		drv_bo_from_format(bo, aligned_width, height, format);
+		bo->total_size = bo->strides[0] * aligned_height
+				 + w_mbs * h_mbs * 128;
+	} else {
+		drv_bo_from_format(bo, width, height, format);
+	}
 
 	memset(&gem_create, 0, sizeof(gem_create));
 	gem_create.size = bo->total_size;
 
 	ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE,
-			   &gem_create);
+		       &gem_create);
 
 	if (ret) {
 		fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed "