Update display contents when metrics change
When display was resized its windows weren't updated because of two problems: old LogicaDisplay#mOverrideDisplayInfo was preventing WM from detecting the change and base display metrics were never updated by resize. Bug: 35258051 Test: android.server.cts.ActivityManagerDisplayTests Test: #testDisplayResize Change-Id: I30155e4d83e61ffe969c81dfcf932f3f3882cc59
This commit is contained in:
@@ -261,6 +261,7 @@ final class LogicalDisplay {
|
||||
|
||||
mPrimaryDisplayDeviceInfo = deviceInfo;
|
||||
mInfo = null;
|
||||
mOverrideDisplayInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -919,6 +919,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
|
||||
void updateDisplayInfo() {
|
||||
mDisplay.getDisplayInfo(mDisplayInfo);
|
||||
mDisplay.getMetrics(mDisplayMetrics);
|
||||
|
||||
// Check if display metrics changed and update base values if needed.
|
||||
updateBaseDisplayMetricsIfNeeded();
|
||||
|
||||
for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
|
||||
mTaskStackContainers.get(i).updateDisplayInfo(null);
|
||||
}
|
||||
@@ -934,10 +938,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
|
||||
}
|
||||
}
|
||||
|
||||
mBaseDisplayWidth = mInitialDisplayWidth = mDisplayInfo.logicalWidth;
|
||||
mBaseDisplayHeight = mInitialDisplayHeight = mDisplayInfo.logicalHeight;
|
||||
mBaseDisplayDensity = mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
|
||||
mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
|
||||
updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
|
||||
mDisplayInfo.logicalDensityDpi);
|
||||
}
|
||||
|
||||
void getLogicalDisplayRect(Rect out) {
|
||||
@@ -967,6 +969,30 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
|
||||
}
|
||||
}
|
||||
|
||||
/** If display metrics changed and it's not just a rotation - update base values. */
|
||||
private void updateBaseDisplayMetricsIfNeeded() {
|
||||
final int orientation = mDisplayInfo.rotation;
|
||||
final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
|
||||
final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
|
||||
final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
|
||||
|
||||
boolean displayMetricsChanged
|
||||
= mBaseDisplayWidth != newWidth || mBaseDisplayHeight != newHeight;
|
||||
displayMetricsChanged |= mBaseDisplayDensity != mDisplayInfo.logicalDensityDpi;
|
||||
|
||||
if (displayMetricsChanged) {
|
||||
updateBaseDisplayMetrics(newWidth, newHeight, mDisplayInfo.logicalDensityDpi);
|
||||
mService.reconfigureDisplayLocked(this);
|
||||
}
|
||||
}
|
||||
|
||||
void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
|
||||
mBaseDisplayWidth = mInitialDisplayWidth = baseWidth;
|
||||
mBaseDisplayHeight = mInitialDisplayHeight = baseHeight;
|
||||
mBaseDisplayDensity = mInitialDisplayDensity = baseDensity;
|
||||
mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
|
||||
}
|
||||
|
||||
void getContentRect(Rect out) {
|
||||
out.set(mContentRect);
|
||||
}
|
||||
|
||||
@@ -5920,8 +5920,8 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
if (displayContent.mBaseDisplayWidth != width
|
||||
|| displayContent.mBaseDisplayHeight != height) {
|
||||
Slog.i(TAG_WM, "FORCED DISPLAY SIZE: " + width + "x" + height);
|
||||
displayContent.mBaseDisplayWidth = width;
|
||||
displayContent.mBaseDisplayHeight = height;
|
||||
displayContent.updateBaseDisplayMetrics(width, height,
|
||||
displayContent.mBaseDisplayDensity);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
@@ -5946,8 +5946,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
// displayContent must not be null
|
||||
private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) {
|
||||
Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
|
||||
displayContent.mBaseDisplayWidth = width;
|
||||
displayContent.mBaseDisplayHeight = height;
|
||||
displayContent.updateBaseDisplayMetrics(width, height, displayContent.mBaseDisplayDensity);
|
||||
reconfigureDisplayLocked(displayContent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user