1/* 2 * Copyright (C) 2013 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 */ 16package android.hardware.display; 17 18import android.os.IBinder; 19import android.view.Display; 20 21/** 22 * Represents a virtual display. The content of a virtual display is rendered to a 23 * {@link android.view.Surface} that you must provide to {@link DisplayManager#createVirtualDisplay 24 * createVirtualDisplay()}. 25 * <p>Because a virtual display renders to a surface provided by the application, it will be 26 * released automatically when the process terminates and all remaining windows on it will 27 * be forcibly removed. However, you should also explicitly call {@link #release} when you're 28 * done with it. 29 * 30 * @see DisplayManager#createVirtualDisplay 31 */ 32public final class VirtualDisplay { 33 private final DisplayManagerGlobal mGlobal; 34 private final Display mDisplay; 35 private IBinder mToken; 36 37 VirtualDisplay(DisplayManagerGlobal global, Display display, IBinder token) { 38 mGlobal = global; 39 mDisplay = display; 40 mToken = token; 41 } 42 43 /** 44 * Gets the virtual display. 45 */ 46 public Display getDisplay() { 47 return mDisplay; 48 } 49 50 /** 51 * Releases the virtual display and destroys its underlying surface. 52 * <p> 53 * All remaining windows on the virtual display will be forcibly removed 54 * as part of releasing the virtual display. 55 * </p> 56 */ 57 public void release() { 58 if (mToken != null) { 59 mGlobal.releaseVirtualDisplay(mToken); 60 mToken = null; 61 } 62 } 63 64 @Override 65 public String toString() { 66 return "VirtualDisplay{display=" + mDisplay + ", token=" + mToken + "}"; 67 } 68} 69