summaryrefslogtreecommitdiff
path: root/core/java/android/view/ViewRootImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/view/ViewRootImpl.java')
-rw-r--r--core/java/android/view/ViewRootImpl.java184
1 files changed, 96 insertions, 88 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index f3a8d9754fd4..96ed131a716a 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -137,7 +137,6 @@ import android.view.View.MeasureSpec;
import android.view.Window.OnContentApplyWindowInsetsListener;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
-import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
@@ -160,6 +159,7 @@ import android.view.contentcapture.ContentCaptureSession;
import android.view.contentcapture.MainContentCaptureSession;
import android.view.inputmethod.InputMethodManager;
import android.widget.Scroller;
+import android.window.ClientWindowFrames;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -559,8 +559,11 @@ public final class ViewRootImpl implements ViewParent,
boolean mAdded;
boolean mAddedTouchMode;
- final Rect mTmpFrame = new Rect();
- final Rect mTmpRect = new Rect();
+ /**
+ * It usually keeps the latest layout result from {@link IWindow#resized} or
+ * {@link IWindowSession#relayout}.
+ */
+ private final ClientWindowFrames mTmpFrames = new ClientWindowFrames();
// These are accessed by multiple threads.
final Rect mWinFrame; // frame given by window manager.
@@ -1032,11 +1035,11 @@ public final class ViewRootImpl implements ViewParent,
collectViewAttributes();
adjustLayoutParamsForCompatibility(mWindowAttributes);
res = mWindowSession.addToDisplayAsUser(mWindow, mSeq, mWindowAttributes,
- getHostVisibility(), mDisplay.getDisplayId(), userId, mTmpFrame,
+ getHostVisibility(), mDisplay.getDisplayId(), userId, mTmpFrames.frame,
mAttachInfo.mContentInsets, mAttachInfo.mStableInsets,
mAttachInfo.mDisplayCutout, inputChannel,
mTempInsets, mTempControls);
- setFrame(mTmpFrame);
+ setFrame(mTmpFrames.frame);
} catch (RemoteException e) {
mAdded = false;
mView = null;
@@ -1474,6 +1477,55 @@ public final class ViewRootImpl implements ViewParent,
scheduleTraversals();
}
+ /** Handles messages {@link #MSG_RESIZED} and {@link #MSG_RESIZED_REPORT}. */
+ private void handleResized(int msg, SomeArgs args) {
+ if (!mAdded) {
+ return;
+ }
+
+ final ClientWindowFrames frames = (ClientWindowFrames) args.arg1;
+ final MergedConfiguration mergedConfiguration = (MergedConfiguration) args.arg2;
+ final boolean forceNextWindowRelayout = args.argi1 != 0;
+ final int displayId = args.argi3;
+ final Rect backdropFrame = frames.backdropFrame;
+ final DisplayCutout displayCutout = frames.displayCutout.get();
+
+ final boolean frameChanged = !mWinFrame.equals(frames.frame);
+ final boolean cutoutChanged = !mPendingDisplayCutout.get().equals(displayCutout);
+ final boolean backdropFrameChanged = !mPendingBackDropFrame.equals(backdropFrame);
+ final boolean configChanged = !mLastReportedMergedConfiguration.equals(mergedConfiguration);
+ final boolean displayChanged = mDisplay.getDisplayId() != displayId;
+ if (msg == MSG_RESIZED && !frameChanged && !cutoutChanged && !backdropFrameChanged
+ && !configChanged && !displayChanged && !forceNextWindowRelayout) {
+ return;
+ }
+
+ if (configChanged) {
+ // If configuration changed - notify about that and, maybe, about move to display.
+ performConfigurationChange(mergedConfiguration, false /* force */,
+ displayChanged ? displayId : INVALID_DISPLAY /* same display */);
+ } else if (displayChanged) {
+ // Moved to display without config change - report last applied one.
+ onMovedToDisplay(displayId, mLastConfigurationFromResources);
+ }
+
+ setFrame(frames.frame);
+ mTmpFrames.displayFrame.set(frames.displayFrame);
+ mPendingDisplayCutout.set(displayCutout);
+ mPendingBackDropFrame.set(backdropFrame);
+ mForceNextWindowRelayout = forceNextWindowRelayout;
+ mPendingAlwaysConsumeSystemBars = args.argi2 != 0;
+
+ if (msg == MSG_RESIZED_REPORT) {
+ reportNextDraw();
+ }
+
+ if (mView != null && (frameChanged || cutoutChanged || configChanged)) {
+ forceLayout(mView);
+ }
+ requestLayout();
+ }
+
private final DisplayListener mDisplayListener = new DisplayListener() {
@Override
public void onDisplayChanged(int displayId) {
@@ -4919,60 +4971,13 @@ public final class ViewRootImpl implements ViewParent,
case MSG_DISPATCH_GET_NEW_SURFACE:
handleGetNewSurface();
break;
- case MSG_RESIZED: {
- // Recycled in the fall through...
- SomeArgs args = (SomeArgs) msg.obj;
- if (mWinFrame.equals(args.arg1)
- && mPendingDisplayCutout.get().equals(args.arg9)
- && mPendingBackDropFrame.equals(args.arg8)
- && mLastReportedMergedConfiguration.equals(args.arg4)
- && args.argi1 == 0
- && mDisplay.getDisplayId() == args.argi3) {
- break;
- }
- } // fall through...
- case MSG_RESIZED_REPORT:
- if (mAdded) {
- SomeArgs args = (SomeArgs) msg.obj;
-
- final int displayId = args.argi3;
- MergedConfiguration mergedConfiguration = (MergedConfiguration) args.arg4;
- final boolean displayChanged = mDisplay.getDisplayId() != displayId;
- boolean configChanged = false;
-
- if (!mLastReportedMergedConfiguration.equals(mergedConfiguration)) {
- // If configuration changed - notify about that and, maybe,
- // about move to display.
- performConfigurationChange(mergedConfiguration, false /* force */,
- displayChanged
- ? displayId : INVALID_DISPLAY /* same display */);
- configChanged = true;
- } else if (displayChanged) {
- // Moved to display without config change - report last applied one.
- onMovedToDisplay(displayId, mLastConfigurationFromResources);
- }
-
- final boolean framesChanged = !mWinFrame.equals(args.arg1)
- || !mPendingDisplayCutout.get().equals(args.arg9);
-
- setFrame((Rect) args.arg1);
- mPendingDisplayCutout.set((DisplayCutout) args.arg9);
- mPendingBackDropFrame.set((Rect) args.arg8);
- mForceNextWindowRelayout = args.argi1 != 0;
- mPendingAlwaysConsumeSystemBars = args.argi2 != 0;
-
- args.recycle();
-
- if (msg.what == MSG_RESIZED_REPORT) {
- reportNextDraw();
- }
-
- if (mView != null && (framesChanged || configChanged)) {
- forceLayout(mView);
- }
- requestLayout();
- }
+ case MSG_RESIZED:
+ case MSG_RESIZED_REPORT: {
+ final SomeArgs args = (SomeArgs) msg.obj;
+ handleResized(msg.what, args);
+ args.recycle();
break;
+ }
case MSG_INSETS_CHANGED:
mInsetsController.onStateChanged((InsetsState) msg.obj);
break;
@@ -5007,11 +5012,11 @@ public final class ViewRootImpl implements ViewParent,
final int h = mWinFrame.height();
final int l = msg.arg1;
final int t = msg.arg2;
- mTmpFrame.left = l;
- mTmpFrame.right = l + w;
- mTmpFrame.top = t;
- mTmpFrame.bottom = t + h;
- setFrame(mTmpFrame);
+ mTmpFrames.frame.left = l;
+ mTmpFrames.frame.right = l + w;
+ mTmpFrames.frame.top = t;
+ mTmpFrames.frame.bottom = t + h;
+ setFrame(mTmpFrames.frame);
mPendingBackDropFrame.set(mWinFrame);
maybeHandleWindowMove(mWinFrame);
@@ -7418,9 +7423,10 @@ public final class ViewRootImpl implements ViewParent,
(int) (mView.getMeasuredWidth() * appScale + 0.5f),
(int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility,
insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, frameNumber,
- mTmpFrame, mTmpRect, mTmpRect, mTmpRect, mPendingBackDropFrame,
- mPendingDisplayCutout, mPendingMergedConfiguration, mSurfaceControl, mTempInsets,
+ mTmpFrames, mPendingMergedConfiguration, mSurfaceControl, mTempInsets,
mTempControls, mSurfaceSize, mBlastSurfaceControl);
+ mPendingDisplayCutout.set(mTmpFrames.displayCutout);
+ mPendingBackDropFrame.set(mTmpFrames.backdropFrame);
if (mSurfaceControl.isValid()) {
if (!useBLAST()) {
mSurface.copyFrom(mSurfaceControl);
@@ -7446,9 +7452,9 @@ public final class ViewRootImpl implements ViewParent,
}
if (mTranslator != null) {
- mTranslator.translateRectInScreenToAppWinFrame(mTmpFrame);
+ mTranslator.translateRectInScreenToAppWinFrame(mTmpFrames.frame);
}
- setFrame(mTmpFrame);
+ setFrame(mTmpFrames.frame);
mInsetsController.onStateChanged(mTempInsets);
mInsetsController.onControlsChanged(mTempControls);
return relayoutResult;
@@ -7460,6 +7466,14 @@ public final class ViewRootImpl implements ViewParent,
}
/**
+ * Gets the current display size in which the window is being laid out, accounting for screen
+ * decorations around it.
+ */
+ void getDisplayFrame(Rect outFrame) {
+ outFrame.set(mTmpFrames.displayFrame);
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -7742,11 +7756,14 @@ public final class ViewRootImpl implements ViewParent,
}
@UnsupportedAppUsage
- private void dispatchResized(Rect frame, Rect contentInsets,
- Rect visibleInsets, Rect stableInsets, boolean reportDraw,
- MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout,
- boolean alwaysConsumeSystemBars, int displayId,
- DisplayCutout.ParcelableWrapper displayCutout) {
+ private void dispatchResized(ClientWindowFrames frames, boolean reportDraw,
+ MergedConfiguration mergedConfiguration, boolean forceLayout,
+ boolean alwaysConsumeSystemBars, int displayId) {
+ final Rect frame = frames.frame;
+ final Rect contentInsets = frames.contentInsets;
+ final Rect visibleInsets = frames.visibleInsets;
+ final Rect stableInsets = frames.stableInsets;
+ final Rect backDropFrame = frames.backdropFrame;
if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString()
+ " contentInsets=" + contentInsets.toShortString()
+ " visibleInsets=" + visibleInsets.toShortString()
@@ -7773,14 +7790,9 @@ public final class ViewRootImpl implements ViewParent,
}
SomeArgs args = SomeArgs.obtain();
final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid());
- args.arg1 = sameProcessCall ? new Rect(frame) : frame;
- args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets;
- args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets;
- args.arg4 = sameProcessCall && mergedConfiguration != null
+ args.arg1 = sameProcessCall ? new ClientWindowFrames(frames) : frames;
+ args.arg2 = sameProcessCall && mergedConfiguration != null
? new MergedConfiguration(mergedConfiguration) : mergedConfiguration;
- args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets;
- args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame;
- args.arg9 = displayCutout.get(); // DisplayCutout is immutable.
args.argi1 = forceLayout ? 1 : 0;
args.argi2 = alwaysConsumeSystemBars ? 1 : 0;
args.argi3 = displayId;
@@ -9074,17 +9086,13 @@ public final class ViewRootImpl implements ViewParent,
}
@Override
- public void resized(Rect frame, Rect contentInsets,
- Rect visibleInsets, Rect stableInsets, boolean reportDraw,
- MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout,
- boolean alwaysConsumeSystemBars, int displayId,
- DisplayCutout.ParcelableWrapper displayCutout) {
+ public void resized(ClientWindowFrames frames, boolean reportDraw,
+ MergedConfiguration mergedConfiguration, boolean forceLayout,
+ boolean alwaysConsumeSystemBars, int displayId) {
final ViewRootImpl viewAncestor = mViewAncestor.get();
if (viewAncestor != null) {
- viewAncestor.dispatchResized(frame, contentInsets,
- visibleInsets, stableInsets, reportDraw, mergedConfiguration,
- backDropFrame, forceLayout, alwaysConsumeSystemBars, displayId,
- displayCutout);
+ viewAncestor.dispatchResized(frames, reportDraw, mergedConfiguration, forceLayout,
+ alwaysConsumeSystemBars, displayId);
}
}