hwc: Add support for panel resolution switch
Add support for panel resolution switch. This feature makes use of
the Linux modedb feature that lists available modes in
/sys/class/graphics/fb0/modes and accepts a mode change when written
to /sys/class/graphics/fb0/mode
Clients can link to APIs exposed in display_config.h, these
internally resolve to binder calls into HWC. For debugging, mode
changes can be made over binder using shell commands.
adb shell service call display.qservice CODE ARGS
ARGS can include config index and display (only primary supported)
setActiveConfig():
adb shell service call display.qservice 25 i32 INDEX i32 0
getActiveConfig():
adb shell service call display.qservice 26 i32 0
getConfigCount():
adb shell service call display.qservice 27 i32 0
getDisplayAttributes():
adb shell service call display.qservice 28 i32 INDEX i32 0
Change-Id: I97d34cc9c0e521a3bd5c948eeea6d1e07db7b7ff
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 7c69633..c5edcc7 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -226,18 +226,11 @@
}
-static void scaleDisplayFrame(hwc_context_t *ctx, int dpy,
- hwc_display_contents_1_t *list) {
- uint32_t origXres = ctx->dpyAttr[dpy].xres;
- uint32_t origYres = ctx->dpyAttr[dpy].yres;
- uint32_t newXres = ctx->dpyAttr[dpy].xres_new;
- uint32_t newYres = ctx->dpyAttr[dpy].yres_new;
- float xresRatio = (float)origXres / (float)newXres;
- float yresRatio = (float)origYres / (float)newYres;
+static void scaleDisplayFrame(hwc_display_contents_1_t *list, float xresRatio,
+ float yresRatio) {
for (size_t i = 0; i < list->numHwLayers; i++) {
hwc_layer_1_t *layer = &list->hwLayers[i];
hwc_rect_t& displayFrame = layer->displayFrame;
- hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
uint32_t layerWidth = displayFrame.right - displayFrame.left;
uint32_t layerHeight = displayFrame.bottom - displayFrame.top;
displayFrame.left = (int)(xresRatio * (float)displayFrame.left);
@@ -249,6 +242,35 @@
}
}
+static void handleFbScaling(hwc_context_t *ctx, int dpy,
+ hwc_display_contents_1_t *list) {
+ //We could switch to a config that does not lead to fb scaling, but
+ //we need to update older display frames and ratios.
+ if (ctx->dpyAttr[dpy].fbScaling or ctx->dpyAttr[dpy].configSwitched) {
+ uint32_t xresPanel = ctx->dpyAttr[dpy].xres;
+ uint32_t yresPanel = ctx->dpyAttr[dpy].yres;
+ uint32_t xresFB = ctx->dpyAttr[dpy].xresFB;
+ uint32_t yresFB = ctx->dpyAttr[dpy].yresFB;
+ float xresRatio = (float)xresPanel / (float)xresFB;
+ float yresRatio = (float)yresPanel / (float)yresFB;
+ if(list->flags & HWC_GEOMETRY_CHANGED) {
+ //In case of geometry changes f/w resets displays frames w.r.t to
+ //FB's dimensions. So any config switch is automatically absorbed.
+ scaleDisplayFrame(list, xresRatio, yresRatio);
+ } else if (ctx->dpyAttr[dpy].configSwitched) {
+ //If there is a primary panel resolution switch without a geometry
+ //change we need to scale-back the previous ratio used and then use
+ //the current ratio. i.e use current ratio / prev ratio
+ scaleDisplayFrame(list,
+ xresRatio / ctx->dpyAttr[dpy].fbWidthScaleRatio,
+ yresRatio / ctx->dpyAttr[dpy].fbHeightScaleRatio);
+ }
+ ctx->dpyAttr[dpy].configSwitched = false;
+ ctx->dpyAttr[dpy].fbWidthScaleRatio = xresRatio;
+ ctx->dpyAttr[dpy].fbHeightScaleRatio = yresRatio;
+ }
+}
+
static int hwc_prepare_primary(hwc_composer_device_1 *dev,
hwc_display_contents_1_t *list) {
ATRACE_CALL();
@@ -277,9 +299,7 @@
ctx->dpyAttr[dpy].isActive = true;
}
- if (ctx->dpyAttr[dpy].customFBSize &&
- list->flags & HWC_GEOMETRY_CHANGED)
- scaleDisplayFrame(ctx, dpy, list);
+ handleFbScaling(ctx, dpy, list);
reset_layer_prop(ctx, dpy, (int)list->numHwLayers - 1);
setListStats(ctx, list, dpy);
@@ -834,8 +854,8 @@
hotPluggable ? refresh : ctx->dpyAttr[disp].vsync_period;
break;
case HWC_DISPLAY_WIDTH:
- if (ctx->dpyAttr[disp].customFBSize)
- values[i] = ctx->dpyAttr[disp].xres_new;
+ if (ctx->dpyAttr[disp].fbScaling)
+ values[i] = ctx->dpyAttr[disp].xresFB;
else
values[i] = hotPluggable ? xres : ctx->dpyAttr[disp].xres;
@@ -843,8 +863,8 @@
values[i]);
break;
case HWC_DISPLAY_HEIGHT:
- if (ctx->dpyAttr[disp].customFBSize)
- values[i] = ctx->dpyAttr[disp].yres_new;
+ if (ctx->dpyAttr[disp].fbScaling)
+ values[i] = ctx->dpyAttr[disp].yresFB;
else
values[i] = hotPluggable ? yres : ctx->dpyAttr[disp].yres;
ALOGD("%s disp = %d, height = %d",__FUNCTION__, disp,
@@ -879,6 +899,10 @@
dumpsys_log(aBuf, " DynRefreshRate=%d\n",
ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate);
for(int dpy = 0; dpy < HWC_NUM_DISPLAY_TYPES; dpy++) {
+ if(dpy == HWC_DISPLAY_PRIMARY)
+ dumpsys_log(aBuf, "Dpy %d: FB Scale Ratio w %.1f, h %.1f\n", dpy,
+ ctx->dpyAttr[dpy].fbWidthScaleRatio,
+ ctx->dpyAttr[dpy].fbHeightScaleRatio);
if(ctx->mMDPComp[dpy])
ctx->mMDPComp[dpy]->dump(aBuf, ctx);
}