blob: 220c7fb1c7f2438336711a5ff6bf5aa1a80f7f82 [file] [log] [blame]
Dianne Hackbornde75cb42011-03-02 17:11:21 -08001/*
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.PixelFormat;
20import android.util.Slog;
21import android.view.Surface;
22import android.view.SurfaceSession;
23
24import java.io.PrintWriter;
25
26class DimSurface {
27 Surface mDimSurface;
28 boolean mDimShown = false;
29 int mDimColor = 0;
30 int mLayer = -1;
31 int mLastDimWidth, mLastDimHeight;
32
33 DimSurface(SurfaceSession session) {
34 if (mDimSurface == null) {
35 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM "
36 + mDimSurface + ": CREATE");
37 try {
38 mDimSurface = new Surface(session, 0,
39 "DimSurface",
40 -1, 16, 16, PixelFormat.OPAQUE,
41 Surface.FX_SURFACE_DIM);
42 mDimSurface.setAlpha(0.0f);
43 } catch (Exception e) {
44 Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
45 }
46 }
47 }
48
49 /**
50 * Show the dim surface.
51 */
52 void show(int dw, int dh, int layer, int color) {
53 if (!mDimShown) {
54 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
55 dw + "x" + dh + ")");
56 mDimShown = true;
57 try {
58 mLastDimWidth = dw;
59 mLastDimHeight = dh;
60 mDimSurface.setPosition(0, 0);
61 mDimSurface.setSize(dw, dh);
62 mDimSurface.show();
63 } catch (RuntimeException e) {
64 Slog.w(WindowManagerService.TAG, "Failure showing dim surface", e);
65 }
66 } else if (mLastDimWidth != dw || mLastDimHeight != dh || mDimColor != color
67 || mLayer != layer) {
68 mLastDimWidth = dw;
69 mLastDimHeight = dh;
70 mLayer = layer;
71 mDimColor = color;
72 mDimSurface.setSize(dw, dh);
73 mDimSurface.setLayer(layer);
74 mDimSurface.setAlpha(((color>>24)&0xff)/255.0f);
75 }
76 }
77
78 void hide() {
79 if (mDimShown) {
80 mDimShown = false;
81 try {
82 mDimSurface.hide();
83 } catch (RuntimeException e) {
84 Slog.w(WindowManagerService.TAG, "Illegal argument exception hiding dim surface");
85 }
86 }
87 }
88
89 public void printTo(String prefix, PrintWriter pw) {
90 pw.print(prefix); pw.print("mDimSurface="); pw.println(mDimSurface);
91 pw.print(prefix); pw.print("mDimShown="); pw.print(mDimShown);
Dianne Hackborn9d132642011-04-21 17:26:39 -070092 pw.print(" mLayer="); pw.print(mLayer);
Dianne Hackbornde75cb42011-03-02 17:11:21 -080093 pw.print(" mDimColor=0x"); pw.println(Integer.toHexString(mDimColor));
94 pw.print(prefix); pw.print("mLastDimWidth="); pw.print(mLastDimWidth);
95 pw.print(" mLastDimWidth="); pw.println(mLastDimWidth);
96 }
97}