blob: 66c8cca8f0e09a231a6897e764ab50b41cee6447 [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;
21
Wale Ogunwale722ff892016-02-18 13:37:55 -080022import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080023import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
24import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080025import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
26import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
27import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070028import static com.android.server.wm.WindowSurfaceControllerProto.LAYER;
29import static com.android.server.wm.WindowSurfaceControllerProto.SHOWN;
Robert Carre6a83512015-11-03 16:09:21 -080030
Robert Carre6a83512015-11-03 16:09:21 -080031import android.graphics.Point;
32import android.graphics.PointF;
33import android.graphics.Rect;
34import android.graphics.Region;
35import android.os.IBinder;
36import android.os.Debug;
Wale Ogunwale4958ad22017-06-22 09:08:14 -070037import android.os.Trace;
Steven Timotiusaf03df62017-07-18 16:56:43 -070038import android.util.proto.ProtoOutputStream;
Robert Carre6a83512015-11-03 16:09:21 -080039import android.view.Surface;
40import android.view.SurfaceControl;
41import android.view.SurfaceSession;
42import android.view.WindowContentFrameStats;
43import android.view.Surface.OutOfResourcesException;
44
45import android.util.Slog;
46
Robert Carr3b716242016-08-16 16:02:21 -070047import java.io.FileDescriptor;
Robert Carre6a83512015-11-03 16:09:21 -080048import java.io.PrintWriter;
49import java.util.ArrayList;
50
51class WindowSurfaceController {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080052 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfaceController" : TAG_WM;
Robert Carre6a83512015-11-03 16:09:21 -080053
54 final WindowStateAnimator mAnimator;
55
Adrian Roos4d18a2e2017-12-19 19:08:05 +010056 SurfaceControl mSurfaceControl;
Robert Carre6a83512015-11-03 16:09:21 -080057
Wale Ogunwale943002b2017-02-15 19:34:01 -080058 // Should only be set from within setShown().
Robert Carre6a83512015-11-03 16:09:21 -080059 private boolean mSurfaceShown = false;
60 private float mSurfaceX = 0;
61 private float mSurfaceY = 0;
Jorim Jaggia5e10572017-11-15 14:36:26 +010062 private int mSurfaceW = 0;
63 private int mSurfaceH = 0;
Robert Carre6a83512015-11-03 16:09:21 -080064
Matthew Bouyack8dd88f62016-10-24 14:01:26 -070065 // Initialize to the identity matrix.
66 private float mLastDsdx = 1;
67 private float mLastDtdx = 0;
68 private float mLastDsdy = 0;
69 private float mLastDtdy = 1;
70
Robert Carre6a83512015-11-03 16:09:21 -080071 private float mSurfaceAlpha = 0;
72
73 private int mSurfaceLayer = 0;
Robert Carre6a83512015-11-03 16:09:21 -080074
75 // Surface flinger doesn't support crop rectangles where width or height is non-positive.
76 // However, we need to somehow handle the situation where the cropping would completely hide
77 // the window. We achieve this by explicitly hiding the surface and not letting it be shown.
78 private boolean mHiddenForCrop = false;
Jorim Jaggi1eb39b02016-02-25 13:36:14 -050079
80 // Initially a surface is hidden after just being created.
81 private boolean mHiddenForOtherReasons = true;
Robert Carre6a83512015-11-03 16:09:21 -080082 private final String title;
83
Robert Carr68e5c9e2016-09-14 10:50:09 -070084 private final WindowManagerService mService;
85
Wale Ogunwale943002b2017-02-15 19:34:01 -080086 private final int mWindowType;
87 private final Session mWindowSession;
88
Chavi Weingartenb736e322018-02-23 00:27:54 +000089 private final SurfaceControl.Transaction mTmpTransaction = new SurfaceControl.Transaction();
90
Albert Chaulk3bf2e572016-11-22 13:59:19 -050091 public WindowSurfaceController(SurfaceSession s, String name, int w, int h, int format,
92 int flags, WindowStateAnimator animator, int windowType, int ownerUid) {
Robert Carre6a83512015-11-03 16:09:21 -080093 mAnimator = animator;
94
95 mSurfaceW = w;
96 mSurfaceH = h;
Robert Carre6a83512015-11-03 16:09:21 -080097
98 title = name;
99
Robert Carr68e5c9e2016-09-14 10:50:09 -0700100 mService = animator.mService;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800101 final WindowState win = animator.mWin;
102 mWindowType = windowType;
103 mWindowSession = win.mSession;
Robert Carr68e5c9e2016-09-14 10:50:09 -0700104
Andrii Kulian283acd22017-08-03 04:03:51 -0700105 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "new SurfaceControl");
Robert Carrb1579c82017-09-05 14:54:47 -0700106 final SurfaceControl.Builder b = win.makeSurface()
107 .setParent(win.getSurfaceControl())
Robert Carre625fcf2017-09-01 12:36:28 -0700108 .setName(name)
109 .setSize(w, h)
110 .setFormat(format)
111 .setFlags(flags)
112 .setMetadata(windowType, ownerUid);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100113 mSurfaceControl = b.build();
Andrii Kulian283acd22017-08-03 04:03:51 -0700114 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carr3b716242016-08-16 16:02:21 -0700115 }
116
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700117 private void logSurface(String msg, RuntimeException where) {
Robert Carre6a83512015-11-03 16:09:21 -0800118 String str = " SURFACE " + msg + ": " + title;
119 if (where != null) {
120 Slog.i(TAG, str, where);
121 } else {
122 Slog.i(TAG, str);
123 }
124 }
125
Robert Carrd5c7dd62017-03-08 10:39:30 -0800126 void reparentChildrenInTransaction(WindowSurfaceController other) {
127 if (SHOW_TRANSACTIONS) Slog.i(TAG, "REPARENT from: " + this + " to: " + other);
128 if ((mSurfaceControl != null) && (other.mSurfaceControl != null)) {
129 mSurfaceControl.reparentChildren(other.getHandle());
130 }
131 }
132
133 void detachChildren() {
134 if (SHOW_TRANSACTIONS) Slog.i(TAG, "SEVER CHILDREN");
135 if (mSurfaceControl != null) {
136 mSurfaceControl.detachChildren();
137 }
138 }
139
Chavi Weingartenb736e322018-02-23 00:27:54 +0000140 void hide(SurfaceControl.Transaction transaction, String reason) {
Filip Gruszczynski63a35e22015-11-05 15:38:59 -0800141 if (SHOW_TRANSACTIONS) logSurface("HIDE ( " + reason + " )", null);
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800142 mHiddenForOtherReasons = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700143
144 mAnimator.destroyPreservedSurfaceLocked();
Chavi Weingartenb736e322018-02-23 00:27:54 +0000145 if (mSurfaceShown) {
146 hideSurface(transaction);
147 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800148 }
149
Chavi Weingartenb736e322018-02-23 00:27:54 +0000150 private void hideSurface(SurfaceControl.Transaction transaction) {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800151 if (mSurfaceControl == null) {
152 return;
153 }
154 setShown(false);
155 try {
Chavi Weingartenb736e322018-02-23 00:27:54 +0000156 transaction.hide(mSurfaceControl);
Wale Ogunwale943002b2017-02-15 19:34:01 -0800157 } catch (RuntimeException e) {
158 Slog.w(TAG, "Exception hiding surface in " + this);
Robert Carre6a83512015-11-03 16:09:21 -0800159 }
160 }
161
Robert Carra8828862018-02-05 16:17:36 -0800162 void destroyNotInTransaction() {
Chong Zhangad23b3f2016-08-31 16:05:27 -0700163 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
164 Slog.i(TAG, "Destroying surface " + this + " called by " + Debug.getCallers(8));
165 }
Robert Carre6a83512015-11-03 16:09:21 -0800166 try {
Wale Ogunwale722ff892016-02-18 13:37:55 -0800167 if (mSurfaceControl != null) {
168 mSurfaceControl.destroy();
169 }
Robert Carre6a83512015-11-03 16:09:21 -0800170 } catch (RuntimeException e) {
171 Slog.w(TAG, "Error destroying surface in: " + this, e);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800172 } finally {
Wale Ogunwale943002b2017-02-15 19:34:01 -0800173 setShown(false);
Wale Ogunwale722ff892016-02-18 13:37:55 -0800174 mSurfaceControl = null;
Robert Carre6a83512015-11-03 16:09:21 -0800175 }
176 }
177
Chong Zhang47e36a32016-02-29 16:44:33 -0800178 void disconnectInTransaction() {
179 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
180 Slog.i(TAG, "Disconnecting client: " + this);
181 }
182
183 try {
184 if (mSurfaceControl != null) {
185 mSurfaceControl.disconnect();
186 }
187 } catch (RuntimeException e) {
188 Slog.w(TAG, "Error disconnecting surface in: " + this, e);
189 }
190 }
191
Robert Carre6a83512015-11-03 16:09:21 -0800192 void setCropInTransaction(Rect clipRect, boolean recoveringMemory) {
193 if (SHOW_TRANSACTIONS) logSurface(
194 "CROP " + clipRect.toShortString(), null);
195 try {
Robert Carr4320d332016-06-10 15:13:32 -0700196 if (clipRect.width() > 0 && clipRect.height() > 0) {
Robert Carre6a83512015-11-03 16:09:21 -0800197 mSurfaceControl.setWindowCrop(clipRect);
198 mHiddenForCrop = false;
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800199 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800200 } else {
Robert Carre6a83512015-11-03 16:09:21 -0800201 mHiddenForCrop = true;
Chong Zhang3cc58dd2016-04-20 17:45:24 -0700202 mAnimator.destroyPreservedSurfaceLocked();
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800203 updateVisibility();
Robert Carre6a83512015-11-03 16:09:21 -0800204 }
205 } catch (RuntimeException e) {
206 Slog.w(TAG, "Error setting crop surface of " + this
207 + " crop=" + clipRect.toShortString(), e);
208 if (!recoveringMemory) {
209 mAnimator.reclaimSomeSurfaceMemory("crop", true);
210 }
211 }
212 }
213
Robert Carr4320d332016-06-10 15:13:32 -0700214 void clearCropInTransaction(boolean recoveringMemory) {
215 if (SHOW_TRANSACTIONS) logSurface(
216 "CLEAR CROP", null);
217 try {
218 Rect clipRect = new Rect(0, 0, -1, -1);
219 mSurfaceControl.setWindowCrop(clipRect);
220 } catch (RuntimeException e) {
221 Slog.w(TAG, "Error setting clearing crop of " + this, e);
222 if (!recoveringMemory) {
223 mAnimator.reclaimSomeSurfaceMemory("crop", true);
224 }
225 }
226 }
227
Jorim Jaggi6a7c90a2016-03-11 15:04:59 +0100228 void setFinalCropInTransaction(Rect clipRect) {
229 if (SHOW_TRANSACTIONS) logSurface(
230 "FINAL CROP " + clipRect.toShortString(), null);
231 try {
232 mSurfaceControl.setFinalCrop(clipRect);
233 } catch (RuntimeException e) {
234 Slog.w(TAG, "Error disconnecting surface in: " + this, e);
235 }
236 }
237
Robert Carrda61ba92017-03-29 15:52:23 -0700238 void setLayerStackInTransaction(int layerStack) {
239 if (mSurfaceControl != null) {
240 mSurfaceControl.setLayerStack(layerStack);
241 }
242 }
243
Robert Carre6a83512015-11-03 16:09:21 -0800244 void setPositionInTransaction(float left, float top, boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700245 setPosition(null, left, top, recoveringMemory);
246 }
247
248 void setPosition(SurfaceControl.Transaction t, float left, float top,
249 boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800250 final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top;
251 if (surfaceMoved) {
252 mSurfaceX = left;
253 mSurfaceY = top;
254
255 try {
Chong Zhangae35fef2016-03-16 15:56:55 -0700256 if (SHOW_TRANSACTIONS) logSurface(
257 "POS (setPositionInTransaction) @ (" + left + "," + top + ")", null);
258
Robert Carr19cdd092018-03-14 11:50:52 -0700259 if (t == null) {
260 mSurfaceControl.setPosition(left, top);
261 } else {
262 t.setPosition(mSurfaceControl, left, top);
263 }
Robert Carre6a83512015-11-03 16:09:21 -0800264 } catch (RuntimeException e) {
265 Slog.w(TAG, "Error positioning surface of " + this
266 + " pos=(" + left + "," + top + ")", e);
267 if (!recoveringMemory) {
268 mAnimator.reclaimSomeSurfaceMemory("position", true);
269 }
270 }
271 }
272 }
273
Robert Carr6da3cc02016-06-16 15:17:07 -0700274 void setGeometryAppliesWithResizeInTransaction(boolean recoveringMemory) {
275 mSurfaceControl.setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700276 }
277
Andrii Kulian283acd22017-08-03 04:03:51 -0700278 void setMatrixInTransaction(float dsdx, float dtdx, float dtdy, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800279 boolean recoveringMemory) {
Robert Carr19cdd092018-03-14 11:50:52 -0700280 setMatrix(null, dsdx, dtdx, dtdy, dsdy, false);
281 }
282
283 void setMatrix(SurfaceControl.Transaction t, float dsdx, float dtdx,
284 float dtdy, float dsdy, boolean recoveringMemory) {
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700285 final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx ||
Andrii Kulian283acd22017-08-03 04:03:51 -0700286 mLastDtdy != dtdy || mLastDsdy != dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700287 if (!matrixChanged) {
288 return;
289 }
290
291 mLastDsdx = dsdx;
292 mLastDtdx = dtdx;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700293 mLastDtdy = dtdy;
Andrii Kulian283acd22017-08-03 04:03:51 -0700294 mLastDsdy = dsdy;
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700295
Robert Carre1034cc32016-02-01 13:08:15 -0800296 try {
297 if (SHOW_TRANSACTIONS) logSurface(
Andrii Kulian283acd22017-08-03 04:03:51 -0700298 "MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carr19cdd092018-03-14 11:50:52 -0700299 if (t == null) {
300 mSurfaceControl.setMatrix(dsdx, dtdx, dtdy, dsdy);
301 } else {
302 t.setMatrix(mSurfaceControl, dsdx, dtdx, dtdy, dsdy);
303 }
Robert Carre1034cc32016-02-01 13:08:15 -0800304 } catch (RuntimeException e) {
305 // If something goes wrong with the surface (such
306 // as running out of memory), don't take down the
307 // entire system.
308 Slog.e(TAG, "Error setting matrix on surface surface" + title
Andrii Kulian283acd22017-08-03 04:03:51 -0700309 + " MATRIX [" + dsdx + "," + dtdx + "," + dtdy + "," + dsdy + "]", null);
Robert Carre1034cc32016-02-01 13:08:15 -0800310 if (!recoveringMemory) {
311 mAnimator.reclaimSomeSurfaceMemory("matrix", true);
312 }
313 }
Robert Carre1034cc32016-02-01 13:08:15 -0800314 }
315
316 boolean setSizeInTransaction(int width, int height, boolean recoveringMemory) {
Robert Carre6a83512015-11-03 16:09:21 -0800317 final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
318 if (surfaceResized) {
319 mSurfaceW = width;
320 mSurfaceH = height;
321
322 try {
323 if (SHOW_TRANSACTIONS) logSurface(
324 "SIZE " + width + "x" + height, null);
325 mSurfaceControl.setSize(width, height);
Robert Carre6a83512015-11-03 16:09:21 -0800326 } catch (RuntimeException e) {
327 // If something goes wrong with the surface (such
328 // as running out of memory), don't take down the
329 // entire system.
330 Slog.e(TAG, "Error resizing surface of " + title
331 + " size=(" + width + "x" + height + ")", e);
332 if (!recoveringMemory) {
333 mAnimator.reclaimSomeSurfaceMemory("size", true);
334 }
335 return false;
336 }
337 return true;
338 }
339 return false;
340 }
341
Robert Carraf422a82017-04-10 18:34:33 -0700342 boolean prepareToShowInTransaction(float alpha,
Robert Carrda61ba92017-03-29 15:52:23 -0700343 float dsdx, float dtdx, float dsdy,
Robert Carre6a83512015-11-03 16:09:21 -0800344 float dtdy, boolean recoveringMemory) {
345 if (mSurfaceControl != null) {
346 try {
347 mSurfaceAlpha = alpha;
348 mSurfaceControl.setAlpha(alpha);
Matthew Bouyack8dd88f62016-10-24 14:01:26 -0700349 mLastDsdx = dsdx;
350 mLastDtdx = dtdx;
351 mLastDsdy = dsdy;
352 mLastDtdy = dtdy;
Robert Carre6a83512015-11-03 16:09:21 -0800353 mSurfaceControl.setMatrix(
354 dsdx, dtdx, dsdy, dtdy);
Robert Carre6a83512015-11-03 16:09:21 -0800355 } catch (RuntimeException e) {
356 Slog.w(TAG, "Error updating surface in " + title, e);
357 if (!recoveringMemory) {
358 mAnimator.reclaimSomeSurfaceMemory("update", true);
359 }
360 return false;
361 }
362 }
363 return true;
364 }
365
366 void setTransparentRegionHint(final Region region) {
367 if (mSurfaceControl == null) {
368 Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
369 return;
370 }
371 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700372 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800373 try {
374 mSurfaceControl.setTransparentRegionHint(region);
375 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200376 mService.closeSurfaceTransaction("setTransparentRegion");
Robert Carre6a83512015-11-03 16:09:21 -0800377 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
378 "<<< CLOSE TRANSACTION setTransparentRegion");
379 }
380 }
381
382 void setOpaque(boolean isOpaque) {
383 if (SHOW_TRANSACTIONS) logSurface("isOpaque=" + isOpaque,
384 null);
385
386 if (mSurfaceControl == null) {
387 return;
388 }
389 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700390 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800391 try {
392 mSurfaceControl.setOpaque(isOpaque);
393 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200394 mService.closeSurfaceTransaction("setOpaqueLocked");
Robert Carre6a83512015-11-03 16:09:21 -0800395 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked");
396 }
397 }
398
399 void setSecure(boolean isSecure) {
400 if (SHOW_TRANSACTIONS) logSurface("isSecure=" + isSecure,
401 null);
402
403 if (mSurfaceControl == null) {
404 return;
405 }
406 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked");
Robert Carr68e5c9e2016-09-14 10:50:09 -0700407 mService.openSurfaceTransaction();
Robert Carre6a83512015-11-03 16:09:21 -0800408 try {
409 mSurfaceControl.setSecure(isSecure);
410 } finally {
Adrian Roos111aff92017-09-27 18:11:46 +0200411 mService.closeSurfaceTransaction("setSecure");
Robert Carre6a83512015-11-03 16:09:21 -0800412 if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked");
413 }
414 }
415
Andrii Kulian283acd22017-08-03 04:03:51 -0700416 void getContainerRect(Rect rect) {
417 mAnimator.getContainerRect(rect);
418 }
419
Robert Carre6a83512015-11-03 16:09:21 -0800420 boolean showRobustlyInTransaction() {
Filip Gruszczynski19723a42015-11-25 15:01:48 -0800421 if (SHOW_TRANSACTIONS) logSurface(
422 "SHOW (performLayout)", null);
423 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
459 void deferTransactionUntil(IBinder handle, long frame) {
460 // TODO: Logging
461 mSurfaceControl.deferTransactionUntil(handle, frame);
462 }
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
490 IBinder getHandle() {
491 if (mSurfaceControl == null) {
492 return null;
493 }
494 return mSurfaceControl.getHandle();
495 }
496
497 void getSurface(Surface outSurface) {
498 outSurface.copyFrom(mSurfaceControl);
499 }
500
501 int getLayer() {
502 return mSurfaceLayer;
503 }
504
505 boolean getShown() {
506 return mSurfaceShown;
507 }
508
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800509 void setShown(boolean surfaceShown) {
510 mSurfaceShown = surfaceShown;
Wale Ogunwale943002b2017-02-15 19:34:01 -0800511
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700512 mService.updateNonSystemOverlayWindowsVisibilityIfNeeded(mAnimator.mWin, surfaceShown);
513
Wale Ogunwale943002b2017-02-15 19:34:01 -0800514 if (mWindowSession != null) {
515 mWindowSession.onWindowSurfaceVisibilityChanged(this, mSurfaceShown, mWindowType);
516 }
Filip Gruszczynski10a80e02015-11-06 09:21:17 -0800517 }
518
Robert Carre6a83512015-11-03 16:09:21 -0800519 float getX() {
520 return mSurfaceX;
521 }
522
523 float getY() {
524 return mSurfaceY;
525 }
526
Jorim Jaggia5e10572017-11-15 14:36:26 +0100527 int getWidth() {
Robert Carrfed10072016-05-26 11:48:49 -0700528 return mSurfaceW;
529 }
530
Jorim Jaggia5e10572017-11-15 14:36:26 +0100531 int getHeight() {
Robert Carrfed10072016-05-26 11:48:49 -0700532 return mSurfaceH;
533 }
534
Steven Timotiusaf03df62017-07-18 16:56:43 -0700535 void writeToProto(ProtoOutputStream proto, long fieldId) {
536 final long token = proto.start(fieldId);
537 proto.write(SHOWN, mSurfaceShown);
538 proto.write(LAYER, mSurfaceLayer);
539 proto.end(token);
540 }
Robert Carrfed10072016-05-26 11:48:49 -0700541
Robert Carre6a83512015-11-03 16:09:21 -0800542 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
543 if (dumpAll) {
544 pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
545 }
546 pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
547 pw.print(" layer="); pw.print(mSurfaceLayer);
548 pw.print(" alpha="); pw.print(mSurfaceAlpha);
549 pw.print(" rect=("); pw.print(mSurfaceX);
550 pw.print(","); pw.print(mSurfaceY);
551 pw.print(") "); pw.print(mSurfaceW);
Jorim Jaggid878e4c2017-03-03 17:17:06 +0100552 pw.print(" x "); pw.print(mSurfaceH);
553 pw.print(" transform=("); pw.print(mLastDsdx); pw.print(", ");
554 pw.print(mLastDtdx); pw.print(", "); pw.print(mLastDsdy);
555 pw.print(", "); pw.print(mLastDtdy); pw.println(")");
Robert Carre6a83512015-11-03 16:09:21 -0800556 }
557
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -0800558 @Override
559 public String toString() {
560 return mSurfaceControl.toString();
561 }
Robert Carre6a83512015-11-03 16:09:21 -0800562}