hwc: Do not use fb handle in hwc_prepare

Do not use fb handle in prepare. Use displayFrame for dimensions,
align them and hardcode format.

b/8316155 - Implement HWComposer 1.3 w/ virtual display support
Change-Id: I5c494a74a807d3a52a1c88257494b58c583700f5
diff --git a/msm8974/libhwcomposer/hwc.cpp b/msm8974/libhwcomposer/hwc.cpp
index 989edb2..8e0afe0 100644
--- a/msm8974/libhwcomposer/hwc.cpp
+++ b/msm8974/libhwcomposer/hwc.cpp
@@ -157,18 +157,14 @@
             ctx->dpyAttr[dpy].isActive) {
         reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
         handleGeomChange(ctx, dpy, list);
-        uint32_t last = list->numHwLayers - 1;
-        hwc_layer_1_t *fbLayer = &list->hwLayers[last];
-        if(fbLayer->handle) {
-            setListStats(ctx, list, dpy);
-            if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
-                const int fbZ = 0;
-                ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
-            }
-            if (ctx->mMDP.version < qdutils::MDP_V4_0) {
-                if(ctx->mCopyBit[dpy])
-                    ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
-            }
+        setListStats(ctx, list, dpy);
+        if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
+            const int fbZ = 0;
+            ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
+        }
+        if (ctx->mMDP.version < qdutils::MDP_V4_0) {
+            if(ctx->mCopyBit[dpy])
+                ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
         }
     }
     return 0;
@@ -186,24 +182,20 @@
             ctx->dpyAttr[dpy].connected) {
         reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
         handleGeomChange(ctx, dpy, list);
-        uint32_t last = list->numHwLayers - 1;
-        hwc_layer_1_t *fbLayer = &list->hwLayers[last];
         if(!ctx->dpyAttr[dpy].isPause) {
-            if(fbLayer->handle) {
-                ctx->dpyAttr[dpy].isConfiguring = false;
-                setListStats(ctx, list, dpy);
-                if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
-                    const int fbZ = 0;
-                    ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
-                }
-
-                /* Temporarily commenting out C2D until we support partial
-                   copybit composition for mixed mode MDP
-
-                if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
-                    ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
-                */
+            ctx->dpyAttr[dpy].isConfiguring = false;
+            setListStats(ctx, list, dpy);
+            if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
+                const int fbZ = 0;
+                ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
             }
+
+            /* Temporarily commenting out C2D until we support partial
+               copybit composition for mixed mode MDP
+
+               if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
+               ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
+             */
         } else {
             // External Display is in Pause state.
             // ToDo:
@@ -225,25 +217,23 @@
         reset_layer_prop(ctx, dpy, list->numHwLayers - 1);
         uint32_t last = list->numHwLayers - 1;
         hwc_layer_1_t *fbLayer = &list->hwLayers[last];
-        if(fbLayer->handle) {
-            int fbWidth = 0, fbHeight = 0;
-            getLayerResolution(fbLayer, fbWidth, fbHeight);
-            ctx->dpyAttr[dpy].xres = fbWidth;
-            ctx->dpyAttr[dpy].yres = fbHeight;
+        int fbWidth = 0, fbHeight = 0;
+        getLayerResolution(fbLayer, fbWidth, fbHeight);
+        ctx->dpyAttr[dpy].xres = fbWidth;
+        ctx->dpyAttr[dpy].yres = fbHeight;
 
-            if(ctx->dpyAttr[dpy].connected == false) {
-                ctx->dpyAttr[dpy].connected = true;
-                setupSecondaryObjs(ctx, dpy);
-            }
+        if(ctx->dpyAttr[dpy].connected == false) {
+            ctx->dpyAttr[dpy].connected = true;
+            setupSecondaryObjs(ctx, dpy);
+        }
 
-            ctx->dpyAttr[dpy].fd = Writeback::getInstance()->getFbFd();
-            Writeback::getInstance()->configureDpyInfo(fbWidth, fbHeight);
-            setListStats(ctx, list, dpy);
+        ctx->dpyAttr[dpy].fd = Writeback::getInstance()->getFbFd();
+        Writeback::getInstance()->configureDpyInfo(fbWidth, fbHeight);
+        setListStats(ctx, list, dpy);
 
-            if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
-                const int fbZ = 0;
-                ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
-            }
+        if(ctx->mMDPComp[dpy]->prepare(ctx, list) < 0) {
+            const int fbZ = 0;
+            ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZ);
         }
     }
     return 0;
diff --git a/msm8974/libhwcomposer/hwc_fbupdate.cpp b/msm8974/libhwcomposer/hwc_fbupdate.cpp
index 9ae5444..9ede498 100644
--- a/msm8974/libhwcomposer/hwc_fbupdate.cpp
+++ b/msm8974/libhwcomposer/hwc_fbupdate.cpp
@@ -69,9 +69,19 @@
     hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
     if (LIKELY(ctx->mOverlay)) {
         overlay::Overlay& ov = *(ctx->mOverlay);
-        private_handle_t *hnd = (private_handle_t *)layer->handle;
-        ovutils::Whf info(getWidth(hnd), getHeight(hnd),
-                          ovutils::getMdpFormat(hnd->format), hnd->size);
+        hwc_rect_t displayFrame = layer->displayFrame;
+        int alignedWidth = 0;
+        int alignedHeight = 0;
+
+        getBufferSizeAndDimensions(displayFrame.right - displayFrame.left,
+                displayFrame.bottom - displayFrame.top,
+                HAL_PIXEL_FORMAT_RGBA_8888,
+                alignedWidth,
+                alignedHeight);
+
+        ovutils::Whf info(alignedWidth,
+                alignedHeight,
+                ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
 
         //Request a pipe
         ovutils::eMdpPipeType type = ovutils::OV_MDP_PIPE_ANY;
@@ -120,7 +130,7 @@
             getNonWormholeRegion(list, sourceCrop);
         }
 
-        hwc_rect_t displayFrame = sourceCrop;
+        displayFrame = sourceCrop;
         ovutils::Dim dpos(displayFrame.left,
                           displayFrame.top,
                           displayFrame.right - displayFrame.left,
@@ -183,9 +193,19 @@
     hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
     if (LIKELY(ctx->mOverlay)) {
         overlay::Overlay& ov = *(ctx->mOverlay);
-        private_handle_t *hnd = (private_handle_t *)layer->handle;
-        ovutils::Whf info(getWidth(hnd), getHeight(hnd),
-                          ovutils::getMdpFormat(hnd->format), hnd->size);
+        hwc_rect_t displayFrame = layer->displayFrame;
+        int alignedWidth = 0;
+        int alignedHeight = 0;
+
+        getBufferSizeAndDimensions(displayFrame.right - displayFrame.left,
+                displayFrame.bottom - displayFrame.top,
+                HAL_PIXEL_FORMAT_RGBA_8888,
+                alignedWidth,
+                alignedHeight);
+
+        ovutils::Whf info(alignedWidth,
+                alignedHeight,
+                ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
 
         //Request left pipe
         ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy,
@@ -234,7 +254,6 @@
         ov.setSource(pargR, destR);
 
         hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
-        hwc_rect_t displayFrame = layer->displayFrame;
 
         const float xres = ctx->dpyAttr[mDpy].xres;
         const int lSplit = getLeftSplit(ctx, mDpy);