blob: fff1fa4dde66a14d6f200c19fc2d651f66c1509c [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;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080021import static com.android.server.wm.WindowManagerDebugConfig.SHOW_SURFACE_ALLOC;
22import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
23import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
24
Dianne Hackborn9fd74802012-03-01 19:26:31 -080025import java.io.PrintWriter;
26
Dianne Hackborn7916ac62011-05-16 20:45:48 -070027import android.graphics.Matrix;
28import android.graphics.PixelFormat;
29import android.graphics.Rect;
30import android.util.Slog;
Igor Murashkina86ab6402013-08-30 12:58:36 -070031import android.view.Surface.OutOfResourcesException;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032import android.view.SurfaceControl;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070033
34/**
35 * Four black surfaces put together to make a black frame.
36 */
37public class BlackFrame {
38 class BlackSurface {
39 final int left;
40 final int top;
Craig Mautner2fb98b12012-03-20 17:24:00 -070041 final int layer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042 final SurfaceControl surface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070043
Robert Carrae606b42018-02-15 15:36:23 -080044 BlackSurface(SurfaceControl.Transaction transaction, int layer,
Robert Carrb1579c82017-09-05 14:54:47 -070045 int l, int t, int r, int b, DisplayContent dc) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070046 left = l;
47 top = t;
Craig Mautner2fb98b12012-03-20 17:24:00 -070048 this.layer = layer;
Dianne Hackborn91c9ac02011-07-21 21:52:09 -070049 int w = r-l;
50 int h = b-t;
Mathias Agopian29479eb2013-02-14 14:36:04 -080051
Robert Carrb1579c82017-09-05 14:54:47 -070052 surface = dc.makeOverlay()
Robert Carre625fcf2017-09-01 12:36:28 -070053 .setName("BlackSurface")
54 .setSize(w, h)
55 .setColorLayer(true)
Robert Carrb1579c82017-09-05 14:54:47 -070056 .setParent(null) // TODO: Work-around for b/69259549
Robert Carre625fcf2017-09-01 12:36:28 -070057 .build();
Mathias Agopian29479eb2013-02-14 14:36:04 -080058
Riddle Hsu654a6f92018-07-13 22:59:36 +080059 transaction.setLayerStack(surface, dc.getDisplayId());
Robert Carrae606b42018-02-15 15:36:23 -080060 transaction.setAlpha(surface, 1);
61 transaction.setLayer(surface, layer);
62 transaction.show(surface);
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080063 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Dianne Hackborn5fd21692011-06-07 14:09:47 -070064 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070065 }
66
Robert Carrae606b42018-02-15 15:36:23 -080067 void setAlpha(SurfaceControl.Transaction t, float alpha) {
68 t.setAlpha(surface, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -070069 }
70
Robert Carrae606b42018-02-15 15:36:23 -080071 void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070072 mTmpMatrix.setTranslate(left, top);
73 mTmpMatrix.postConcat(matrix);
74 mTmpMatrix.getValues(mTmpFloats);
Robert Carrae606b42018-02-15 15:36:23 -080075 t.setPosition(surface, mTmpFloats[Matrix.MTRANS_X],
Dianne Hackbornd040edb2011-08-31 12:47:58 -070076 mTmpFloats[Matrix.MTRANS_Y]);
Robert Carrae606b42018-02-15 15:36:23 -080077 t.setMatrix(surface,
Dianne Hackborn7916ac62011-05-16 20:45:48 -070078 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
79 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
80 if (false) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080081 Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): ("
Dianne Hackborn7916ac62011-05-16 20:45:48 -070082 + mTmpFloats[Matrix.MTRANS_X] + ","
83 + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=["
84 + mTmpFloats[Matrix.MSCALE_X] + ","
85 + mTmpFloats[Matrix.MSCALE_Y] + "]["
86 + mTmpFloats[Matrix.MSKEW_X] + ","
87 + mTmpFloats[Matrix.MSKEW_Y] + "]");
88 }
89 }
90
Robert Carrae606b42018-02-15 15:36:23 -080091 void clearMatrix(SurfaceControl.Transaction t) {
92 t.setMatrix(surface, 1, 0, 0, 1);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070093 }
94 }
95
Dianne Hackborn9fd74802012-03-01 19:26:31 -080096 final Rect mOuterRect;
97 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070098 final Matrix mTmpMatrix = new Matrix();
99 final float[] mTmpFloats = new float[9];
100 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
101
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700102 final boolean mForceDefaultOrientation;
103
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800104 public void printTo(String prefix, PrintWriter pw) {
105 pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
106 pw.print(" / Inner: "); mInnerRect.printShortString(pw);
107 pw.println();
108 for (int i=0; i<mBlackSurfaces.length; i++) {
109 BlackSurface bs = mBlackSurfaces[i];
110 pw.print(prefix); pw.print("#"); pw.print(i);
111 pw.print(": "); pw.print(bs.surface);
112 pw.print(" left="); pw.print(bs.left);
113 pw.print(" top="); pw.println(bs.top);
114 }
115 }
116
Robert Carrae606b42018-02-15 15:36:23 -0800117 public BlackFrame(SurfaceControl.Transaction t,
118 Rect outer, Rect inner, int layer, DisplayContent dc,
Igor Murashkina86ab6402013-08-30 12:58:36 -0700119 boolean forceDefaultOrientation) throws OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700120 boolean success = false;
121
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700122 mForceDefaultOrientation = forceDefaultOrientation;
123
Robert Carrb1579c82017-09-05 14:54:47 -0700124 // TODO: Why do we use 4 surfaces instead of just one big one behind the screenshot?
125 // b/68253229
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800126 mOuterRect = new Rect(outer);
127 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700128 try {
129 if (outer.top < inner.top) {
Robert Carrae606b42018-02-15 15:36:23 -0800130 mBlackSurfaces[0] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700131 outer.left, outer.top, inner.right, inner.top, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700132 }
133 if (outer.left < inner.left) {
Robert Carrae606b42018-02-15 15:36:23 -0800134 mBlackSurfaces[1] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700135 outer.left, inner.top, inner.left, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700136 }
137 if (outer.bottom > inner.bottom) {
Robert Carrae606b42018-02-15 15:36:23 -0800138 mBlackSurfaces[2] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700139 inner.left, inner.bottom, outer.right, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700140 }
141 if (outer.right > inner.right) {
Robert Carrae606b42018-02-15 15:36:23 -0800142 mBlackSurfaces[3] = new BlackSurface(t, layer,
Robert Carrb1579c82017-09-05 14:54:47 -0700143 inner.right, outer.top, outer.right, inner.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700144 }
145 success = true;
146 } finally {
147 if (!success) {
148 kill();
149 }
150 }
151 }
152
153 public void kill() {
154 if (mBlackSurfaces != null) {
155 for (int i=0; i<mBlackSurfaces.length; i++) {
156 if (mBlackSurfaces[i] != null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800157 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
158 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700159 mBlackSurfaces[i].surface.destroy();
160 mBlackSurfaces[i] = null;
161 }
162 }
163 }
164 }
165
Robert Carrae606b42018-02-15 15:36:23 -0800166 public void hide(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700167 if (mBlackSurfaces != null) {
168 for (int i=0; i<mBlackSurfaces.length; i++) {
169 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800170 t.hide(mBlackSurfaces[i].surface);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700171 }
172 }
173 }
174 }
175
Robert Carrae606b42018-02-15 15:36:23 -0800176 public void setAlpha(SurfaceControl.Transaction t, float alpha) {
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700177 for (int i=0; i<mBlackSurfaces.length; i++) {
178 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800179 mBlackSurfaces[i].setAlpha(t, alpha);
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700180 }
181 }
182 }
183
Robert Carrae606b42018-02-15 15:36:23 -0800184 public void setMatrix(SurfaceControl.Transaction t, Matrix matrix) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700185 for (int i=0; i<mBlackSurfaces.length; i++) {
186 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800187 mBlackSurfaces[i].setMatrix(t, matrix);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700188 }
189 }
190 }
191
Robert Carrae606b42018-02-15 15:36:23 -0800192 public void clearMatrix(SurfaceControl.Transaction t) {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700193 for (int i=0; i<mBlackSurfaces.length; i++) {
194 if (mBlackSurfaces[i] != null) {
Robert Carrae606b42018-02-15 15:36:23 -0800195 mBlackSurfaces[i].clearMatrix(t);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700196 }
197 }
198 }
199}