• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 package com.android.server.display;
18 
19 import android.Manifest;
20 import android.annotation.NonNull;
21 import android.annotation.RequiresPermission;
22 import android.os.IBinder;
23 import android.view.Display;
24 
25 import java.util.Objects;
26 
27 /**
28  * Calls into SurfaceFlinger for Display creation and deletion.
29  */
30 public class DisplayControl {
nativeCreateVirtualDisplay(String name, boolean secure, boolean optimizeForPower, String uniqueId, float requestedRefreshRate)31     private static native IBinder nativeCreateVirtualDisplay(String name, boolean secure,
32             boolean optimizeForPower, String uniqueId, float requestedRefreshRate);
nativeDestroyVirtualDisplay(IBinder displayToken)33     private static native void nativeDestroyVirtualDisplay(IBinder displayToken);
nativeOverrideHdrTypes(IBinder displayToken, int[] modes)34     private static native void nativeOverrideHdrTypes(IBinder displayToken, int[] modes);
nativeGetPhysicalDisplayIds()35     private static native long[] nativeGetPhysicalDisplayIds();
nativeGetPhysicalDisplayToken(long physicalDisplayId)36     private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
nativeSetHdrConversionMode(int conversionMode, int preferredHdrOutputType, int[] autoHdrTypes, int autoHdrTypesLength)37     private static native int nativeSetHdrConversionMode(int conversionMode,
38             int preferredHdrOutputType, int[] autoHdrTypes, int autoHdrTypesLength);
nativeGetSupportedHdrOutputTypes()39     private static native int[] nativeGetSupportedHdrOutputTypes();
nativeGetHdrOutputTypesWithLatency()40     private static native int[] nativeGetHdrOutputTypesWithLatency();
nativeGetHdrOutputConversionSupport()41     private static native boolean nativeGetHdrOutputConversionSupport();
42 
43     /**
44      * Create a virtual display in SurfaceFlinger.
45      *
46      * @param name The name of the virtual display.
47      * @param secure Whether this display is secure.
48      * @return The token reference for the display in SurfaceFlinger.
49      */
createVirtualDisplay(String name, boolean secure)50     public static IBinder createVirtualDisplay(String name, boolean secure) {
51         Objects.requireNonNull(name, "name must not be null");
52         return nativeCreateVirtualDisplay(name, secure, true, "", 0.0f);
53     }
54 
55     /**
56      * Create a virtual display in SurfaceFlinger.
57      *
58      * @param name The name of the virtual display.
59      * @param secure Whether this display is secure.
60      * @param optimizeForPower Whether SurfaceFlinger should optimize for power (instead of
61      *                         performance). Such displays will depend on another display for it to
62      *                         be shown and rendered, and that display will optimize for
63      *                         performance when it is on.
64      * @param uniqueId The unique ID for the display.
65      * @param requestedRefreshRate The requested refresh rate in frames per second.
66      * For best results, specify a divisor of the physical refresh rate, e.g., 30 or 60 on
67      * 120hz display. If an arbitrary refresh rate is specified, the rate will be rounded
68      * up or down to a divisor of the physical display. If 0 is specified, the virtual
69      * display is refreshed at the physical display refresh rate.
70      * @return The token reference for the display in SurfaceFlinger.
71      */
createVirtualDisplay(String name, boolean secure, boolean optimizeForPower, String uniqueId, float requestedRefreshRate)72     public static IBinder createVirtualDisplay(String name, boolean secure,
73             boolean optimizeForPower, String uniqueId, float requestedRefreshRate) {
74         Objects.requireNonNull(name, "name must not be null");
75         Objects.requireNonNull(uniqueId, "uniqueId must not be null");
76         return nativeCreateVirtualDisplay(name, secure, optimizeForPower, uniqueId,
77                 requestedRefreshRate);
78     }
79 
80     /**
81      * Destroy a virtual display in SurfaceFlinger.
82      *
83      * @param displayToken The display token for the virtual display to be destroyed.
84      */
destroyVirtualDisplay(IBinder displayToken)85     public static void destroyVirtualDisplay(IBinder displayToken) {
86         if (displayToken == null) {
87             throw new IllegalArgumentException("displayToken must not be null");
88         }
89         nativeDestroyVirtualDisplay(displayToken);
90     }
91 
92     /**
93      * Overrides HDR modes for a display device.
94      */
95     @RequiresPermission(Manifest.permission.ACCESS_SURFACE_FLINGER)
overrideHdrTypes(@onNull IBinder displayToken, @NonNull int[] modes)96     public static void overrideHdrTypes(@NonNull IBinder displayToken, @NonNull int[] modes) {
97         nativeOverrideHdrTypes(displayToken, modes);
98     }
99 
100     /**
101      * Gets all the physical display ids.
102      */
getPhysicalDisplayIds()103     public static long[] getPhysicalDisplayIds() {
104         return nativeGetPhysicalDisplayIds();
105     }
106 
107     /**
108      * Gets the display's token from the physical display id
109      */
getPhysicalDisplayToken(long physicalDisplayId)110     public static IBinder getPhysicalDisplayToken(long physicalDisplayId) {
111         return nativeGetPhysicalDisplayToken(physicalDisplayId);
112     }
113 
114     /**
115      * Sets the HDR conversion mode for the device.
116      *
117      * Returns the system preferred HDR output type in case when HDR conversion mode is
118      * {@link android.hardware.display.HdrConversionMode#HDR_CONVERSION_SYSTEM}.
119      * Returns Hdr::INVALID in other cases.
120      * @hide
121      */
setHdrConversionMode(int conversionMode, int preferredHdrOutputType, int[] autoHdrTypes)122     public static int setHdrConversionMode(int conversionMode, int preferredHdrOutputType,
123             int[] autoHdrTypes) {
124         int length = autoHdrTypes != null ? autoHdrTypes.length : 0;
125         return nativeSetHdrConversionMode(
126                 conversionMode, preferredHdrOutputType, autoHdrTypes, length);
127     }
128 
129     /**
130      * Returns the HDR output types supported by the device.
131      * @hide
132      */
getSupportedHdrOutputTypes()133     public static @Display.HdrCapabilities.HdrType int[] getSupportedHdrOutputTypes() {
134         return nativeGetSupportedHdrOutputTypes();
135     }
136 
137     /**
138      * Returns the HDR output types which introduces latency on conversion to them.
139      * @hide
140      */
getHdrOutputTypesWithLatency()141     public static @Display.HdrCapabilities.HdrType int[] getHdrOutputTypesWithLatency() {
142         return nativeGetHdrOutputTypesWithLatency();
143     }
144 
145     /**
146      * Returns whether the HDR output conversion is supported by the device.
147      * @hide
148      */
getHdrOutputConversionSupport()149     public static boolean getHdrOutputConversionSupport() {
150         return nativeGetHdrOutputConversionSupport();
151     }
152 }
153