Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 19 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC; |
| 20 | import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 22 | |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 23 | import android.graphics.Matrix; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
| 25 | import android.util.Slog; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 26 | import android.view.Surface.OutOfResourcesException; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 27 | import android.view.SurfaceControl; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 28 | |
Vishnu Nair | a1d1481 | 2018-10-26 08:14:02 -0700 | [diff] [blame] | 29 | import java.io.PrintWriter; |
| 30 | |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Four black surfaces put together to make a black frame. |
| 33 | */ |
| 34 | public class BlackFrame { |
| 35 | class BlackSurface { |
| 36 | final int left; |
| 37 | final int top; |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 38 | final int layer; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 39 | final SurfaceControl surface; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 40 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 41 | BlackSurface(SurfaceControl.Transaction transaction, int layer, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 42 | int l, int t, int r, int b, DisplayContent dc) throws OutOfResourcesException { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 43 | left = l; |
| 44 | top = t; |
Craig Mautner | 2fb98b1 | 2012-03-20 17:24:00 -0700 | [diff] [blame] | 45 | this.layer = layer; |
Dianne Hackborn | 91c9ac0 | 2011-07-21 21:52:09 -0700 | [diff] [blame] | 46 | int w = r-l; |
| 47 | int h = b-t; |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 48 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 49 | surface = dc.makeOverlay() |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 50 | .setName("BlackSurface") |
Chavi Weingarten | 6ef9cc6 | 2019-02-07 16:28:45 +0000 | [diff] [blame] | 51 | .setColorLayer() |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 52 | .setParent(null) // TODO: Work-around for b/69259549 |
Robert Carr | e625fcf | 2017-09-01 12:36:28 -0700 | [diff] [blame] | 53 | .build(); |
Vishnu Nair | d454442d | 2018-11-13 13:51:01 -0800 | [diff] [blame] | 54 | transaction.setWindowCrop(surface, w, h); |
Riddle Hsu | 654a6f9 | 2018-07-13 22:59:36 +0800 | [diff] [blame] | 55 | transaction.setLayerStack(surface, dc.getDisplayId()); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 56 | transaction.setAlpha(surface, 1); |
| 57 | transaction.setLayer(surface, layer); |
Vishnu Nair | a1d1481 | 2018-10-26 08:14:02 -0700 | [diff] [blame] | 58 | transaction.setPosition(surface, left, top); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 59 | transaction.show(surface); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 60 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM, |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 61 | " BLACK " + surface + ": CREATE layer=" + layer); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 64 | void setAlpha(SurfaceControl.Transaction t, float alpha) { |
| 65 | t.setAlpha(surface, alpha); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 68 | void setMatrix(SurfaceControl.Transaction t, Matrix matrix) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 69 | mTmpMatrix.setTranslate(left, top); |
| 70 | mTmpMatrix.postConcat(matrix); |
| 71 | mTmpMatrix.getValues(mTmpFloats); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 72 | t.setPosition(surface, mTmpFloats[Matrix.MTRANS_X], |
Dianne Hackborn | d040edb | 2011-08-31 12:47:58 -0700 | [diff] [blame] | 73 | mTmpFloats[Matrix.MTRANS_Y]); |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 74 | t.setMatrix(surface, |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 75 | mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y], |
| 76 | mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]); |
| 77 | if (false) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 78 | Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): (" |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 79 | + mTmpFloats[Matrix.MTRANS_X] + "," |
| 80 | + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=[" |
| 81 | + mTmpFloats[Matrix.MSCALE_X] + "," |
| 82 | + mTmpFloats[Matrix.MSCALE_Y] + "][" |
| 83 | + mTmpFloats[Matrix.MSKEW_X] + "," |
| 84 | + mTmpFloats[Matrix.MSKEW_Y] + "]"); |
| 85 | } |
| 86 | } |
| 87 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 88 | void clearMatrix(SurfaceControl.Transaction t) { |
| 89 | t.setMatrix(surface, 1, 0, 0, 1); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 93 | final Rect mOuterRect; |
| 94 | final Rect mInnerRect; |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 95 | final Matrix mTmpMatrix = new Matrix(); |
| 96 | final float[] mTmpFloats = new float[9]; |
| 97 | final BlackSurface[] mBlackSurfaces = new BlackSurface[4]; |
| 98 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 99 | final boolean mForceDefaultOrientation; |
| 100 | |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 101 | public void printTo(String prefix, PrintWriter pw) { |
| 102 | pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw); |
| 103 | pw.print(" / Inner: "); mInnerRect.printShortString(pw); |
| 104 | pw.println(); |
| 105 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 106 | BlackSurface bs = mBlackSurfaces[i]; |
| 107 | pw.print(prefix); pw.print("#"); pw.print(i); |
| 108 | pw.print(": "); pw.print(bs.surface); |
| 109 | pw.print(" left="); pw.print(bs.left); |
| 110 | pw.print(" top="); pw.println(bs.top); |
| 111 | } |
| 112 | } |
| 113 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 114 | public BlackFrame(SurfaceControl.Transaction t, |
| 115 | Rect outer, Rect inner, int layer, DisplayContent dc, |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 116 | boolean forceDefaultOrientation) throws OutOfResourcesException { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 117 | boolean success = false; |
| 118 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 119 | mForceDefaultOrientation = forceDefaultOrientation; |
| 120 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 121 | // TODO: Why do we use 4 surfaces instead of just one big one behind the screenshot? |
| 122 | // b/68253229 |
Dianne Hackborn | 9fd7480 | 2012-03-01 19:26:31 -0800 | [diff] [blame] | 123 | mOuterRect = new Rect(outer); |
| 124 | mInnerRect = new Rect(inner); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 125 | try { |
| 126 | if (outer.top < inner.top) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 127 | mBlackSurfaces[0] = new BlackSurface(t, layer, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 128 | outer.left, outer.top, inner.right, inner.top, dc); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 129 | } |
| 130 | if (outer.left < inner.left) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 131 | mBlackSurfaces[1] = new BlackSurface(t, layer, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 132 | outer.left, inner.top, inner.left, outer.bottom, dc); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 133 | } |
| 134 | if (outer.bottom > inner.bottom) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 135 | mBlackSurfaces[2] = new BlackSurface(t, layer, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 136 | inner.left, inner.bottom, outer.right, outer.bottom, dc); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 137 | } |
| 138 | if (outer.right > inner.right) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 139 | mBlackSurfaces[3] = new BlackSurface(t, layer, |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 140 | inner.right, outer.top, outer.right, inner.bottom, dc); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 141 | } |
| 142 | success = true; |
| 143 | } finally { |
| 144 | if (!success) { |
| 145 | kill(); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | public void kill() { |
| 151 | if (mBlackSurfaces != null) { |
| 152 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 153 | if (mBlackSurfaces[i] != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 154 | if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM, |
| 155 | " BLACK " + mBlackSurfaces[i].surface + ": DESTROY"); |
Robert Carr | 5ea304d | 2019-02-04 16:04:55 -0800 | [diff] [blame] | 156 | mBlackSurfaces[i].surface.remove(); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 157 | mBlackSurfaces[i] = null; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 163 | public void hide(SurfaceControl.Transaction t) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 164 | if (mBlackSurfaces != null) { |
| 165 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 166 | if (mBlackSurfaces[i] != null) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 167 | t.hide(mBlackSurfaces[i].surface); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 173 | public void setAlpha(SurfaceControl.Transaction t, float alpha) { |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 174 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 175 | if (mBlackSurfaces[i] != null) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 176 | mBlackSurfaces[i].setAlpha(t, alpha); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 181 | public void setMatrix(SurfaceControl.Transaction t, Matrix matrix) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 182 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 183 | if (mBlackSurfaces[i] != null) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 184 | mBlackSurfaces[i].setMatrix(t, matrix); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 189 | public void clearMatrix(SurfaceControl.Transaction t) { |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 190 | for (int i=0; i<mBlackSurfaces.length; i++) { |
| 191 | if (mBlackSurfaces[i] != null) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 192 | mBlackSurfaces[i].clearMatrix(t); |
Dianne Hackborn | 7916ac6 | 2011-05-16 20:45:48 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |