Merge "hwc: Remove unused utility function"
diff --git a/Android.mk b/Android.mk
index b3015af..a128327 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,13 +1,16 @@
-# This flag will be set to true during migration to Snapdragon Display Engine.
-TARGET_USES_SDE = false
+ifeq ($(call is-board-platform-in-list, thulium),true)
+    TARGET_USES_SDE = true
+else
+    TARGET_USES_SDE = false
+endif
 
-display-hals := libgralloc libcopybit liblight libmemtrack libqservice
+display-hals := libgralloc libcopybit liblight libmemtrack libqservice libqdutils
 
 ifeq ($(TARGET_USES_SDE), true)
     sde-libs := displayengine/libs
     display-hals += $(sde-libs)/utils $(sde-libs)/core $(sde-libs)/hwc
 else
-    display-hals += libgenlock libhwcomposer liboverlay libqdutils libhdmi
+    display-hals += libgenlock libhwcomposer liboverlay libhdmi
 endif
 
 ifeq ($(call is-vendor-board-platform,QCOM),true)
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index b84daad..adf48e7 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -255,6 +255,8 @@
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     const int dpy = HWC_DISPLAY_PRIMARY;
     bool fbComp = false;
+    if (!ctx->mBootAnimCompleted)
+        processBootAnimCompleted(ctx);
     if (LIKELY(list && list->numHwLayers > 1) && ctx->dpyAttr[dpy].connected &&
             (ctx->dpyAttr[dpy].isActive ||
              ctx->mHDMIDisplay->isHDMIPrimaryDisplay())
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 7343814..caa1344 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -2772,19 +2772,21 @@
     const uint32_t lSplit = getLeftSplit(ctx, mDpy);
     const uint32_t dstWidth = dst.right - dst.left;
     const uint32_t dstHeight = dst.bottom - dst.top;
-    const uint32_t cropWidth = has90Transform(layer) ? crop.bottom - crop.top :
+    uint32_t cropWidth = has90Transform(layer) ? crop.bottom - crop.top :
             crop.right - crop.left;
-    const uint32_t cropHeight = has90Transform(layer) ? crop.right - crop.left :
+    uint32_t cropHeight = has90Transform(layer) ? crop.right - crop.left :
             crop.bottom - crop.top;
     //Approximation to actual clock, ignoring the common factors in pipe and
     //mixer cases like line_time
     const uint32_t layerClock = getLayerClock(dstWidth, dstHeight, cropHeight);
     const uint32_t mixerClock = lSplit;
 
-    //TODO Even if a 4k video is going to be rot-downscaled to dimensions under
-    //pipe line length, we are still using 2 pipes. This is fine just because
-    //this is source split where destination doesn't matter. Evaluate later to
-    //see if going through all the calcs to save a pipe is worth it
+    const uint32_t downscale = getRotDownscale(ctx, layer);
+    if(downscale) {
+        cropWidth /= downscale;
+        cropHeight /= downscale;
+    }
+
     if(dstWidth > mdpHw.getMaxPipeWidth() or
             cropWidth > mdpHw.getMaxPipeWidth() or
             (primarySplitAlways and
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 0da52d8..9ea8246 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -44,6 +44,7 @@
 #include "hwc_virtual.h"
 #include "qd_utils.h"
 #include <sys/sysinfo.h>
+#include <dlfcn.h>
 
 using namespace qClient;
 using namespace qService;
@@ -389,6 +390,9 @@
     property_get("debug.sf.hwc.canUseABC", value, "0");
     ctx->enableABC  = atoi(value) ? true : false;
 
+    // Initializing boot anim completed check to false
+    ctx->mBootAnimCompleted = false;
+
     // Initialize gpu perfomance hint related parameters
     property_get("sys.hwc.gpu_perf_mode", value, "0");
 #ifdef QCOM_BSP
@@ -2487,6 +2491,36 @@
     return (eqBounds == 3);
 }
 
+void processBootAnimCompleted(hwc_context_t *ctx) {
+    char value[PROPERTY_VALUE_MAX];
+    int boot_finished = 0, ret = -1;
+    int (*applyMode)(int) = NULL;
+    void *modeHandle = NULL;
+
+    // Reading property set on boot finish in SF
+    property_get("service.bootanim.exit", value, "0");
+    boot_finished = atoi(value);
+    if (!boot_finished)
+        return;
+
+    modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
+    if (modeHandle) {
+        *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
+        if (applyMode) {
+            ret = applyMode(HWC_DISPLAY_PRIMARY);
+            if (ret)
+                ALOGD("%s: Not able to apply default mode", __FUNCTION__);
+        } else {
+            ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
+        }
+        dlclose(modeHandle);
+    } else {
+        ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
+    }
+
+    ctx->mBootAnimCompleted = true;
+}
+
 void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
         const private_handle_t *hnd,
         const hwc_rect_t& crop, const hwc_rect_t& dst,
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index f838840..4f1b5e6 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -441,6 +441,9 @@
 // Returns true if rect1 is peripheral to rect2, false otherwise.
 bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2);
 
+// Checks if boot animation has completed and applies default mode
+void processBootAnimCompleted(hwc_context_t *ctx);
+
 // Inline utility functions
 static inline bool isSkipLayer(const hwc_layer_1_t* l) {
     return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
@@ -643,6 +646,8 @@
     bool mUseMetaDataRefreshRate;
    // Stores the hpd enabled status- avoids re-enabling HDP on suspend resume.
     bool mHPDEnabled;
+    //Used to notify that boot has completed
+    bool mBootAnimCompleted;
 };
 
 namespace qhwc {