[MMFMWK-7936] kmssink: add protection for (x,y) < 0 case when resize

If DTRC not enable, (x,y) < 0 will cause driver return error. Add protection
here. Need improve to do input crop later

upstream status: imx specific
diff --git a/sys/kms/gstkmssink.c b/sys/kms/gstkmssink.c
index 79b0133..4967109 100644
--- a/sys/kms/gstkmssink.c
+++ b/sys/kms/gstkmssink.c
@@ -490,6 +490,32 @@
 }
 
 static gboolean
+check_vsi_tile_enable (GstKMSSink * self, GstBuffer * buffer)
+{
+  GstDmabufMeta *dmabuf_meta;
+  gint64 drm_modifier = 0;
+
+  if (!buffer)
+    buffer = self->hold_buf[0];
+
+  if (!buffer)
+    return FALSE;
+
+  if (!gst_is_dmabuf_memory (gst_buffer_peek_memory (buffer, 0)))
+    return FALSE;
+
+  dmabuf_meta = gst_buffer_get_dmabuf_meta (buffer);
+  if (dmabuf_meta)
+    drm_modifier = dmabuf_meta->drm_modifier;
+
+  GST_INFO_OBJECT (self, "buffer modifier type %d", drm_modifier);
+
+  return drm_modifier == DRM_FORMAT_MOD_VSI_G1_TILED
+         || drm_modifier == DRM_FORMAT_MOD_VSI_G2_TILED
+         || drm_modifier == DRM_FORMAT_MOD_VSI_G2_TILED_COMPRESSED;
+}
+
+static gboolean
 configure_mode_setting (GstKMSSink * self, GstVideoInfo * vinfo)
 {
   gboolean ret;
@@ -1807,7 +1833,15 @@
   gst_video_sink_center_rect (src, dst, &result, can_scale);
 
   result.x = GST_ROUND_DOWN_N (result.x + self->preferred_rect.x, alignment);
-  result.y = GST_ROUND_DOWN_N (result.y + self->preferred_rect.y, alignment);;
+  result.y = GST_ROUND_DOWN_N (result.y + self->preferred_rect.y, alignment);
+
+  if (result.x < 0 || result.y < 0) {
+    /* FIXME: need improve cropping handle when DTRC is not enable */
+    if (!check_vsi_tile_enable (self, buf)) {
+      result.x = result.x < 0 ? 0 : result.x;
+      result.y = result.y < 0 ? 0 : result.y;
+    }
+  }
 
   if (crop) {
     src.w = crop->width;