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