Merge "hwc: Refactor windowboxing feature"
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 4a74e96..2904e6f 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -1956,6 +1956,8 @@
     if(!mDpy && qdutils::MDPVersion::getInstance().isDynFpsSupported()) {
         FrameInfo frame;
         frame.reset(mCurrentFrame.layerCount);
+        memset(&frame.drop, 0, sizeof(frame.drop));
+        frame.dropCount = 0;
         ALOGD_IF(isDebug(), "%s: Update Cache and YUVInfo for Dyn Refresh Rate",
                  __FUNCTION__);
         updateLayerCache(ctx, list, frame);
diff --git a/libhwcomposer/hwc_uevents.cpp b/libhwcomposer/hwc_uevents.cpp
index 65e041b..6b2316b 100644
--- a/libhwcomposer/hwc_uevents.cpp
+++ b/libhwcomposer/hwc_uevents.cpp
@@ -107,10 +107,11 @@
                 break;
             }
 
-            Locker::Autolock _l(ctx->mDrawLock);
+            ctx->mDrawLock.lock();
             destroyCompositionResources(ctx, dpy);
             ctx->mHDMIDisplay->teardown();
             resetDisplayInfo(ctx, dpy);
+            ctx->mDrawLock.unlock();
 
             /* We need to send hotplug to SF only when we are disconnecting
              * HDMI */
@@ -127,19 +128,19 @@
                          "for display: %d", __FUNCTION__, dpy);
                 break;
             }
-            {
-                //Force composition to give up resources like pipes and
-                //close fb. For example if assertive display is going on,
-                //fb2 could be open, thus connecting Layer Mixer#0 to
-                //WriteBack module. If HDMI attempts to open fb1, the driver
-                //will try to attach Layer Mixer#0 to HDMI INT, which will
-                //fail, since Layer Mixer#0 is still connected to WriteBack.
-                //This block will force composition to close fb2 in above
-                //example.
-                Locker::Autolock _l(ctx->mDrawLock);
-                ctx->dpyAttr[dpy].isConfiguring = true;
-                ctx->proc->invalidate(ctx->proc);
-            }
+            ctx->mDrawLock.lock();
+            //Force composition to give up resources like pipes and
+            //close fb. For example if assertive display is going on,
+            //fb2 could be open, thus connecting Layer Mixer#0 to
+            //WriteBack module. If HDMI attempts to open fb1, the driver
+            //will try to attach Layer Mixer#0 to HDMI INT, which will
+            //fail, since Layer Mixer#0 is still connected to WriteBack.
+            //This block will force composition to close fb2 in above
+            //example.
+            ctx->dpyAttr[dpy].isConfiguring = true;
+            ctx->mDrawLock.unlock();
+
+            ctx->proc->invalidate(ctx->proc);
             //2 cycles for slower content
             usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
                    * 2 / 1000);
@@ -166,12 +167,13 @@
             ctx->mHDMIDisplay->configure();
             ctx->mHDMIDisplay->activateDisplay();
 
-            Locker::Autolock _l(ctx->mDrawLock);
+            ctx->mDrawLock.lock();
             updateDisplayInfo(ctx, dpy);
             initCompositionResources(ctx, dpy);
             ctx->dpyAttr[dpy].isPause = false;
             ctx->dpyAttr[dpy].connected = true;
             ctx->dpyAttr[dpy].isConfiguring = true;
+            ctx->mDrawLock.unlock();
 
             /* External display is HDMI */
             ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL ONLINE"
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 7e77d95..20ff6c7 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -101,19 +101,21 @@
     char *yptr = NULL;
     if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
         yptr = strcasestr(property,"x");
-        int xres_new = atoi(property);
-        int yres_new = atoi(yptr + 1);
-        if (isValidResolution(ctx,xres_new,yres_new) &&
-                 xres_new != xres_orig && yres_new != yres_orig) {
-            ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
-            ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
-            ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
+        if(yptr) {
+            int xres_new = atoi(property);
+            int yres_new = atoi(yptr + 1);
+            if (isValidResolution(ctx,xres_new,yres_new) &&
+                xres_new != xres_orig && yres_new != yres_orig) {
+                ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
+                ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
+                ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
 
-            //Caluculate DPI according to changed resolution.
-            float xdpi = ((float)xres_new * 25.4f) / (float)width;
-            float ydpi = ((float)yres_new * 25.4f) / (float)height;
-            ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
-            ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
+                //Caluculate DPI according to changed resolution.
+                float xdpi = ((float)xres_new * 25.4f) / (float)width;
+                float ydpi = ((float)yres_new * 25.4f) / (float)height;
+                ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
+                ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
+            }
         }
     }
 }
@@ -1478,7 +1480,7 @@
             rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
         }
         int ret = 0;
-        if(not ctx->mLayerRotMap[dpy]->isRotCached(i))
+        if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
             ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
 
         if(ret < 0) {
@@ -1500,43 +1502,45 @@
     //Accumulate acquireFenceFds for MDP Overlays
     if(list->outbufAcquireFenceFd >= 0) {
         //Writeback output buffer
-        acquireFd[count++] = list->outbufAcquireFenceFd;
+        if(LIKELY(!swapzero) )
+            acquireFd[count++] = list->outbufAcquireFenceFd;
     }
 
     for(uint32_t i = 0; i < list->numHwLayers; i++) {
         if(((isAbcInUse(ctx)== true ) ||
           (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
                         list->hwLayers[i].acquireFenceFd >= 0) {
-            if(UNLIKELY(swapzero))
-                acquireFd[count++] = -1;
-            // if ABC is enabled for more than one layer.
-            // renderBufIndexforABC will work as FB.Hence
-            // set the acquireFD from fd - which is coming from copybit
-            else if(fd >= 0 && (isAbcInUse(ctx) == true)) {
-                if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
-                   acquireFd[count++] = fd;
-                else
-                   continue;
-            } else
-                acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
+            if(LIKELY(!swapzero) ) {
+                // if ABC is enabled for more than one layer.
+                // renderBufIndexforABC will work as FB.Hence
+                // set the acquireFD from fd - which is coming from copybit
+                if(fd >= 0 && (isAbcInUse(ctx) == true)) {
+                    if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
+                        acquireFd[count++] = fd;
+                    else
+                        continue;
+                } else
+                    acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
+            }
         }
         if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
-            if(UNLIKELY(swapzero))
-                acquireFd[count++] = -1;
-            else if(fd >= 0) {
-                //set the acquireFD from fd - which is coming from c2d
-                acquireFd[count++] = fd;
-                // Buffer sync IOCTL should be async when using c2d fence is
-                // used
-                data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
-            } else if(list->hwLayers[i].acquireFenceFd >= 0)
-                acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
+            if(LIKELY(!swapzero) ) {
+                if(fd >= 0) {
+                    //set the acquireFD from fd - which is coming from c2d
+                    acquireFd[count++] = fd;
+                    // Buffer sync IOCTL should be async when using c2d fence is
+                    // used
+                    data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
+                } else if(list->hwLayers[i].acquireFenceFd >= 0)
+                    acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
+            }
         }
     }
 
     if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
         // Acquire c2d fence of Overlap render buffer
-        acquireFd[count++] = fd;
+        if(LIKELY(!swapzero) )
+            acquireFd[count++] = fd;
     }
 
     data.acq_fen_fd_cnt = count;