hwc: Derive view frame for external display.
Derive viewframe rectangle for external display from primary
resolution and primary device orientation.
Change-Id: I1885b660cd6343e41e4b574e358fd063cd47a54d
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 6869454..5692ef1 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -744,6 +744,28 @@
}
}
+hwc_rect_t calculateDisplayViewFrame(hwc_context_t *ctx, int dpy) {
+ int dstWidth = ctx->dpyAttr[dpy].xres;
+ int dstHeight = ctx->dpyAttr[dpy].yres;
+ int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
+ int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
+ // default we assume viewframe as a full frame for primary display
+ hwc_rect outRect = {0, 0, dstWidth, dstHeight};
+ if(dpy) {
+ // swap srcWidth and srcHeight, if the device orientation is 90 or 270.
+ if(ctx->deviceOrientation & 0x1) {
+ swap(srcWidth, srcHeight);
+ }
+ // Get Aspect Ratio for external
+ getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
+ srcHeight, outRect);
+ }
+ ALOGD_IF(HWC_UTILS_DEBUG, "%s: view frame for dpy %d is [%d %d %d %d]",
+ __FUNCTION__, dpy, outRect.left, outRect.top,
+ outRect.right, outRect.bottom);
+ return outRect;
+}
+
void setListStats(hwc_context_t *ctx,
hwc_display_contents_1_t *list, int dpy) {
const int prevYuvCount = ctx->listStats[dpy].yuvCount;
@@ -767,13 +789,14 @@
trimList(ctx, list, dpy);
optimizeLayerRects(ctx, list, dpy);
+ // Calculate view frame of ext display from primary resolution
+ // and primary device orientation.
+ ctx->mViewFrame[dpy] = calculateDisplayViewFrame(ctx, dpy);
+
for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
hwc_layer_1_t const* layer = &list->hwLayers[i];
private_handle_t *hnd = (private_handle_t *)layer->handle;
- // Calculate view frame of each display from the layer displayframe
- ctx->mViewFrame[dpy] = getUnion(ctx->mViewFrame[dpy],
- layer->displayFrame);
#ifdef QCOM_BSP
if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
ctx->listStats[dpy].isDisplayAnimating = true;