Merge "libhwcomposer: MDP composition for Higher Resolution panels"
diff --git a/libcopybit/copybit_c2d.cpp b/libcopybit/copybit_c2d.cpp
index 2fa55cd..c186242 100644
--- a/libcopybit/copybit_c2d.cpp
+++ b/libcopybit/copybit_c2d.cpp
@@ -600,7 +600,13 @@
         ctx->blit_list[i].next = &(ctx->blit_list[i+1]);
     }
     ctx->blit_list[ctx->blit_count-1].next = NULL;
-    if(LINK_c2dDraw(target,ctx->trg_transform, 0x0, 0, 0, ctx->blit_list,
+    uint32_t target_transform = ctx->trg_transform;
+    if (ctx->c2d_driver_info.capabilities_mask &
+        C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) {
+        // For A3xx - set 0x0 as the transform is set in the config_mask
+        target_transform = 0x0;
+    }
+    if(LINK_c2dDraw(target, target_transform, 0x0, 0, 0, ctx->blit_list,
                     ctx->blit_count)) {
         ALOGE("%s: LINK_c2dDraw ERROR", __FUNCTION__);
         return COPYBIT_FAILURE;
@@ -784,17 +790,15 @@
                 }
             }
 
-            if (transform != ctx->trg_transform) {
-                if (ctx->c2d_driver_info.capabilities_mask &
-                    C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) {
-                    ctx->config_mask |= config_mask;
-                } else {
-                    // The transform for this surface does not match the current
-                    // target transform. Draw all previous surfaces. This will be
-                    // changed once we have a new mechanism to send different
-                    // target rotations to c2d.
-                    finish_copybit(dev);
-                }
+            if (ctx->c2d_driver_info.capabilities_mask &
+                C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) {
+                ctx->config_mask |= config_mask;
+            } else {
+                // The transform for this surface does not match the current
+                // target transform. Draw all previous surfaces. This will be
+                // changed once we have a new mechanism to send different
+                // target rotations to c2d.
+                finish_copybit(dev);
             }
             ctx->trg_transform = transform;
         }
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 519126f..c2688b5 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -343,9 +343,11 @@
         }
         if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
             ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
-            return -1;
+            ret = -1;
         }
     }
+
+    closeAcquireFds(list);
     return ret;
 }
 
@@ -382,9 +384,11 @@
         }
         if (!ctx->mExtDisplay->post()) {
             ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
-            return -1;
+            ret = -1;
         }
     }
+
+    closeAcquireFds(list);
     return ret;
 }
 
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 3504066..82ab25c 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -368,6 +368,17 @@
     return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
 }
 
+void closeAcquireFds(hwc_display_contents_1_t* list) {
+    for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
+        //Close the acquireFenceFds
+        //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
+        if(list->hwLayers[i].acquireFenceFd >= 0) {
+            close(list->hwLayers[i].acquireFenceFd);
+            list->hwLayers[i].acquireFenceFd = -1;
+        }
+    }
+}
+
 int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
                                                         int fd) {
     int ret = 0;
@@ -419,22 +430,15 @@
         ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
                             __FUNCTION__, (size_t) ns2ms(systemTime() - start));
     }
+
     if(ret < 0) {
         ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s",
                 strerror(errno));
     }
+
     for(uint32_t i = 0; i < list->numHwLayers; i++) {
         if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
            list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
-            //Close the acquireFenceFds
-            if(list->hwLayers[i].acquireFenceFd >= 0) {
-                close(list->hwLayers[i].acquireFenceFd);
-                list->hwLayers[i].acquireFenceFd = -1;
-            }
-            if(fd >= 0) {
-                close(fd);
-                fd = -1;
-            }
             //Populate releaseFenceFds.
             if(UNLIKELY(swapzero))
                 list->hwLayers[i].releaseFenceFd = -1;
@@ -442,12 +446,19 @@
                 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
         }
     }
+
+    if(fd >= 0) {
+        close(fd);
+        fd = -1;
+    }
+
     if(UNLIKELY(swapzero)){
         list->retireFenceFd = -1;
         close(releaseFd);
     } else {
         list->retireFenceFd = releaseFd;
     }
+
     return ret;
 }
 
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 36d4f14..671fbba 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -144,6 +144,9 @@
 void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
                                         uint32_t& y, uint32_t& w, uint32_t& h);
 
+//Close acquireFenceFds of all layers of incoming list
+void closeAcquireFds(hwc_display_contents_1_t* list);
+
 //Sync point impl.
 int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
                                                     int fd);