weston: recalculate afrc buffer stride [1/1]

PD#SWPL-174653

Problem:
stride of 1920x4 is required for 1080p displaying

Solution:
set stride to 4x for afrc buffer

Verify:
s7d

Change-Id: I35ac8b881b603a9b04cc9076d0ab00acae83c4cf
Signed-off-by: xiaotao.wei <xiaotao.wei@amlogic.com>
diff --git a/libweston/backend-drm/fb.c b/libweston/backend-drm/fb.c
index 5ac46ef..0f63119 100644
--- a/libweston/backend-drm/fb.c
+++ b/libweston/backend-drm/fb.c
@@ -44,6 +44,14 @@
 #include "linux-dmabuf.h"
 
 #include "aml-weston/aml-backend.h"
+#include <limits.h> /* CHAR_BIT */
+
+#ifndef DRM_FORMAT_MOD_ARM_TYPE_MASK
+#define DRM_FORMAT_MOD_ARM_TYPE_MASK 0xf
+#endif
+
+#define fourcc_mod_code_get_vendor(val) ((val) >> 56)
+#define fourcc_mod_code_get_type(val) (((val) >> 52) & DRM_FORMAT_MOD_ARM_TYPE_MASK)
 
 static void
 drm_fb_destroy(struct drm_fb *fb)
@@ -331,6 +339,14 @@
 #endif
 }
 
+/* Returns true if the modifier describes an AFRC format. */
+static bool drm_fourcc_modifier_is_afrc(uint64_t modifier)
+{
+	uint32_t vendor = fourcc_mod_code_get_vendor(modifier);
+	uint32_t type = fourcc_mod_code_get_type(modifier);
+	return DRM_FORMAT_MOD_VENDOR_ARM == vendor && DRM_FORMAT_MOD_ARM_TYPE_AFRC == type;
+}
+
 struct drm_fb *
 drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
 		   bool is_opaque, enum drm_fb_type type)
@@ -364,7 +380,11 @@
 		fb->modifier = gbm_bo_get_modifier(bo);
 		fb->num_planes = gbm_bo_get_plane_count(bo);
 		for (i = 0; i < fb->num_planes; i++) {
-			fb->strides[i] = gbm_bo_get_stride_for_plane(bo, i);
+			if (drm_fourcc_modifier_is_afrc(fb->modifier)) {
+				fb->strides[i] = fb->width * gbm_bo_get_bpp(bo) / CHAR_BIT;
+			} else {
+				fb->strides[i] = gbm_bo_get_stride_for_plane(bo, i);
+			}
 			fb->handles[i] = gbm_bo_get_handle_for_plane(bo, i).u32;
 			fb->offsets[i] = gbm_bo_get_offset(bo, i);
 		}
diff --git a/shared/weston-drm-fourcc.h b/shared/weston-drm-fourcc.h
index 41b86ed..8bf1a2d 100644
--- a/shared/weston-drm-fourcc.h
+++ b/shared/weston-drm-fourcc.h
@@ -28,7 +28,7 @@
 #ifndef WESTON_DRM_FOURCC_H
 #define WESTON_DRM_FOURCC_H
 
-#include <drm_fourcc.h>
+#include <drm/drm_fourcc.h>
 
 /* The kernel header drm_fourcc.h defines the DRM formats below.  We duplicate
  * some of the definitions here so that building Weston won't require