blob: e6861d83d2fd9d7dbcaee7924599631375bb3735 [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
14 * limitations under the License
15 */
16
17package android.view;
18
19import static android.view.Surface.ROTATION_180;
20import static android.view.Surface.ROTATION_270;
21import static android.view.Surface.ROTATION_90;
22import static com.android.server.wm.proto.DisplayFramesProto.STABLE_BOUNDS;
23
24import android.graphics.Rect;
25import android.util.proto.ProtoOutputStream;
26
27import java.io.PrintWriter;
28
29/**
30 * Container class for all the display frames that affect how we do window layout on a display.
31 * @hide
32 */
33public class DisplayFrames {
34 public final int mDisplayId;
35
36 /**
37 * The current size of the screen; really; extends into the overscan area of the screen and
38 * doesn't account for any system elements like the status bar.
39 */
40 public final Rect mOverscan = new Rect();
41
42 /**
43 * The current visible size of the screen; really; (ir)regardless of whether the status bar can
44 * be hidden but not extending into the overscan area.
45 */
46 public final Rect mUnrestricted = new Rect();
47
48 /** Like mOverscan*, but allowed to move into the overscan region where appropriate. */
49 public final Rect mRestrictedOverscan = new Rect();
50
51 /**
52 * The current size of the screen; these may be different than (0,0)-(dw,dh) if the status bar
53 * can't be hidden; in that case it effectively carves out that area of the display from all
54 * other windows.
55 */
56 public final Rect mRestricted = new Rect();
57
58 /**
59 * During layout, the current screen borders accounting for any currently visible system UI
60 * elements.
61 */
62 public final Rect mSystem = new Rect();
63
64 /** For applications requesting stable content insets, these are them. */
65 public final Rect mStable = new Rect();
66
67 /**
68 * For applications requesting stable content insets but have also set the fullscreen window
69 * flag, these are the stable dimensions without the status bar.
70 */
71 public final Rect mStableFullscreen = new Rect();
72
73 /**
74 * During layout, the current screen borders with all outer decoration (status bar, input method
75 * dock) accounted for.
76 */
77 public final Rect mCurrent = new Rect();
78
79 /**
80 * During layout, the frame in which content should be displayed to the user, accounting for all
81 * screen decoration except for any space they deem as available for other content. This is
82 * usually the same as mCurrent*, but may be larger if the screen decor has supplied content
83 * insets.
84 */
85 public final Rect mContent = new Rect();
86
87 /**
88 * During layout, the frame in which voice content should be displayed to the user, accounting
89 * for all screen decoration except for any space they deem as available for other content.
90 */
91 public final Rect mVoiceContent = new Rect();
92
93 /** During layout, the current screen borders along which input method windows are placed. */
94 public final Rect mDock = new Rect();
95
96 private final Rect mDisplayInfoOverscan = new Rect();
97 private final Rect mRotatedDisplayInfoOverscan = new Rect();
98 public int mDisplayWidth;
99 public int mDisplayHeight;
100
101 public int mRotation;
102
103 public DisplayFrames(int displayId, DisplayInfo info) {
104 mDisplayId = displayId;
105 onDisplayInfoUpdated(info);
106 }
107
108 public void onDisplayInfoUpdated(DisplayInfo info) {
109 mDisplayWidth = info.logicalWidth;
110 mDisplayHeight = info.logicalHeight;
111 mRotation = info.rotation;
112 mDisplayInfoOverscan.set(
113 info.overscanLeft, info.overscanTop, info.overscanRight, info.overscanBottom);
114 }
115
116 public void onBeginLayout() {
117 switch (mRotation) {
118 case ROTATION_90:
119 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.top;
120 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.right;
121 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.bottom;
122 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.left;
123 break;
124 case ROTATION_180:
125 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.right;
126 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.bottom;
127 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.left;
128 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.top;
129 break;
130 case ROTATION_270:
131 mRotatedDisplayInfoOverscan.left = mDisplayInfoOverscan.bottom;
132 mRotatedDisplayInfoOverscan.top = mDisplayInfoOverscan.left;
133 mRotatedDisplayInfoOverscan.right = mDisplayInfoOverscan.top;
134 mRotatedDisplayInfoOverscan.bottom = mDisplayInfoOverscan.right;
135 break;
136 default:
137 mRotatedDisplayInfoOverscan.set(mDisplayInfoOverscan);
138 break;
139 }
140
141 mRestrictedOverscan.set(0, 0, mDisplayWidth, mDisplayHeight);
142 mOverscan.set(mRestrictedOverscan);
143 mSystem.set(mRestrictedOverscan);
144 mUnrestricted.set(mRotatedDisplayInfoOverscan);
145 mUnrestricted.right = mDisplayWidth - mUnrestricted.right;
146 mUnrestricted.bottom = mDisplayHeight - mUnrestricted.bottom;
147 mRestricted.set(mUnrestricted);
148 mDock.set(mUnrestricted);
149 mContent.set(mUnrestricted);
150 mVoiceContent.set(mUnrestricted);
151 mStable.set(mUnrestricted);
152 mStableFullscreen.set(mUnrestricted);
153 mCurrent.set(mUnrestricted);
154
155 }
156
157 public int getInputMethodWindowVisibleHeight() {
158 return mDock.bottom - mCurrent.bottom;
159 }
160
161 public void writeToProto(ProtoOutputStream proto, long fieldId) {
162 final long token = proto.start(fieldId);
163 mStable.writeToProto(proto, STABLE_BOUNDS);
164 proto.end(token);
165 }
166
167 public void dump(String prefix, PrintWriter pw) {
168 pw.println(prefix + "DisplayFrames w=" + mDisplayWidth + " h=" + mDisplayHeight
169 + " r=" + mRotation);
170 final String myPrefix = prefix + " ";
171 dumpFrame(mStable, "mStable", myPrefix, pw);
172 dumpFrame(mStableFullscreen, "mStableFullscreen", myPrefix, pw);
173 dumpFrame(mDock, "mDock", myPrefix, pw);
174 dumpFrame(mCurrent, "mCurrent", myPrefix, pw);
175 dumpFrame(mSystem, "mSystem", myPrefix, pw);
176 dumpFrame(mContent, "mContent", myPrefix, pw);
177 dumpFrame(mVoiceContent, "mVoiceContent", myPrefix, pw);
178 dumpFrame(mOverscan, "mOverscan", myPrefix, pw);
179 dumpFrame(mRestrictedOverscan, "mRestrictedOverscan", myPrefix, pw);
180 dumpFrame(mRestricted, "mRestricted", myPrefix, pw);
181 dumpFrame(mUnrestricted, "mUnrestricted", myPrefix, pw);
182 dumpFrame(mDisplayInfoOverscan, "mDisplayInfoOverscan", myPrefix, pw);
183 dumpFrame(mRotatedDisplayInfoOverscan, "mRotatedDisplayInfoOverscan", myPrefix, pw);
184 }
185
186 private void dumpFrame(Rect frame, String name, String prefix, PrintWriter pw) {
187 pw.print(prefix + name + "="); frame.printShortString(pw); pw.println();
188 }
189}