hwc: Set full screen aspect ratio deviation within tolerance level

1. Set tagged video layer to be full screen on external, if the
   deviation between aspect ratio of external and aspect ratio of
   video layer is within the tolerance level.
2. Set sys.hwc.windowbox_aspect_ratio_tolerance property to change the
   tolerance level.

Example:
   Set sys.hwc.windowbox_aspect_ratio_tolerance to 5 for +/- 5%
   tolerance level

Change-Id: I5b3e962dfa1c9fc19036e42cb4599d0490b04da9
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 7e77d95..5da24a4 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -354,6 +354,9 @@
     ctx->deviceOrientation = 0;
     ctx->mBufferMirrorMode = false;
 
+    property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
+    ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
+
     ctx->enableABC = false;
     property_get("debug.sf.hwc.canUseABC", value, "0");
     ctx->enableABC  = atoi(value) ? true : false;
@@ -1868,9 +1871,14 @@
     int extW = ctx->dpyAttr[dpy].xres;
     int extH = ctx->dpyAttr[dpy].yres;
     // Set the destination coordinates of external display to full screen,
-    // when zoom in mode is enabled or video aspect ratio matches with the
-    // external display aspect ratio
-    if((srcCrop.w * extH == extW * srcCrop.h) || (isZoomModeEnabled(crop))) {
+    // when zoom in mode is enabled or the ratio between video aspect ratio
+    // and external display aspect ratio is below the minimum tolerance level
+    // and above maximum tolerance level
+    float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
+    float extDisplayAspectRatio = ((float)extW / (float)extH);
+    float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
+    if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
+        (isZoomModeEnabled(crop))) {
         dst.left = 0;
         dst.top = 0;
         dst.right = extW;