blob: 5c29a0aabd372827d921cc288a9069e93091caa1 [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
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080019import static android.graphics.PixelFormat.OPAQUE;
20import static android.view.SurfaceControl.FX_SURFACE_DIM;
21import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
22import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
23import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
24import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
25
Dianne Hackborn9fd74802012-03-01 19:26:31 -080026import java.io.PrintWriter;
27
Dianne Hackborn7916ac62011-05-16 20:45:48 -070028import android.graphics.Matrix;
29import android.graphics.PixelFormat;
30import android.graphics.Rect;
31import android.util.Slog;
Igor Murashkina86ab6402013-08-30 12:58:36 -070032import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080033import android.view.SurfaceControl;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070034import android.view.SurfaceSession;
35
36/**
37 * Four black surfaces put together to make a black frame.
38 */
39public class BlackFrame {
40 class BlackSurface {
41 final int left;
42 final int top;
Craig Mautner2fb98b12012-03-20 17:24:00 -070043 final int layer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044 final SurfaceControl surface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070045
Craig Mautnerb47bbc32012-08-22 17:41:48 -070046 BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b, int layerStack)
Igor Murashkina86ab6402013-08-30 12:58:36 -070047 throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070048 left = l;
49 top = t;
Craig Mautner2fb98b12012-03-20 17:24:00 -070050 this.layer = layer;
Dianne Hackborn91c9ac02011-07-21 21:52:09 -070051 int w = r-l;
52 int h = b-t;
Mathias Agopian29479eb2013-02-14 14:36:04 -080053
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080054 if (DEBUG_SURFACE_TRACE) {
Robert Carre6a83512015-11-03 16:09:21 -080055 surface = new WindowSurfaceController.SurfaceTrace(session, "BlackSurface("
Mathias Agopian29479eb2013-02-14 14:36:04 -080056 + l + ", " + t + ")",
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080057 w, h, OPAQUE, FX_SURFACE_DIM | SurfaceControl.HIDDEN);
Mathias Agopian29479eb2013-02-14 14:36:04 -080058 } else {
59 surface = new SurfaceControl(session, "BlackSurface",
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080060 w, h, OPAQUE, FX_SURFACE_DIM | SurfaceControl.HIDDEN);
Craig Mautner924d9b72012-05-06 13:12:04 -070061 }
Mathias Agopian29479eb2013-02-14 14:36:04 -080062
Craig Mautner924d9b72012-05-06 13:12:04 -070063 surface.setAlpha(1);
Jeff Brown64a55af2012-08-26 02:47:39 -070064 surface.setLayerStack(layerStack);
Craig Mautner924d9b72012-05-06 13:12:04 -070065 surface.setLayer(layer);
66 surface.show();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080067 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Dianne Hackborn5fd21692011-06-07 14:09:47 -070068 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070069 }
70
Craig Mautner46ac6fa2013-08-01 10:06:34 -070071 void setAlpha(float alpha) {
72 surface.setAlpha(alpha);
73 }
74
Dianne Hackborn7916ac62011-05-16 20:45:48 -070075 void setMatrix(Matrix matrix) {
76 mTmpMatrix.setTranslate(left, top);
77 mTmpMatrix.postConcat(matrix);
78 mTmpMatrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -070079 surface.setPosition(mTmpFloats[Matrix.MTRANS_X],
80 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070081 surface.setMatrix(
82 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
83 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
84 if (false) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080085 Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): ("
Dianne Hackborn7916ac62011-05-16 20:45:48 -070086 + 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 Hackborn9fd74802012-03-01 19:26:31 -0800100 final Rect mOuterRect;
101 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700102 final Matrix mTmpMatrix = new Matrix();
103 final float[] mTmpFloats = new float[9];
104 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
105
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700106 final boolean mForceDefaultOrientation;
107
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800108 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 Mautner46ac6fa2013-08-01 10:06:34 -0700121 public BlackFrame(SurfaceSession session, Rect outer, Rect inner, int layer, int layerStack,
Igor Murashkina86ab6402013-08-30 12:58:36 -0700122 boolean forceDefaultOrientation) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700123 boolean success = false;
124
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700125 mForceDefaultOrientation = forceDefaultOrientation;
126
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800127 mOuterRect = new Rect(outer);
128 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700129 try {
130 if (outer.top < inner.top) {
131 mBlackSurfaces[0] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700132 outer.left, outer.top, inner.right, inner.top, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700133 }
134 if (outer.left < inner.left) {
135 mBlackSurfaces[1] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700136 outer.left, inner.top, inner.left, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700137 }
138 if (outer.bottom > inner.bottom) {
139 mBlackSurfaces[2] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700140 inner.left, inner.bottom, outer.right, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700141 }
142 if (outer.right > inner.right) {
143 mBlackSurfaces[3] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700144 inner.right, outer.top, outer.right, inner.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700145 }
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 Gruszczynski0bd180d2015-12-07 15:43:52 -0800158 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
159 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700160 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 Mautner46ac6fa2013-08-01 10:06:34 -0700177 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 Hackborn7916ac62011-05-16 20:45:48 -0700185 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 Hackborn7916ac62011-05-16 20:45:48 -0700193 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}