kmsallocator: add alignment when create fb

drm driver will check width and height alignment

upstream status: Pending
https://bugzilla.gnome.org/show_bug.cgi?id=792812

Conflicts:
	sys/kms/gstkmsallocator.c
diff --git a/sys/kms/gstkmsallocator.c b/sys/kms/gstkmsallocator.c
index 2258e58..cec14a6 100644
--- a/sys/kms/gstkmsallocator.c
+++ b/sys/kms/gstkmsallocator.c
@@ -442,7 +442,7 @@
 {
   gint i, ret;
   gint num_planes = GST_VIDEO_INFO_N_PLANES (vinfo);
-  guint32 w, h, fmt, bo_handles[4] = { 0, };
+  guint32 w, h, fmt, alignment, bo_handles[4] = { 0, };
   guint32 pitches[4] = { 0, };
   guint32 offsets[4] = { 0, };
   guint64 modifier[4] = { 0, };
@@ -453,6 +453,9 @@
   w = GST_VIDEO_INFO_WIDTH (vinfo);
   h = GST_VIDEO_INFO_HEIGHT (vinfo);
   fmt = gst_drm_format_from_video (GST_VIDEO_INFO_FORMAT (vinfo));
+  alignment = gst_drm_alignment_from_drm_format (fmt);
+  w = GST_ROUND_UP_N (w, alignment);
+  h = GST_ROUND_UP_N (h, alignment);
 
   for (i = 0; i < num_planes; i++) {
     if (kmsmem->bo)
diff --git a/sys/kms/gstkmsutils.c b/sys/kms/gstkmsutils.c
index 23b3cc7..2816f00 100644
--- a/sys/kms/gstkmsutils.c
+++ b/sys/kms/gstkmsutils.c
@@ -126,6 +126,31 @@
 }
 
 guint32
+gst_drm_alignment_from_drm_format (guint32 drmfmt)
+{
+  guint32 alignment;
+
+  switch (drmfmt) {
+    case DRM_FORMAT_YUV420:
+    case DRM_FORMAT_YVU420:
+    case DRM_FORMAT_YUV422:
+    case DRM_FORMAT_NV12:
+    case DRM_FORMAT_NV21:
+    case DRM_FORMAT_NV16:
+    case DRM_FORMAT_UYVY:
+    case DRM_FORMAT_YUYV:
+    case DRM_FORMAT_YVYU:
+      alignment = 2;
+      break;
+    default:
+      alignment = 1;
+      break;
+  }
+
+  return alignment;
+}
+
+guint32
 gst_drm_height_from_drm (guint32 drmfmt, guint32 height)
 {
   guint32 ret;
diff --git a/sys/kms/gstkmsutils.h b/sys/kms/gstkmsutils.h
index 95e81f8..17b51b9 100644
--- a/sys/kms/gstkmsutils.h
+++ b/sys/kms/gstkmsutils.h
@@ -33,6 +33,7 @@
 GstVideoFormat gst_video_format_from_drm (guint32 drmfmt);
 guint32        gst_drm_format_from_video (GstVideoFormat fmt);
 guint32        gst_drm_bpp_from_drm (guint32 drmfmt);
+guint32        gst_drm_alignment_from_drm_format (guint32 drmfmt);
 guint32        gst_drm_height_from_drm (guint32 drmfmt, guint32 height);
 GstCaps *      gst_kms_sink_caps_template_fill (void);
 void           gst_video_calculate_device_ratio (guint dev_width,