Merge "Let the client compute the backdrop frame on its own" into tm-dev

This commit is contained in:
Tiger Huang
2022-03-22 04:05:18 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 67 deletions

View File

@@ -401,10 +401,8 @@ public final class ViewRootImpl implements ViewParent,
private static boolean sAlwaysAssignFocus;
/**
* This list must only be modified by the main thread, so a lock is only needed when changing
* the list or when accessing the list from a non-main thread.
* This list must only be modified by the main thread.
*/
@GuardedBy("mWindowCallbacks")
final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>();
@UnsupportedAppUsage
@UiContext
@@ -973,15 +971,11 @@ public final class ViewRootImpl implements ViewParent,
}
public void addWindowCallbacks(WindowCallbacks callback) {
synchronized (mWindowCallbacks) {
mWindowCallbacks.add(callback);
}
mWindowCallbacks.add(callback);
}
public void removeWindowCallbacks(WindowCallbacks callback) {
synchronized (mWindowCallbacks) {
mWindowCallbacks.remove(callback);
}
mWindowCallbacks.remove(callback);
}
public void reportDrawFinish() {
@@ -1703,15 +1697,19 @@ public final class ViewRootImpl implements ViewParent,
final boolean forceNextWindowRelayout = args.argi1 != 0;
final int displayId = args.argi3;
final int resizeMode = args.argi5;
final Rect backdropFrame = frames.backdropFrame;
final boolean frameChanged = !mWinFrame.equals(frames.frame);
final boolean backdropFrameChanged = !mPendingBackDropFrame.equals(backdropFrame);
final Rect frame = frames.frame;
final Rect displayFrame = frames.displayFrame;
if (mTranslator != null) {
mTranslator.translateRectInScreenToAppWindow(frame);
mTranslator.translateRectInScreenToAppWindow(displayFrame);
}
final boolean frameChanged = !mWinFrame.equals(frame);
final boolean configChanged = !mLastReportedMergedConfiguration.equals(mergedConfiguration);
final boolean displayChanged = mDisplay.getDisplayId() != displayId;
final boolean resizeModeChanged = mResizeMode != resizeMode;
if (msg == MSG_RESIZED && !frameChanged && !backdropFrameChanged && !configChanged
&& !displayChanged && !resizeModeChanged && !forceNextWindowRelayout) {
if (msg == MSG_RESIZED && !frameChanged && !configChanged && !displayChanged
&& !resizeModeChanged && !forceNextWindowRelayout) {
return;
}
@@ -1727,9 +1725,17 @@ public final class ViewRootImpl implements ViewParent,
onMovedToDisplay(displayId, mLastConfigurationFromResources);
}
setFrame(frames.frame);
mTmpFrames.displayFrame.set(frames.displayFrame);
mPendingBackDropFrame.set(backdropFrame);
setFrame(frame);
mTmpFrames.displayFrame.set(displayFrame);
if (mDragResizing && mUseMTRenderer) {
boolean fullscreen = frame.equals(mPendingBackDropFrame);
for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) {
mWindowCallbacks.get(i).onWindowSizeIsChanging(mPendingBackDropFrame, fullscreen,
mAttachInfo.mVisibleInsets, mAttachInfo.mStableInsets);
}
}
mForceNextWindowRelayout = forceNextWindowRelayout;
mPendingAlwaysConsumeSystemBars = args.argi2 != 0;
mSyncSeqId = args.argi4;
@@ -5619,8 +5625,6 @@ public final class ViewRootImpl implements ViewParent,
mTmpFrames.frame.top = t;
mTmpFrames.frame.bottom = t + h;
setFrame(mTmpFrames.frame);
mPendingBackDropFrame.set(mWinFrame);
maybeHandleWindowMove(mWinFrame);
}
break;
@@ -8118,7 +8122,6 @@ public final class ViewRootImpl implements ViewParent,
getConfiguration().windowConfiguration.getBounds());
}
mPendingBackDropFrame.set(mTmpFrames.backdropFrame);
if (mSurfaceControl.isValid()) {
if (!useBLAST()) {
mSurface.copyFrom(mSurfaceControl);
@@ -8149,6 +8152,7 @@ public final class ViewRootImpl implements ViewParent,
if (mTranslator != null) {
mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame);
mTranslator.translateRectInScreenToAppWindow(mTmpFrames.displayFrame);
mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
}
@@ -8193,6 +8197,13 @@ public final class ViewRootImpl implements ViewParent,
private void setFrame(Rect frame) {
mWinFrame.set(frame);
// Surface position is now inherited from parent, and BackdropFrameRenderer uses backdrop
// frame to position content. Thus, we just keep the size of backdrop frame, and remove the
// offset to avoid double offset from display origin.
mPendingBackDropFrame.set(frame);
mPendingBackDropFrame.offsetTo(0, 0);
mInsetsController.onFrameChanged(mOverrideInsetsFrame != null ?
mOverrideInsetsFrame : frame);
}
@@ -8584,28 +8595,7 @@ public final class ViewRootImpl implements ViewParent,
private void dispatchResized(ClientWindowFrames frames, boolean reportDraw,
MergedConfiguration mergedConfiguration, boolean forceLayout,
boolean alwaysConsumeSystemBars, int displayId, int seqId, int resizeMode) {
final Rect frame = frames.frame;
final Rect backDropFrame = frames.backdropFrame;
if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString()
+ " reportDraw=" + reportDraw
+ " backDropFrame=" + backDropFrame);
// Tell all listeners that we are resizing the window so that the chrome can get
// updated as fast as possible on a separate thread,
if (mDragResizing && mUseMTRenderer) {
boolean fullscreen = frame.equals(backDropFrame);
synchronized (mWindowCallbacks) {
for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) {
mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen,
mAttachInfo.mVisibleInsets, mAttachInfo.mStableInsets);
}
}
}
Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED);
if (mTranslator != null) {
mTranslator.translateRectInScreenToAppWindow(frame);
}
SomeArgs args = SomeArgs.obtain();
final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid());
args.arg1 = sameProcessCall ? new ClientWindowFrames(frames) : frames;

View File

@@ -40,9 +40,6 @@ public class ClientWindowFrames implements Parcelable {
*/
public final @NonNull Rect parentFrame = new Rect();
/** The background area while the window is resizing. */
public final @NonNull Rect backdropFrame = new Rect();
public boolean isParentFrameClippedByDisplayCutout;
public ClientWindowFrames() {
@@ -52,7 +49,6 @@ public class ClientWindowFrames implements Parcelable {
frame.set(other.frame);
displayFrame.set(other.displayFrame);
parentFrame.set(other.parentFrame);
backdropFrame.set(other.backdropFrame);
isParentFrameClippedByDisplayCutout = other.isParentFrameClippedByDisplayCutout;
}
@@ -65,7 +61,6 @@ public class ClientWindowFrames implements Parcelable {
frame.readFromParcel(in);
displayFrame.readFromParcel(in);
parentFrame.readFromParcel(in);
backdropFrame.readFromParcel(in);
isParentFrameClippedByDisplayCutout = in.readBoolean();
}
@@ -74,7 +69,6 @@ public class ClientWindowFrames implements Parcelable {
frame.writeToParcel(dest, flags);
displayFrame.writeToParcel(dest, flags);
parentFrame.writeToParcel(dest, flags);
backdropFrame.writeToParcel(dest, flags);
dest.writeBoolean(isParentFrameClippedByDisplayCutout);
}
@@ -84,7 +78,6 @@ public class ClientWindowFrames implements Parcelable {
return "ClientWindowFrames{frame=" + frame.toShortString(sb)
+ " display=" + displayFrame.toShortString(sb)
+ " parentFrame=" + parentFrame.toShortString(sb)
+ " backdrop=" + backdropFrame.toShortString(sb)
+ " parentClippedByDisplayCutout=" + isParentFrameClippedByDisplayCutout + "}";
}

View File

@@ -3869,25 +3869,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
outFrames.displayFrame.scale(mInvGlobalScale);
}
final Rect backdropFrame = outFrames.backdropFrame;
// When the task is docked, we send fullscreen sized backdropFrame as soon as resizing
// start even if we haven't received the relayout window, so that the client requests
// the relayout sooner. When dragging stops, backdropFrame needs to stay fullscreen
// until the window to small size, otherwise the multithread renderer will shift last
// one or more frame to wrong offset. So here we send fullscreen backdrop if either
// isDragResizing() or isDragResizeChanged() is true.
final boolean resizing = isDragResizing() || isDragResizeChanged();
if (!resizing || getWindowConfiguration().useWindowFrameForBackdrop()) {
// Surface position is now inherited from parent, and BackdropFrameRenderer uses
// backdrop frame to position content. Thus we just keep the size of backdrop frame,
// and remove the offset to avoid double offset from display origin.
backdropFrame.set(outFrames.frame);
backdropFrame.offsetTo(0, 0);
} else {
final DisplayInfo displayInfo = getDisplayInfo();
backdropFrame.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
}
// Note: in the cases where the window is tied to an activity, we should not send a
// configuration update when the window has requested to be hidden. Doing so can lead to
// the client erroneously accepting a configuration that would have otherwise caused an