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