Hwc : Calculate copybit destination rect properly in PTOR

When the layer destination rect is not transformed properly on target
render buffer location of that PTOR layer,  it results in corruption
on the PTOR layer. This corruption is observed when the overlapping
region of any below layer different from PTOR display frame.

To fix this, destination rect for copybit is calculated as follows:
i.   Find the intersection of layer display frame with PTOR layer
     with respect to screen co-ordinates
ii.  Calculated the destination rect by transforming the overlapping
     region of layer display frame with respect to PTOR display frame
iii. Transform the destination rect on to render buffer

Change-Id: I9468e194ac87de4e3d37f7b1df90bfa6473a1921
diff --git a/libhwcomposer/hwc_copybit.cpp b/libhwcomposer/hwc_copybit.cpp
index 67cca88..269c3d7 100644
--- a/libhwcomposer/hwc_copybit.cpp
+++ b/libhwcomposer/hwc_copybit.cpp
@@ -639,9 +639,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__);