Merge "overlay: mdssRot: Fix stale rotation flag values."
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 7b2c1d8..f11a5fe 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -44,6 +44,7 @@
     common.module  = const_cast<hw_module_t*>(&module->base.common);
     common.close   = gralloc_close;
     alloc          = gralloc_alloc;
+    allocSize      = gralloc_alloc_size;
     free           = gralloc_free;
 
 }
@@ -236,7 +237,7 @@
 
     if ((ssize_t)size <= 0)
         return -EINVAL;
-    size = (bufferSize >= size)? bufferSize : size;
+    size = (bufferSize != 0)? bufferSize : size;
 
     // All buffers marked as protected or for external
     // display need to go to overlay
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index f49ab2e..ac1be19 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 The Android Open Source Project
- * Copyright (C) 2012, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -233,7 +233,12 @@
             break;
         case HWC_DISPLAY_EXTERNAL:
             if(blank) {
-                //TODO actual
+                // External Display post commits the changes to display
+                // Call this on blank, so that any pipe unsets gets committed
+                if (!ctx->mExtDisplay->post()) {
+                    ret = -1;
+                    ALOGE("%s:ctx->mExtDisplay->post fail!! ", __FUNCTION__);
+                }
             } else {
             }
             break;
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index c65c056..2c0a77a 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -369,7 +369,7 @@
     int numAppLayers = ctx->listStats[dpy].numAppLayers;
 
     overlay::Overlay& ov = *ctx->mOverlay;
-    int availablePipes = ov.availablePipes();
+    int availablePipes = ov.availablePipes(dpy);
 
     if(numAppLayers < 1 || numAppLayers > (uint32_t)availablePipes) {
         ALOGD_IF(isDebug(), "%s: Unsupported number of layers",__FUNCTION__);
diff --git a/liboverlay/overlay.h b/liboverlay/overlay.h
index 2378889..151cfb3 100644
--- a/liboverlay/overlay.h
+++ b/liboverlay/overlay.h
@@ -71,8 +71,8 @@
     static void initOverlay();
     /* Returns the singleton instance of overlay */
     static Overlay* getInstance();
-    /* Returns total of available ("unallocated") pipes */
-    static int availablePipes();
+    /* Returns available ("unallocated") pipes for a display */
+    int availablePipes(int dpy);
     /* set the framebuffer index for external display */
     void setExtFbNum(int fbNum);
     /* Returns framebuffer index of the current external display */
@@ -111,8 +111,6 @@
         static void resetAllocation(int index);
         static bool isAllocated(int index);
         static bool isNotAllocated(int index);
-        /* Returns total of available ("unallocated") pipes */
-        static int availablePipes();
 
         static int NUM_PIPES;
 
@@ -149,8 +147,15 @@
             utils::getDestStr((utils::eDest)index));
 }
 
-inline int Overlay::availablePipes() {
-    return PipeBook::availablePipes();
+inline int Overlay::availablePipes(int dpy) {
+     int avail = 0;
+     for(int i = 0; i < PipeBook::NUM_PIPES; i++) {
+       if((mPipeBook[i].mDisplay == PipeBook::DPY_UNUSED ||
+           mPipeBook[i].mDisplay == dpy) && PipeBook::isNotAllocated(i)) {
+                avail++;
+        }
+    }
+    return avail;
 }
 
 inline void Overlay::setExtFbNum(int fbNum) {
@@ -163,16 +168,6 @@
     return sExtFbIndex;
 }
 
-inline int Overlay::PipeBook::availablePipes() {
-    int used = 0;
-    int bmp = sAllocatedBitmap;
-    for(; bmp; used++) {
-        //clearing from lsb
-        bmp = bmp & (bmp - 1);
-    }
-    return NUM_PIPES - used;
-}
-
 inline bool Overlay::PipeBook::valid() {
     return (mPipe != NULL);
 }