Merge "hwc: Disable mdpcomp for MDP3 targets by default"
diff --git a/libhwcomposer/hwc_copybit.cpp b/libhwcomposer/hwc_copybit.cpp
index 67cca88..38c0810 100644
--- a/libhwcomposer/hwc_copybit.cpp
+++ b/libhwcomposer/hwc_copybit.cpp
@@ -603,6 +603,12 @@
         return fd;
     }
 
+    //Clear the transparent or left out region on the render buffer
+    hwc_rect_t clearRegion = {0,0,0,0};
+    LayerProp *layerProp = ctx->layerProp[0];
+    if(CBUtils::getuiClearRegion(list, clearRegion, layerProp))
+        clear(renderBuffer, clearRegion);
+
     int copybitLayerCount = 0;
     for(int j = 0; j < ptorInfo->count; j++) {
         int ovlapIndex = ptorInfo->layerIndex[j];
@@ -639,9 +645,27 @@
                 close(list->hwLayers[i].acquireFenceFd);
                 list->hwLayers[i].acquireFenceFd = -1;
             }
+            /*
+             * Find the intersection of layer display frame with PTOR layer
+             * with respect to screen co-ordinates
+             *
+             * Calculated the destination rect by transforming the overlapping
+             * region of layer display frame with respect to PTOR display frame
+             *
+             * Transform the destination rect on to render buffer
+             * */
+            hwc_rect_t destRect = getIntersection(overlap, layer->displayFrame);
+            destRect.left = destRect.left - overlap.left +
+                                            ptorInfo->displayFrame[j].left;
+            destRect.right = destRect.right- overlap.left +
+                                            ptorInfo->displayFrame[j].left;
+            destRect.top = destRect.top - overlap.top +
+                                            ptorInfo->displayFrame[j].top;
+            destRect.bottom = destRect.bottom - overlap.top +
+                                            ptorInfo->displayFrame[j].top;
 
-            int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer, overlap,
-                                                ptorInfo->displayFrame[j]);
+            int retVal = drawRectUsingCopybit(ctx, layer, renderBuffer,
+                                                          overlap, destRect);
             copybitLayerCount++;
             if(retVal < 0) {
                 ALOGE("%s: drawRectUsingCopybit failed", __FUNCTION__);