drm_hwcomposer: Merge 'aosp/upstream-main' into HEAD am: a393df4bcf

Original change: https://android-review.googlesource.com/c/platform/external/drm_hwcomposer/+/2238060

Change-Id: Ibfb3376003cc553d7074de65f00d41f5fb3d2fe4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/bufferinfo/legacy/BufferInfoImagination.cpp b/bufferinfo/legacy/BufferInfoImagination.cpp
index 1858ddb..6d917c2 100644
--- a/bufferinfo/legacy/BufferInfoImagination.cpp
+++ b/bufferinfo/legacy/BufferInfoImagination.cpp
@@ -51,7 +51,7 @@
   switch (hnd->iFormat) {
 #ifdef HAL_PIXEL_FORMAT_BGRX_8888
     case HAL_PIXEL_FORMAT_BGRX_8888:
-      bo->format = DRM_FORMAT_XRGB8888;
+      bi.format = DRM_FORMAT_XRGB8888;
       break;
 #endif
     default:
diff --git a/drm/DrmDisplayPipeline.cpp b/drm/DrmDisplayPipeline.cpp
index f993d28..e81544d 100644
--- a/drm/DrmDisplayPipeline.cpp
+++ b/drm/DrmDisplayPipeline.cpp
@@ -86,15 +86,15 @@
     return {};
   }
 
-  if (primary_planes.size() > 1) {
-    ALOGE("Found more than 1 primary plane for CRTC %d", crtc.GetId());
-    return {};
+  for (const auto &plane : primary_planes) {
+    pipe->primary_plane = plane->BindPipeline(pipe.get());
+    if (pipe->primary_plane) {
+      break;
+    }
   }
 
-  pipe->primary_plane = primary_planes[0]->BindPipeline(pipe.get());
   if (!pipe->primary_plane) {
-    ALOGE("Primary plane %d is already owned. Internal error.",
-          primary_planes[0]->GetId());
+    ALOGE("Failed to bind primary plane");
     return {};
   }
 
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 329ef1c..5051d35 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -148,6 +148,23 @@
 }
 
 bool DrmPlane::IsCrtcSupported(const DrmCrtc &crtc) const {
+  unsigned int crtc_property_value = 0;
+  std::tie(std::ignore, crtc_property_value) = crtc_property_.value();
+  if (crtc_property_value != 0 && crtc_property_value != crtc.GetId() &&
+      GetType() == DRM_PLANE_TYPE_PRIMARY) {
+    // Some DRM driver such as omap_drm allows sharing primary plane between
+    // CRTCs, but the primay plane could not be shared if it has been used by
+    // any CRTC already, which is protected by the plane_switching_crtc function
+    // in the kernel drivers/gpu/drm/drm_atomic.c file.
+    // The current drm_hwc design is not ready to support such scenario yet,
+    // so adding the CRTC status check here to workaorund for now.
+    ALOGW(
+        "%s: This Plane(id=%d) is activated for Crtc(id=%d), could not be used "
+        "for Crtc (id=%d)",
+        __FUNCTION__, GetId(), crtc_property_value, crtc.GetId());
+    return false;
+  }
+
   return ((1 << crtc.GetIndexInResArray()) & plane_->possible_crtcs) != 0;
 }