blob: 383c0d9ab3d4287aa5b4bfae8dda0a0a24ae3606 [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
Adrian Roosb125e0b2019-10-02 14:55:14 +020024import static com.android.server.wm.ProtoLogGroup.WM_SHOW_SURFACE_ALLOC;
25import static com.android.server.wm.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
Vishnu Naire86bd982018-11-28 13:23:17 -080026import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
27import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_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;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070036import android.os.Trace;
Vishnu Naire86bd982018-11-28 13:23:17 -080037import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070038import android.util.proto.ProtoOutputStream;
Robert Carre6a83512015-11-03 16:09:21 -080039import android.view.SurfaceControl;
Robert Carre6a83512015-11-03 16:09:21 -080040import android.view.WindowContentFrameStats;
Robert Carr48ec4e02019-07-16 14:28:47 -070041import android.view.WindowManager;
Robert Carre6a83512015-11-03 16:09:21 -080042
Adrian Roosb125e0b2019-10-02 14:55:14 +020043import com.android.server.protolog.common.ProtoLog;
44
Robert Carre6a83512015-11-03 16:09:21 -080045import java.io.PrintWriter;
Robert Carre6a83512015-11-03 16:09:21 -080046
47class WindowSurfaceController {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080048 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfaceController" : TAG_WM;
Robert Carre6a83512015-11-03 16:09:21 -080049
50 final WindowStateAnimator mAnimator;
51
Adrian Roos4d18a2e2017-12-19 19:08:05 +010052 SurfaceControl mSurfaceControl;
Robert Carre6a83512015-11-03 16:09:21 -080053
Robert Carr2e20bcd2020-01-22 13:32:38 -080054 /**
55 * WM only uses for deferred transactions.
56 */
57 SurfaceControl mBLASTSurfaceControl;
58
Wale Ogunwale943002b2017-02-15 19:34:01 -080059 // Should only be set from within setShown().
Robert Carre6a83512015-11-03 16:09:21 -080060 private boolean mSurfaceShown = false;
61 private float mSurfaceX = 0;
62 private float mSurfaceY = 0;
Jorim Jaggia5e10572017-11-15 14:36:26 +010063 private int mSurfaceW = 0;
64 private int mSurfaceH = 0;
Jorim Jaggi4981f152019-03-26 18:58:45 +010065 private Rect mSurfaceCrop = new Rect(0, 0, -1, -1);
Robert Carre6a83512015-11-03 16:09:21 -080066
Matthew Bouyack8dd88f62016-10-24 14:01:26 -070067 // Initialize to the identity matrix.
68 private float mLastDsdx = 1;
69 private float mLastDtdx = 0;
70 private float mLastDsdy = 0;
71 private float mLastDtdy = 1;
72
Robert Carre6a83512015-11-03 16:09:21 -080073 private float mSurfaceAlpha = 0;
74
75 private int mSurfaceLayer = 0;
Robert Carre6a83512015-11-03 16:09:21 -080076
77 // Surface flinger doesn't support crop rectangles where width or height is non-positive.
78 // However, we need to somehow handle the situation where the cropping would completely hide
79 // the window. We achieve this by explicitly hiding the surface and not letting it be shown.
80 private boolean mHiddenForCrop = false;
Jorim Jaggi1eb39b02016-02-25 13:36:14 -050081
82 // Initially a surface is hidden after just being created.
83 private boolean mHiddenForOtherReasons = true;
Robert Carre6a83512015-11-03 16:09:21 -080084 private final String title;
85
Robert Carr68e5c9e2016-09-14 10:50:09 -070086 private final WindowManagerService mService;
87
Wale Ogunwale943002b2017-02-15 19:34:01 -080088 private final int mWindowType;
89 private final Session mWindowSession;
90
Vishnu Nair33197392019-08-30 10:29:37 -070091 private final SurfaceControl.Transaction mTmpTransaction;
Chavi Weingartenb736e322018-02-23 00:27:54 +000092
chaviw619da692019-06-10 15:39:40 -070093 WindowSurfaceController(String name, int w, int h, int format,
Albert Chaulk3bf2e572016-11-22 13:59:19 -050094 int flags, WindowStateAnimator animator, int windowType, int ownerUid) {
Robert Carre6a83512015-11-03 16:09:21 -080095 mAnimator = animator;
96
97 mSurfaceW = w;
98 mSurfaceH = h;
Robert Carre6a83512015-11-03 16:09:21 -080099
100 title = name;
101
Robert Carr68e5c9e2016-09-14 10:50:09 -0700102 mService = animator.mService;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800103 final WindowState win = animator.mWin;
104 mWindowType = windowType;
105 mWindowSession = win.mSession;
Vishnu Nair33197392019-08-30 10:29:37 -0700106 mTmpTransaction = mService.mTransactionFactory.get();
Robert Carr68e5c9e2016-09-14 10:50:09 -0700107
Andrii Kulian283acd22017-08-03 04:03:51 -0700108 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl");
Robert Carrb1579c82017-09-05 14:54:47 -0700109 final SurfaceControl.Builder b = win.makeSurface()
110 .setParent(win.getSurfaceControl())
Robert Carre625fcf2017-09-01 12:36:28 -0700111 .setName(name)
Vishnu Naire86bd982018-11-28 13:23:17 -0800112 .setBufferSize(w, h)
Robert Carre625fcf2017-09-01 12:36:28 -0700113 .setFormat(format)
114 .setFlags(flags)
Evan Rosky485df202018-12-06 14:11:12 -0800115 .setMetadata(METADATA_WINDOW_TYPE, windowType)
116 .setMetadata(METADATA_OWNER_UID, ownerUid);
Robert Carr48ec4e02019-07-16 14:28:47 -0700117
Robert Carr2e20bcd2020-01-22 13:32:38 -0800118 final boolean useBLAST = (win.getAttrs().privateFlags &
119 WindowManager.LayoutParams.PRIVATE_FLAG_USE_BLAST) != 0;
120 if (useBLAST) {
Robert Carr48ec4e02019-07-16 14:28:47 -0700121 b.setContainerLayer();
122 }
123
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100124 mSurfaceControl = b.build();
Robert Carr2e20bcd2020-01-22 13:32:38 -0800125
126 if (useBLAST) {
127 mBLASTSurfaceControl = win.makeSurface()
128 .setParent(mSurfaceControl)
129 .setName("BLAST Adapter Layer")
130 .setBLASTLayer()
131 .build();
132 }
133
Andrii Kulian283acd22017-08-03 04:03:51 -0700134 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carr3b716242016-08-16 16:02:21 -0700135 }
136
Robert Carrd5c7dd62017-03-08 10:39:30 -0800137 void reparentChildrenInTransaction(WindowSurfaceController other) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200138 ProtoLog.i(WM_SHOW_TRANSACTIONS, "REPARENT from: %s to: %s", this, other);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800139 if ((mSurfaceControl != null) && (other.mSurfaceControl != null)) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700140 mSurfaceControl.reparentChildren(other.mSurfaceControl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800141 }
142 }
143
144 void detachChildren() {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200145 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SEVER CHILDREN");
Robert Carrd5c7dd62017-03-08 10:39:30 -0800146 if (mSurfaceControl != null) {
147 mSurfaceControl.detachChildren();
148 }
149 }
150
Chavi Weingartenb736e322018-02-23 00:27:54 +0000151 void hide(SurfaceControl.Transaction transaction, String reason) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200152 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE HIDE ( %s ): %s", reason, title);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800153 mHiddenForOtherReasons = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700154
155 mAnimator.destroyPreservedSurfaceLocked();
Chavi Weingartenb736e322018-02-23 00:27:54 +0000156 if (mSurfaceShown) {
157 hideSurface(transaction);
158 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800159 }
160
Chavi Weingartenb736e322018-02-23 00:27:54 +0000161 private void hideSurface(SurfaceControl.Transaction transaction) {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800162 if (mSurfaceControl == null) {
163 return;
164 }
165 setShown(false);
166 try {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000167 transaction.hide(mSurfaceControl);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800168 } catch (RuntimeException e) {
169 Slog.w(TAG, "Exception hiding surface in " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800170 }
171 }
172
Robert Carra8828862018-02-05 16:17:36 -0800173 void destroyNotInTransaction() {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200174 ProtoLog.i(WM_SHOW_SURFACE_ALLOC,
175 "Destroying surface %s called by %s", this, Debug.getCallers(8));
Robert Carre6a83512015-11-03 16:09:21 -0800176 try {
Wale Ogunwale722ff892016-02-18 13:37:55 -0800177 if (mSurfaceControl != null) {
chaviw9f6171e2019-06-07 16:33:50 -0700178 mTmpTransaction.remove(mSurfaceControl).apply();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800179 }
Robert Carre6a83512015-11-03 16:09:21 -0800180 } catch (RuntimeException e) {
181 Slog.w(TAG, "Error destroying surface in: " + this, e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800182 } finally {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800183 setShown(false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800184 mSurfaceControl = null;
Robert Carr2e20bcd2020-01-22 13:32:38 -0800185 if (mBLASTSurfaceControl != null) {
186 mBLASTSurfaceControl.release();
187 }
Robert Carre6a83512015-11-03 16:09:21 -0800188 }
189 }
190
191 void setCropInTransaction(Rect clipRect, boolean recoveringMemory) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200192 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE CROP %s: %s", clipRect.toShortString(), title);
Robert Carre6a83512015-11-03 16:09:21 -0800193 try {
Robert Carr4320d332016-06-10 15:13:32 -0700194 if (clipRect.width() > 0 && clipRect.height() > 0) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100195 if (!clipRect.equals(mSurfaceCrop)) {
196 mSurfaceControl.setWindowCrop(clipRect);
197 mSurfaceCrop.set(clipRect);
198 }
Robert Carre6a83512015-11-03 16:09:21 -0800199 mHiddenForCrop = false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800200 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800201 } else {
Robert Carre6a83512015-11-03 16:09:21 -0800202 mHiddenForCrop = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700203 mAnimator.destroyPreservedSurfaceLocked();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800204 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800205 }
206 } catch (RuntimeException e) {
207 Slog.w(TAG, "Error setting crop surface of " + this
208 + " crop=" + clipRect.toShortString(), e);
209 if (!recoveringMemory) {
210 mAnimator.reclaimSomeSurfaceMemory("crop", true);
211 }
212 }
213 }
214
Robert Carr4320d332016-06-10 15:13:32 -0700215 void clearCropInTransaction(boolean recoveringMemory) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200216 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE CLEAR CROP: %s", title);
Robert Carr4320d332016-06-10 15:13:32 -0700217 try {
218 Rect clipRect = new Rect(0, 0, -1, -1);
Jorim Jaggi4981f152019-03-26 18:58:45 +0100219 if (mSurfaceCrop.equals(clipRect)) {
220 return;
221 }
Robert Carr4320d332016-06-10 15:13:32 -0700222 mSurfaceControl.setWindowCrop(clipRect);
Jorim Jaggi4981f152019-03-26 18:58:45 +0100223 mSurfaceCrop.set(clipRect);
Robert Carr4320d332016-06-10 15:13:32 -0700224 } catch (RuntimeException e) {
225 Slog.w(TAG, "Error setting clearing crop of " + this, e);
226 if (!recoveringMemory) {
227 mAnimator.reclaimSomeSurfaceMemory("crop", true);
228 }
229 }
230 }
231
Robert Carre6a83512015-11-03 16:09:21 -0800232 void setPositionInTransaction(float left, float top, boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700233 setPosition(null, left, top, recoveringMemory);
234 }
235
236 void setPosition(SurfaceControl.Transaction t, float left, float top,
237 boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800238 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top;
239 if (surfaceMoved) {
240 mSurfaceX = left;
241 mSurfaceY = top;
242
243 try {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200244 ProtoLog.i(WM_SHOW_TRANSACTIONS,
245 "SURFACE POS (setPositionInTransaction) @ (%f,%f): %s", left, top, title);
Chong Zhangae35fef2016-03-16 15:56:55 -0700246
Robert Carr19cdd092018-03-14 11:50:52 -0700247 if (t == null) {
248 mSurfaceControl.setPosition(left, top);
249 } else {
250 t.setPosition(mSurfaceControl, left, top);
251 }
Robert Carre6a83512015-11-03 16:09:21 -0800252 } catch (RuntimeException e) {
253 Slog.w(TAG, "Error positioning surface of " + this
254 + " pos=(" + left + "," + top + ")", e);
255 if (!recoveringMemory) {
256 mAnimator.reclaimSomeSurfaceMemory("position", true);
257 }
258 }
259 }
260 }
261
Andrii Kulian283acd22017-08-03 04:03:51 -0700262 void setMatrixInTransaction(float dsdx, float dtdx, float dtdy, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800263 boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700264 setMatrix(null, dsdx, dtdx, dtdy, dsdy, false);
265 }
266
267 void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx,
268 float dtdy, float dsdy, boolean recoveringMemory) {
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700269 final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx ||
Andrii Kulian283acd22017-08-03 04:03:51 -0700270 mLastDtdy != dtdy || mLastDsdy != dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700271 if (!matrixChanged) {
272 return;
273 }
274
275 mLastDsdx = dsdx;
276 mLastDtdx = dtdx;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700277 mLastDtdy = dtdy;
Andrii Kulian283acd22017-08-03 04:03:51 -0700278 mLastDsdy = dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700279
Robert Carre1034cc32016-02-01 13:08:15 -0800280 try {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200281 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE MATRIX [%f,%f,%f,%f]: %s",
282 dsdx, dtdx, dtdy, dsdy, title);
Robert Carr19cdd092018-03-14 11:50:52 -0700283 if (t == null) {
284 mSurfaceControl.setMatrix(dsdx, dtdx, dtdy, dsdy);
285 } else {
286 t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy);
287 }
Robert Carre1034cc32016-02-01 13:08:15 -0800288 } catch (RuntimeException e) {
289 // If something goes wrong with the surface (such
290 // as running out of memory), don't take down the
291 // entire system.
292 Slog.e(TAG, "Error setting matrix on surface surface" + title
Andrii Kulian283acd22017-08-03 04:03:51 -0700293 + " MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carre1034cc32016-02-01 13:08:15 -0800294 if (!recoveringMemory) {
295 mAnimator.reclaimSomeSurfaceMemory("matrix", true);
296 }
297 }
Robert Carre1034cc32016-02-01 13:08:15 -0800298 }
299
Vishnu Naire86bd982018-11-28 13:23:17 -0800300 boolean setBufferSizeInTransaction(int width, int height, boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800301 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
302 if (surfaceResized) {
303 mSurfaceW = width;
304 mSurfaceH = height;
305
306 try {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200307 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SIZE %dx%d: %s", width, height, title);
Vishnu Naire86bd982018-11-28 13:23:17 -0800308 mSurfaceControl.setBufferSize(width, height);
Robert Carre6a83512015-11-03 16:09:21 -0800309 } catch (RuntimeException e) {
310 // If something goes wrong with the surface (such
311 // as running out of memory), don't take down the
312 // entire system.
313 Slog.e(TAG, "Error resizing surface of " + title
314 + " size=(" + width + "x" + height + ")", e);
315 if (!recoveringMemory) {
316 mAnimator.reclaimSomeSurfaceMemory("size", true);
317 }
318 return false;
319 }
320 return true;
321 }
322 return false;
323 }
324
Robert Carraf422a82017-04-10 18:34:33 -0700325 boolean prepareToShowInTransaction(float alpha,
Robert Carrda61ba92017-03-29 15:52:23 -0700326 float dsdx, float dtdx, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800327 float dtdy, boolean recoveringMemory) {
328 if (mSurfaceControl != null) {
329 try {
330 mSurfaceAlpha = alpha;
331 mSurfaceControl.setAlpha(alpha);
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700332 mLastDsdx = dsdx;
333 mLastDtdx = dtdx;
334 mLastDsdy = dsdy;
335 mLastDtdy = dtdy;
Robert Carre6a83512015-11-03 16:09:21 -0800336 mSurfaceControl.setMatrix(
337 dsdx, dtdx, dsdy, dtdy);
Robert Carre6a83512015-11-03 16:09:21 -0800338 } catch (RuntimeException e) {
339 Slog.w(TAG, "Error updating surface in " + title, e);
340 if (!recoveringMemory) {
341 mAnimator.reclaimSomeSurfaceMemory("update", true);
342 }
343 return false;
344 }
345 }
346 return true;
347 }
348
349 void setTransparentRegionHint(final Region region) {
350 if (mSurfaceControl == null) {
351 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
352 return;
353 }
354 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700355 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800356 try {
357 mSurfaceControl.setTransparentRegionHint(region);
358 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200359 mService.closeSurfaceTransaction("setTransparentRegion");
Robert Carre6a83512015-11-03 16:09:21 -0800360 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
361 "<<< CLOSE TRANSACTION setTransparentRegion");
362 }
363 }
364
365 void setOpaque(boolean isOpaque) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200366 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isOpaque=%b: %s", isOpaque, title);
Robert Carre6a83512015-11-03 16:09:21 -0800367
368 if (mSurfaceControl == null) {
369 return;
370 }
371 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700372 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800373 try {
374 mSurfaceControl.setOpaque(isOpaque);
375 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200376 mService.closeSurfaceTransaction("setOpaqueLocked");
Robert Carre6a83512015-11-03 16:09:21 -0800377 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked");
378 }
379 }
380
381 void setSecure(boolean isSecure) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200382 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isSecure=%b: %s", isSecure, title);
Robert Carre6a83512015-11-03 16:09:21 -0800383
384 if (mSurfaceControl == null) {
385 return;
386 }
387 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700388 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800389 try {
390 mSurfaceControl.setSecure(isSecure);
391 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200392 mService.closeSurfaceTransaction("setSecure");
Robert Carre6a83512015-11-03 16:09:21 -0800393 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked");
394 }
395 }
396
Peiyong Lin75045382019-03-04 19:22:33 -0800397 void setColorSpaceAgnostic(boolean agnostic) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200398 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE isColorSpaceAgnostic=%b: %s", agnostic, title);
Peiyong Lin75045382019-03-04 19:22:33 -0800399
400 if (mSurfaceControl == null) {
401 return;
402 }
403 if (SHOW_LIGHT_TRANSACTIONS) {
404 Slog.i(TAG, ">>> OPEN TRANSACTION setColorSpaceAgnosticLocked");
405 }
406 mService.openSurfaceTransaction();
407 try {
408 mSurfaceControl.setColorSpaceAgnostic(agnostic);
409 } finally {
410 mService.closeSurfaceTransaction("setColorSpaceAgnostic");
411 if (SHOW_LIGHT_TRANSACTIONS) {
412 Slog.i(TAG, "<<< CLOSE TRANSACTION setColorSpaceAgnosticLocked");
413 }
414 }
415 }
416
Andrii Kulian283acd22017-08-03 04:03:51 -0700417 void getContainerRect(Rect rect) {
418 mAnimator.getContainerRect(rect);
419 }
420
Robert Carre6a83512015-11-03 16:09:21 -0800421 boolean showRobustlyInTransaction() {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200422 ProtoLog.i(WM_SHOW_TRANSACTIONS, "SURFACE SHOW (performLayout): %s", title);
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800423 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
424 + " during relayout");
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800425 mHiddenForOtherReasons = false;
426 return updateVisibility();
427 }
Robert Carre6a83512015-11-03 16:09:21 -0800428
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800429 private boolean updateVisibility() {
430 if (mHiddenForCrop || mHiddenForOtherReasons) {
431 if (mSurfaceShown) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000432 hideSurface(mTmpTransaction);
433 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800434 }
Robert Carre6a83512015-11-03 16:09:21 -0800435 return false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800436 } else {
437 if (!mSurfaceShown) {
438 return showSurface();
439 } else {
440 return true;
441 }
Robert Carre6a83512015-11-03 16:09:21 -0800442 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800443 }
Robert Carre6a83512015-11-03 16:09:21 -0800444
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800445 private boolean showSurface() {
Robert Carre6a83512015-11-03 16:09:21 -0800446 try {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800447 setShown(true);
Robert Carre6a83512015-11-03 16:09:21 -0800448 mSurfaceControl.show();
449 return true;
450 } catch (RuntimeException e) {
451 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + this, e);
452 }
453
454 mAnimator.reclaimSomeSurfaceMemory("show", true);
455
456 return false;
457 }
458
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700459 void deferTransactionUntil(SurfaceControl barrier, long frame) {
Robert Carre6a83512015-11-03 16:09:21 -0800460 // TODO: Logging
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700461 mSurfaceControl.deferTransactionUntil(barrier, frame);
Robert Carre6a83512015-11-03 16:09:21 -0800462 }
463
Robert Carr1ca6a332016-04-11 18:00:43 -0700464 void forceScaleableInTransaction(boolean force) {
465 // -1 means we don't override the default or client specified
466 // scaling mode.
467 int scalingMode = force ? SCALING_MODE_SCALE_TO_WINDOW : -1;
468 mSurfaceControl.setOverrideScalingMode(scalingMode);
469 }
470
Robert Carre6a83512015-11-03 16:09:21 -0800471 boolean clearWindowContentFrameStats() {
472 if (mSurfaceControl == null) {
473 return false;
474 }
475 return mSurfaceControl.clearContentFrameStats();
476 }
477
478 boolean getWindowContentFrameStats(WindowContentFrameStats outStats) {
479 if (mSurfaceControl == null) {
480 return false;
481 }
482 return mSurfaceControl.getContentFrameStats(outStats);
483 }
484
485
486 boolean hasSurface() {
487 return mSurfaceControl != null;
488 }
489
Robert Carr5fea55b2018-12-10 13:05:52 -0800490 void getSurfaceControl(SurfaceControl outSurfaceControl) {
491 outSurfaceControl.copyFrom(mSurfaceControl);
Robert Carre6a83512015-11-03 16:09:21 -0800492 }
493
Robert Carr2e20bcd2020-01-22 13:32:38 -0800494 void getBLASTSurfaceControl(SurfaceControl outSurfaceControl) {
495 if (mBLASTSurfaceControl != null) {
496 outSurfaceControl.copyFrom(mBLASTSurfaceControl);
497 }
498 }
499
Robert Carre6a83512015-11-03 16:09:21 -0800500 int getLayer() {
501 return mSurfaceLayer;
502 }
503
504 boolean getShown() {
505 return mSurfaceShown;
506 }
507
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800508 void setShown(boolean surfaceShown) {
509 mSurfaceShown = surfaceShown;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800510
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700511 mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mAnimator.mWin, surfaceShown);
512
Adrian Roos5f2c9a12019-07-03 18:31:46 +0200513 mAnimator.mWin.onSurfaceShownChanged(surfaceShown);
514
Wale Ogunwale943002b2017-02-15 19:34:01 -0800515 if (mWindowSession != null) {
516 mWindowSession.onWindowSurfaceVisibilityChanged(this, mSurfaceShown, mWindowType);
517 }
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800518 }
519
Robert Carre6a83512015-11-03 16:09:21 -0800520 float getX() {
521 return mSurfaceX;
522 }
523
524 float getY() {
525 return mSurfaceY;
526 }
527
Jorim Jaggia5e10572017-11-15 14:36:26 +0100528 int getWidth() {
Robert Carrfed10072016-05-26 11:48:49 -0700529 return mSurfaceW;
530 }
531
Jorim Jaggia5e10572017-11-15 14:36:26 +0100532 int getHeight() {
Robert Carrfed10072016-05-26 11:48:49 -0700533 return mSurfaceH;
534 }
535
Robert Carr2e20bcd2020-01-22 13:32:38 -0800536 SurfaceControl getDeferTransactionBarrier() {
537 if (mBLASTSurfaceControl != null) {
538 return mBLASTSurfaceControl;
539 }
540 return mSurfaceControl;
541 }
542
Jeffrey Huangcb782852019-12-05 11:28:11 -0800543 void dumpDebug(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -0700544 final long token = proto.start(fieldId);
545 proto.write(SHOWN, mSurfaceShown);
546 proto.write(LAYER, mSurfaceLayer);
547 proto.end(token);
548 }
Robert Carrfed10072016-05-26 11:48:49 -0700549
Robert Carre6a83512015-11-03 16:09:21 -0800550 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
551 if (dumpAll) {
552 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
553 }
554 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
555 pw.print(" layer="); pw.print(mSurfaceLayer);
556 pw.print(" alpha="); pw.print(mSurfaceAlpha);
557 pw.print(" rect=("); pw.print(mSurfaceX);
558 pw.print(","); pw.print(mSurfaceY);
559 pw.print(") "); pw.print(mSurfaceW);
Jorim Jaggid878e4c2017-03-03 17:17:06 +0100560 pw.print(" x "); pw.print(mSurfaceH);
561 pw.print(" transform=("); pw.print(mLastDsdx); pw.print(", ");
562 pw.print(mLastDtdx); pw.print(", "); pw.print(mLastDsdy);
563 pw.print(", "); pw.print(mLastDtdy); pw.println(")");
Robert Carre6a83512015-11-03 16:09:21 -0800564 }
565
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800566 @Override
567 public String toString() {
568 return mSurfaceControl.toString();
569 }
Robert Carre6a83512015-11-03 16:09:21 -0800570}