hwc: Set DMA mode to LINE after UNSET, commit of BLOCK session

Set DMA mode to LINE only after we UNSET and commit the sessions
in BLOCK mode from previous rounds.
Currently, it is incorrectly set to LINE always at the beginning
of a draw cycle.
Now we set it to LINE only at the end of a draw cycle if no rotator
sessions are active.

Change-Id: I6e2351d214d01764eced0673b639f709fbd193c3
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 148a0fc..fcaf34b 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -273,8 +273,6 @@
     ctx->mRotMgr->configBegin();
     overlay::Writeback::configBegin();
 
-    Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
-
     for (int32_t i = numDisplays; i >= 0; i--) {
         hwc_display_contents_1_t *list = displays[i];
         int dpy = getDpyforExternalDisplay(ctx, i);
@@ -666,6 +664,8 @@
     CALC_FPS();
     MDPComp::resetIdleFallBack();
     ctx->mVideoTransFlag = false;
+    if(ctx->mRotMgr->getNumActiveSessions() == 0)
+        Overlay::setDMAMode(Overlay::DMA_LINE_MODE);
     //Was locked at the beginning of prepare
     ctx->mDrawLock.unlock();
     return ret;
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index f551f1d..7c1095f 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -238,6 +238,7 @@
      */
     void getDump(char *buf, size_t len);
     int getRotDevFd();
+    int getNumActiveSessions() { return mUseCount; }
 private:
     overlay::Rotator *mRot[MAX_ROT_SESS];
     int mUseCount;