blob: f19cd0ff96f70af5550001e7ee769c2c1cc2ca35 [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 Carrb1579c82017-09-05 14:54:47 -070044 BlackSurface(int layer,
45 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
Craig Mautner924d9b72012-05-06 13:12:04 -070059 surface.setAlpha(1);
60 surface.setLayer(layer);
61 surface.show();
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080062 if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG_WM,
Dianne Hackborn5fd21692011-06-07 14:09:47 -070063 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070064 }
65
Craig Mautner46ac6fa2013-08-01 10:06:34 -070066 void setAlpha(float alpha) {
67 surface.setAlpha(alpha);
68 }
69
Dianne Hackborn7916ac62011-05-16 20:45:48 -070070 void setMatrix(Matrix matrix) {
71 mTmpMatrix.setTranslate(left, top);
72 mTmpMatrix.postConcat(matrix);
73 mTmpMatrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -070074 surface.setPosition(mTmpFloats[Matrix.MTRANS_X],
75 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070076 surface.setMatrix(
77 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
78 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
79 if (false) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080080 Slog.i(TAG_WM, "Black Surface @ (" + left + "," + top + "): ("
Dianne Hackborn7916ac62011-05-16 20:45:48 -070081 + mTmpFloats[Matrix.MTRANS_X] + ","
82 + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=["
83 + mTmpFloats[Matrix.MSCALE_X] + ","
84 + mTmpFloats[Matrix.MSCALE_Y] + "]["
85 + mTmpFloats[Matrix.MSKEW_X] + ","
86 + mTmpFloats[Matrix.MSKEW_Y] + "]");
87 }
88 }
89
90 void clearMatrix() {
91 surface.setMatrix(1, 0, 0, 1);
92 }
93 }
94
Dianne Hackborn9fd74802012-03-01 19:26:31 -080095 final Rect mOuterRect;
96 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070097 final Matrix mTmpMatrix = new Matrix();
98 final float[] mTmpFloats = new float[9];
99 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
100
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700101 final boolean mForceDefaultOrientation;
102
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800103 public void printTo(String prefix, PrintWriter pw) {
104 pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
105 pw.print(" / Inner: "); mInnerRect.printShortString(pw);
106 pw.println();
107 for (int i=0; i<mBlackSurfaces.length; i++) {
108 BlackSurface bs = mBlackSurfaces[i];
109 pw.print(prefix); pw.print("#"); pw.print(i);
110 pw.print(": "); pw.print(bs.surface);
111 pw.print(" left="); pw.print(bs.left);
112 pw.print(" top="); pw.println(bs.top);
113 }
114 }
115
Robert Carrb1579c82017-09-05 14:54:47 -0700116 public BlackFrame(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 Carrb1579c82017-09-05 14:54:47 -0700128 mBlackSurfaces[0] = new BlackSurface(layer,
129 outer.left, outer.top, inner.right, inner.top, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700130 }
131 if (outer.left < inner.left) {
Robert Carrb1579c82017-09-05 14:54:47 -0700132 mBlackSurfaces[1] = new BlackSurface(layer,
133 outer.left, inner.top, inner.left, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700134 }
135 if (outer.bottom > inner.bottom) {
Robert Carrb1579c82017-09-05 14:54:47 -0700136 mBlackSurfaces[2] = new BlackSurface(layer,
137 inner.left, inner.bottom, outer.right, outer.bottom, dc);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700138 }
139 if (outer.right > inner.right) {
Robert Carrb1579c82017-09-05 14:54:47 -0700140 mBlackSurfaces[3] = new BlackSurface(layer,
141 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
164 public void hide() {
165 if (mBlackSurfaces != null) {
166 for (int i=0; i<mBlackSurfaces.length; i++) {
167 if (mBlackSurfaces[i] != null) {
168 mBlackSurfaces[i].surface.hide();
169 }
170 }
171 }
172 }
173
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700174 public void setAlpha(float alpha) {
175 for (int i=0; i<mBlackSurfaces.length; i++) {
176 if (mBlackSurfaces[i] != null) {
177 mBlackSurfaces[i].setAlpha(alpha);
178 }
179 }
180 }
181
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700182 public void setMatrix(Matrix matrix) {
183 for (int i=0; i<mBlackSurfaces.length; i++) {
184 if (mBlackSurfaces[i] != null) {
185 mBlackSurfaces[i].setMatrix(matrix);
186 }
187 }
188 }
189
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700190 public void clearMatrix() {
191 for (int i=0; i<mBlackSurfaces.length; i++) {
192 if (mBlackSurfaces[i] != null) {
193 mBlackSurfaces[i].clearMatrix();
194 }
195 }
196 }
197}