Merge branch 'aosp/upstream-main' into 'aosp/master'

... to update Minigbm for Cuttlefish to pull in fix for XBGR format
layout from https://crrev.com/c/3414504

Bug: b/216316318
Test: launch_cvd --gpu_mode=guest_swiftshader
Test: launch_cvd --gpu_mode=gfxstream
Change-Id: Iee7e6da7f27de9ea3968d9615a1a859bddd6d117
diff --git a/OWNERS b/OWNERS
index 1facc15..892eb39 100644
--- a/OWNERS
+++ b/OWNERS
@@ -5,6 +5,7 @@
 hiroh@chromium.org
 hoegsberg@chromium.org
 marcheu@chromium.org
+mcasas@chromium.org
 olv@google.com
 robdclark@chromium.org
 stevensd@chromium.org
@@ -14,7 +15,7 @@
 # just reference for backend specific reviews
 per-file amdgpu.c = basni@chromium.org, ddavenport@chromium.org
 per-file i915.c = chadversary@chromium.org, hoegsberg@chromium.org
-per-file mediatek.c = fshao@chromium.org, tzungbi@chromium.org
+per-file mediatek.c = fshao@chromium.org, hsinyi@chromium.org, tzungbi@chromium.org
 per-file msm.c = robdclark@chromium.org, hoegsberg@chromium.org
 per-file rockchip.c = tfiga@chromium.org
 per-file virtgpu* = jbates@chromium.org, natsu@google.com, olv@google.com, zzyiwei@chromium.org
diff --git a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
index 63ec8af..6c07189 100644
--- a/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
+++ b/cros_gralloc/gralloc4/CrosGralloc4Utils.cc
@@ -315,13 +315,13 @@
 
                     {DRM_FORMAT_XBGR8888,
                      {{
-                             .components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
+                             .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
                                              .offsetInBits = 0,
                                              .sizeInBits = 8},
                                             {.type = android::gralloc4::PlaneLayoutComponentType_G,
                                              .offsetInBits = 8,
                                              .sizeInBits = 8},
-                                            {.type = android::gralloc4::PlaneLayoutComponentType_R,
+                                            {.type = android::gralloc4::PlaneLayoutComponentType_B,
                                              .offsetInBits = 16,
                                              .sizeInBits = 8}},
                              .sampleIncrementInBits = 32,
diff --git a/mediatek.c b/mediatek.c
index f6a4c17..8456edd 100644
--- a/mediatek.c
+++ b/mediatek.c
@@ -25,6 +25,15 @@
 
 #define TILE_TYPE_LINEAR 0
 
+#if defined(MTK_MT8183) || defined(MTK_MT8186)
+#define SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
+#endif
+
+// All platforms except MT8173 should USE_NV12_FOR_HW_VIDEO_DECODING.
+#if defined(MTK_MT8183) || defined(MTK_MT8186) || defined(MTK_MT8192) || defined(MTK_MT8195)
+#define USE_NV12_FOR_HW_VIDEO_DECODING
+#endif
+
 struct mediatek_private_map_data {
 	void *cached_addr;
 	void *gem_addr;
@@ -35,16 +44,19 @@
 						  DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
 						  DRM_FORMAT_XRGB8888 };
 
-#ifdef MTK_MT8183
+// clang-format off
 static const uint32_t texture_source_formats[] = {
-	DRM_FORMAT_NV21,	 DRM_FORMAT_NV12,	    DRM_FORMAT_YUYV,
-	DRM_FORMAT_YVU420,	 DRM_FORMAT_YVU420_ANDROID, DRM_FORMAT_ABGR2101010,
-	DRM_FORMAT_ABGR16161616F
-};
-#else
-static const uint32_t texture_source_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID,
-						   DRM_FORMAT_NV12 };
+#ifdef SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
+	DRM_FORMAT_NV21,
+	DRM_FORMAT_YUYV,
+	DRM_FORMAT_ABGR2101010,
+	DRM_FORMAT_ABGR16161616F,
 #endif
+	DRM_FORMAT_NV12,
+	DRM_FORMAT_YVU420,
+	DRM_FORMAT_YVU420_ANDROID
+};
+// clang-format on
 
 static int mediatek_init(struct driver *drv)
 {
@@ -67,7 +79,7 @@
 	metadata.modifier = DRM_FORMAT_MOD_LINEAR;
 	drv_modify_combination(drv, DRM_FORMAT_YVU420, &metadata, BO_USE_HW_VIDEO_DECODER);
 	drv_modify_combination(drv, DRM_FORMAT_YVU420_ANDROID, &metadata, BO_USE_HW_VIDEO_DECODER);
-#if defined(MTK_MT8183) || defined(MTK_MT8192) || defined(MTK_MT8195)
+#ifdef USE_NV12_FOR_HW_VIDEO_DECODING
 	// TODO(hiroh): Switch to use NV12 for video decoder on MT8173 as well.
 	drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, BO_USE_HW_VIDEO_DECODER);
 #endif
@@ -135,7 +147,7 @@
 
 		drv_bo_from_format_and_padding(bo, stride, aligned_height, format, padding);
 	} else {
-#ifdef MTK_MT8183
+#ifdef SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
 		/*
 		 * JPEG Encoder Accelerator requires 16x16 alignment. We want the buffer
 		 * from camera can be put in JEA directly so align the height to 16
@@ -304,7 +316,7 @@
 		*out_use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
 		break;
 	case DRM_FORMAT_FLEX_YCbCr_420_888:
-#if defined(MTK_MT8183) || defined(MTK_MT8192) || defined(MTK_MT8195)
+#ifdef USE_NV12_FOR_HW_VIDEO_DECODING
 		// TODO(hiroh): Switch to use NV12 for video decoder on MT8173 as well.
 		if (use_flags & (BO_USE_HW_VIDEO_DECODER)) {
 			*out_format = DRM_FORMAT_NV12;
diff --git a/msm.c b/msm.c
index f3be2be..255e723 100644
--- a/msm.c
+++ b/msm.c
@@ -38,7 +38,8 @@
 
 static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
 						  DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
-						  DRM_FORMAT_XRGB8888 };
+						  DRM_FORMAT_XRGB8888, DRM_FORMAT_ABGR2101010,
+						  DRM_FORMAT_ABGR16161616F };
 
 static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV12, DRM_FORMAT_R8,
 						   DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID,