blob: dc6cc0d025f0af48a45f73707b38aa29492c95b3 [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) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -070035 if (WindowManagerService.SHOW_TRANSACTIONS ||
36 WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(WindowManagerService.TAG,
37 " DIM " + mDimSurface + ": CREATE");
Dianne Hackbornde75cb42011-03-02 17:11:21 -080038 try {
39 mDimSurface = new Surface(session, 0,
40 "DimSurface",
41 -1, 16, 16, PixelFormat.OPAQUE,
42 Surface.FX_SURFACE_DIM);
43 mDimSurface.setAlpha(0.0f);
44 } catch (Exception e) {
45 Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
46 }
47 }
48 }
49
50 /**
51 * Show the dim surface.
52 */
53 void show(int dw, int dh, int layer, int color) {
54 if (!mDimShown) {
55 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
Dianne Hackbornd02a9e92011-09-12 13:47:31 -070056 dw + "x" + dh + " layer=" + layer + ")");
Dianne Hackbornde75cb42011-03-02 17:11:21 -080057 mDimShown = true;
58 try {
59 mLastDimWidth = dw;
60 mLastDimHeight = dh;
61 mDimSurface.setPosition(0, 0);
62 mDimSurface.setSize(dw, dh);
Dianne Hackbornd02a9e92011-09-12 13:47:31 -070063 mDimSurface.setLayer(layer);
Dianne Hackbornde75cb42011-03-02 17:11:21 -080064 mDimSurface.show();
65 } catch (RuntimeException e) {
66 Slog.w(WindowManagerService.TAG, "Failure showing dim surface", e);
67 }
68 } else if (mLastDimWidth != dw || mLastDimHeight != dh || mDimColor != color
69 || mLayer != layer) {
Dianne Hackbornd02a9e92011-09-12 13:47:31 -070070 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " DIM " + mDimSurface + ": pos=(0,0) (" +
71 dw + "x" + dh + " layer=" + layer + ")");
Dianne Hackbornde75cb42011-03-02 17:11:21 -080072 mLastDimWidth = dw;
73 mLastDimHeight = dh;
74 mLayer = layer;
75 mDimColor = color;
76 mDimSurface.setSize(dw, dh);
77 mDimSurface.setLayer(layer);
78 mDimSurface.setAlpha(((color>>24)&0xff)/255.0f);
79 }
80 }
81
82 void hide() {
83 if (mDimShown) {
84 mDimShown = false;
85 try {
Dianne Hackbornd02a9e92011-09-12 13:47:31 -070086 if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, " HIDE " + mDimSurface);
Dianne Hackbornde75cb42011-03-02 17:11:21 -080087 mDimSurface.hide();
88 } catch (RuntimeException e) {
89 Slog.w(WindowManagerService.TAG, "Illegal argument exception hiding dim surface");
90 }
91 }
92 }
93
94 public void printTo(String prefix, PrintWriter pw) {
95 pw.print(prefix); pw.print("mDimSurface="); pw.println(mDimSurface);
96 pw.print(prefix); pw.print("mDimShown="); pw.print(mDimShown);
Dianne Hackborn29735682011-04-21 17:26:39 -070097 pw.print(" mLayer="); pw.print(mLayer);
Dianne Hackbornde75cb42011-03-02 17:11:21 -080098 pw.print(" mDimColor=0x"); pw.println(Integer.toHexString(mDimColor));
99 pw.print(prefix); pw.print("mLastDimWidth="); pw.print(mLastDimWidth);
100 pw.print(" mLastDimWidth="); pw.println(mLastDimWidth);
101 }
102}