blob: acb98237b5d119db14f5459e727ad077077da664 [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;
Robert Carre6a83512015-11-03 16:09:21 -080059
Matthew Bouyack8dd88f62016-10-24 14:01:26 -070060 // Initialize to the identity matrix.
61 private float mLastDsdx = 1;
62 private float mLastDtdx = 0;
63 private float mLastDsdy = 0;
64 private float mLastDtdy = 1;
65
Robert Carre6a83512015-11-03 16:09:21 -080066 private float mSurfaceAlpha = 0;
67
68 private int mSurfaceLayer = 0;
Robert Carre6a83512015-11-03 16:09:21 -080069
70 // Surface flinger doesn't support crop rectangles where width or height is non-positive.
71 // However, we need to somehow handle the situation where the cropping would completely hide
72 // the window. We achieve this by explicitly hiding the surface and not letting it be shown.
73 private boolean mHiddenForCrop = false;
Jorim Jaggi1eb39b02016-02-25 13:36:14 -050074
75 // Initially a surface is hidden after just being created.
76 private boolean mHiddenForOtherReasons = true;
Robert Carre6a83512015-11-03 16:09:21 -080077 private final String title;
78
Robert Carr68e5c9e2016-09-14 10:50:09 -070079 private final WindowManagerService mService;
80
Wale Ogunwale943002b2017-02-15 19:34:01 -080081 private final int mWindowType;
82 private final Session mWindowSession;
83
Chavi Weingartenb736e322018-02-23 00:27:54 +000084 private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
85
Albert Chaulk3bf2e572016-11-22 13:59:19 -050086 public WindowSurfaceController(SurfaceSession s, String name, int w, int h, int format,
87 int flags, WindowStateAnimator animator, int windowType, int ownerUid) {
Robert Carre6a83512015-11-03 16:09:21 -080088 mAnimator = animator;
89
90 mSurfaceW = w;
91 mSurfaceH = h;
Robert Carre6a83512015-11-03 16:09:21 -080092
93 title = name;
94
Robert Carr68e5c9e2016-09-14 10:50:09 -070095 mService = animator.mService;
Wale Ogunwale943002b2017-02-15 19:34:01 -080096 final WindowState win = animator.mWin;
97 mWindowType = windowType;
98 mWindowSession = win.mSession;
Robert Carr68e5c9e2016-09-14 10:50:09 -070099
Andrii Kulian283acd22017-08-03 04:03:51 -0700100 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl");
Robert Carrb1579c82017-09-05 14:54:47 -0700101 final SurfaceControl.Builder b = win.makeSurface()
102 .setParent(win.getSurfaceControl())
Robert Carre625fcf2017-09-01 12:36:28 -0700103 .setName(name)
Vishnu Naire86bd982018-11-28 13:23:17 -0800104 .setBufferSize(w, h)
Robert Carre625fcf2017-09-01 12:36:28 -0700105 .setFormat(format)
106 .setFlags(flags)
Evan Rosky485df202018-12-06 14:11:12 -0800107 .setMetadata(METADATA_WINDOW_TYPE, windowType)
108 .setMetadata(METADATA_OWNER_UID, ownerUid);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100109 mSurfaceControl = b.build();
Andrii Kulian283acd22017-08-03 04:03:51 -0700110 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carr3b716242016-08-16 16:02:21 -0700111 }
112
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700113 private void logSurface(String msg, RuntimeException where) {
Robert Carre6a83512015-11-03 16:09:21 -0800114 String str = " SURFACE " + msg + ": " + title;
115 if (where != null) {
116 Slog.i(TAG, str, where);
117 } else {
118 Slog.i(TAG, str);
119 }
120 }
121
Robert Carrd5c7dd62017-03-08 10:39:30 -0800122 void reparentChildrenInTransaction(WindowSurfaceController other) {
123 if (SHOW_TRANSACTIONS) Slog.i(TAG, "REPARENT from: " + this + " to: " + other);
124 if ((mSurfaceControl != null) && (other.mSurfaceControl != null)) {
125 mSurfaceControl.reparentChildren(other.getHandle());
126 }
127 }
128
129 void detachChildren() {
130 if (SHOW_TRANSACTIONS) Slog.i(TAG, "SEVER CHILDREN");
131 if (mSurfaceControl != null) {
132 mSurfaceControl.detachChildren();
133 }
134 }
135
Chavi Weingartenb736e322018-02-23 00:27:54 +0000136 void hide(SurfaceControl.Transaction transaction, String reason) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800137 if (SHOW_TRANSACTIONS) logSurface("HIDE ( " + reason + " )", null);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800138 mHiddenForOtherReasons = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700139
140 mAnimator.destroyPreservedSurfaceLocked();
Chavi Weingartenb736e322018-02-23 00:27:54 +0000141 if (mSurfaceShown) {
142 hideSurface(transaction);
143 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800144 }
145
Chavi Weingartenb736e322018-02-23 00:27:54 +0000146 private void hideSurface(SurfaceControl.Transaction transaction) {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800147 if (mSurfaceControl == null) {
148 return;
149 }
150 setShown(false);
151 try {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000152 transaction.hide(mSurfaceControl);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800153 } catch (RuntimeException e) {
154 Slog.w(TAG, "Exception hiding surface in " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800155 }
156 }
157
Robert Carra8828862018-02-05 16:17:36 -0800158 void destroyNotInTransaction() {
Chong Zhangad23b3f2016-08-31 16:05:27 -0700159 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
160 Slog.i(TAG, "Destroying surface " + this + " called by " + Debug.getCallers(8));
161 }
Robert Carre6a83512015-11-03 16:09:21 -0800162 try {
Wale Ogunwale722ff892016-02-18 13:37:55 -0800163 if (mSurfaceControl != null) {
Robert Carr5ea304d2019-02-04 16:04:55 -0800164 mSurfaceControl.remove();
Wale Ogunwale722ff892016-02-18 13:37:55 -0800165 }
Robert Carre6a83512015-11-03 16:09:21 -0800166 } catch (RuntimeException e) {
167 Slog.w(TAG, "Error destroying surface in: " + this, e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800168 } finally {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800169 setShown(false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800170 mSurfaceControl = null;
Robert Carre6a83512015-11-03 16:09:21 -0800171 }
172 }
173
Chong Zhang47e36a32016-02-29 16:44:33 -0800174 void disconnectInTransaction() {
175 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
176 Slog.i(TAG, "Disconnecting client: " + this);
177 }
178
179 try {
180 if (mSurfaceControl != null) {
181 mSurfaceControl.disconnect();
182 }
183 } catch (RuntimeException e) {
184 Slog.w(TAG, "Error disconnecting surface in: " + this, e);
185 }
186 }
187
Robert Carre6a83512015-11-03 16:09:21 -0800188 void setCropInTransaction(Rect clipRect, boolean recoveringMemory) {
189 if (SHOW_TRANSACTIONS) logSurface(
190 "CROP " + clipRect.toShortString(), null);
191 try {
Robert Carr4320d332016-06-10 15:13:32 -0700192 if (clipRect.width() > 0 && clipRect.height() > 0) {
Robert Carre6a83512015-11-03 16:09:21 -0800193 mSurfaceControl.setWindowCrop(clipRect);
194 mHiddenForCrop = false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800195 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800196 } else {
Robert Carre6a83512015-11-03 16:09:21 -0800197 mHiddenForCrop = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700198 mAnimator.destroyPreservedSurfaceLocked();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800199 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800200 }
201 } catch (RuntimeException e) {
202 Slog.w(TAG, "Error setting crop surface of " + this
203 + " crop=" + clipRect.toShortString(), e);
204 if (!recoveringMemory) {
205 mAnimator.reclaimSomeSurfaceMemory("crop", true);
206 }
207 }
208 }
209
Robert Carr4320d332016-06-10 15:13:32 -0700210 void clearCropInTransaction(boolean recoveringMemory) {
211 if (SHOW_TRANSACTIONS) logSurface(
212 "CLEAR CROP", null);
213 try {
214 Rect clipRect = new Rect(0, 0, -1, -1);
215 mSurfaceControl.setWindowCrop(clipRect);
216 } catch (RuntimeException e) {
217 Slog.w(TAG, "Error setting clearing crop of " + this, e);
218 if (!recoveringMemory) {
219 mAnimator.reclaimSomeSurfaceMemory("crop", true);
220 }
221 }
222 }
223
Robert Carrda61ba92017-03-29 15:52:23 -0700224 void setLayerStackInTransaction(int layerStack) {
225 if (mSurfaceControl != null) {
226 mSurfaceControl.setLayerStack(layerStack);
227 }
228 }
229
Robert Carre6a83512015-11-03 16:09:21 -0800230 void setPositionInTransaction(float left, float top, boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700231 setPosition(null, left, top, recoveringMemory);
232 }
233
234 void setPosition(SurfaceControl.Transaction t, float left, float top,
235 boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800236 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top;
237 if (surfaceMoved) {
238 mSurfaceX = left;
239 mSurfaceY = top;
240
241 try {
Chong Zhangae35fef2016-03-16 15:56:55 -0700242 if (SHOW_TRANSACTIONS) logSurface(
243 "POS (setPositionInTransaction) @ (" + left + "," + top + ")", null);
244
Robert Carr19cdd092018-03-14 11:50:52 -0700245 if (t == null) {
246 mSurfaceControl.setPosition(left, top);
247 } else {
248 t.setPosition(mSurfaceControl, left, top);
249 }
Robert Carre6a83512015-11-03 16:09:21 -0800250 } catch (RuntimeException e) {
251 Slog.w(TAG, "Error positioning surface of " + this
252 + " pos=(" + left + "," + top + ")", e);
253 if (!recoveringMemory) {
254 mAnimator.reclaimSomeSurfaceMemory("position", true);
255 }
256 }
257 }
258 }
259
Robert Carr6da3cc02016-06-16 15:17:07 -0700260 void setGeometryAppliesWithResizeInTransaction(boolean recoveringMemory) {
261 mSurfaceControl.setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700262 }
263
Andrii Kulian283acd22017-08-03 04:03:51 -0700264 void setMatrixInTransaction(float dsdx, float dtdx, float dtdy, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800265 boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700266 setMatrix(null, dsdx, dtdx, dtdy, dsdy, false);
267 }
268
269 void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx,
270 float dtdy, float dsdy, boolean recoveringMemory) {
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700271 final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx ||
Andrii Kulian283acd22017-08-03 04:03:51 -0700272 mLastDtdy != dtdy || mLastDsdy != dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700273 if (!matrixChanged) {
274 return;
275 }
276
277 mLastDsdx = dsdx;
278 mLastDtdx = dtdx;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700279 mLastDtdy = dtdy;
Andrii Kulian283acd22017-08-03 04:03:51 -0700280 mLastDsdy = dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700281
Robert Carre1034cc32016-02-01 13:08:15 -0800282 try {
283 if (SHOW_TRANSACTIONS) logSurface(
Andrii Kulian283acd22017-08-03 04:03:51 -0700284 "MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carr19cdd092018-03-14 11:50:52 -0700285 if (t == null) {
286 mSurfaceControl.setMatrix(dsdx, dtdx, dtdy, dsdy);
287 } else {
288 t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy);
289 }
Robert Carre1034cc32016-02-01 13:08:15 -0800290 } catch (RuntimeException e) {
291 // If something goes wrong with the surface (such
292 // as running out of memory), don't take down the
293 // entire system.
294 Slog.e(TAG, "Error setting matrix on surface surface" + title
Andrii Kulian283acd22017-08-03 04:03:51 -0700295 + " MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carre1034cc32016-02-01 13:08:15 -0800296 if (!recoveringMemory) {
297 mAnimator.reclaimSomeSurfaceMemory("matrix", true);
298 }
299 }
Robert Carre1034cc32016-02-01 13:08:15 -0800300 }
301
Vishnu Naire86bd982018-11-28 13:23:17 -0800302 boolean setBufferSizeInTransaction(int width, int height, boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800303 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
304 if (surfaceResized) {
305 mSurfaceW = width;
306 mSurfaceH = height;
307
308 try {
309 if (SHOW_TRANSACTIONS) logSurface(
310 "SIZE " + width + "x" + height, null);
Vishnu Naire86bd982018-11-28 13:23:17 -0800311 mSurfaceControl.setBufferSize(width, height);
Robert Carre6a83512015-11-03 16:09:21 -0800312 } catch (RuntimeException e) {
313 // If something goes wrong with the surface (such
314 // as running out of memory), don't take down the
315 // entire system.
316 Slog.e(TAG, "Error resizing surface of " + title
317 + " size=(" + width + "x" + height + ")", e);
318 if (!recoveringMemory) {
319 mAnimator.reclaimSomeSurfaceMemory("size", true);
320 }
321 return false;
322 }
323 return true;
324 }
325 return false;
326 }
327
Robert Carraf422a82017-04-10 18:34:33 -0700328 boolean prepareToShowInTransaction(float alpha,
Robert Carrda61ba92017-03-29 15:52:23 -0700329 float dsdx, float dtdx, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800330 float dtdy, boolean recoveringMemory) {
331 if (mSurfaceControl != null) {
332 try {
333 mSurfaceAlpha = alpha;
334 mSurfaceControl.setAlpha(alpha);
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700335 mLastDsdx = dsdx;
336 mLastDtdx = dtdx;
337 mLastDsdy = dsdy;
338 mLastDtdy = dtdy;
Robert Carre6a83512015-11-03 16:09:21 -0800339 mSurfaceControl.setMatrix(
340 dsdx, dtdx, dsdy, dtdy);
Robert Carre6a83512015-11-03 16:09:21 -0800341 } catch (RuntimeException e) {
342 Slog.w(TAG, "Error updating surface in " + title, e);
343 if (!recoveringMemory) {
344 mAnimator.reclaimSomeSurfaceMemory("update", true);
345 }
346 return false;
347 }
348 }
349 return true;
350 }
351
352 void setTransparentRegionHint(final Region region) {
353 if (mSurfaceControl == null) {
354 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
355 return;
356 }
357 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700358 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800359 try {
360 mSurfaceControl.setTransparentRegionHint(region);
361 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200362 mService.closeSurfaceTransaction("setTransparentRegion");
Robert Carre6a83512015-11-03 16:09:21 -0800363 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
364 "<<< CLOSE TRANSACTION setTransparentRegion");
365 }
366 }
367
368 void setOpaque(boolean isOpaque) {
369 if (SHOW_TRANSACTIONS) logSurface("isOpaque=" + isOpaque,
370 null);
371
372 if (mSurfaceControl == null) {
373 return;
374 }
375 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700376 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800377 try {
378 mSurfaceControl.setOpaque(isOpaque);
379 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200380 mService.closeSurfaceTransaction("setOpaqueLocked");
Robert Carre6a83512015-11-03 16:09:21 -0800381 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked");
382 }
383 }
384
385 void setSecure(boolean isSecure) {
386 if (SHOW_TRANSACTIONS) logSurface("isSecure=" + isSecure,
387 null);
388
389 if (mSurfaceControl == null) {
390 return;
391 }
392 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700393 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800394 try {
395 mSurfaceControl.setSecure(isSecure);
396 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200397 mService.closeSurfaceTransaction("setSecure");
Robert Carre6a83512015-11-03 16:09:21 -0800398 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked");
399 }
400 }
401
Peiyong Lin75045382019-03-04 19:22:33 -0800402 void setColorSpaceAgnostic(boolean agnostic) {
403 if (SHOW_TRANSACTIONS) {
404 logSurface("isColorSpaceAgnostic=" + agnostic, null);
405 }
406
407 if (mSurfaceControl == null) {
408 return;
409 }
410 if (SHOW_LIGHT_TRANSACTIONS) {
411 Slog.i(TAG, ">>> OPEN TRANSACTION setColorSpaceAgnosticLocked");
412 }
413 mService.openSurfaceTransaction();
414 try {
415 mSurfaceControl.setColorSpaceAgnostic(agnostic);
416 } finally {
417 mService.closeSurfaceTransaction("setColorSpaceAgnostic");
418 if (SHOW_LIGHT_TRANSACTIONS) {
419 Slog.i(TAG, "<<< CLOSE TRANSACTION setColorSpaceAgnosticLocked");
420 }
421 }
422 }
423
Andrii Kulian283acd22017-08-03 04:03:51 -0700424 void getContainerRect(Rect rect) {
425 mAnimator.getContainerRect(rect);
426 }
427
Robert Carre6a83512015-11-03 16:09:21 -0800428 boolean showRobustlyInTransaction() {
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800429 if (SHOW_TRANSACTIONS) logSurface(
430 "SHOW (performLayout)", null);
431 if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this
432 + " during relayout");
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800433 mHiddenForOtherReasons = false;
434 return updateVisibility();
435 }
Robert Carre6a83512015-11-03 16:09:21 -0800436
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800437 private boolean updateVisibility() {
438 if (mHiddenForCrop || mHiddenForOtherReasons) {
439 if (mSurfaceShown) {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000440 hideSurface(mTmpTransaction);
441 SurfaceControl.mergeToGlobalTransaction(mTmpTransaction);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800442 }
Robert Carre6a83512015-11-03 16:09:21 -0800443 return false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800444 } else {
445 if (!mSurfaceShown) {
446 return showSurface();
447 } else {
448 return true;
449 }
Robert Carre6a83512015-11-03 16:09:21 -0800450 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800451 }
Robert Carre6a83512015-11-03 16:09:21 -0800452
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800453 private boolean showSurface() {
Robert Carre6a83512015-11-03 16:09:21 -0800454 try {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800455 setShown(true);
Robert Carre6a83512015-11-03 16:09:21 -0800456 mSurfaceControl.show();
457 return true;
458 } catch (RuntimeException e) {
459 Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + this, e);
460 }
461
462 mAnimator.reclaimSomeSurfaceMemory("show", true);
463
464 return false;
465 }
466
467 void deferTransactionUntil(IBinder handle, long frame) {
468 // TODO: Logging
469 mSurfaceControl.deferTransactionUntil(handle, frame);
470 }
471
Robert Carr1ca6a332016-04-11 18:00:43 -0700472 void forceScaleableInTransaction(boolean force) {
473 // -1 means we don't override the default or client specified
474 // scaling mode.
475 int scalingMode = force ? SCALING_MODE_SCALE_TO_WINDOW : -1;
476 mSurfaceControl.setOverrideScalingMode(scalingMode);
477 }
478
Robert Carre6a83512015-11-03 16:09:21 -0800479 boolean clearWindowContentFrameStats() {
480 if (mSurfaceControl == null) {
481 return false;
482 }
483 return mSurfaceControl.clearContentFrameStats();
484 }
485
486 boolean getWindowContentFrameStats(WindowContentFrameStats outStats) {
487 if (mSurfaceControl == null) {
488 return false;
489 }
490 return mSurfaceControl.getContentFrameStats(outStats);
491 }
492
493
494 boolean hasSurface() {
495 return mSurfaceControl != null;
496 }
497
498 IBinder getHandle() {
499 if (mSurfaceControl == null) {
500 return null;
501 }
502 return mSurfaceControl.getHandle();
503 }
504
Robert Carr5fea55b2018-12-10 13:05:52 -0800505 void getSurfaceControl(SurfaceControl outSurfaceControl) {
506 outSurfaceControl.copyFrom(mSurfaceControl);
Robert Carre6a83512015-11-03 16:09:21 -0800507 }
508
509 int getLayer() {
510 return mSurfaceLayer;
511 }
512
513 boolean getShown() {
514 return mSurfaceShown;
515 }
516
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800517 void setShown(boolean surfaceShown) {
518 mSurfaceShown = surfaceShown;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800519
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700520 mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mAnimator.mWin, surfaceShown);
521
Wale Ogunwale943002b2017-02-15 19:34:01 -0800522 if (mWindowSession != null) {
523 mWindowSession.onWindowSurfaceVisibilityChanged(this, mSurfaceShown, mWindowType);
524 }
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800525 }
526
Robert Carre6a83512015-11-03 16:09:21 -0800527 float getX() {
528 return mSurfaceX;
529 }
530
531 float getY() {
532 return mSurfaceY;
533 }
534
Jorim Jaggia5e10572017-11-15 14:36:26 +0100535 int getWidth() {
Robert Carrfed10072016-05-26 11:48:49 -0700536 return mSurfaceW;
537 }
538
Jorim Jaggia5e10572017-11-15 14:36:26 +0100539 int getHeight() {
Robert Carrfed10072016-05-26 11:48:49 -0700540 return mSurfaceH;
541 }
542
Steven Timotiusaf03df62017-07-18 16:56:43 -0700543 void writeToProto(ProtoOutputStream proto, long fieldId) {
544 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}