blob: 53bbd7010b5dba2e1ca8c286b217182c0bcf84a1 [file] [log] [blame]
Robert Carre6a83512015-11-03 16:09:21 -08001/*
2 * Copyright (C) 2015 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 com.android.server.wm;
18
Wale Ogunwale4958ad22017-06-22 09:08:14 -070019import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Steven Timotiusaf03df62017-07-18 16:56:43 -070020import static android.view.Surface.SCALING_MODE_SCALE_TO_WINDOW;
Evan Rosky485df202018-12-06 14:11:12 -080021import static android.view.SurfaceControl.METADATA_OWNER_UID;
22import static android.view.SurfaceControl.METADATA_WINDOW_TYPE;
Steven Timotiusaf03df62017-07-18 16:56:43 -070023
Vishnu Naire86bd982018-11-28 13:23:17 -080024import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
25import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Wale Ogunwale722ff892016-02-18 13:37:55 -080026import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080027import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
29import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070030import static com.android.server.wm.WindowSurfaceControllerProto.LAYER;
31import static com.android.server.wm.WindowSurfaceControllerProto.SHOWN;
Robert Carre6a83512015-11-03 16:09:21 -080032
Robert Carre6a83512015-11-03 16:09:21 -080033import android.graphics.Rect;
34import android.graphics.Region;
Robert Carre6a83512015-11-03 16:09:21 -080035import android.os.Debug;
Vishnu Naire86bd982018-11-28 13:23:17 -080036import android.os.IBinder;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070037import android.os.Trace;
Vishnu Naire86bd982018-11-28 13:23:17 -080038import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070039import android.util.proto.ProtoOutputStream;
Robert Carre6a83512015-11-03 16:09:21 -080040import android.view.SurfaceControl;
41import android.view.SurfaceSession;
42import android.view.WindowContentFrameStats;
Robert Carre6a83512015-11-03 16:09:21 -080043
Robert Carre6a83512015-11-03 16:09:21 -080044import java.io.PrintWriter;
Robert Carre6a83512015-11-03 16:09:21 -080045
46class WindowSurfaceController {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080047 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfaceController" : TAG_WM;
Robert Carre6a83512015-11-03 16:09:21 -080048
49 final WindowStateAnimator mAnimator;
50
Adrian Roos4d18a2e2017-12-19 19:08:05 +010051 SurfaceControl mSurfaceControl;
Robert Carre6a83512015-11-03 16:09:21 -080052
Wale Ogunwale943002b2017-02-15 19:34:01 -080053 // Should only be set from within setShown().
Robert Carre6a83512015-11-03 16:09:21 -080054 private boolean mSurfaceShown = false;
55 private float mSurfaceX = 0;
56 private float mSurfaceY = 0;
Jorim Jaggia5e10572017-11-15 14:36:26 +010057 private int mSurfaceW = 0;
58 private int mSurfaceH = 0;
Jorim Jaggi4981f152019-03-26 18:58:45 +010059 private Rect mSurfaceCrop = new Rect(0, 0, -1, -1);
Robert Carre6a83512015-11-03 16:09:21 -080060
Matthew Bouyack8dd88f62016-10-24 14:01:26 -070061 // Initialize to the identity matrix.
62 private float mLastDsdx = 1;
63 private float mLastDtdx = 0;
64 private float mLastDsdy = 0;
65 private float mLastDtdy = 1;
66
Robert Carre6a83512015-11-03 16:09:21 -080067 private float mSurfaceAlpha = 0;
68
69 private int mSurfaceLayer = 0;
Robert Carre6a83512015-11-03 16:09:21 -080070
71 // Surface flinger doesn't support crop rectangles where width or height is non-positive.
72 // However, we need to somehow handle the situation where the cropping would completely hide
73 // the window. We achieve this by explicitly hiding the surface and not letting it be shown.
74 private boolean mHiddenForCrop = false;
Jorim Jaggi1eb39b02016-02-25 13:36:14 -050075
76 // Initially a surface is hidden after just being created.
77 private boolean mHiddenForOtherReasons = true;
Robert Carre6a83512015-11-03 16:09:21 -080078 private final String title;
79
Robert Carr68e5c9e2016-09-14 10:50:09 -070080 private final WindowManagerService mService;
81
Wale Ogunwale943002b2017-02-15 19:34:01 -080082 private final int mWindowType;
83 private final Session mWindowSession;
84
Chavi Weingartenb736e322018-02-23 00:27:54 +000085 private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
86
Albert Chaulk3bf2e572016-11-22 13:59:19 -050087 public WindowSurfaceController(SurfaceSession s, String name, int w, int h, int format,
88 int flags, WindowStateAnimator animator, int windowType, int ownerUid) {
Robert Carre6a83512015-11-03 16:09:21 -080089 mAnimator = animator;
90
91 mSurfaceW = w;
92 mSurfaceH = h;
Robert Carre6a83512015-11-03 16:09:21 -080093
94 title = name;
95
Robert Carr68e5c9e2016-09-14 10:50:09 -070096 mService = animator.mService;
Wale Ogunwale943002b2017-02-15 19:34:01 -080097 final WindowState win = animator.mWin;
98 mWindowType = windowType;
99 mWindowSession = win.mSession;
Robert Carr68e5c9e2016-09-14 10:50:09 -0700100
Andrii Kulian283acd22017-08-03 04:03:51 -0700101 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl");
Robert Carrb1579c82017-09-05 14:54:47 -0700102 final SurfaceControl.Builder b = win.makeSurface()
103 .setParent(win.getSurfaceControl())
Robert Carre625fcf2017-09-01 12:36:28 -0700104 .setName(name)
Vishnu Naire86bd982018-11-28 13:23:17 -0800105 .setBufferSize(w, h)
Robert Carre625fcf2017-09-01 12:36:28 -0700106 .setFormat(format)
107 .setFlags(flags)
Evan Rosky485df202018-12-06 14:11:12 -0800108 .setMetadata(METADATA_WINDOW_TYPE, windowType)
109 .setMetadata(METADATA_OWNER_UID, ownerUid);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100110 mSurfaceControl = b.build();
Andrii Kulian283acd22017-08-03 04:03:51 -0700111 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carr3b716242016-08-16 16:02:21 -0700112 }
113
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700114 private void logSurface(String msg, RuntimeException where) {
Robert Carre6a83512015-11-03 16:09:21 -0800115 String str = " SURFACE " + msg + ": " + title;
116 if (where != null) {
117 Slog.i(TAG, str, where);
118 } else {
119 Slog.i(TAG, str);
120 }
121 }
122
Robert Carrd5c7dd62017-03-08 10:39:30 -0800123 void reparentChildrenInTransaction(WindowSurfaceController other) {
124 if (SHOW_TRANSACTIONS) Slog.i(TAG, "REPARENT from: " + this + " to: " + other);
125 if ((mSurfaceControl != null) && (other.mSurfaceControl != null)) {
126 mSurfaceControl.reparentChildren(other.getHandle());
127 }
128 }
129
130 void detachChildren() {
131 if (SHOW_TRANSACTIONS) Slog.i(TAG, "SEVER CHILDREN");
132 if (mSurfaceControl != null) {
133 mSurfaceControl.detachChildren();
134 }
135 }
136
Chavi Weingartenb736e322018-02-23 00:27:54 +0000137 void hide(SurfaceControl.Transaction transaction, String reason) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800138 if (SHOW_TRANSACTIONS) logSurface("HIDE ( " + reason + " )", null);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800139 mHiddenForOtherReasons = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700140
141 mAnimator.destroyPreservedSurfaceLocked();
Chavi Weingartenb736e322018-02-23 00:27:54 +0000142 if (mSurfaceShown) {
143 hideSurface(transaction);
144 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800145 }
146
Chavi Weingartenb736e322018-02-23 00:27:54 +0000147 private void hideSurface(SurfaceControl.Transaction transaction) {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800148 if (mSurfaceControl == null) {
149 return;
150 }
151 setShown(false);
152 try {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000153 transaction.hide(mSurfaceControl);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800154 } catch (RuntimeException e) {
155 Slog.w(TAG, "Exception hiding surface in " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800156 }
157 }
158
Robert Carra8828862018-02-05 16:17:36 -0800159 void destroyNotInTransaction() {
Chong Zhangad23b3f2016-08-31 16:05:27 -0700160 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
161 Slog.i(TAG, "Destroying surface " + this + " called by " + Debug.getCallers(8));
162 }
Robert Carre6a83512015-11-03 16:09:21 -0800163 try {
Wale Ogunwale722ff892016-02-18 13:37:55 -0800164 if (mSurfaceControl != null) {
Robert Carr5ea304d2019-02-04 16:04:55 -0800165 mSurfaceControl.remove();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800166 }
Robert Carre6a83512015-11-03 16:09:21 -0800167 } catch (RuntimeException e) {
168 Slog.w(TAG, "Error destroying surface in: " + this, e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800169 } finally {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800170 setShown(false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800171 mSurfaceControl = null;
Robert Carre6a83512015-11-03 16:09:21 -0800172 }
173 }
174
175 void setCropInTransaction(Rect clipRect, boolean recoveringMemory) {
176 if (SHOW_TRANSACTIONS) logSurface(
177 "CROP " + clipRect.toShortString(), null);
178 try {
Robert Carr4320d332016-06-10 15:13:32 -0700179 if (clipRect.width() > 0 && clipRect.height() > 0) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100180 if (!clipRect.equals(mSurfaceCrop)) {
181 mSurfaceControl.setWindowCrop(clipRect);
182 mSurfaceCrop.set(clipRect);
183 }
Robert Carre6a83512015-11-03 16:09:21 -0800184 mHiddenForCrop = false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800185 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800186 } else {
Robert Carre6a83512015-11-03 16:09:21 -0800187 mHiddenForCrop = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700188 mAnimator.destroyPreservedSurfaceLocked();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800189 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800190 }
191 } catch (RuntimeException e) {
192 Slog.w(TAG, "Error setting crop surface of " + this
193 + " crop=" + clipRect.toShortString(), e);
194 if (!recoveringMemory) {
195 mAnimator.reclaimSomeSurfaceMemory("crop", true);
196 }
197 }
198 }
199
Robert Carr4320d332016-06-10 15:13:32 -0700200 void clearCropInTransaction(boolean recoveringMemory) {
201 if (SHOW_TRANSACTIONS) logSurface(
202 "CLEAR CROP", null);
203 try {
204 Rect clipRect = new Rect(0, 0, -1, -1);
Jorim Jaggi4981f152019-03-26 18:58:45 +0100205 if (mSurfaceCrop.equals(clipRect)) {
206 return;
207 }
Robert Carr4320d332016-06-10 15:13:32 -0700208 mSurfaceControl.setWindowCrop(clipRect);
Jorim Jaggi4981f152019-03-26 18:58:45 +0100209 mSurfaceCrop.set(clipRect);
Robert Carr4320d332016-06-10 15:13:32 -0700210 } catch (RuntimeException e) {
211 Slog.w(TAG, "Error setting clearing crop of " + this, e);
212 if (!recoveringMemory) {
213 mAnimator.reclaimSomeSurfaceMemory("crop", true);
214 }
215 }
216 }
217
Robert Carre6a83512015-11-03 16:09:21 -0800218 void setPositionInTransaction(float left, float top, boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700219 setPosition(null, left, top, recoveringMemory);
220 }
221
222 void setPosition(SurfaceControl.Transaction t, float left, float top,
223 boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800224 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top;
225 if (surfaceMoved) {
226 mSurfaceX = left;
227 mSurfaceY = top;
228
229 try {
Chong Zhangae35fef2016-03-16 15:56:55 -0700230 if (SHOW_TRANSACTIONS) logSurface(
231 "POS (setPositionInTransaction) @ (" + left + "," + top + ")", null);
232
Robert Carr19cdd092018-03-14 11:50:52 -0700233 if (t == null) {
234 mSurfaceControl.setPosition(left, top);
235 } else {
236 t.setPosition(mSurfaceControl, left, top);
237 }
Robert Carre6a83512015-11-03 16:09:21 -0800238 } catch (RuntimeException e) {
239 Slog.w(TAG, "Error positioning surface of " + this
240 + " pos=(" + left + "," + top + ")", e);
241 if (!recoveringMemory) {
242 mAnimator.reclaimSomeSurfaceMemory("position", true);
243 }
244 }
245 }
246 }
247
Robert Carr6da3cc02016-06-16 15:17:07 -0700248 void setGeometryAppliesWithResizeInTransaction(boolean recoveringMemory) {
249 mSurfaceControl.setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700250 }
251
Andrii Kulian283acd22017-08-03 04:03:51 -0700252 void setMatrixInTransaction(float dsdx, float dtdx, float dtdy, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800253 boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700254 setMatrix(null, dsdx, dtdx, dtdy, dsdy, false);
255 }
256
257 void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx,
258 float dtdy, float dsdy, boolean recoveringMemory) {
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700259 final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx ||
Andrii Kulian283acd22017-08-03 04:03:51 -0700260 mLastDtdy != dtdy || mLastDsdy != dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700261 if (!matrixChanged) {
262 return;
263 }
264
265 mLastDsdx = dsdx;
266 mLastDtdx = dtdx;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700267 mLastDtdy = dtdy;
Andrii Kulian283acd22017-08-03 04:03:51 -0700268 mLastDsdy = dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700269
Robert Carre1034cc32016-02-01 13:08:15 -0800270 try {
271 if (SHOW_TRANSACTIONS) logSurface(
Andrii Kulian283acd22017-08-03 04:03:51 -0700272 "MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carr19cdd092018-03-14 11:50:52 -0700273 if (t == null) {
274 mSurfaceControl.setMatrix(dsdx, dtdx, dtdy, dsdy);
275 } else {
276 t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy);
277 }
Robert Carre1034cc32016-02-01 13:08:15 -0800278 } catch (RuntimeException e) {
279 // If something goes wrong with the surface (such
280 // as running out of memory), don't take down the
281 // entire system.
282 Slog.e(TAG, "Error setting matrix on surface surface" + title
Andrii Kulian283acd22017-08-03 04:03:51 -0700283 + " MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carre1034cc32016-02-01 13:08:15 -0800284 if (!recoveringMemory) {
285 mAnimator.reclaimSomeSurfaceMemory("matrix", true);
286 }
287 }
Robert Carre1034cc32016-02-01 13:08:15 -0800288 }
289
Vishnu Naire86bd982018-11-28 13:23:17 -0800290 boolean setBufferSizeInTransaction(int width, int height, boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800291 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
292 if (surfaceResized) {
293 mSurfaceW = width;
294 mSurfaceH = height;
295
296 try {
297 if (SHOW_TRANSACTIONS) logSurface(
298 "SIZE " + width + "x" + height, null);
Vishnu Naire86bd982018-11-28 13:23:17 -0800299 mSurfaceControl.setBufferSize(width, height);
Robert Carre6a83512015-11-03 16:09:21 -0800300 } catch (RuntimeException e) {
301 // If something goes wrong with the surface (such
302 // as running out of memory), don't take down the
303 // entire system.
304 Slog.e(TAG, "Error resizing surface of " + title
305 + " size=(" + width + "x" + height + ")", e);
306 if (!recoveringMemory) {
307 mAnimator.reclaimSomeSurfaceMemory("size", true);
308 }
309 return false;
310 }
311 return true;
312 }
313 return false;
314 }
315
Robert Carraf422a82017-04-10 18:34:33 -0700316 boolean prepareToShowInTransaction(float alpha,
Robert Carrda61ba92017-03-29 15:52:23 -0700317 float dsdx, float dtdx, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800318 float dtdy, boolean recoveringMemory) {
319 if (mSurfaceControl != null) {
320 try {
321 mSurfaceAlpha = alpha;
322 mSurfaceControl.setAlpha(alpha);
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700323 mLastDsdx = dsdx;
324 mLastDtdx = dtdx;
325 mLastDsdy = dsdy;
326 mLastDtdy = dtdy;
Robert Carre6a83512015-11-03 16:09:21 -0800327 mSurfaceControl.setMatrix(
328 dsdx, dtdx, dsdy, dtdy);
Robert Carre6a83512015-11-03 16:09:21 -0800329 } catch (RuntimeException e) {
330 Slog.w(TAG, "Error updating surface in " + title, e);
331 if (!recoveringMemory) {
332 mAnimator.reclaimSomeSurfaceMemory("update", true);
333 }
334 return false;
335 }
336 }
337 return true;
338 }
339
340 void setTransparentRegionHint(final Region region) {
341 if (mSurfaceControl == null) {
342 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
343 return;
344 }
345 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700346 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800347 try {
348 mSurfaceControl.setTransparentRegionHint(region);
349 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200350 mService.closeSurfaceTransaction("setTransparentRegion");
Robert Carre6a83512015-11-03 16:09:21 -0800351 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
352 "<<< CLOSE TRANSACTION setTransparentRegion");
353 }
354 }
355
356 void setOpaque(boolean isOpaque) {
357 if (SHOW_TRANSACTIONS) logSurface("isOpaque=" + isOpaque,
358 null);
359
360 if (mSurfaceControl == null) {
361 return;
362 }
363 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700364 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800365 try {
366 mSurfaceControl.setOpaque(isOpaque);
367 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200368 mService.closeSurfaceTransaction("setOpaqueLocked");
Robert Carre6a83512015-11-03 16:09:21 -0800369 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked");
370 }
371 }
372
373 void setSecure(boolean isSecure) {
374 if (SHOW_TRANSACTIONS) logSurface("isSecure=" + isSecure,
375 null);
376
377 if (mSurfaceControl == null) {
378 return;
379 }
380 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700381 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800382 try {
383 mSurfaceControl.setSecure(isSecure);
384 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200385 mService.closeSurfaceTransaction("setSecure");
Robert Carre6a83512015-11-03 16:09:21 -0800386 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked");
387 }
388 }
389
Peiyong Lin75045382019-03-04 19:22:33 -0800390 void setColorSpaceAgnostic(boolean agnostic) {
391 if (SHOW_TRANSACTIONS) {
392 logSurface("isColorSpaceAgnostic=" + agnostic, null);
393 }
394
395 if (mSurfaceControl == null) {
396 return;
397 }
398 if (SHOW_LIGHT_TRANSACTIONS) {
399 Slog.i(TAG, ">>> OPEN TRANSACTION setColorSpaceAgnosticLocked");
400 }
401 mService.openSurfaceTransaction();
402 try {
403 mSurfaceControl.setColorSpaceAgnostic(agnostic);
404 } finally {
405 mService.closeSurfaceTransaction("setColorSpaceAgnostic");
406 if (SHOW_LIGHT_TRANSACTIONS) {
407 Slog.i(TAG, "<<< CLOSE TRANSACTION setColorSpaceAgnosticLocked");
408 }
409 }
410 }
411
Andrii Kulian283acd22017-08-03 04:03:51 -0700412 void getContainerRect(Rect rect) {
413 mAnimator.getContainerRect(rect);
414 }
415
Robert Carre6a83512015-11-03 16:09:21 -0800416 boolean showRobustlyInTransaction() {
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800417 if (SHOW_TRANSACTIONS) logSurface(
418 "SHOW (performLayout)", null);
419 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
420 + " during relayout");
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800421 mHiddenForOtherReasons = false;
422 return updateVisibility();
423 }
Robert Carre6a83512015-11-03 16:09:21 -0800424
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800425 private boolean updateVisibility() {
426 if (mHiddenForCrop || mHiddenForOtherReasons) {
427 if (mSurfaceShown) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000428 hideSurface(mTmpTransaction);
429 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800430 }
Robert Carre6a83512015-11-03 16:09:21 -0800431 return false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800432 } else {
433 if (!mSurfaceShown) {
434 return showSurface();
435 } else {
436 return true;
437 }
Robert Carre6a83512015-11-03 16:09:21 -0800438 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800439 }
Robert Carre6a83512015-11-03 16:09:21 -0800440
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800441 private boolean showSurface() {
Robert Carre6a83512015-11-03 16:09:21 -0800442 try {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800443 setShown(true);
Robert Carre6a83512015-11-03 16:09:21 -0800444 mSurfaceControl.show();
445 return true;
446 } catch (RuntimeException e) {
447 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + this, e);
448 }
449
450 mAnimator.reclaimSomeSurfaceMemory("show", true);
451
452 return false;
453 }
454
455 void deferTransactionUntil(IBinder handle, long frame) {
456 // TODO: Logging
457 mSurfaceControl.deferTransactionUntil(handle, frame);
458 }
459
Robert Carr1ca6a332016-04-11 18:00:43 -0700460 void forceScaleableInTransaction(boolean force) {
461 // -1 means we don't override the default or client specified
462 // scaling mode.
463 int scalingMode = force ? SCALING_MODE_SCALE_TO_WINDOW : -1;
464 mSurfaceControl.setOverrideScalingMode(scalingMode);
465 }
466
Robert Carre6a83512015-11-03 16:09:21 -0800467 boolean clearWindowContentFrameStats() {
468 if (mSurfaceControl == null) {
469 return false;
470 }
471 return mSurfaceControl.clearContentFrameStats();
472 }
473
474 boolean getWindowContentFrameStats(WindowContentFrameStats outStats) {
475 if (mSurfaceControl == null) {
476 return false;
477 }
478 return mSurfaceControl.getContentFrameStats(outStats);
479 }
480
481
482 boolean hasSurface() {
483 return mSurfaceControl != null;
484 }
485
486 IBinder getHandle() {
487 if (mSurfaceControl == null) {
488 return null;
489 }
490 return mSurfaceControl.getHandle();
491 }
492
Robert Carr5fea55b2018-12-10 13:05:52 -0800493 void getSurfaceControl(SurfaceControl outSurfaceControl) {
494 outSurfaceControl.copyFrom(mSurfaceControl);
Robert Carre6a83512015-11-03 16:09:21 -0800495 }
496
497 int getLayer() {
498 return mSurfaceLayer;
499 }
500
501 boolean getShown() {
502 return mSurfaceShown;
503 }
504
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800505 void setShown(boolean surfaceShown) {
506 mSurfaceShown = surfaceShown;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800507
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700508 mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mAnimator.mWin, surfaceShown);
509
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200510 mAnimator.mWin.onSurfaceShownChanged(surfaceShown);
511
Wale Ogunwale943002b2017-02-15 19:34:01 -0800512 if (mWindowSession != null) {
513 mWindowSession.onWindowSurfaceVisibilityChanged(this, mSurfaceShown, mWindowType);
514 }
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800515 }
516
Robert Carre6a83512015-11-03 16:09:21 -0800517 float getX() {
518 return mSurfaceX;
519 }
520
521 float getY() {
522 return mSurfaceY;
523 }
524
Jorim Jaggia5e10572017-11-15 14:36:26 +0100525 int getWidth() {
Robert Carrfed10072016-05-26 11:48:49 -0700526 return mSurfaceW;
527 }
528
Jorim Jaggia5e10572017-11-15 14:36:26 +0100529 int getHeight() {
Robert Carrfed10072016-05-26 11:48:49 -0700530 return mSurfaceH;
531 }
532
Steven Timotiusaf03df62017-07-18 16:56:43 -0700533 void writeToProto(ProtoOutputStream proto, long fieldId) {
534 final long token = proto.start(fieldId);
535 proto.write(SHOWN, mSurfaceShown);
536 proto.write(LAYER, mSurfaceLayer);
537 proto.end(token);
538 }
Robert Carrfed10072016-05-26 11:48:49 -0700539
Robert Carre6a83512015-11-03 16:09:21 -0800540 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
541 if (dumpAll) {
542 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
543 }
544 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
545 pw.print(" layer="); pw.print(mSurfaceLayer);
546 pw.print(" alpha="); pw.print(mSurfaceAlpha);
547 pw.print(" rect=("); pw.print(mSurfaceX);
548 pw.print(","); pw.print(mSurfaceY);
549 pw.print(") "); pw.print(mSurfaceW);
Jorim Jaggid878e4c2017-03-03 17:17:06 +0100550 pw.print(" x "); pw.print(mSurfaceH);
551 pw.print(" transform=("); pw.print(mLastDsdx); pw.print(", ");
552 pw.print(mLastDtdx); pw.print(", "); pw.print(mLastDsdy);
553 pw.print(", "); pw.print(mLastDtdy); pw.println(")");
Robert Carre6a83512015-11-03 16:09:21 -0800554 }
555
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800556 @Override
557 public String toString() {
558 return mSurfaceControl.toString();
559 }
Robert Carre6a83512015-11-03 16:09:21 -0800560}