blob: 84ba5ca94f8cbb9733c585702d3819f5c41485ae [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")
Chavi Weingarten6ef9cc62019-02-07 16:28:45 +000051 .setColorLayer()
Robert Carrb1579c82017-09-05 14:54:47 -070052 .setParent(null) // TODO: Work-around for b/69259549
Robert Carre625fcf2017-09-01 12:36:28 -070053 .build();
Vishnu Naird454442d2018-11-13 13:51:01 -080054 transaction.setWindowCrop(surface, w, h);
Riddle Hsu654a6f92018-07-13 22:59:36 +080055 transaction.setLayerStack(surface, dc.getDisplayId());
Robert Carrae606b42018-02-15 15:36:23 -080056 transaction.setAlpha(surface, 1);
57 transaction.setLayer(surface, layer);
Vishnu Naira1d14812018-10-26 08:14:02 -070058 transaction.setPosition(surface, left, top);
Robert Carrae606b42018-02-15 15:36:23 -080059 transaction.show(surface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080060 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Dianne Hackborn5fd21692011-06-07 14:09:47 -070061 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070062 }
63
Robert Carrae606b42018-02-15 15:36:23 -080064 void setAlpha(SurfaceControl.Transaction t, float alpha) {
65 t.setAlpha(surface, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -070066 }
67
Robert Carrae606b42018-02-15 15:36:23 -080068 void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070069 mTmpMatrix.setTranslate(left, top);
70 mTmpMatrix.postConcat(matrix);
71 mTmpMatrix.getValues(mTmpFloats);
Robert Carrae606b42018-02-15 15:36:23 -080072 t.setPosition(surface, mTmpFloats[Matrix.MTRANS_X],
Dianne Hackbornd040edb2011-08-31 12:47:58 -070073 mTmpFloats[Matrix.MTRANS_Y]);
Robert Carrae606b42018-02-15 15:36:23 -080074 t.setMatrix(surface,
Dianne Hackborn7916ac62011-05-16 20:45:48 -070075 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
76 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
77 if (false) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080078 Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): ("
Dianne Hackborn7916ac62011-05-16 20:45:48 -070079 + mTmpFloats[Matrix.MTRANS_X] + ","
80 + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=["
81 + mTmpFloats[Matrix.MSCALE_X] + ","
82 + mTmpFloats[Matrix.MSCALE_Y] + "]["
83 + mTmpFloats[Matrix.MSKEW_X] + ","
84 + mTmpFloats[Matrix.MSKEW_Y] + "]");
85 }
86 }
87
Robert Carrae606b42018-02-15 15:36:23 -080088 void clearMatrix(SurfaceControl.Transaction t) {
89 t.setMatrix(surface, 1, 0, 0, 1);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070090 }
91 }
92
Dianne Hackborn9fd74802012-03-01 19:26:31 -080093 final Rect mOuterRect;
94 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070095 final Matrix mTmpMatrix = new Matrix();
96 final float[] mTmpFloats = new float[9];
97 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
98
Craig Mautner46ac6fa2013-08-01 10:06:34 -070099 final boolean mForceDefaultOrientation;
100
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800101 public void printTo(String prefix, PrintWriter pw) {
102 pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
103 pw.print(" / Inner: "); mInnerRect.printShortString(pw);
104 pw.println();
105 for (int i=0; i<mBlackSurfaces.length; i++) {
106 BlackSurface bs = mBlackSurfaces[i];
107 pw.print(prefix); pw.print("#"); pw.print(i);
108 pw.print(": "); pw.print(bs.surface);
109 pw.print(" left="); pw.print(bs.left);
110 pw.print(" top="); pw.println(bs.top);
111 }
112 }
113
Robert Carrae606b42018-02-15 15:36:23 -0800114 public BlackFrame(SurfaceControl.Transaction t,
115 Rect outer, Rect inner, int layer, DisplayContent dc,
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
Robert Carrb1579c82017-09-05 14:54:47 -0700121 // TODO: Why do we use 4 surfaces instead of just one big one behind the screenshot?
122 // b/68253229
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800123 mOuterRect = new Rect(outer);
124 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700125 try {
126 if (outer.top < inner.top) {
Robert Carrae606b42018-02-15 15:36:23 -0800127 mBlackSurfaces[0] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700128 outer.left, outer.top, inner.right, inner.top, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700129 }
130 if (outer.left < inner.left) {
Robert Carrae606b42018-02-15 15:36:23 -0800131 mBlackSurfaces[1] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700132 outer.left, inner.top, inner.left, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700133 }
134 if (outer.bottom > inner.bottom) {
Robert Carrae606b42018-02-15 15:36:23 -0800135 mBlackSurfaces[2] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700136 inner.left, inner.bottom, outer.right, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700137 }
138 if (outer.right > inner.right) {
Robert Carrae606b42018-02-15 15:36:23 -0800139 mBlackSurfaces[3] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700140 inner.right, outer.top, outer.right, inner.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700141 }
142 success = true;
143 } finally {
144 if (!success) {
145 kill();
146 }
147 }
148 }
149
150 public void kill() {
151 if (mBlackSurfaces != null) {
152 for (int i=0; i<mBlackSurfaces.length; i++) {
153 if (mBlackSurfaces[i] != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800154 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
155 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Robert Carr5ea304d2019-02-04 16:04:55 -0800156 mBlackSurfaces[i].surface.remove();
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700157 mBlackSurfaces[i] = null;
158 }
159 }
160 }
161 }
162
Robert Carrae606b42018-02-15 15:36:23 -0800163 public void hide(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700164 if (mBlackSurfaces != null) {
165 for (int i=0; i<mBlackSurfaces.length; i++) {
166 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800167 t.hide(mBlackSurfaces[i].surface);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700168 }
169 }
170 }
171 }
172
Robert Carrae606b42018-02-15 15:36:23 -0800173 public void setAlpha(SurfaceControl.Transaction t, float alpha) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700174 for (int i=0; i<mBlackSurfaces.length; i++) {
175 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800176 mBlackSurfaces[i].setAlpha(t, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700177 }
178 }
179 }
180
Robert Carrae606b42018-02-15 15:36:23 -0800181 public void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700182 for (int i=0; i<mBlackSurfaces.length; i++) {
183 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800184 mBlackSurfaces[i].setMatrix(t, matrix);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700185 }
186 }
187 }
188
Robert Carrae606b42018-02-15 15:36:23 -0800189 public void clearMatrix(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700190 for (int i=0; i<mBlackSurfaces.length; i++) {
191 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800192 mBlackSurfaces[i].clearMatrix(t);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700193 }
194 }
195 }
196}