Merge "overlay: Handle return value of validateAndSet gracefully"
diff --git a/libhwcomposer/hwc_dump_layers.cpp b/libhwcomposer/hwc_dump_layers.cpp
index e717c26..6a8feb2 100644
--- a/libhwcomposer/hwc_dump_layers.cpp
+++ b/libhwcomposer/hwc_dump_layers.cpp
@@ -319,7 +319,7 @@
         bool bResult = false;
         char dumpFilename[PATH_MAX];
         SkBitmap *tempSkBmp = new SkBitmap();
-        SkBitmap::Config tempSkBmpConfig = SkBitmap::kNo_Config;
+        SkColorType tempSkBmpColor = kUnknown_SkColorType;
         snprintf(dumpFilename, sizeof(dumpFilename),
             "%s/sfdump%03d.layer%zu.%s.png", mDumpDirPng,
             mDumpCntrPng, layerIndex, mDisplayName);
@@ -327,21 +327,24 @@
         switch (hnd->format) {
             case HAL_PIXEL_FORMAT_RGBA_8888:
             case HAL_PIXEL_FORMAT_RGBX_8888:
+                tempSkBmpColor = kRGBA_8888_SkColorType;
+                break;
             case HAL_PIXEL_FORMAT_BGRA_8888:
-                tempSkBmpConfig = SkBitmap::kARGB_8888_Config;
+                tempSkBmpColor = kBGRA_8888_SkColorType;
                 break;
             case HAL_PIXEL_FORMAT_RGB_565:
+                tempSkBmpColor = kRGB_565_SkColorType;
+                break;
             case HAL_PIXEL_FORMAT_RGBA_5551:
             case HAL_PIXEL_FORMAT_RGBA_4444:
-                tempSkBmpConfig = SkBitmap::kRGB_565_Config;
-                break;
             case HAL_PIXEL_FORMAT_RGB_888:
             default:
-                tempSkBmpConfig = SkBitmap::kNo_Config;
+                tempSkBmpColor = kUnknown_SkColorType;
                 break;
         }
-        if (SkBitmap::kNo_Config != tempSkBmpConfig) {
-            tempSkBmp->setConfig(tempSkBmpConfig, getWidth(hnd), getHeight(hnd));
+        if (kUnknown_SkColorType != tempSkBmpColor) {
+            tempSkBmp->setInfo(SkImageInfo::Make(getWidth(hnd), getHeight(hnd),
+                    tempSkBmpColor, kIgnore_SkAlphaType), 0);
             tempSkBmp->setPixels((void*)hnd->base);
             bResult = SkImageEncoder::EncodeFile(dumpFilename,
                                     *tempSkBmp, SkImageEncoder::kPNG_Type, 100);
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 466151b..2a72968 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -46,6 +46,7 @@
 int MDPComp::sMaxPipesPerMixer = 0;
 bool MDPComp::sEnableYUVsplit = false;
 bool MDPComp::sSrcSplitEnabled = false;
+int MDPComp::sMaxSecLayers = 1;
 bool MDPComp::enablePartialUpdateForMDP3 = false;
 MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
     if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
@@ -139,6 +140,16 @@
             sMaxPipesPerMixer = min(val, sMaxPipesPerMixer);
     }
 
+    /* Maximum layers allowed to use MDP on secondary panels. If property
+     * doesn't exist, default to 1. Using the property it can be set to 0 or
+     * more.
+     */
+    if(property_get("persist.hwc.maxseclayers", property, "1") > 0) {
+        int val = atoi(property);
+        sMaxSecLayers = (val >= 0) ? val : 1;
+        sMaxSecLayers = min(sMaxSecLayers, sMaxPipesPerMixer);
+    }
+
     if(ctx->mMDP.panel != MIPI_CMD_PANEL) {
         sIdleInvalidator = IdleInvalidator::getInstance();
         if(sIdleInvalidator->init(timeout_handler, ctx) < 0) {
@@ -832,13 +843,6 @@
     if(sSimulationFlags & MDPCOMP_AVOID_FULL_MDP)
         return false;
 
-    //Will benefit presentation / secondary-only layer.
-    if((mDpy > HWC_DISPLAY_PRIMARY) &&
-            (list->numHwLayers - 1) > MAX_SEC_LAYERS) {
-        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
-        return false;
-    }
-
     const int numAppLayers = ctx->listStats[mDpy].numAppLayers;
     for(int i = 0; i < numAppLayers; i++) {
         hwc_layer_1_t* layer = &list->hwLayers[i];
@@ -1160,14 +1164,6 @@
         adjustForSourceSplit(ctx, list);
     }
 
-    //Will benefit cases where a video has non-updating background.
-    if((mDpy > HWC_DISPLAY_PRIMARY) and
-            (mdpCount > MAX_SEC_LAYERS)) {
-        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
-        reset(ctx);
-        return false;
-    }
-
     if(!postHeuristicsHandling(ctx, list)) {
         ALOGD_IF(isDebug(), "post heuristic handling failed");
         reset(ctx);
@@ -1819,6 +1815,14 @@
         ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
         return false;
     }
+
+    //Will benefit cases where a video has non-updating background.
+    if((mDpy > HWC_DISPLAY_PRIMARY) and
+            (mCurrentFrame.mdpCount > sMaxSecLayers)) {
+        ALOGD_IF(isDebug(), "%s: Exceeds max secondary pipes",__FUNCTION__);
+        return false;
+    }
+
     // Init rotCount to number of rotate sessions used by other displays
     int rotCount = ctx->mRotMgr->getNumActiveSessions();
     // Count the number of rotator sessions required for current display
diff --git a/libhwcomposer/hwc_mdpcomp.h b/libhwcomposer/hwc_mdpcomp.h
index 7fa6674..8929c40 100644
--- a/libhwcomposer/hwc_mdpcomp.h
+++ b/libhwcomposer/hwc_mdpcomp.h
@@ -58,8 +58,6 @@
     static void setMaxPipesPerMixer(const uint32_t value);
 
 protected:
-    enum { MAX_SEC_LAYERS = 1 }; //TODO add property support
-
     enum ePipeType {
         MDPCOMP_OV_RGB = ovutils::OV_MDP_PIPE_RGB,
         MDPCOMP_OV_VG = ovutils::OV_MDP_PIPE_VG,
@@ -258,6 +256,7 @@
     static int sMaxPipesPerMixer;
     static bool sSrcSplitEnabled;
     static IdleInvalidator *sIdleInvalidator;
+    static int sMaxSecLayers;
     struct FrameInfo mCurrentFrame;
     struct LayerCache mCachedFrame;
     //Enable 4kx2k yuv layer split
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 300e90a..9d53bda 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -81,8 +81,8 @@
 
 namespace qhwc {
 
-//Std refresh rates for digital videos- 24p, 30p and 48p
-uint32_t stdRefreshRates[] = { 30, 24, 48 };
+// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
+uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
 
 bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
 {