blob: 774b1652434f048123b517cd9a48a20298f5b815 [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
Dianne Hackborn9fd74802012-03-01 19:26:31 -080019import java.io.PrintWriter;
20
Dianne Hackborn7916ac62011-05-16 20:45:48 -070021import android.graphics.Matrix;
22import android.graphics.PixelFormat;
23import android.graphics.Rect;
24import android.util.Slog;
25import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080026import android.view.SurfaceControl;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070027import android.view.SurfaceSession;
28
29/**
30 * Four black surfaces put together to make a black frame.
31 */
32public class BlackFrame {
33 class BlackSurface {
34 final int left;
35 final int top;
Craig Mautner2fb98b12012-03-20 17:24:00 -070036 final int layer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080037 final SurfaceControl surface;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070038
Craig Mautnerb47bbc32012-08-22 17:41:48 -070039 BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b, int layerStack)
Mathias Agopian29479eb2013-02-14 14:36:04 -080040 throws SurfaceControl.OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -070041 left = l;
42 top = t;
Craig Mautner2fb98b12012-03-20 17:24:00 -070043 this.layer = layer;
Dianne Hackborn91c9ac02011-07-21 21:52:09 -070044 int w = r-l;
45 int h = b-t;
Mathias Agopian29479eb2013-02-14 14:36:04 -080046
47 if (WindowManagerService.DEBUG_SURFACE_TRACE) {
48 surface = new WindowStateAnimator.SurfaceTrace(session, "BlackSurface("
49 + l + ", " + t + ")",
50 w, h, PixelFormat.OPAQUE, SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
51 } else {
52 surface = new SurfaceControl(session, "BlackSurface",
53 w, h, PixelFormat.OPAQUE, SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
Craig Mautner924d9b72012-05-06 13:12:04 -070054 }
Mathias Agopian29479eb2013-02-14 14:36:04 -080055
Craig Mautner924d9b72012-05-06 13:12:04 -070056 surface.setAlpha(1);
Jeff Brown64a55af2012-08-26 02:47:39 -070057 surface.setLayerStack(layerStack);
Craig Mautner924d9b72012-05-06 13:12:04 -070058 surface.setLayer(layer);
59 surface.show();
Dianne Hackborn5fd21692011-06-07 14:09:47 -070060 if (WindowManagerService.SHOW_TRANSACTIONS ||
61 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
62 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070063 }
64
65 void setMatrix(Matrix matrix) {
66 mTmpMatrix.setTranslate(left, top);
67 mTmpMatrix.postConcat(matrix);
68 mTmpMatrix.getValues(mTmpFloats);
Dianne Hackbornd040edb2011-08-31 12:47:58 -070069 surface.setPosition(mTmpFloats[Matrix.MTRANS_X],
70 mTmpFloats[Matrix.MTRANS_Y]);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070071 surface.setMatrix(
72 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
73 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
74 if (false) {
75 Slog.i(WindowManagerService.TAG, "Black Surface @ (" + left + "," + top + "): ("
76 + mTmpFloats[Matrix.MTRANS_X] + ","
77 + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=["
78 + mTmpFloats[Matrix.MSCALE_X] + ","
79 + mTmpFloats[Matrix.MSCALE_Y] + "]["
80 + mTmpFloats[Matrix.MSKEW_X] + ","
81 + mTmpFloats[Matrix.MSKEW_Y] + "]");
82 }
83 }
84
85 void clearMatrix() {
86 surface.setMatrix(1, 0, 0, 1);
87 }
88 }
89
Dianne Hackborn9fd74802012-03-01 19:26:31 -080090 final Rect mOuterRect;
91 final Rect mInnerRect;
Dianne Hackborn7916ac62011-05-16 20:45:48 -070092 final Matrix mTmpMatrix = new Matrix();
93 final float[] mTmpFloats = new float[9];
94 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
95
Dianne Hackborn9fd74802012-03-01 19:26:31 -080096 public void printTo(String prefix, PrintWriter pw) {
97 pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
98 pw.print(" / Inner: "); mInnerRect.printShortString(pw);
99 pw.println();
100 for (int i=0; i<mBlackSurfaces.length; i++) {
101 BlackSurface bs = mBlackSurfaces[i];
102 pw.print(prefix); pw.print("#"); pw.print(i);
103 pw.print(": "); pw.print(bs.surface);
104 pw.print(" left="); pw.print(bs.left);
105 pw.print(" top="); pw.println(bs.top);
106 }
107 }
108
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700109 public BlackFrame(SurfaceSession session, Rect outer, Rect inner,
Mathias Agopian29479eb2013-02-14 14:36:04 -0800110 int layer, final int layerStack) throws SurfaceControl.OutOfResourcesException {
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700111 boolean success = false;
112
Dianne Hackborn9fd74802012-03-01 19:26:31 -0800113 mOuterRect = new Rect(outer);
114 mInnerRect = new Rect(inner);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700115 try {
116 if (outer.top < inner.top) {
117 mBlackSurfaces[0] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700118 outer.left, outer.top, inner.right, inner.top, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700119 }
120 if (outer.left < inner.left) {
121 mBlackSurfaces[1] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700122 outer.left, inner.top, inner.left, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700123 }
124 if (outer.bottom > inner.bottom) {
125 mBlackSurfaces[2] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700126 inner.left, inner.bottom, outer.right, outer.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700127 }
128 if (outer.right > inner.right) {
129 mBlackSurfaces[3] = new BlackSurface(session, layer,
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700130 inner.right, outer.top, outer.right, inner.bottom, layerStack);
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700131 }
132 success = true;
133 } finally {
134 if (!success) {
135 kill();
136 }
137 }
138 }
139
140 public void kill() {
141 if (mBlackSurfaces != null) {
142 for (int i=0; i<mBlackSurfaces.length; i++) {
143 if (mBlackSurfaces[i] != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700144 if (WindowManagerService.SHOW_TRANSACTIONS ||
145 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(
146 WindowManagerService.TAG,
147 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700148 mBlackSurfaces[i].surface.destroy();
149 mBlackSurfaces[i] = null;
150 }
151 }
152 }
153 }
154
155 public void hide() {
156 if (mBlackSurfaces != null) {
157 for (int i=0; i<mBlackSurfaces.length; i++) {
158 if (mBlackSurfaces[i] != null) {
159 mBlackSurfaces[i].surface.hide();
160 }
161 }
162 }
163 }
164
165 public void setMatrix(Matrix matrix) {
166 for (int i=0; i<mBlackSurfaces.length; i++) {
167 if (mBlackSurfaces[i] != null) {
168 mBlackSurfaces[i].setMatrix(matrix);
169 }
170 }
171 }
172
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700173 public void clearMatrix() {
174 for (int i=0; i<mBlackSurfaces.length; i++) {
175 if (mBlackSurfaces[i] != null) {
176 mBlackSurfaces[i].clearMatrix();
177 }
178 }
179 }
180}