blob: dc6b49127f7b4fcf4f22bc9b02e6f9edabbd4a44 [file] [log] [blame]
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
Adrian Roose99bc052017-11-20 17:55:31 +010014 * limitations under the License.
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000015 */
16
Adrian Roose99bc052017-11-20 17:55:31 +010017package com.android.server.wm;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000018
19import static android.view.Surface.ROTATION_180;
20import static android.view.Surface.ROTATION_270;
21import static android.view.Surface.ROTATION_90;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070022import static com.android.server.wm.DisplayFramesProto.STABLE_BOUNDS;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000023
Adrian Roos5c6b6222017-11-07 17:36:10 +010024import android.annotation.NonNull;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000025import android.graphics.Rect;
26import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +010027import android.view.DisplayCutout;
Adrian Roose99bc052017-11-20 17:55:31 +010028import android.view.DisplayInfo;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000029
Adrian Roos6a4fa0e2018-03-05 19:50:16 +010030import com.android.server.wm.utils.WmDisplayCutout;
31
Wale Ogunwale828ff7e2017-11-14 01:01:29 +000032import java.io.PrintWriter;
33
34/**
35 * Container class for all the display frames that affect how we do window layout on a display.
36 * @hide
37 */
38public class DisplayFrames {
39 public final int mDisplayId;
40
41 /**
42 * The current size of the screen; really; extends into the overscan area of the screen and
43 * doesn't account for any system elements like the status bar.
44 */
45 public final Rect mOverscan = new Rect();
46
47 /**
48 * The current visible size of the screen; really; (ir)regardless of whether the status bar can
49 * be hidden but not extending into the overscan area.
50 */
51 public final Rect mUnrestricted = new Rect();
52
53 /** Like mOverscan*, but allowed to move into the overscan region where appropriate. */
54 public final Rect mRestrictedOverscan = new Rect();
55
56 /**
57 * The current size of the screen; these may be different than (0,0)-(dw,dh) if the status bar
58 * can't be hidden; in that case it effectively carves out that area of the display from all
59 * other windows.
60 */
61 public final Rect mRestricted = new Rect();
62
63 /**
64 * During layout, the current screen borders accounting for any currently visible system UI
65 * elements.
66 */
67 public final Rect mSystem = new Rect();
68
69 /** For applications requesting stable content insets, these are them. */
70 public final Rect mStable = new Rect();
71
72 /**
73 * For applications requesting stable content insets but have also set the fullscreen window
74 * flag, these are the stable dimensions without the status bar.
75 */
76 public final Rect mStableFullscreen = new Rect();
77
78 /**
79 * During layout, the current screen borders with all outer decoration (status bar, input method
80 * dock) accounted for.
81 */
82 public final Rect mCurrent = new Rect();
83
84 /**
85 * During layout, the frame in which content should be displayed to the user, accounting for all
86 * screen decoration except for any space they deem as available for other content. This is
87 * usually the same as mCurrent*, but may be larger if the screen decor has supplied content
88 * insets.
89 */
90 public final Rect mContent = new Rect();
91
92 /**
93 * During layout, the frame in which voice content should be displayed to the user, accounting
94 * for all screen decoration except for any space they deem as available for other content.
95 */
96 public final Rect mVoiceContent = new Rect();
97
98 /** During layout, the current screen borders along which input method windows are placed. */
99 public final Rect mDock = new Rect();
100
Adrian Roos30f53212018-01-05 16:14:34 +0100101 /** The display cutout used for layout (after rotation) */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100102 @NonNull public WmDisplayCutout mDisplayCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100103
Adrian Roos1cf585052018-01-03 18:43:27 +0100104 /** The cutout as supplied by display info */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100105 @NonNull public WmDisplayCutout mDisplayInfoCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +0100106
Adrian Roos5c6b6222017-11-07 17:36:10 +0100107 /**
108 * During layout, the frame that is display-cutout safe, i.e. that does not intersect with it.
109 */
110 public final Rect mDisplayCutoutSafe = new Rect();
111
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000112 private final Rect mDisplayInfoOverscan = new Rect();
113 private final Rect mRotatedDisplayInfoOverscan = new Rect();
114 public int mDisplayWidth;
115 public int mDisplayHeight;
116
117 public int mRotation;
118
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100119 public DisplayFrames(int displayId, DisplayInfo info, WmDisplayCutout displayCutout) {
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000120 mDisplayId = displayId;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100121 onDisplayInfoUpdated(info, displayCutout);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000122 }
123
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100124 public void onDisplayInfoUpdated(DisplayInfo info, WmDisplayCutout displayCutout) {
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000125 mDisplayWidth = info.logicalWidth;
126 mDisplayHeight = info.logicalHeight;
127 mRotation = info.rotation;
128 mDisplayInfoOverscan.set(
129 info.overscanLeft, info.overscanTop, info.overscanRight, info.overscanBottom);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100130 mDisplayInfoCutout = displayCutout != null ? displayCutout : WmDisplayCutout.NO_CUTOUT;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000131 }
132
Adrian Roos30f53212018-01-05 16:14:34 +0100133 public void onBeginLayout() {
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000134 switch (mRotation) {
135 case ROTATION_90:
136 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.top;
137 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.right;
138 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.bottom;
139 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.left;
140 break;
141 case ROTATION_180:
142 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.right;
143 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.bottom;
144 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.left;
145 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.top;
146 break;
147 case ROTATION_270:
148 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.bottom;
149 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.left;
150 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.top;
151 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.right;
152 break;
153 default:
154 mRotatedDisplayInfoOverscan.set(mDisplayInfoOverscan);
155 break;
156 }
157
158 mRestrictedOverscan.set(0, 0, mDisplayWidth, mDisplayHeight);
159 mOverscan.set(mRestrictedOverscan);
160 mSystem.set(mRestrictedOverscan);
161 mUnrestricted.set(mRotatedDisplayInfoOverscan);
162 mUnrestricted.right = mDisplayWidth - mUnrestricted.right;
163 mUnrestricted.bottom = mDisplayHeight - mUnrestricted.bottom;
164 mRestricted.set(mUnrestricted);
165 mDock.set(mUnrestricted);
166 mContent.set(mUnrestricted);
167 mVoiceContent.set(mUnrestricted);
168 mStable.set(mUnrestricted);
169 mStableFullscreen.set(mUnrestricted);
170 mCurrent.set(mUnrestricted);
Adrian Roos1cf585052018-01-03 18:43:27 +0100171
Adrian Roos24264212018-02-19 16:26:15 +0100172 mDisplayCutout = mDisplayInfoCutout;
Adrian Roos1cf585052018-01-03 18:43:27 +0100173 mDisplayCutoutSafe.set(Integer.MIN_VALUE, Integer.MIN_VALUE,
174 Integer.MAX_VALUE, Integer.MAX_VALUE);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100175 if (!mDisplayCutout.getDisplayCutout().isEmpty()) {
176 final DisplayCutout c = mDisplayCutout.getDisplayCutout();
Adrian Roos1cf585052018-01-03 18:43:27 +0100177 if (c.getSafeInsetLeft() > 0) {
178 mDisplayCutoutSafe.left = mRestrictedOverscan.left + c.getSafeInsetLeft();
179 }
180 if (c.getSafeInsetTop() > 0) {
181 mDisplayCutoutSafe.top = mRestrictedOverscan.top + c.getSafeInsetTop();
182 }
183 if (c.getSafeInsetRight() > 0) {
184 mDisplayCutoutSafe.right = mRestrictedOverscan.right - c.getSafeInsetRight();
185 }
186 if (c.getSafeInsetBottom() > 0) {
187 mDisplayCutoutSafe.bottom = mRestrictedOverscan.bottom - c.getSafeInsetBottom();
188 }
189 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000190 }
191
192 public int getInputMethodWindowVisibleHeight() {
193 return mDock.bottom - mCurrent.bottom;
194 }
195
196 public void writeToProto(ProtoOutputStream proto, long fieldId) {
197 final long token = proto.start(fieldId);
198 mStable.writeToProto(proto, STABLE_BOUNDS);
199 proto.end(token);
200 }
201
202 public void dump(String prefix, PrintWriter pw) {
203 pw.println(prefix + "DisplayFrames w=" + mDisplayWidth + " h=" + mDisplayHeight
204 + " r=" + mRotation);
205 final String myPrefix = prefix + " ";
206 dumpFrame(mStable, "mStable", myPrefix, pw);
207 dumpFrame(mStableFullscreen, "mStableFullscreen", myPrefix, pw);
208 dumpFrame(mDock, "mDock", myPrefix, pw);
209 dumpFrame(mCurrent, "mCurrent", myPrefix, pw);
210 dumpFrame(mSystem, "mSystem", myPrefix, pw);
211 dumpFrame(mContent, "mContent", myPrefix, pw);
212 dumpFrame(mVoiceContent, "mVoiceContent", myPrefix, pw);
213 dumpFrame(mOverscan, "mOverscan", myPrefix, pw);
214 dumpFrame(mRestrictedOverscan, "mRestrictedOverscan", myPrefix, pw);
215 dumpFrame(mRestricted, "mRestricted", myPrefix, pw);
216 dumpFrame(mUnrestricted, "mUnrestricted", myPrefix, pw);
217 dumpFrame(mDisplayInfoOverscan, "mDisplayInfoOverscan", myPrefix, pw);
218 dumpFrame(mRotatedDisplayInfoOverscan, "mRotatedDisplayInfoOverscan", myPrefix, pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +0100219 pw.println(myPrefix + "mDisplayCutout=" + mDisplayCutout);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000220 }
221
222 private void dumpFrame(Rect frame, String name, String prefix, PrintWriter pw) {
223 pw.print(prefix + name + "="); frame.printShortString(pw); pw.println();
224 }
225}