Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 26 | import static android.view.Surface.SCALING_MODE_FREEZE; |
| 27 | import static android.view.Surface.SCALING_MODE_SCALE_TO_WINDOW; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 28 | |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 29 | import android.graphics.PixelFormat; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 30 | import android.graphics.Point; |
| 31 | import android.graphics.PointF; |
| 32 | import android.graphics.Rect; |
| 33 | import android.graphics.Region; |
| 34 | import android.os.IBinder; |
| 35 | import android.os.Debug; |
| 36 | import android.view.Surface; |
| 37 | import android.view.SurfaceControl; |
| 38 | import android.view.SurfaceSession; |
| 39 | import android.view.WindowContentFrameStats; |
| 40 | import android.view.Surface.OutOfResourcesException; |
| 41 | |
| 42 | import android.util.Slog; |
| 43 | |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 44 | import java.io.FileDescriptor; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 45 | import java.io.PrintWriter; |
| 46 | import java.util.ArrayList; |
| 47 | |
| 48 | class WindowSurfaceController { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 49 | static final String TAG = TAG_WITH_CLASS_NAME ? "WindowSurfaceController" : TAG_WM; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 50 | |
| 51 | final WindowStateAnimator mAnimator; |
| 52 | |
| 53 | private SurfaceControl mSurfaceControl; |
| 54 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 55 | // Should only be set from within setShown(). |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 56 | private boolean mSurfaceShown = false; |
| 57 | private float mSurfaceX = 0; |
| 58 | private float mSurfaceY = 0; |
| 59 | private float mSurfaceW = 0; |
| 60 | private float mSurfaceH = 0; |
| 61 | |
Matthew Bouyack | 8dd88f6 | 2016-10-24 14:01:26 -0700 | [diff] [blame] | 62 | // Initialize to the identity matrix. |
| 63 | private float mLastDsdx = 1; |
| 64 | private float mLastDtdx = 0; |
| 65 | private float mLastDsdy = 0; |
| 66 | private float mLastDtdy = 1; |
| 67 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 68 | private float mSurfaceAlpha = 0; |
| 69 | |
| 70 | private int mSurfaceLayer = 0; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 71 | |
| 72 | // Surface flinger doesn't support crop rectangles where width or height is non-positive. |
| 73 | // However, we need to somehow handle the situation where the cropping would completely hide |
| 74 | // the window. We achieve this by explicitly hiding the surface and not letting it be shown. |
| 75 | private boolean mHiddenForCrop = false; |
Jorim Jaggi | 1eb39b0 | 2016-02-25 13:36:14 -0500 | [diff] [blame] | 76 | |
| 77 | // Initially a surface is hidden after just being created. |
| 78 | private boolean mHiddenForOtherReasons = true; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 79 | private final String title; |
| 80 | |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 81 | private final WindowManagerService mService; |
| 82 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 83 | private final int mWindowType; |
| 84 | private final Session mWindowSession; |
| 85 | |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 86 | public WindowSurfaceController(SurfaceSession s, String name, int w, int h, int format, |
| 87 | int flags, WindowStateAnimator animator, int windowType, int ownerUid) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 88 | mAnimator = animator; |
| 89 | |
| 90 | mSurfaceW = w; |
| 91 | mSurfaceH = h; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 92 | |
| 93 | title = name; |
| 94 | |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 95 | mService = animator.mService; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 96 | final WindowState win = animator.mWin; |
| 97 | mWindowType = windowType; |
| 98 | mWindowSession = win.mSession; |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 99 | |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 100 | // For opaque child windows placed under parent windows, we use a special SurfaceControl |
| 101 | // which mirrors commands to a black-out layer placed one Z-layer below the surface. |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 102 | // This prevents holes to whatever app/wallpaper is underneath. |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 103 | if (win.isChildWindow() && win.mSubLayer < 0 && win.mAppToken != null) { |
| 104 | mSurfaceControl = new SurfaceControlWithBackground( |
| 105 | s, name, w, h, format, flags, win.mAppToken, windowType, ownerUid); |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 106 | } else if (DEBUG_SURFACE_TRACE) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 107 | mSurfaceControl = new SurfaceTrace( |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 108 | s, name, w, h, format, flags, windowType, ownerUid); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 109 | } else { |
| 110 | mSurfaceControl = new SurfaceControl( |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 111 | s, name, w, h, format, flags, windowType, ownerUid); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 112 | } |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 113 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 114 | if (mService.mRoot.mSurfaceTraceEnabled) { |
| 115 | mSurfaceControl = new RemoteSurfaceTrace( |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 116 | mService.mRoot.mSurfaceTraceFd.getFileDescriptor(), mSurfaceControl, win); |
Robert Carr | 3b71624 | 2016-08-16 16:02:21 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | void installRemoteTrace(FileDescriptor fd) { |
| 121 | mSurfaceControl = new RemoteSurfaceTrace(fd, mSurfaceControl, mAnimator.mWin); |
| 122 | } |
| 123 | |
| 124 | void removeRemoteTrace() { |
| 125 | mSurfaceControl = new SurfaceControl(mSurfaceControl); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 129 | private void logSurface(String msg, RuntimeException where) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 130 | String str = " SURFACE " + msg + ": " + title; |
| 131 | if (where != null) { |
| 132 | Slog.i(TAG, str, where); |
| 133 | } else { |
| 134 | Slog.i(TAG, str); |
| 135 | } |
| 136 | } |
| 137 | |
Filip Gruszczynski | 63a35e2 | 2015-11-05 15:38:59 -0800 | [diff] [blame] | 138 | void hideInTransaction(String reason) { |
| 139 | if (SHOW_TRANSACTIONS) logSurface("HIDE ( " + reason + " )", null); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 140 | mHiddenForOtherReasons = true; |
Chong Zhang | 3cc58dd | 2016-04-20 17:45:24 -0700 | [diff] [blame] | 141 | |
| 142 | mAnimator.destroyPreservedSurfaceLocked(); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 143 | updateVisibility(); |
| 144 | } |
| 145 | |
| 146 | private void hideSurface() { |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 147 | if (mSurfaceControl == null) { |
| 148 | return; |
| 149 | } |
| 150 | setShown(false); |
| 151 | try { |
| 152 | mSurfaceControl.hide(); |
| 153 | } catch (RuntimeException e) { |
| 154 | Slog.w(TAG, "Exception hiding surface in " + this); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
| 158 | void setPositionAndLayer(float left, float top, int layerStack, int layer) { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 159 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 160 | try { |
| 161 | mSurfaceX = left; |
| 162 | mSurfaceY = top; |
| 163 | |
| 164 | try { |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 165 | if (SHOW_TRANSACTIONS) logSurface( |
| 166 | "POS (setPositionAndLayer) @ (" + left + "," + top + ")", null); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 167 | mSurfaceControl.setPosition(left, top); |
| 168 | mSurfaceControl.setLayerStack(layerStack); |
| 169 | |
| 170 | mSurfaceControl.setLayer(layer); |
| 171 | mSurfaceControl.setAlpha(0); |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 172 | setShown(false); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 173 | } catch (RuntimeException e) { |
| 174 | Slog.w(TAG, "Error creating surface in " + this, e); |
| 175 | mAnimator.reclaimSomeSurfaceMemory("create-init", true); |
| 176 | } |
| 177 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 178 | mService.closeSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 179 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 180 | "<<< CLOSE TRANSACTION setPositionAndLayer"); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void destroyInTransaction() { |
Chong Zhang | ad23b3f | 2016-08-31 16:05:27 -0700 | [diff] [blame] | 185 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 186 | Slog.i(TAG, "Destroying surface " + this + " called by " + Debug.getCallers(8)); |
| 187 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 188 | try { |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 189 | if (mSurfaceControl != null) { |
| 190 | mSurfaceControl.destroy(); |
| 191 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 192 | } catch (RuntimeException e) { |
| 193 | Slog.w(TAG, "Error destroying surface in: " + this, e); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 194 | } finally { |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 195 | setShown(false); |
Wale Ogunwale | 722ff89 | 2016-02-18 13:37:55 -0800 | [diff] [blame] | 196 | mSurfaceControl = null; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Chong Zhang | 47e36a3 | 2016-02-29 16:44:33 -0800 | [diff] [blame] | 200 | void disconnectInTransaction() { |
| 201 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) { |
| 202 | Slog.i(TAG, "Disconnecting client: " + this); |
| 203 | } |
| 204 | |
| 205 | try { |
| 206 | if (mSurfaceControl != null) { |
| 207 | mSurfaceControl.disconnect(); |
| 208 | } |
| 209 | } catch (RuntimeException e) { |
| 210 | Slog.w(TAG, "Error disconnecting surface in: " + this, e); |
| 211 | } |
| 212 | } |
| 213 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 214 | void setCropInTransaction(Rect clipRect, boolean recoveringMemory) { |
| 215 | if (SHOW_TRANSACTIONS) logSurface( |
| 216 | "CROP " + clipRect.toShortString(), null); |
| 217 | try { |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 218 | if (clipRect.width() > 0 && clipRect.height() > 0) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 219 | mSurfaceControl.setWindowCrop(clipRect); |
| 220 | mHiddenForCrop = false; |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 221 | updateVisibility(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 222 | } else { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 223 | mHiddenForCrop = true; |
Chong Zhang | 3cc58dd | 2016-04-20 17:45:24 -0700 | [diff] [blame] | 224 | mAnimator.destroyPreservedSurfaceLocked(); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 225 | updateVisibility(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 226 | } |
| 227 | } catch (RuntimeException e) { |
| 228 | Slog.w(TAG, "Error setting crop surface of " + this |
| 229 | + " crop=" + clipRect.toShortString(), e); |
| 230 | if (!recoveringMemory) { |
| 231 | mAnimator.reclaimSomeSurfaceMemory("crop", true); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
Robert Carr | 4320d33 | 2016-06-10 15:13:32 -0700 | [diff] [blame] | 236 | void clearCropInTransaction(boolean recoveringMemory) { |
| 237 | if (SHOW_TRANSACTIONS) logSurface( |
| 238 | "CLEAR CROP", null); |
| 239 | try { |
| 240 | Rect clipRect = new Rect(0, 0, -1, -1); |
| 241 | mSurfaceControl.setWindowCrop(clipRect); |
| 242 | } catch (RuntimeException e) { |
| 243 | Slog.w(TAG, "Error setting clearing crop of " + this, e); |
| 244 | if (!recoveringMemory) { |
| 245 | mAnimator.reclaimSomeSurfaceMemory("crop", true); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 250 | void setFinalCropInTransaction(Rect clipRect) { |
| 251 | if (SHOW_TRANSACTIONS) logSurface( |
| 252 | "FINAL CROP " + clipRect.toShortString(), null); |
| 253 | try { |
| 254 | mSurfaceControl.setFinalCrop(clipRect); |
| 255 | } catch (RuntimeException e) { |
| 256 | Slog.w(TAG, "Error disconnecting surface in: " + this, e); |
| 257 | } |
| 258 | } |
| 259 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 260 | void setLayer(int layer) { |
| 261 | if (mSurfaceControl != null) { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 262 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 263 | try { |
| 264 | mSurfaceControl.setLayer(layer); |
| 265 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 266 | mService.closeSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | void setPositionInTransaction(float left, float top, boolean recoveringMemory) { |
| 272 | final boolean surfaceMoved = mSurfaceX != left || mSurfaceY != top; |
| 273 | if (surfaceMoved) { |
| 274 | mSurfaceX = left; |
| 275 | mSurfaceY = top; |
| 276 | |
| 277 | try { |
Chong Zhang | ae35fef | 2016-03-16 15:56:55 -0700 | [diff] [blame] | 278 | if (SHOW_TRANSACTIONS) logSurface( |
| 279 | "POS (setPositionInTransaction) @ (" + left + "," + top + ")", null); |
| 280 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 281 | mSurfaceControl.setPosition(left, top); |
| 282 | } catch (RuntimeException e) { |
| 283 | Slog.w(TAG, "Error positioning surface of " + this |
| 284 | + " pos=(" + left + "," + top + ")", e); |
| 285 | if (!recoveringMemory) { |
| 286 | mAnimator.reclaimSomeSurfaceMemory("position", true); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 292 | void setGeometryAppliesWithResizeInTransaction(boolean recoveringMemory) { |
| 293 | mSurfaceControl.setGeometryAppliesWithResize(); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 296 | void setMatrixInTransaction(float dsdx, float dtdx, float dsdy, float dtdy, |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 297 | boolean recoveringMemory) { |
Matthew Bouyack | 8dd88f6 | 2016-10-24 14:01:26 -0700 | [diff] [blame] | 298 | final boolean matrixChanged = mLastDsdx != dsdx || mLastDtdx != dtdx || |
| 299 | mLastDsdy != dsdy || mLastDtdy != dtdy; |
| 300 | if (!matrixChanged) { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | mLastDsdx = dsdx; |
| 305 | mLastDtdx = dtdx; |
| 306 | mLastDsdy = dsdy; |
| 307 | mLastDtdy = dtdy; |
| 308 | |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 309 | try { |
| 310 | if (SHOW_TRANSACTIONS) logSurface( |
| 311 | "MATRIX [" + dsdx + "," + dtdx + "," + dsdy + "," + dtdy + "]", null); |
| 312 | mSurfaceControl.setMatrix( |
| 313 | dsdx, dtdx, dsdy, dtdy); |
| 314 | } catch (RuntimeException e) { |
| 315 | // If something goes wrong with the surface (such |
| 316 | // as running out of memory), don't take down the |
| 317 | // entire system. |
| 318 | Slog.e(TAG, "Error setting matrix on surface surface" + title |
| 319 | + " MATRIX [" + dsdx + "," + dtdx + "," + dsdy + "," + dtdy + "]", null); |
| 320 | if (!recoveringMemory) { |
| 321 | mAnimator.reclaimSomeSurfaceMemory("matrix", true); |
| 322 | } |
| 323 | } |
Robert Carr | e1034cc3 | 2016-02-01 13:08:15 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | boolean setSizeInTransaction(int width, int height, boolean recoveringMemory) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 327 | final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height; |
| 328 | if (surfaceResized) { |
| 329 | mSurfaceW = width; |
| 330 | mSurfaceH = height; |
| 331 | |
| 332 | try { |
| 333 | if (SHOW_TRANSACTIONS) logSurface( |
| 334 | "SIZE " + width + "x" + height, null); |
| 335 | mSurfaceControl.setSize(width, height); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 336 | } catch (RuntimeException e) { |
| 337 | // If something goes wrong with the surface (such |
| 338 | // as running out of memory), don't take down the |
| 339 | // entire system. |
| 340 | Slog.e(TAG, "Error resizing surface of " + title |
| 341 | + " size=(" + width + "x" + height + ")", e); |
| 342 | if (!recoveringMemory) { |
| 343 | mAnimator.reclaimSomeSurfaceMemory("size", true); |
| 344 | } |
| 345 | return false; |
| 346 | } |
| 347 | return true; |
| 348 | } |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | boolean prepareToShowInTransaction(float alpha, int layer, float dsdx, float dtdx, float dsdy, |
| 353 | float dtdy, boolean recoveringMemory) { |
| 354 | if (mSurfaceControl != null) { |
| 355 | try { |
| 356 | mSurfaceAlpha = alpha; |
| 357 | mSurfaceControl.setAlpha(alpha); |
| 358 | mSurfaceLayer = layer; |
| 359 | mSurfaceControl.setLayer(layer); |
Matthew Bouyack | 8dd88f6 | 2016-10-24 14:01:26 -0700 | [diff] [blame] | 360 | mLastDsdx = dsdx; |
| 361 | mLastDtdx = dtdx; |
| 362 | mLastDsdy = dsdy; |
| 363 | mLastDtdy = dtdy; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 364 | mSurfaceControl.setMatrix( |
| 365 | dsdx, dtdx, dsdy, dtdy); |
| 366 | |
| 367 | } catch (RuntimeException e) { |
| 368 | Slog.w(TAG, "Error updating surface in " + title, e); |
| 369 | if (!recoveringMemory) { |
| 370 | mAnimator.reclaimSomeSurfaceMemory("update", true); |
| 371 | } |
| 372 | return false; |
| 373 | } |
| 374 | } |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | void setTransparentRegionHint(final Region region) { |
| 379 | if (mSurfaceControl == null) { |
| 380 | Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true"); |
| 381 | return; |
| 382 | } |
| 383 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 384 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 385 | try { |
| 386 | mSurfaceControl.setTransparentRegionHint(region); |
| 387 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 388 | mService.closeSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 389 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, |
| 390 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | void setOpaque(boolean isOpaque) { |
| 395 | if (SHOW_TRANSACTIONS) logSurface("isOpaque=" + isOpaque, |
| 396 | null); |
| 397 | |
| 398 | if (mSurfaceControl == null) { |
| 399 | return; |
| 400 | } |
| 401 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaqueLocked"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 402 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 403 | try { |
| 404 | mSurfaceControl.setOpaque(isOpaque); |
| 405 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 406 | mService.closeSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 407 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaqueLocked"); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void setSecure(boolean isSecure) { |
| 412 | if (SHOW_TRANSACTIONS) logSurface("isSecure=" + isSecure, |
| 413 | null); |
| 414 | |
| 415 | if (mSurfaceControl == null) { |
| 416 | return; |
| 417 | } |
| 418 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked"); |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 419 | mService.openSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 420 | try { |
| 421 | mSurfaceControl.setSecure(isSecure); |
| 422 | } finally { |
Robert Carr | 68e5c9e | 2016-09-14 10:50:09 -0700 | [diff] [blame] | 423 | mService.closeSurfaceTransaction(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 424 | if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked"); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | boolean showRobustlyInTransaction() { |
Filip Gruszczynski | 19723a4 | 2015-11-25 15:01:48 -0800 | [diff] [blame] | 429 | if (SHOW_TRANSACTIONS) logSurface( |
| 430 | "SHOW (performLayout)", null); |
| 431 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| 432 | + " during relayout"); |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 433 | mHiddenForOtherReasons = false; |
| 434 | return updateVisibility(); |
| 435 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 436 | |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 437 | private boolean updateVisibility() { |
| 438 | if (mHiddenForCrop || mHiddenForOtherReasons) { |
| 439 | if (mSurfaceShown) { |
| 440 | hideSurface(); |
| 441 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 442 | return false; |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 443 | } else { |
| 444 | if (!mSurfaceShown) { |
| 445 | return showSurface(); |
| 446 | } else { |
| 447 | return true; |
| 448 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 449 | } |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 450 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 451 | |
Jorim Jaggi | 5e6968d | 2016-02-19 18:02:13 -0800 | [diff] [blame] | 452 | private boolean showSurface() { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 453 | try { |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 454 | setShown(true); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 455 | mSurfaceControl.show(); |
| 456 | return true; |
| 457 | } catch (RuntimeException e) { |
| 458 | Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + this, e); |
| 459 | } |
| 460 | |
| 461 | mAnimator.reclaimSomeSurfaceMemory("show", true); |
| 462 | |
| 463 | return false; |
| 464 | } |
| 465 | |
| 466 | void deferTransactionUntil(IBinder handle, long frame) { |
| 467 | // TODO: Logging |
| 468 | mSurfaceControl.deferTransactionUntil(handle, frame); |
| 469 | } |
| 470 | |
Robert Carr | 1ca6a33 | 2016-04-11 18:00:43 -0700 | [diff] [blame] | 471 | void forceScaleableInTransaction(boolean force) { |
| 472 | // -1 means we don't override the default or client specified |
| 473 | // scaling mode. |
| 474 | int scalingMode = force ? SCALING_MODE_SCALE_TO_WINDOW : -1; |
| 475 | mSurfaceControl.setOverrideScalingMode(scalingMode); |
| 476 | } |
| 477 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 478 | boolean clearWindowContentFrameStats() { |
| 479 | if (mSurfaceControl == null) { |
| 480 | return false; |
| 481 | } |
| 482 | return mSurfaceControl.clearContentFrameStats(); |
| 483 | } |
| 484 | |
| 485 | boolean getWindowContentFrameStats(WindowContentFrameStats outStats) { |
| 486 | if (mSurfaceControl == null) { |
| 487 | return false; |
| 488 | } |
| 489 | return mSurfaceControl.getContentFrameStats(outStats); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | boolean hasSurface() { |
| 494 | return mSurfaceControl != null; |
| 495 | } |
| 496 | |
| 497 | IBinder getHandle() { |
| 498 | if (mSurfaceControl == null) { |
| 499 | return null; |
| 500 | } |
| 501 | return mSurfaceControl.getHandle(); |
| 502 | } |
| 503 | |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 504 | boolean getTransformToDisplayInverse() { |
| 505 | return mSurfaceControl.getTransformToDisplayInverse(); |
| 506 | } |
| 507 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 508 | void getSurface(Surface outSurface) { |
| 509 | outSurface.copyFrom(mSurfaceControl); |
| 510 | } |
| 511 | |
| 512 | int getLayer() { |
| 513 | return mSurfaceLayer; |
| 514 | } |
| 515 | |
| 516 | boolean getShown() { |
| 517 | return mSurfaceShown; |
| 518 | } |
| 519 | |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 520 | void setShown(boolean surfaceShown) { |
| 521 | mSurfaceShown = surfaceShown; |
Wale Ogunwale | 943002b | 2017-02-15 19:34:01 -0800 | [diff] [blame] | 522 | |
| 523 | if (mWindowSession != null) { |
| 524 | mWindowSession.onWindowSurfaceVisibilityChanged(this, mSurfaceShown, mWindowType); |
| 525 | } |
Filip Gruszczynski | 10a80e0 | 2015-11-06 09:21:17 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 528 | float getX() { |
| 529 | return mSurfaceX; |
| 530 | } |
| 531 | |
| 532 | float getY() { |
| 533 | return mSurfaceY; |
| 534 | } |
| 535 | |
Robert Carr | fed1007 | 2016-05-26 11:48:49 -0700 | [diff] [blame] | 536 | float getWidth() { |
| 537 | return mSurfaceW; |
| 538 | } |
| 539 | |
| 540 | float getHeight() { |
| 541 | return mSurfaceH; |
| 542 | } |
| 543 | |
| 544 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 545 | public void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 546 | if (dumpAll) { |
| 547 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl); |
| 548 | } |
| 549 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 550 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 551 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 552 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 553 | pw.print(","); pw.print(mSurfaceY); |
| 554 | pw.print(") "); pw.print(mSurfaceW); |
| 555 | pw.print(" x "); pw.println(mSurfaceH); |
| 556 | } |
| 557 | |
Filip Gruszczynski | 78a08ee | 2015-11-08 18:04:32 -0800 | [diff] [blame] | 558 | @Override |
| 559 | public String toString() { |
| 560 | return mSurfaceControl.toString(); |
| 561 | } |
| 562 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 563 | static class SurfaceTrace extends SurfaceControl { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 564 | private final static String SURFACE_TAG = TAG_WITH_CLASS_NAME ? "SurfaceTrace" : TAG_WM; |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 565 | private final static boolean LOG_SURFACE_TRACE = DEBUG_SURFACE_TRACE; |
| 566 | final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>(); |
| 567 | |
| 568 | private float mSurfaceTraceAlpha = 0; |
| 569 | private int mLayer; |
| 570 | private final PointF mPosition = new PointF(); |
| 571 | private final Point mSize = new Point(); |
| 572 | private final Rect mWindowCrop = new Rect(); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 573 | private final Rect mFinalCrop = new Rect(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 574 | private boolean mShown = false; |
| 575 | private int mLayerStack; |
| 576 | private boolean mIsOpaque; |
| 577 | private float mDsdx, mDtdx, mDsdy, mDtdy; |
| 578 | private final String mName; |
| 579 | |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 580 | public SurfaceTrace(SurfaceSession s, String name, int w, int h, int format, int flags, |
| 581 | int windowType, int ownerUid) |
| 582 | throws OutOfResourcesException { |
| 583 | super(s, name, w, h, format, flags, windowType, ownerUid); |
| 584 | mName = name != null ? name : "Not named"; |
| 585 | mSize.set(w, h); |
| 586 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by " |
| 587 | + Debug.getCallers(3)); |
| 588 | synchronized (sSurfaces) { |
| 589 | sSurfaces.add(0, this); |
| 590 | } |
| 591 | } |
| 592 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 593 | public SurfaceTrace(SurfaceSession s, |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 594 | String name, int w, int h, int format, int flags) { |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 595 | super(s, name, w, h, format, flags); |
| 596 | mName = name != null ? name : "Not named"; |
| 597 | mSize.set(w, h); |
| 598 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by " |
| 599 | + Debug.getCallers(3)); |
| 600 | synchronized (sSurfaces) { |
| 601 | sSurfaces.add(0, this); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public void setAlpha(float alpha) { |
| 607 | if (mSurfaceTraceAlpha != alpha) { |
| 608 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + |
| 609 | ". Called by " + Debug.getCallers(3)); |
| 610 | mSurfaceTraceAlpha = alpha; |
| 611 | } |
| 612 | super.setAlpha(alpha); |
| 613 | } |
| 614 | |
| 615 | @Override |
| 616 | public void setLayer(int zorder) { |
| 617 | if (zorder != mLayer) { |
| 618 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this |
| 619 | + ". Called by " + Debug.getCallers(3)); |
| 620 | mLayer = zorder; |
| 621 | } |
| 622 | super.setLayer(zorder); |
| 623 | |
| 624 | synchronized (sSurfaces) { |
| 625 | sSurfaces.remove(this); |
| 626 | int i; |
| 627 | for (i = sSurfaces.size() - 1; i >= 0; i--) { |
| 628 | SurfaceTrace s = sSurfaces.get(i); |
| 629 | if (s.mLayer < zorder) { |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | sSurfaces.add(i + 1, this); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | @Override |
| 638 | public void setPosition(float x, float y) { |
| 639 | if (x != mPosition.x || y != mPosition.y) { |
| 640 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" |
| 641 | + this + ". Called by " + Debug.getCallers(3)); |
| 642 | mPosition.set(x, y); |
| 643 | } |
| 644 | super.setPosition(x, y); |
| 645 | } |
| 646 | |
| 647 | @Override |
Robert Carr | 6da3cc0 | 2016-06-16 15:17:07 -0700 | [diff] [blame] | 648 | public void setGeometryAppliesWithResize() { |
| 649 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setGeometryAppliesWithResize(): OLD: " |
| 650 | + this + ". Called by" + Debug.getCallers(3)); |
| 651 | super.setGeometryAppliesWithResize(); |
Robert Carr | a9408d4 | 2016-06-03 13:28:48 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | @Override |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 655 | public void setSize(int w, int h) { |
| 656 | if (w != mSize.x || h != mSize.y) { |
| 657 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" |
| 658 | + this + ". Called by " + Debug.getCallers(3)); |
| 659 | mSize.set(w, h); |
| 660 | } |
| 661 | super.setSize(w, h); |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public void setWindowCrop(Rect crop) { |
| 666 | if (crop != null) { |
| 667 | if (!crop.equals(mWindowCrop)) { |
| 668 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setWindowCrop(" |
| 669 | + crop.toShortString() + "): OLD:" + this + ". Called by " |
| 670 | + Debug.getCallers(3)); |
| 671 | mWindowCrop.set(crop); |
| 672 | } |
| 673 | } |
| 674 | super.setWindowCrop(crop); |
| 675 | } |
| 676 | |
| 677 | @Override |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 678 | public void setFinalCrop(Rect crop) { |
| 679 | if (crop != null) { |
| 680 | if (!crop.equals(mFinalCrop)) { |
| 681 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setFinalCrop(" |
| 682 | + crop.toShortString() + "): OLD:" + this + ". Called by " |
| 683 | + Debug.getCallers(3)); |
| 684 | mFinalCrop.set(crop); |
| 685 | } |
| 686 | } |
| 687 | super.setFinalCrop(crop); |
| 688 | } |
| 689 | |
| 690 | @Override |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 691 | public void setLayerStack(int layerStack) { |
| 692 | if (layerStack != mLayerStack) { |
| 693 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" |
| 694 | + this + ". Called by " + Debug.getCallers(3)); |
| 695 | mLayerStack = layerStack; |
| 696 | } |
| 697 | super.setLayerStack(layerStack); |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public void setOpaque(boolean isOpaque) { |
| 702 | if (isOpaque != mIsOpaque) { |
| 703 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:" |
| 704 | + this + ". Called by " + Debug.getCallers(3)); |
| 705 | mIsOpaque = isOpaque; |
| 706 | } |
| 707 | super.setOpaque(isOpaque); |
| 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public void setSecure(boolean isSecure) { |
| 712 | super.setSecure(isSecure); |
| 713 | } |
| 714 | |
| 715 | @Override |
| 716 | public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 717 | if (dsdx != mDsdx || dtdx != mDtdx || dsdy != mDsdy || dtdy != mDtdy) { |
| 718 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setMatrix(" + dsdx + "," + dtdx + "," |
| 719 | + dsdy + "," + dtdy + "): OLD:" + this + ". Called by " |
| 720 | + Debug.getCallers(3)); |
| 721 | mDsdx = dsdx; |
| 722 | mDtdx = dtdx; |
| 723 | mDsdy = dsdy; |
| 724 | mDtdy = dtdy; |
| 725 | } |
| 726 | super.setMatrix(dsdx, dtdx, dsdy, dtdy); |
| 727 | } |
| 728 | |
| 729 | @Override |
| 730 | public void hide() { |
| 731 | if (mShown) { |
| 732 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " |
| 733 | + Debug.getCallers(3)); |
| 734 | mShown = false; |
| 735 | } |
| 736 | super.hide(); |
| 737 | } |
| 738 | |
| 739 | @Override |
| 740 | public void show() { |
| 741 | if (!mShown) { |
| 742 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " |
| 743 | + Debug.getCallers(3)); |
| 744 | mShown = true; |
| 745 | } |
| 746 | super.show(); |
| 747 | } |
| 748 | |
| 749 | @Override |
| 750 | public void destroy() { |
| 751 | super.destroy(); |
| 752 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " |
| 753 | + Debug.getCallers(3)); |
| 754 | synchronized (sSurfaces) { |
| 755 | sSurfaces.remove(this); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public void release() { |
| 761 | super.release(); |
| 762 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "release: " + this + ". Called by " |
| 763 | + Debug.getCallers(3)); |
| 764 | synchronized (sSurfaces) { |
| 765 | sSurfaces.remove(this); |
| 766 | } |
| 767 | } |
| 768 | |
Robert Carr | 6a19b4f | 2016-03-14 19:17:20 -0700 | [diff] [blame] | 769 | @Override |
| 770 | public void setTransparentRegionHint(Region region) { |
| 771 | if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "setTransparentRegionHint(" + region |
| 772 | + "): OLD: " + this + " . Called by " + Debug.getCallers(3)); |
| 773 | super.setTransparentRegionHint(region); |
| 774 | } |
| 775 | |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 776 | static void dumpAllSurfaces(PrintWriter pw, String header) { |
| 777 | synchronized (sSurfaces) { |
| 778 | final int N = sSurfaces.size(); |
| 779 | if (N <= 0) { |
| 780 | return; |
| 781 | } |
| 782 | if (header != null) { |
| 783 | pw.println(header); |
| 784 | } |
| 785 | pw.println("WINDOW MANAGER SURFACES (dumpsys window surfaces)"); |
| 786 | for (int i = 0; i < N; i++) { |
| 787 | SurfaceTrace s = sSurfaces.get(i); |
| 788 | pw.print(" Surface #"); pw.print(i); pw.print(": #"); |
| 789 | pw.print(Integer.toHexString(System.identityHashCode(s))); |
| 790 | pw.print(" "); pw.println(s.mName); |
| 791 | pw.print(" mLayerStack="); pw.print(s.mLayerStack); |
| 792 | pw.print(" mLayer="); pw.println(s.mLayer); |
| 793 | pw.print(" mShown="); pw.print(s.mShown); pw.print(" mAlpha="); |
| 794 | pw.print(s.mSurfaceTraceAlpha); pw.print(" mIsOpaque="); |
| 795 | pw.println(s.mIsOpaque); |
| 796 | pw.print(" mPosition="); pw.print(s.mPosition.x); pw.print(","); |
| 797 | pw.print(s.mPosition.y); |
| 798 | pw.print(" mSize="); pw.print(s.mSize.x); pw.print("x"); |
| 799 | pw.println(s.mSize.y); |
| 800 | pw.print(" mCrop="); s.mWindowCrop.printShortString(pw); pw.println(); |
Jorim Jaggi | 6a7c90a | 2016-03-11 15:04:59 +0100 | [diff] [blame] | 801 | pw.print(" mFinalCrop="); s.mFinalCrop.printShortString(pw); pw.println(); |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 802 | pw.print(" Transform: ("); pw.print(s.mDsdx); pw.print(", "); |
| 803 | pw.print(s.mDtdx); pw.print(", "); pw.print(s.mDsdy); |
| 804 | pw.print(", "); pw.print(s.mDtdy); pw.println(")"); |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | @Override |
| 810 | public String toString() { |
| 811 | return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " " |
| 812 | + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer |
| 813 | + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y |
| 814 | + " " + mSize.x + "x" + mSize.y |
| 815 | + " crop=" + mWindowCrop.toShortString() |
| 816 | + " opaque=" + mIsOpaque |
| 817 | + " (" + mDsdx + "," + mDtdx + "," + mDsdy + "," + mDtdy + ")"; |
| 818 | } |
| 819 | } |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 820 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 821 | class SurfaceControlWithBackground extends SurfaceControl { |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 822 | private SurfaceControl mBackgroundControl; |
| 823 | private boolean mOpaque = true; |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 824 | private boolean mAppForcedInvisible = false; |
| 825 | private AppWindowToken mAppToken; |
| 826 | public boolean mVisible = false; |
| 827 | public int mLayer = -1; |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 828 | |
Albert Chaulk | 3bf2e57 | 2016-11-22 13:59:19 -0500 | [diff] [blame] | 829 | public SurfaceControlWithBackground(SurfaceSession s, String name, int w, int h, int format, |
| 830 | int flags, AppWindowToken token, int windowType, int ownerUid) |
| 831 | throws OutOfResourcesException { |
| 832 | super(s, name, w, h, format, flags, windowType, ownerUid); |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 833 | mBackgroundControl = new SurfaceControl(s, name, w, h, |
| 834 | PixelFormat.OPAQUE, flags | SurfaceControl.FX_SURFACE_DIM); |
| 835 | mOpaque = (flags & SurfaceControl.OPAQUE) != 0; |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 836 | mAppToken = token; |
| 837 | |
| 838 | mAppToken.addSurfaceViewBackground(this); |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | @Override |
| 842 | public void setAlpha(float alpha) { |
| 843 | super.setAlpha(alpha); |
| 844 | mBackgroundControl.setAlpha(alpha); |
| 845 | } |
| 846 | |
| 847 | @Override |
| 848 | public void setLayer(int zorder) { |
| 849 | super.setLayer(zorder); |
| 850 | mBackgroundControl.setLayer(zorder - 1); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 851 | if (mLayer != zorder) { |
| 852 | mLayer = zorder; |
| 853 | mAppToken.updateSurfaceViewBackgroundVisibilities(); |
| 854 | } |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | @Override |
| 858 | public void setPosition(float x, float y) { |
| 859 | super.setPosition(x, y); |
| 860 | mBackgroundControl.setPosition(x, y); |
| 861 | } |
| 862 | |
| 863 | @Override |
| 864 | public void setSize(int w, int h) { |
| 865 | super.setSize(w, h); |
| 866 | mBackgroundControl.setSize(w, h); |
| 867 | } |
| 868 | |
| 869 | @Override |
| 870 | public void setWindowCrop(Rect crop) { |
| 871 | super.setWindowCrop(crop); |
| 872 | mBackgroundControl.setWindowCrop(crop); |
| 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public void setFinalCrop(Rect crop) { |
| 877 | super.setFinalCrop(crop); |
| 878 | mBackgroundControl.setFinalCrop(crop); |
| 879 | } |
| 880 | |
| 881 | @Override |
| 882 | public void setLayerStack(int layerStack) { |
| 883 | super.setLayerStack(layerStack); |
| 884 | mBackgroundControl.setLayerStack(layerStack); |
| 885 | } |
| 886 | |
| 887 | @Override |
| 888 | public void setOpaque(boolean isOpaque) { |
| 889 | super.setOpaque(isOpaque); |
| 890 | mOpaque = isOpaque; |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 891 | updateBackgroundVisibility(mAppForcedInvisible); |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | @Override |
| 895 | public void setSecure(boolean isSecure) { |
| 896 | super.setSecure(isSecure); |
| 897 | } |
| 898 | |
| 899 | @Override |
| 900 | public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 901 | super.setMatrix(dsdx, dtdx, dsdy, dtdy); |
| 902 | mBackgroundControl.setMatrix(dsdx, dtdx, dsdy, dtdy); |
| 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public void hide() { |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 907 | super.hide(); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 908 | if (mVisible) { |
| 909 | mVisible = false; |
| 910 | mAppToken.updateSurfaceViewBackgroundVisibilities(); |
| 911 | } |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | @Override |
| 915 | public void show() { |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 916 | super.show(); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 917 | if (!mVisible) { |
| 918 | mVisible = true; |
| 919 | mAppToken.updateSurfaceViewBackgroundVisibilities(); |
| 920 | } |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public void destroy() { |
| 925 | super.destroy(); |
| 926 | mBackgroundControl.destroy(); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 927 | mAppToken.removeSurfaceViewBackground(this); |
| 928 | } |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 929 | |
| 930 | @Override |
| 931 | public void release() { |
| 932 | super.release(); |
| 933 | mBackgroundControl.release(); |
| 934 | } |
| 935 | |
| 936 | @Override |
| 937 | public void setTransparentRegionHint(Region region) { |
| 938 | super.setTransparentRegionHint(region); |
| 939 | mBackgroundControl.setTransparentRegionHint(region); |
| 940 | } |
| 941 | |
| 942 | @Override |
| 943 | public void deferTransactionUntil(IBinder handle, long frame) { |
| 944 | super.deferTransactionUntil(handle, frame); |
| 945 | mBackgroundControl.deferTransactionUntil(handle, frame); |
| 946 | } |
| 947 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 948 | void updateBackgroundVisibility(boolean forcedInvisible) { |
| 949 | mAppForcedInvisible = forcedInvisible; |
| 950 | if (mOpaque && mVisible && !mAppForcedInvisible) { |
Robert Carr | 086d292 | 2016-06-09 10:22:38 -0700 | [diff] [blame] | 951 | mBackgroundControl.show(); |
| 952 | } else { |
| 953 | mBackgroundControl.hide(); |
| 954 | } |
| 955 | } |
| 956 | } |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 957 | } |