blob: 5aa266d473bd03ae9399fed1ccdfdab7d98ef055 [file] [log] [blame]
Dianne Hackborn7916ac62011-05-16 20:45:48 -07001/*
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
17package com.android.server.wm;
18
Dianne Hackborn9fd74802012-03-01 19:26:31 -080019import java.io.PrintWriter;
20
Dianne Hackborn7916ac62011-05-16 20:45:48 -070021import android.graphics.Matrix;
22import android.graphics.PixelFormat;
23import android.graphics.Rect;
24import android.util.Slog;
Igor Murashkina86ab6402013-08-30 12:58:36 -070025import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080026import android.view.SurfaceControl;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070027import android.view.SurfaceSession;
28
29/**
30 * Four black surfaces put together to make a black frame.
31 */
32public class BlackFrame {
33 class BlackSurface {
34 final int left;
35 final int top;
Craig Mautner2fb98b12012-03-20 17:24:00 -070036 final int layer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080037 final SurfaceControl surface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070038
Craig Mautnerb47bbc32012-08-22 17:41:48 -070039 BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b, int layerStack)
Igor Murashkina86ab6402013-08-30 12:58:36 -070040 throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070041 left = l;
42 top = t;
Craig Mautner2fb98b12012-03-20 17:24:00 -070043 this.layer = layer;
Dianne Hackborn91c9ac02011-07-21 21:52:09 -070044 int w = r-l;
45 int h = b-t;
Mathias Agopian29479eb2013-02-14 14:36:04 -080046
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 Mautner924d9b72012-05-06 13:12:04 -070054 }
Mathias Agopian29479eb2013-02-14 14:36:04 -080055
Craig Mautner924d9b72012-05-06 13:12:04 -070056 surface.setAlpha(1);
Jeff Brown64a55af2012-08-26 02:47:39 -070057 surface.setLayerStack(layerStack);
Craig Mautner924d9b72012-05-06 13:12:04 -070058 surface.setLayer(layer);
59 surface.show();
Dianne Hackborn5fd21692011-06-07 14:09:47 -070060 if (WindowManagerService.SHOW_TRANSACTIONS ||
61 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
62 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070063 }
64
Craig Mautner46ac6fa2013-08-01 10:06:34 -070065 void setAlpha(float alpha) {
66 surface.setAlpha(alpha);
67 }
68
Dianne Hackborn7916ac62011-05-16 20:45:48 -070069 void setMatrix(Matrix matrix) {
70 mTmpMatrix.setTranslate(left, top);
71 mTmpMatrix.postConcat(matrix);
72 mTmpMatrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -070073 surface.setPosition(mTmpFloats[Matrix.MTRANS_X],
74 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070075 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 Hackborn9fd74802012-03-01 19:26:31 -080094 final Rect mOuterRect;
95 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070096 final Matrix mTmpMatrix = new Matrix();
97 final float[] mTmpFloats = new float[9];
98 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
99
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700100 final boolean mForceDefaultOrientation;
101
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800102 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 Mautner46ac6fa2013-08-01 10:06:34 -0700115 public BlackFrame(SurfaceSession session, Rect outer, Rect inner, int layer, int layerStack,
Igor Murashkina86ab6402013-08-30 12:58:36 -0700116 boolean forceDefaultOrientation) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700117 boolean success = false;
118
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700119 mForceDefaultOrientation = forceDefaultOrientation;
120
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800121 mOuterRect = new Rect(outer);
122 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700123 try {
124 if (outer.top < inner.top) {
125 mBlackSurfaces[0] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700126 outer.left, outer.top, inner.right, inner.top, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700127 }
128 if (outer.left < inner.left) {
129 mBlackSurfaces[1] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700130 outer.left, inner.top, inner.left, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700131 }
132 if (outer.bottom > inner.bottom) {
133 mBlackSurfaces[2] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700134 inner.left, inner.bottom, outer.right, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700135 }
136 if (outer.right > inner.right) {
137 mBlackSurfaces[3] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700138 inner.right, outer.top, outer.right, inner.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700139 }
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 Hackborn5fd21692011-06-07 14:09:47 -0700152 if (WindowManagerService.SHOW_TRANSACTIONS ||
153 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(
154 WindowManagerService.TAG,
155 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700156 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 Mautner46ac6fa2013-08-01 10:06:34 -0700173 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 Hackborn7916ac62011-05-16 20:45:48 -0700181 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 Hackborn7916ac62011-05-16 20:45:48 -0700189 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}