hwc: vd: Add support for Dynamic Resolution Change (DRC)

1. Add support for Dynamic Resolution Change

We add support for DRC on virtual displays. This is achieved
by reading the width and height attributes that are set as
part of the buffer handle metadata.

For the WFD use cases, the WFD  MultiMedia framework will
update the width and height during DRC by using setMetaData
API with UPDATE_BUFFER_GEOMETRY. We then proceed to configure
WB with the new resolution for subsequent frames.

2. Update WB dump with output buffer format and resolution

Update WB dump with output buffer format and resolution. This is
helpful for debugging purposes.

Change-Id: I537277499041bffc7bfc5c6e3d024b67f80fce44
diff --git a/libhwcomposer/hwc_virtual.cpp b/libhwcomposer/hwc_virtual.cpp
index b1dde9d..146d671 100644
--- a/libhwcomposer/hwc_virtual.cpp
+++ b/libhwcomposer/hwc_virtual.cpp
@@ -40,6 +40,7 @@
 
 void HWCVirtualVDS::init(hwc_context_t *ctx) {
     const int dpy = HWC_DISPLAY_VIRTUAL;
+    mScalingWidth = 0, mScalingHeight = 0;
     ctx->mFBUpdate[dpy] =
             IFBUpdate::getObject(ctx, dpy);
     ctx->mMDPComp[dpy] =  MDPComp::getObject(ctx, dpy);
@@ -106,8 +107,14 @@
             ctx->dpyAttr[dpy].isConfiguring = false;
             ctx->dpyAttr[dpy].fd = Writeback::getInstance()->getFbFd();
             private_handle_t *ohnd = (private_handle_t *)list->outbuf;
-            Writeback::getInstance()->configureDpyInfo(ohnd->width,
-                                                          ohnd->height);
+
+            setMDPScalingMode(ctx, ohnd, dpy);
+
+            mScalingWidth = getWidth(ohnd);
+            mScalingHeight = getHeight(ohnd);
+
+            Writeback::getInstance()->configureDpyInfo(mScalingWidth,
+                                                        mScalingHeight);
             setListStats(ctx, list, dpy);
 
             if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
@@ -258,3 +265,20 @@
     }
     return;
 }
+
+/* We set scaling mode on the VD if the output handle width and height
+   differs from the virtual frame buffer width and height. */
+void HWCVirtualVDS::setMDPScalingMode(hwc_context_t* ctx,
+        private_handle_t* ohnd, int dpy) {
+    bool scalingMode = false;
+    int fbWidth = ctx->dpyAttr[dpy].xres;
+    int fbHeight =  ctx->dpyAttr[dpy].yres;
+    if((getWidth(ohnd) != fbWidth) || (getHeight(ohnd) != fbHeight)) {
+        scalingMode = true;
+    }
+    ctx->dpyAttr[dpy].mMDPScalingMode = scalingMode;
+
+    ALOGD_IF(HWCVIRTUAL_LOG, "%s fb(%dx%d) outputBuffer(%dx%d) scalingMode=%d",
+            __FUNCTION__, fbWidth, fbHeight,
+            getWidth(ohnd), getHeight(ohnd), scalingMode);
+}