hwc: Use ib instead of ab for bandwidth checks

The ab (average bandwidth) is just the average and there could be
underruns when ib (instantaneous bandwidth) is attempted to be used.
Add additional factor to use ib instead of ab. This means we need to
assume that all the layer contents could be requested together, rather
than one after another.

Also use the trimmed layer dimensions for calculations.

Change-Id: I771f964e1c80b5db564faa01cdfb75d75b54f97a
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 6e44234..44db2bc 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -751,9 +751,12 @@
             private_handle_t *hnd = (private_handle_t *)layer->handle;
             if (hnd) {
                 hwc_rect_t crop = layer->sourceCrop;
+                hwc_rect_t dst = layer->displayFrame;
+                trimLayer(ctx, mDpy, layer->transform, crop, dst);
                 float bpp = ((float)hnd->size) / (hnd->width * hnd->height);
-                size += bpp * ((crop.right - crop.left) *
-                    (crop.bottom - crop.top));
+                size += bpp * (crop.right - crop.left) *
+                    (crop.bottom - crop.top) *
+                    ctx->dpyAttr[mDpy].yres / (dst.bottom - dst.top);
             }
         }
     }