Merge "Handle general display size change for screen decorations" into udc-qpr-dev
This commit is contained in:
@@ -36,6 +36,7 @@ import android.graphics.Color;
|
|||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.graphics.common.AlphaInterpretation;
|
import android.hardware.graphics.common.AlphaInterpretation;
|
||||||
@@ -171,7 +172,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
private int mTintColor = Color.BLACK;
|
private int mTintColor = Color.BLACK;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected DisplayDecorationSupport mHwcScreenDecorationSupport;
|
protected DisplayDecorationSupport mHwcScreenDecorationSupport;
|
||||||
private Display.Mode mDisplayMode;
|
private final Point mDisplaySize = new Point();
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected DisplayInfo mDisplayInfo = new DisplayInfo();
|
protected DisplayInfo mDisplayInfo = new DisplayInfo();
|
||||||
private DisplayCutout mDisplayCutout;
|
private DisplayCutout mDisplayCutout;
|
||||||
@@ -484,7 +485,8 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
mWindowManager = mContext.getSystemService(WindowManager.class);
|
mWindowManager = mContext.getSystemService(WindowManager.class);
|
||||||
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
||||||
mRotation = mDisplayInfo.rotation;
|
mRotation = mDisplayInfo.rotation;
|
||||||
mDisplayMode = mDisplayInfo.getMode();
|
mDisplaySize.x = mDisplayInfo.getNaturalWidth();
|
||||||
|
mDisplaySize.y = mDisplayInfo.getNaturalHeight();
|
||||||
mDisplayUniqueId = mDisplayInfo.uniqueId;
|
mDisplayUniqueId = mDisplayInfo.uniqueId;
|
||||||
mDisplayCutout = mDisplayInfo.displayCutout;
|
mDisplayCutout = mDisplayInfo.displayCutout;
|
||||||
mRoundedCornerResDelegate =
|
mRoundedCornerResDelegate =
|
||||||
@@ -505,10 +507,12 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
public void onDisplayChanged(int displayId) {
|
public void onDisplayChanged(int displayId) {
|
||||||
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
||||||
final int newRotation = mDisplayInfo.rotation;
|
final int newRotation = mDisplayInfo.rotation;
|
||||||
final Display.Mode newDisplayMode = mDisplayInfo.getMode();
|
|
||||||
if ((mOverlays != null || mScreenDecorHwcWindow != null)
|
if ((mOverlays != null || mScreenDecorHwcWindow != null)
|
||||||
&& (mRotation != newRotation
|
&& (mRotation != newRotation
|
||||||
|| displayModeChanged(mDisplayMode, newDisplayMode))) {
|
|| displaySizeChanged(mDisplaySize, mDisplayInfo))) {
|
||||||
|
final Point newSize = new Point();
|
||||||
|
newSize.x = mDisplayInfo.getNaturalWidth();
|
||||||
|
newSize.y = mDisplayInfo.getNaturalHeight();
|
||||||
// We cannot immediately update the orientation. Otherwise
|
// We cannot immediately update the orientation. Otherwise
|
||||||
// WindowManager is still deferring layout until it has finished dispatching
|
// WindowManager is still deferring layout until it has finished dispatching
|
||||||
// the config changes, which may cause divergence between what we draw
|
// the config changes, which may cause divergence between what we draw
|
||||||
@@ -520,9 +524,8 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
if (mRotation != newRotation) {
|
if (mRotation != newRotation) {
|
||||||
mLogger.logRotationChangeDeferred(mRotation, newRotation);
|
mLogger.logRotationChangeDeferred(mRotation, newRotation);
|
||||||
}
|
}
|
||||||
if (displayModeChanged(mDisplayMode, newDisplayMode)) {
|
if (!mDisplaySize.equals(newSize)) {
|
||||||
mLogger.logDisplayModeChanged(
|
mLogger.logDisplaySizeChanged(mDisplaySize, newSize);
|
||||||
newDisplayMode.getModeId(), mDisplayMode.getModeId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOverlays != null) {
|
if (mOverlays != null) {
|
||||||
@@ -531,7 +534,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
final ViewGroup overlayView = mOverlays[i].getRootView();
|
final ViewGroup overlayView = mOverlays[i].getRootView();
|
||||||
overlayView.getViewTreeObserver().addOnPreDrawListener(
|
overlayView.getViewTreeObserver().addOnPreDrawListener(
|
||||||
new RestartingPreDrawListener(
|
new RestartingPreDrawListener(
|
||||||
overlayView, i, newRotation, newDisplayMode));
|
overlayView, i, newRotation, newSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,7 +544,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
new RestartingPreDrawListener(
|
new RestartingPreDrawListener(
|
||||||
mScreenDecorHwcWindow,
|
mScreenDecorHwcWindow,
|
||||||
-1, // Pass -1 for views with no specific position.
|
-1, // Pass -1 for views with no specific position.
|
||||||
newRotation, newDisplayMode));
|
newRotation, newSize));
|
||||||
}
|
}
|
||||||
if (mScreenDecorHwcLayer != null) {
|
if (mScreenDecorHwcLayer != null) {
|
||||||
mScreenDecorHwcLayer.pendingConfigChange = true;
|
mScreenDecorHwcLayer.pendingConfigChange = true;
|
||||||
@@ -943,15 +946,8 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean displayModeChanged(Display.Mode oldMode, Display.Mode newMode) {
|
private static boolean displaySizeChanged(Point size, DisplayInfo info) {
|
||||||
if (oldMode == null) {
|
return size.x != info.getNaturalWidth() || size.y != info.getNaturalHeight();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We purposely ignore refresh rate and id changes here, because we don't need to
|
|
||||||
// invalidate for those, and they can trigger the refresh rate to increase
|
|
||||||
return oldMode.getPhysicalWidth() != newMode.getPhysicalWidth()
|
|
||||||
|| oldMode.getPhysicalHeight() != newMode.getPhysicalHeight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOverlayWindowGravity(@BoundsPosition int pos) {
|
private int getOverlayWindowGravity(@BoundsPosition int pos) {
|
||||||
@@ -1170,14 +1166,14 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
if (mRotation != newRotation) {
|
if (mRotation != newRotation) {
|
||||||
mDotViewController.setNewRotation(newRotation);
|
mDotViewController.setNewRotation(newRotation);
|
||||||
}
|
}
|
||||||
final Display.Mode newMod = mDisplayInfo.getMode();
|
|
||||||
final DisplayCutout newCutout = mDisplayInfo.displayCutout;
|
final DisplayCutout newCutout = mDisplayInfo.displayCutout;
|
||||||
|
|
||||||
if (!mPendingConfigChange
|
if (!mPendingConfigChange
|
||||||
&& (newRotation != mRotation || displayModeChanged(mDisplayMode, newMod)
|
&& (newRotation != mRotation || displaySizeChanged(mDisplaySize, mDisplayInfo)
|
||||||
|| !Objects.equals(newCutout, mDisplayCutout))) {
|
|| !Objects.equals(newCutout, mDisplayCutout))) {
|
||||||
mRotation = newRotation;
|
mRotation = newRotation;
|
||||||
mDisplayMode = newMod;
|
mDisplaySize.x = mDisplayInfo.getNaturalWidth();
|
||||||
|
mDisplaySize.y = mDisplayInfo.getNaturalHeight();
|
||||||
mDisplayCutout = newCutout;
|
mDisplayCutout = newCutout;
|
||||||
float ratio = getPhysicalPixelDisplaySizeRatio();
|
float ratio = getPhysicalPixelDisplaySizeRatio();
|
||||||
mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio(ratio);
|
mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio(ratio);
|
||||||
@@ -1494,31 +1490,29 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
|
|
||||||
private final View mView;
|
private final View mView;
|
||||||
private final int mTargetRotation;
|
private final int mTargetRotation;
|
||||||
private final Display.Mode mTargetDisplayMode;
|
private final Point mTargetDisplaySize;
|
||||||
// Pass -1 for ScreenDecorHwcLayer since it's a fullscreen window and has no specific
|
// Pass -1 for ScreenDecorHwcLayer since it's a fullscreen window and has no specific
|
||||||
// position.
|
// position.
|
||||||
private final int mPosition;
|
private final int mPosition;
|
||||||
|
|
||||||
private RestartingPreDrawListener(View view, @BoundsPosition int position,
|
private RestartingPreDrawListener(View view, @BoundsPosition int position,
|
||||||
int targetRotation, Display.Mode targetDisplayMode) {
|
int targetRotation, Point targetDisplaySize) {
|
||||||
mView = view;
|
mView = view;
|
||||||
mTargetRotation = targetRotation;
|
mTargetRotation = targetRotation;
|
||||||
mTargetDisplayMode = targetDisplayMode;
|
mTargetDisplaySize = targetDisplaySize;
|
||||||
mPosition = position;
|
mPosition = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreDraw() {
|
public boolean onPreDraw() {
|
||||||
mView.getViewTreeObserver().removeOnPreDrawListener(this);
|
mView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||||
if (mTargetRotation == mRotation
|
if (mTargetRotation == mRotation && mDisplaySize.equals(mTargetDisplaySize)) {
|
||||||
&& !displayModeChanged(mDisplayMode, mTargetDisplayMode)) {
|
|
||||||
if (DEBUG_LOGGING) {
|
if (DEBUG_LOGGING) {
|
||||||
final String title = mPosition < 0 ? "ScreenDecorHwcLayer"
|
final String title = mPosition < 0 ? "ScreenDecorHwcLayer"
|
||||||
: getWindowTitleByPos(mPosition);
|
: getWindowTitleByPos(mPosition);
|
||||||
Log.i(TAG, title + " already in target rot "
|
Log.i(TAG, title + " already in target rot "
|
||||||
+ mTargetRotation + " and in target resolution "
|
+ mTargetRotation + " and in target resolution "
|
||||||
+ mTargetDisplayMode.getPhysicalWidth() + "x"
|
+ mTargetDisplaySize.x + "x" + mTargetDisplaySize.y
|
||||||
+ mTargetDisplayMode.getPhysicalHeight()
|
|
||||||
+ ", allow draw without restarting it");
|
+ ", allow draw without restarting it");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1533,8 +1527,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
: getWindowTitleByPos(mPosition);
|
: getWindowTitleByPos(mPosition);
|
||||||
Log.i(TAG, title
|
Log.i(TAG, title
|
||||||
+ " restarting listener fired, restarting draw for rot " + mRotation
|
+ " restarting listener fired, restarting draw for rot " + mRotation
|
||||||
+ ", resolution " + mDisplayMode.getPhysicalWidth() + "x"
|
+ ", resolution " + mDisplaySize.x + "x" + mDisplaySize.y);
|
||||||
+ mDisplayMode.getPhysicalHeight());
|
|
||||||
}
|
}
|
||||||
mView.invalidate();
|
mView.invalidate();
|
||||||
return false;
|
return false;
|
||||||
@@ -1560,19 +1553,18 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
|
|||||||
public boolean onPreDraw() {
|
public boolean onPreDraw() {
|
||||||
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
mContext.getDisplay().getDisplayInfo(mDisplayInfo);
|
||||||
final int displayRotation = mDisplayInfo.rotation;
|
final int displayRotation = mDisplayInfo.rotation;
|
||||||
final Display.Mode displayMode = mDisplayInfo.getMode();
|
if ((displayRotation != mRotation || displaySizeChanged(mDisplaySize, mDisplayInfo))
|
||||||
if ((displayRotation != mRotation || displayModeChanged(mDisplayMode, displayMode))
|
|
||||||
&& !mPendingConfigChange) {
|
&& !mPendingConfigChange) {
|
||||||
if (DEBUG_LOGGING) {
|
if (DEBUG_LOGGING) {
|
||||||
if (displayRotation != mRotation) {
|
if (displayRotation != mRotation) {
|
||||||
Log.i(TAG, "Drawing rot " + mRotation + ", but display is at rot "
|
Log.i(TAG, "Drawing rot " + mRotation + ", but display is at rot "
|
||||||
+ displayRotation + ". Restarting draw");
|
+ displayRotation + ". Restarting draw");
|
||||||
}
|
}
|
||||||
if (displayModeChanged(mDisplayMode, displayMode)) {
|
if (displaySizeChanged(mDisplaySize, mDisplayInfo)) {
|
||||||
Log.i(TAG, "Drawing at " + mDisplayMode.getPhysicalWidth()
|
Log.i(TAG, "Drawing at " + mDisplaySize.x + "x" + mDisplaySize.y
|
||||||
+ "x" + mDisplayMode.getPhysicalHeight() + ", but display is at "
|
+ ", but display is at "
|
||||||
+ displayMode.getPhysicalWidth() + "x"
|
+ mDisplayInfo.getNaturalWidth() + "x"
|
||||||
+ displayMode.getPhysicalHeight() + ". Restarting draw");
|
+ mDisplayInfo.getNaturalHeight() + ". Restarting draw");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mView.invalidate();
|
mView.invalidate();
|
||||||
|
|||||||
@@ -189,15 +189,15 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logDisplayModeChanged(currentMode: Int, newMode: Int) {
|
fun logDisplaySizeChanged(currentSize: Point, newSize: Point) {
|
||||||
logBuffer.log(
|
logBuffer.log(
|
||||||
TAG,
|
TAG,
|
||||||
INFO,
|
INFO,
|
||||||
{
|
{
|
||||||
int1 = currentMode
|
str1 = currentSize.flattenToString()
|
||||||
int2 = newMode
|
str2 = newSize.flattenToString()
|
||||||
},
|
},
|
||||||
{ "Resolution changed, deferring mode change to $int2, staying at $int1" },
|
{ "Resolution changed, deferring size change to $str2, staying at $str1" },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user