hwc: Populate frame rate in rotator set

- Populate frame_rate in rotator set, so that driver
  can vote for honest BW for rotator based on frame rate.
- If metadata contains source fps, frame_rate will be set
  to source fps, else it will be set to primary refresh rate.
- frame_rate will be populated for primary with
  source fps from metada, only when secondary is not active.

Change-Id: Icaacd0ed67ec09591d31868591680d2e86fe54a2
diff --git a/libhwcomposer/hwc_fbupdate.cpp b/libhwcomposer/hwc_fbupdate.cpp
index 74d95e7..8145d82 100644
--- a/libhwcomposer/hwc_fbupdate.cpp
+++ b/libhwcomposer/hwc_fbupdate.cpp
@@ -101,7 +101,8 @@
         // viewFrame with sourceCrop to avoid those black bars
         sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
         //Configure rotator for pre-rotation
-        if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
+        if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0,
+                    ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate) < 0) {
             ALOGE("%s: configRotator Failed!", __FUNCTION__);
             mRot = NULL;
             return false;
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index e2c4677..1f16416 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -3103,8 +3103,14 @@
             BwcPM::setBwc(ctx, mDpy, hnd, crop, dst, transform, downscale,
                     mdpFlags);
         }
+        uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
+        if(!mDpy && !isSecondaryConnected(ctx)) {
+            if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
+                frame_rate = metadata->refreshrate;
+        }
         //Configure rotator for pre-rotation
-        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
+        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale,
+                    frame_rate) < 0) {
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 5de3081..7bc4d23 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -1922,7 +1922,8 @@
 
 int configRotator(Rotator *rot, Whf& whf,
         hwc_rect_t& crop, const eMdpFlags& mdpFlags,
-        const eTransform& orient, const int& downscale) {
+        const eTransform& orient, const int& downscale,
+        const uint32_t& frame_rate) {
 
     // Fix alignments for TILED format
     if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
@@ -1939,6 +1940,7 @@
         rot->setCrop(rotCrop);
     }
 
+    rot->setFrameRate(frame_rate);
     rot->setFlags(mdpFlags);
     rot->setTransform(orient);
     rot->setDownscale(downscale);
@@ -2226,8 +2228,14 @@
         ctx->mLayerRotMap[dpy]->add(layer, *rot);
         BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
                 mdpFlags);
+        uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
+        if(!dpy && !isSecondaryConnected(ctx)) {
+            if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
+                frame_rate = metadata->refreshrate;
+        }
         //Configure rotator for pre-rotation
-        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
+        if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale,
+                    frame_rate) < 0) {
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
@@ -2335,8 +2343,14 @@
         (*rot) = ctx->mRotMgr->getNext();
         if((*rot) == NULL) return -1;
         ctx->mLayerRotMap[dpy]->add(layer, *rot);
+        uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
+        if(!dpy && !isSecondaryConnected(ctx)) {
+            if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
+                frame_rate = metadata->refreshrate;
+        }
         //Configure rotator for pre-rotation
-        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
+        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
+                    frame_rate) < 0) {
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
@@ -2459,8 +2473,14 @@
         (*rot) = ctx->mRotMgr->getNext();
         if((*rot) == NULL) return -1;
         ctx->mLayerRotMap[dpy]->add(layer, *rot);
+        uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
+        if(!dpy && !isSecondaryConnected(ctx)) {
+            if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
+                frame_rate = metadata->refreshrate;
+        }
         //Configure rotator for pre-rotation
-        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
+        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
+                    frame_rate) < 0) {
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
@@ -2577,8 +2597,14 @@
         (*rot) = ctx->mRotMgr->getNext();
         if((*rot) == NULL) return -1;
         ctx->mLayerRotMap[dpy]->add(layer, *rot);
+        uint32_t frame_rate = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate;
+        if(!dpy && !isSecondaryConnected(ctx)) {
+            if(metadata && (metadata->operation & UPDATE_REFRESH_RATE))
+                frame_rate = metadata->refreshrate;
+        }
         //Configure rotator for pre-rotation
-        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
+        if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale,
+                    frame_rate) < 0) {
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 4849baf..41dd258 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -420,7 +420,8 @@
 
 int configRotator(overlay::Rotator *rot, ovutils::Whf& whf,
         hwc_rect_t& crop, const ovutils::eMdpFlags& mdpFlags,
-        const ovutils::eTransform& orient, const int& downscale);
+        const ovutils::eTransform& orient, const int& downscale,
+        const uint32_t& frame_rate);
 
 int configMdp(overlay::Overlay *ov, const ovutils::PipeArgs& parg,
         const ovutils::eTransform& orient, const hwc_rect_t& crop,
diff --git a/liboverlay/overlayMdpRot.cpp b/liboverlay/overlayMdpRot.cpp
index d322897..b5a90ad 100755
--- a/liboverlay/overlayMdpRot.cpp
+++ b/liboverlay/overlayMdpRot.cpp
@@ -126,6 +126,10 @@
     // NO-OP for non-mdss rotator due to possible h/w limitations
 }
 
+void MdpRot::setFrameRate(uint32_t /*frame_rate*/) {
+    // NO-OP for non-mdss rotator
+}
+
 void MdpRot::setFlags(const utils::eMdpFlags& flags) {
     mRotImgInfo.secure = 0;
     if(flags & utils::OV_MDP_SECURE_OVERLAY_SESSION)
diff --git a/liboverlay/overlayMdssRot.cpp b/liboverlay/overlayMdssRot.cpp
index 87e134a..39b240d 100644
--- a/liboverlay/overlayMdssRot.cpp
+++ b/liboverlay/overlayMdssRot.cpp
@@ -129,6 +129,10 @@
     mDownscale = downscale;
 }
 
+void MdssRot::setFrameRate(uint32_t frame_rate) {
+    mRotInfo.frame_rate = frame_rate;
+}
+
 void MdssRot::setFlags(const utils::eMdpFlags& flags) {
     mRotInfo.flags = flags;
 }
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index e045b44..0766c86 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -97,6 +97,7 @@
     virtual bool queueBuffer(int fd, uint32_t offset) = 0;
     virtual void dump() const = 0;
     virtual void getDump(char *buf, size_t len) const = 0;
+    virtual void setFrameRate(uint32_t frame_rate) = 0;
     inline void setCurrBufReleaseFd(const int& fence) {
         mMem.setCurrBufReleaseFd(fence);
     }
@@ -150,6 +151,7 @@
     virtual bool queueBuffer(int fd, uint32_t offset);
     virtual void dump() const;
     virtual void getDump(char *buf, size_t len) const;
+    virtual void setFrameRate(uint32_t frame_rate);
 
 private:
     explicit MdpRot();
@@ -222,6 +224,7 @@
     virtual bool queueBuffer(int fd, uint32_t offset);
     virtual void dump() const;
     virtual void getDump(char *buf, size_t len) const;
+    virtual void setFrameRate(uint32_t frame_rate);
 
 private:
     explicit MdssRot();