drm_hwcomposer: check if the primary plane is being used by any crtc

Some DRM driver such as omap_drm allow sharing primary plane between CRTCs.
drm_hwcomposer isn't ready for such a scenarios and fails with an error:

    Found more than 1 primary plane for CRTC

Don't report multiple primary planes for single CRTC to satisfy the drm_hwc.

Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
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;
 }