blob: d8fd7fe84a7399d67cfae439b7e6742482d98ac5 [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
19import android.graphics.Matrix;
20import android.graphics.PixelFormat;
21import android.graphics.Rect;
22import android.util.Slog;
23import android.view.Surface;
24import android.view.SurfaceSession;
25
26/**
27 * Four black surfaces put together to make a black frame.
28 */
29public class BlackFrame {
30 class BlackSurface {
31 final int left;
32 final int top;
33 final Surface surface;
34
35 BlackSurface(SurfaceSession session, int layer, int l, int t, int w, int h)
36 throws Surface.OutOfResourcesException {
37 left = l;
38 top = t;
39 surface = new Surface(session, 0, "BlackSurface",
40 -1, w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM);
Dianne Hackborn5fd21692011-06-07 14:09:47 -070041 if (WindowManagerService.SHOW_TRANSACTIONS ||
42 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
43 " BLACK " + surface + ": CREATE layer=" + layer);
Dianne Hackborn7916ac62011-05-16 20:45:48 -070044 surface.setAlpha(1.0f);
45 surface.setLayer(layer);
46 }
47
48 void setMatrix(Matrix matrix) {
49 mTmpMatrix.setTranslate(left, top);
50 mTmpMatrix.postConcat(matrix);
51 mTmpMatrix.getValues(mTmpFloats);
52 surface.setPosition((int)mTmpFloats[Matrix.MTRANS_X],
53 (int)mTmpFloats[Matrix.MTRANS_Y]);
54 surface.setMatrix(
55 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
56 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
57 if (false) {
58 Slog.i(WindowManagerService.TAG, "Black Surface @ (" + left + "," + top + "): ("
59 + mTmpFloats[Matrix.MTRANS_X] + ","
60 + mTmpFloats[Matrix.MTRANS_Y] + ") matrix=["
61 + mTmpFloats[Matrix.MSCALE_X] + ","
62 + mTmpFloats[Matrix.MSCALE_Y] + "]["
63 + mTmpFloats[Matrix.MSKEW_X] + ","
64 + mTmpFloats[Matrix.MSKEW_Y] + "]");
65 }
66 }
67
68 void clearMatrix() {
69 surface.setMatrix(1, 0, 0, 1);
70 }
71 }
72
73 final Matrix mTmpMatrix = new Matrix();
74 final float[] mTmpFloats = new float[9];
75 final BlackSurface[] mBlackSurfaces = new BlackSurface[4];
76
77 public BlackFrame(SurfaceSession session, Rect outer, Rect inner,
78 int layer) throws Surface.OutOfResourcesException {
79 boolean success = false;
80
81 try {
82 if (outer.top < inner.top) {
83 mBlackSurfaces[0] = new BlackSurface(session, layer,
84 outer.left, outer.top, inner.right, inner.top);
85 }
86 if (outer.left < inner.left) {
87 mBlackSurfaces[1] = new BlackSurface(session, layer,
88 outer.left, inner.top, inner.left, outer.bottom);
89 }
90 if (outer.bottom > inner.bottom) {
91 mBlackSurfaces[2] = new BlackSurface(session, layer,
92 inner.left, inner.bottom, outer.right, outer.bottom);
93 }
94 if (outer.right > inner.right) {
95 mBlackSurfaces[3] = new BlackSurface(session, layer,
96 inner.right, outer.top, outer.right, inner.bottom);
97 }
98 success = true;
99 } finally {
100 if (!success) {
101 kill();
102 }
103 }
104 }
105
106 public void kill() {
107 if (mBlackSurfaces != null) {
108 for (int i=0; i<mBlackSurfaces.length; i++) {
109 if (mBlackSurfaces[i] != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700110 if (WindowManagerService.SHOW_TRANSACTIONS ||
111 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(
112 WindowManagerService.TAG,
113 " BLACK " + mBlackSurfaces[i].surface + ": DESTROY");
Dianne Hackborn7916ac62011-05-16 20:45:48 -0700114 mBlackSurfaces[i].surface.destroy();
115 mBlackSurfaces[i] = null;
116 }
117 }
118 }
119 }
120
121 public void hide() {
122 if (mBlackSurfaces != null) {
123 for (int i=0; i<mBlackSurfaces.length; i++) {
124 if (mBlackSurfaces[i] != null) {
125 mBlackSurfaces[i].surface.hide();
126 }
127 }
128 }
129 }
130
131 public void setMatrix(Matrix matrix) {
132 for (int i=0; i<mBlackSurfaces.length; i++) {
133 if (mBlackSurfaces[i] != null) {
134 mBlackSurfaces[i].setMatrix(matrix);
135 }
136 }
137 }
138
139 public void clearMatrix() {
140 for (int i=0; i<mBlackSurfaces.length; i++) {
141 if (mBlackSurfaces[i] != null) {
142 mBlackSurfaces[i].clearMatrix();
143 }
144 }
145 }
146}