blob: e358ad5ed756b32ed17b9d96c161b53a8751811e [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 com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
20import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
21import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
22
Dianne Hackborn7916ac62011-05-16 20:45:48 -070023import android.graphics.Matrix;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070024import android.graphics.Rect;
25import android.util.Slog;
Igor Murashkina86ab6402013-08-30 12:58:36 -070026import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080027import android.view.SurfaceControl;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070028
Vishnu Naira1d14812018-10-26 08:14:02 -070029import java.io.PrintWriter;
30
Dianne Hackborn7916ac62011-05-16 20:45:48 -070031/**
32 * Four black surfaces put together to make a black frame.
33 */
34public class BlackFrame {
35 class BlackSurface {
36 final int left;
37 final int top;
Craig Mautner2fb98b12012-03-20 17:24:00 -070038 final int layer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039 final SurfaceControl surface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070040
Robert Carrae606b42018-02-15 15:36:23 -080041 BlackSurface(SurfaceControl.Transaction transaction, int layer,
Robert Carrb1579c82017-09-05 14:54:47 -070042 int l, int t, int r, int b, DisplayContent dc) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070043 left = l;
44 top = t;
Craig Mautner2fb98b12012-03-20 17:24:00 -070045 this.layer = layer;
Dianne Hackborn91c9ac02011-07-21 21:52:09 -070046 int w = r-l;
47 int h = b-t;
Mathias Agopian29479eb2013-02-14 14:36:04 -080048
Robert Carrb1579c82017-09-05 14:54:47 -070049 surface = dc.makeOverlay()
Robert Carre625fcf2017-09-01 12:36:28 -070050 .setName("BlackSurface")
51 .setSize(w, h)
52 .setColorLayer(true)
Robert Carrb1579c82017-09-05 14:54:47 -070053 .setParent(null) // TODO: Work-around for b/69259549
Robert Carre625fcf2017-09-01 12:36:28 -070054 .build();
Mathias Agopian29479eb2013-02-14 14:36:04 -080055
Riddle Hsu654a6f92018-07-13 22:59:36 +080056 transaction.setLayerStack(surface, dc.getDisplayId());
Robert Carrae606b42018-02-15 15:36:23 -080057 transaction.setAlpha(surface, 1);
58 transaction.setLayer(surface, layer);
Vishnu Naira1d14812018-10-26 08:14:02 -070059 transaction.setPosition(surface, left, top);
Robert Carrae606b42018-02-15 15:36:23 -080060 transaction.show(surface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080061 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Dianne Hackborn5fd21692011-06-07 14:09:47 -070062 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070063 }
64
Robert Carrae606b42018-02-15 15:36:23 -080065 void setAlpha(SurfaceControl.Transaction t, float alpha) {
66 t.setAlpha(surface, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -070067 }
68
Robert Carrae606b42018-02-15 15:36:23 -080069 void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070070 mTmpMatrix.setTranslate(left, top);
71 mTmpMatrix.postConcat(matrix);
72 mTmpMatrix.getValues(mTmpFloats);
Robert Carrae606b42018-02-15 15:36:23 -080073 t.setPosition(surface, mTmpFloats[Matrix.MTRANS_X],
Dianne Hackbornd040edb2011-08-31 12:47:58 -070074 mTmpFloats[Matrix.MTRANS_Y]);
Robert Carrae606b42018-02-15 15:36:23 -080075 t.setMatrix(surface,
Dianne Hackborn7916ac62011-05-16 20:45:48 -070076 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
77 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
78 if (false) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080079 Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): ("
Dianne Hackborn7916ac62011-05-16 20:45:48 -070080 + 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
Robert Carrae606b42018-02-15 15:36:23 -080089 void clearMatrix(SurfaceControl.Transaction t) {
90 t.setMatrix(surface, 1, 0, 0, 1);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070091 }
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
Robert Carrae606b42018-02-15 15:36:23 -0800115 public BlackFrame(SurfaceControl.Transaction t,
116 Rect outer, Rect inner, int layer, DisplayContent dc,
Igor Murashkina86ab6402013-08-30 12:58:36 -0700117 boolean forceDefaultOrientation) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700118 boolean success = false;
119
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700120 mForceDefaultOrientation = forceDefaultOrientation;
121
Robert Carrb1579c82017-09-05 14:54:47 -0700122 // TODO: Why do we use 4 surfaces instead of just one big one behind the screenshot?
123 // b/68253229
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800124 mOuterRect = new Rect(outer);
125 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700126 try {
127 if (outer.top < inner.top) {
Robert Carrae606b42018-02-15 15:36:23 -0800128 mBlackSurfaces[0] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700129 outer.left, outer.top, inner.right, inner.top, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700130 }
131 if (outer.left < inner.left) {
Robert Carrae606b42018-02-15 15:36:23 -0800132 mBlackSurfaces[1] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700133 outer.left, inner.top, inner.left, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700134 }
135 if (outer.bottom > inner.bottom) {
Robert Carrae606b42018-02-15 15:36:23 -0800136 mBlackSurfaces[2] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700137 inner.left, inner.bottom, outer.right, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700138 }
139 if (outer.right > inner.right) {
Robert Carrae606b42018-02-15 15:36:23 -0800140 mBlackSurfaces[3] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700141 inner.right, outer.top, outer.right, inner.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700142 }
143 success = true;
144 } finally {
145 if (!success) {
146 kill();
147 }
148 }
149 }
150
151 public void kill() {
152 if (mBlackSurfaces != null) {
153 for (int i=0; i<mBlackSurfaces.length; i++) {
154 if (mBlackSurfaces[i] != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800155 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
156 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700157 mBlackSurfaces[i].surface.destroy();
158 mBlackSurfaces[i] = null;
159 }
160 }
161 }
162 }
163
Robert Carrae606b42018-02-15 15:36:23 -0800164 public void hide(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700165 if (mBlackSurfaces != null) {
166 for (int i=0; i<mBlackSurfaces.length; i++) {
167 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800168 t.hide(mBlackSurfaces[i].surface);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700169 }
170 }
171 }
172 }
173
Robert Carrae606b42018-02-15 15:36:23 -0800174 public void setAlpha(SurfaceControl.Transaction t, float alpha) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700175 for (int i=0; i<mBlackSurfaces.length; i++) {
176 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800177 mBlackSurfaces[i].setAlpha(t, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700178 }
179 }
180 }
181
Robert Carrae606b42018-02-15 15:36:23 -0800182 public void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700183 for (int i=0; i<mBlackSurfaces.length; i++) {
184 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800185 mBlackSurfaces[i].setMatrix(t, matrix);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700186 }
187 }
188 }
189
Robert Carrae606b42018-02-15 15:36:23 -0800190 public void clearMatrix(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700191 for (int i=0; i<mBlackSurfaces.length; i++) {
192 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800193 mBlackSurfaces[i].clearMatrix(t);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700194 }
195 }
196 }
197}