hwc: Deduce overlapping region from layers below PTOR layer

Use intersection of PTOR layer and the layers below it to
address usecases like
   * PTOR layer is not peripheral to the layers below it
   * Some layer/layers completely below PTOR layer

Change-Id: Ieb456a60df12cc2f5ad46fbbba2d99a16853278d
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index aa7783c..466151b 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -1041,7 +1041,7 @@
             // Update layer attributes
             hwc_rect_t srcCrop = integerizeSourceCrop(layer->sourceCropf);
             hwc_rect_t destRect = deductRect(layer->displayFrame,
-                                             overlapRect[j]);
+                        getIntersection(layer->displayFrame, overlapRect[j]));
             qhwc::calculate_crop_rects(srcCrop, layer->displayFrame, destRect,
                                        layer->transform);
             layer->sourceCropf.left = (float)srcCrop.left;
@@ -1055,8 +1055,14 @@
     mCurrentFrame.fbCount = 0;
     mCurrentFrame.fbZ = -1;
 
-    for (int j = 0; j < numAppLayers; j++)
-        mCurrentFrame.isFBComposed[j] = false;
+    for (int j = 0; j < numAppLayers; j++) {
+        if(isValidRect(list->hwLayers[j].displayFrame)) {
+            mCurrentFrame.isFBComposed[j] = false;
+        } else {
+            mCurrentFrame.mdpCount--;
+            mCurrentFrame.drop[j] = true;
+        }
+    }
 
     bool result = postHeuristicsHandling(ctx, list);