hqd: Adjust resolution based on aspect ratio
When the MDP downscale path is enabled we assign the primary
resolution as the external display's dimensions. However, the
aspect ratios of the external and primary displays can be different.
As a result, directly assigning primary resolution could lead
to an incorrect final image.
We get around this by calculating a new resolution by
keeping aspect ratio intact.
Change-Id: I217718a5474862154fe60837fc6518408d2c32c7
diff --git a/libvirtual/virtual.cpp b/libvirtual/virtual.cpp
index 795d8a1..e80109f 100644
--- a/libvirtual/virtual.cpp
+++ b/libvirtual/virtual.cpp
@@ -48,6 +48,7 @@
#include "overlayUtils.h"
#include "overlay.h"
#include "mdp_version.h"
+#include "qd_utils.h"
using namespace android;
@@ -127,14 +128,25 @@
// by SUPPORTED_VIRTUAL_AREA).
if((maxArea == (priW * priH))
&& (maxArea <= SUPPORTED_VIRTUAL_AREA)) {
- extW = priW;
- extH = priH;
+ // tmpW and tmpH will hold the primary dimensions before we
+ // update the aspect ratio if necessary.
+ uint32_t tmpW = priW;
+ uint32_t tmpH = priH;
// If WFD is in landscape, assign the higher dimension
// to WFD's xres.
if(priH > priW) {
- extW = priH;
- extH = priW;
+ tmpW = priH;
+ tmpH = priW;
}
+ // The aspect ratios of the external and primary displays
+ // can be different. As a result, directly assigning primary
+ // resolution could lead to an incorrect final image.
+ // We get around this by calculating a new resolution by
+ // keeping aspect ratio intact.
+ hwc_rect r = {0, 0, 0, 0};
+ getAspectRatioPosition(tmpW, tmpH, extW, extH, r);
+ extW = r.right - r.left;
+ extH = r.bottom - r.top;
}
}