• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 android.gui;
18 
19 import android.gui.Color;
20 import android.gui.CompositionPreference;
21 import android.gui.ContentSamplingAttributes;
22 import android.gui.DisplayBrightness;
23 import android.gui.DisplayCaptureArgs;
24 import android.gui.DisplayDecorationSupport;
25 import android.gui.DisplayedFrameStats;
26 import android.gui.DisplayModeSpecs;
27 import android.gui.DisplayPrimaries;
28 import android.gui.DisplayState;
29 import android.gui.DisplayStatInfo;
30 import android.gui.DynamicDisplayInfo;
31 import android.gui.FrameEvent;
32 import android.gui.FrameStats;
33 import android.gui.HdrConversionCapability;
34 import android.gui.HdrConversionStrategy;
35 import android.gui.IDisplayEventConnection;
36 import android.gui.IFpsListener;
37 import android.gui.IHdrLayerInfoListener;
38 import android.gui.IRegionSamplingListener;
39 import android.gui.IScreenCaptureListener;
40 import android.gui.ISurfaceComposerClient;
41 import android.gui.ITunnelModeEnabledListener;
42 import android.gui.IWindowInfosListener;
43 import android.gui.IWindowInfosPublisher;
44 import android.gui.LayerCaptureArgs;
45 import android.gui.LayerDebugInfo;
46 import android.gui.OverlayProperties;
47 import android.gui.PullAtomData;
48 import android.gui.ARect;
49 import android.gui.StalledTransactionInfo;
50 import android.gui.StaticDisplayInfo;
51 import android.gui.WindowInfosListenerInfo;
52 
53 /** @hide */
54 interface ISurfaceComposer {
55 
56     enum VsyncSource {
57         eVsyncSourceApp = 0,
58         eVsyncSourceSurfaceFlinger = 1
59     }
60 
61     enum EventRegistration {
62         modeChanged = 1 << 0,
63         frameRateOverride = 1 << 1,
64     }
65 
66     /**
67      * Signal that we're done booting.
68      * Requires ACCESS_SURFACE_FLINGER permission
69      */
bootFinished()70     void bootFinished();
71 
72     /**
73      * Create a display event connection
74      *
75      * layerHandle
76      *     Optional binder handle representing a Layer in SF to associate the new
77      *     DisplayEventConnection with. This handle can be found inside a surface control after
78      *     surface creation, see ISurfaceComposerClient::createSurface. Set to null if no layer
79      *     association should be made.
80      */
createDisplayEventConnection(VsyncSource vsyncSource, EventRegistration eventRegistration, @nullable IBinder layerHandle)81     @nullable IDisplayEventConnection createDisplayEventConnection(VsyncSource vsyncSource,
82             EventRegistration eventRegistration, @nullable IBinder layerHandle);
83 
84     /**
85      * Create a connection with SurfaceFlinger.
86      */
createConnection()87     @nullable ISurfaceComposerClient createConnection();
88 
89     /**
90      * Create a virtual display
91      *
92      * displayName
93      *     The name of the virtual display
94      * secure
95      *     Whether this virtual display is secure
96      * requestedRefreshRate
97      *     The refresh rate, frames per second, to request on the virtual display.
98      *     This is just a request, the actual rate may be adjusted to align well
99      *     with physical displays running concurrently. If 0 is specified, the
100      *     virtual display is refreshed at the physical display refresh rate.
101      *
102      * requires ACCESS_SURFACE_FLINGER permission.
103      */
createDisplay(@tf8InCpp String displayName, boolean secure, float requestedRefreshRate)104     @nullable IBinder createDisplay(@utf8InCpp String displayName, boolean secure,
105             float requestedRefreshRate);
106 
107     /**
108      * Destroy a virtual display
109      * requires ACCESS_SURFACE_FLINGER permission.
110      */
destroyDisplay(IBinder display)111     void destroyDisplay(IBinder display);
112 
113     /**
114      * Get stable IDs for connected physical displays.
115      */
getPhysicalDisplayIds()116     long[] getPhysicalDisplayIds();
117 
118     /**
119      * Get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or
120      * a DisplayEventReceiver hotplug event.
121      */
getPhysicalDisplayToken(long displayId)122     @nullable IBinder getPhysicalDisplayToken(long displayId);
123 
124     /**
125      * Returns the frame timestamps supported by SurfaceFlinger.
126      */
getSupportedFrameTimestamps()127     FrameEvent[] getSupportedFrameTimestamps();
128 
129     /**
130      * Set display power mode. depending on the mode, it can either trigger
131      * screen on, off or low power mode and wait for it to complete.
132      * requires ACCESS_SURFACE_FLINGER permission.
133      */
setPowerMode(IBinder display, int mode)134     void setPowerMode(IBinder display, int mode);
135 
136     /**
137      * Returns display statistics for a given display
138      * intended to be used by the media framework to properly schedule
139      * video frames */
getDisplayStats(@ullable IBinder display)140     DisplayStatInfo getDisplayStats(@nullable IBinder display);
141 
142     /**
143      * Get transactional state of given display.
144      */
getDisplayState(IBinder display)145     DisplayState getDisplayState(IBinder display);
146 
147     /**
148      * Gets immutable information about given physical display.
149      */
getStaticDisplayInfo(long displayId)150     StaticDisplayInfo getStaticDisplayInfo(long displayId);
151 
152     /**
153      * Gets dynamic information about given physical display.
154      */
getDynamicDisplayInfoFromId(long displayId)155     DynamicDisplayInfo getDynamicDisplayInfoFromId(long displayId);
156 
getDynamicDisplayInfoFromToken(IBinder display)157     DynamicDisplayInfo getDynamicDisplayInfoFromToken(IBinder display);
158 
getDisplayNativePrimaries(IBinder display)159     DisplayPrimaries getDisplayNativePrimaries(IBinder display);
160 
setActiveColorMode(IBinder display, int colorMode)161     void setActiveColorMode(IBinder display, int colorMode);
162 
163     /**
164      * Sets the user-preferred display mode that a device should boot in.
165      */
setBootDisplayMode(IBinder display, int displayModeId)166     void setBootDisplayMode(IBinder display, int displayModeId);
167 
168     /**
169      * Clears the user-preferred display mode. The device should now boot in system preferred
170      * display mode.
171      */
clearBootDisplayMode(IBinder display)172     void clearBootDisplayMode(IBinder display);
173 
174     /**
175      * Gets whether boot time display mode operations are supported on the device.
176      *
177      * outSupport
178      *      An output parameter for whether boot time display mode operations are supported.
179      *
180      * Returns NO_ERROR upon success. Otherwise,
181      *      NAME_NOT_FOUND if the display is invalid, or
182      *      BAD_VALUE      if the output parameter is invalid.
183      */
184     // TODO(b/213909104) : Add unit tests to verify surface flinger boot time APIs
getBootDisplayModeSupport()185     boolean getBootDisplayModeSupport();
186 
187     /**
188      * Gets the HDR conversion capabilities of the device. The conversion capability defines whether
189      * conversion from sourceType to outputType is possible (with or without latency).
190      *
191      * Requires the ACCESS_SURFACE_FLINGER permission.
192      */
getHdrConversionCapabilities()193      List<HdrConversionCapability> getHdrConversionCapabilities();
194 
195      /**
196       * Sets the HDR conversion strategy of the device.
197       * Returns the preferred HDR output type of the device, in case when HdrConversionStrategy has
198       * autoAllowedHdrTypes set. Returns Hdr::INVALID in other cases.
199       *
200       * Requires the ACCESS_SURFACE_FLINGER permission.
201       */
setHdrConversionStrategy(in HdrConversionStrategy hdrConversionStrategy)202      int setHdrConversionStrategy(in HdrConversionStrategy hdrConversionStrategy);
203 
204      /**
205       * Gets whether HDR output conversion operations are supported on the device.
206       */
getHdrOutputConversionSupport()207      boolean getHdrOutputConversionSupport();
208 
209     /**
210      * Switches Auto Low Latency Mode on/off on the connected display, if it is
211      * available. This should only be called if the display supports Auto Low
212      * Latency Mode as reported in #getDynamicDisplayInfo.
213      * For more information, see the HDMI 2.1 specification.
214      */
setAutoLowLatencyMode(IBinder display, boolean on)215     void setAutoLowLatencyMode(IBinder display, boolean on);
216 
217     /**
218      * This will start sending infoframes to the connected display with
219      * ContentType=Game (if on=true). This should only be called if the display
220      * Game Content Type as reported in #getDynamicDisplayInfo.
221      * For more information, see the HDMI 1.4 specification.
222      */
setGameContentType(IBinder display, boolean on)223     void setGameContentType(IBinder display, boolean on);
224 
225     /**
226      * Capture the specified screen. This requires READ_FRAME_BUFFER
227      * permission.  This function will fail if there is a secure window on
228      * screen and DisplayCaptureArgs.captureSecureLayers is false.
229      *
230      * This function can capture a subregion (the source crop) of the screen.
231      * The subregion can be optionally rotated.  It will also be scaled to
232      * match the size of the output buffer.
233      */
captureDisplay(in DisplayCaptureArgs args, IScreenCaptureListener listener)234     void captureDisplay(in DisplayCaptureArgs args, IScreenCaptureListener listener);
235 
236     /**
237      * Capture the specified screen. This requires the READ_FRAME_BUFFER
238      * permission.
239      */
captureDisplayById(long displayId, IScreenCaptureListener listener)240     void captureDisplayById(long displayId, IScreenCaptureListener listener);
241 
242     /**
243      * Capture a subtree of the layer hierarchy, potentially ignoring the root node.
244      * This requires READ_FRAME_BUFFER permission. This function will fail if there
245      * is a secure window on screen
246      */
captureLayers(in LayerCaptureArgs args, IScreenCaptureListener listener)247     void captureLayers(in LayerCaptureArgs args, IScreenCaptureListener listener);
248 
249     /**
250      * Clears the frame statistics for animations.
251      *
252      * Requires the ACCESS_SURFACE_FLINGER permission.
253      */
clearAnimationFrameStats()254     void clearAnimationFrameStats();
255 
256     /**
257      * Gets the frame statistics for animations.
258      *
259      * Requires the ACCESS_SURFACE_FLINGER permission.
260      */
getAnimationFrameStats()261     FrameStats getAnimationFrameStats();
262 
263     /**
264      * Overrides the supported HDR modes for the given display device.
265      *
266      * Requires the ACCESS_SURFACE_FLINGER permission.
267      */
overrideHdrTypes(IBinder display, in int[] hdrTypes)268     void overrideHdrTypes(IBinder display, in int[] hdrTypes);
269 
270     /**
271      * Pulls surfaceflinger atoms global stats and layer stats to pipe to statsd.
272      *
273      * Requires the calling uid be from system server.
274      */
onPullAtom(int atomId)275     PullAtomData onPullAtom(int atomId);
276 
277     /**
278      * Gets the list of active layers in Z order for debugging purposes
279      *
280      * Requires the ACCESS_SURFACE_FLINGER permission.
281      */
getLayerDebugInfo()282     List<LayerDebugInfo> getLayerDebugInfo();
283 
getColorManagement()284     boolean getColorManagement();
285 
286     /**
287      * Gets the composition preference of the default data space and default pixel format,
288      * as well as the wide color gamut data space and wide color gamut pixel format.
289      * If the wide color gamut data space is V0_SRGB, then it implies that the platform
290      * has no wide color gamut support.
291      *
292      */
getCompositionPreference()293     CompositionPreference getCompositionPreference();
294 
295     /**
296      * Requires the ACCESS_SURFACE_FLINGER permission.
297      */
getDisplayedContentSamplingAttributes(IBinder display)298     ContentSamplingAttributes getDisplayedContentSamplingAttributes(IBinder display);
299 
300     /**
301      * Turns on the color sampling engine on the display.
302      *
303      * Requires the ACCESS_SURFACE_FLINGER permission.
304      */
setDisplayContentSamplingEnabled(IBinder display, boolean enable, byte componentMask, long maxFrames)305     void setDisplayContentSamplingEnabled(IBinder display, boolean enable, byte componentMask, long maxFrames);
306 
307     /**
308      * Returns statistics on the color profile of the last frame displayed for a given display
309      *
310      * Requires the ACCESS_SURFACE_FLINGER permission.
311      */
getDisplayedContentSample(IBinder display, long maxFrames, long timestamp)312     DisplayedFrameStats getDisplayedContentSample(IBinder display, long maxFrames, long timestamp);
313 
314     /**
315      * Gets whether SurfaceFlinger can support protected content in GPU composition.
316      */
getProtectedContentSupport()317     boolean getProtectedContentSupport();
318 
319     /**
320      * Queries whether the given display is a wide color display.
321      * Requires the ACCESS_SURFACE_FLINGER permission.
322      */
isWideColorDisplay(IBinder token)323     boolean isWideColorDisplay(IBinder token);
324 
325     /**
326      * Registers a listener to stream median luma updates from SurfaceFlinger.
327      *
328      * The sampling area is bounded by both samplingArea and the given stopLayerHandle
329      * (i.e., only layers behind the stop layer will be captured and sampled).
330      *
331      * Multiple listeners may be provided so long as they have independent listeners.
332      * If multiple listeners are provided, the effective sampling region for each listener will
333      * be bounded by whichever stop layer has a lower Z value.
334      *
335      * Requires the same permissions as captureLayers and captureScreen.
336      */
addRegionSamplingListener(in ARect samplingArea, @nullable IBinder stopLayerHandle, IRegionSamplingListener listener)337     void addRegionSamplingListener(in ARect samplingArea, @nullable IBinder stopLayerHandle, IRegionSamplingListener listener);
338 
339     /**
340      * Removes a listener that was streaming median luma updates from SurfaceFlinger.
341      */
removeRegionSamplingListener(IRegionSamplingListener listener)342     void removeRegionSamplingListener(IRegionSamplingListener listener);
343 
344     /**
345      * Registers a listener that streams fps updates from SurfaceFlinger.
346      *
347      * The listener will stream fps updates for the layer tree rooted at the layer denoted by the
348      * task ID, i.e., the layer must have the task ID as part of its layer metadata with key
349      * METADATA_TASK_ID. If there is no such layer, then no fps is expected to be reported.
350      *
351      * Multiple listeners may be supported.
352      *
353      * Requires the READ_FRAME_BUFFER permission.
354      */
addFpsListener(int taskId, IFpsListener listener)355     void addFpsListener(int taskId, IFpsListener listener);
356 
357     /**
358      * Removes a listener that was streaming fps updates from SurfaceFlinger.
359      */
removeFpsListener(IFpsListener listener)360     void removeFpsListener(IFpsListener listener);
361 
362     /**
363      * Registers a listener to receive tunnel mode enabled updates from SurfaceFlinger.
364      *
365      * Requires ACCESS_SURFACE_FLINGER permission.
366      */
addTunnelModeEnabledListener(ITunnelModeEnabledListener listener)367     void addTunnelModeEnabledListener(ITunnelModeEnabledListener listener);
368 
369     /**
370      * Removes a listener that was receiving tunnel mode enabled updates from SurfaceFlinger.
371      *
372      * Requires ACCESS_SURFACE_FLINGER permission.
373      */
removeTunnelModeEnabledListener(ITunnelModeEnabledListener listener)374     void removeTunnelModeEnabledListener(ITunnelModeEnabledListener listener);
375 
376     /**
377      * Sets the refresh rate boundaries for the display.
378      *
379      * @see DisplayModeSpecs.aidl for details.
380      */
setDesiredDisplayModeSpecs(IBinder displayToken, in DisplayModeSpecs specs)381     void setDesiredDisplayModeSpecs(IBinder displayToken, in DisplayModeSpecs specs);
382 
getDesiredDisplayModeSpecs(IBinder displayToken)383     DisplayModeSpecs getDesiredDisplayModeSpecs(IBinder displayToken);
384 
385     /**
386      * Gets whether brightness operations are supported on a display.
387      *
388      * displayToken
389      *      The token of the display.
390      * outSupport
391      *      An output parameter for whether brightness operations are supported.
392      *
393      * Returns NO_ERROR upon success. Otherwise,
394      *      NAME_NOT_FOUND if the display is invalid, or
395      *      BAD_VALUE      if the output parameter is invalid.
396      */
getDisplayBrightnessSupport(IBinder displayToken)397     boolean getDisplayBrightnessSupport(IBinder displayToken);
398 
399     /**
400      * Sets the brightness of a display.
401      *
402      * displayToken
403      *      The token of the display whose brightness is set.
404      * brightness
405      *      The DisplayBrightness info to set on the desired display.
406      *
407      * Returns NO_ERROR upon success. Otherwise,
408      *      NAME_NOT_FOUND    if the display is invalid, or
409      *      BAD_VALUE         if the brightness is invalid, or
410      *      INVALID_OPERATION if brightness operations are not supported.
411      */
setDisplayBrightness(IBinder displayToken, in DisplayBrightness brightness)412     void setDisplayBrightness(IBinder displayToken, in DisplayBrightness brightness);
413 
414     /**
415      * Adds a listener that receives HDR layer information. This is used in combination
416      * with setDisplayBrightness to adjust the display brightness depending on factors such
417      * as whether or not HDR is in use.
418      *
419      * Returns NO_ERROR upon success or NAME_NOT_FOUND if the display is invalid.
420      */
addHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener)421     void addHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener);
422 
423     /**
424      * Removes a listener that was added with addHdrLayerInfoListener.
425      *
426      * Returns NO_ERROR upon success, NAME_NOT_FOUND if the display is invalid, and BAD_VALUE if
427      *     the listener wasn't registered.
428      *
429      */
removeHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener)430     void removeHdrLayerInfoListener(IBinder displayToken, IHdrLayerInfoListener listener);
431 
432     /**
433      * Sends a power boost to the composer. This function is asynchronous.
434      *
435      * boostId
436      *      boost id according to android::hardware::power::Boost
437      *
438      * Returns NO_ERROR upon success.
439      */
notifyPowerBoost(int boostId)440     oneway void notifyPowerBoost(int boostId);
441 
442     /*
443      * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows
444      * material design guidelines.
445      *
446      * ambientColor
447      *      Color to the ambient shadow. The alpha is premultiplied.
448      *
449      * spotColor
450      *      Color to the spot shadow. The alpha is premultiplied. The position of the spot shadow
451      *      depends on the light position.
452      *
453      * lightPosY/lightPosZ
454      *      Position of the light used to cast the spot shadow. The X value is always the display
455      *      width / 2.
456      *
457      * lightRadius
458      *      Radius of the light casting the shadow.
459      */
setGlobalShadowSettings(in Color ambientColor, in Color spotColor, float lightPosY, float lightPosZ, float lightRadius)460     oneway void setGlobalShadowSettings(in Color ambientColor, in Color spotColor, float lightPosY, float lightPosZ, float lightRadius);
461 
462     /**
463      * Gets whether a display supports DISPLAY_DECORATION layers.
464      *
465      * displayToken
466      *      The token of the display.
467      * outSupport
468      *      An output parameter for whether/how the display supports
469      *      DISPLAY_DECORATION layers.
470      *
471      * Returns NO_ERROR upon success. Otherwise,
472      *      NAME_NOT_FOUND if the display is invalid, or
473      *      BAD_VALUE      if the output parameter is invalid.
474      */
getDisplayDecorationSupport(IBinder displayToken)475     @nullable DisplayDecorationSupport getDisplayDecorationSupport(IBinder displayToken);
476 
477     /**
478      * Set the override frame rate for a specified uid by GameManagerService.
479      * Passing the frame rate and uid to SurfaceFlinger to update the override mapping
480      * in the scheduler.
481      */
setOverrideFrameRate(int uid, float frameRate)482     void setOverrideFrameRate(int uid, float frameRate);
483 
updateSmallAreaDetection(in int[] uids, in float[] thresholds)484     oneway void updateSmallAreaDetection(in int[] uids, in float[] thresholds);
485 
486     /**
487      * Set the small area detection threshold for a specified uid by SmallAreaDetectionController.
488      * Passing the threshold and uid to SurfaceFlinger to update the uid-threshold mapping
489      * in the scheduler.
490      */
setSmallAreaDetectionThreshold(int uid, float threshold)491     oneway void setSmallAreaDetectionThreshold(int uid, float threshold);
492 
493     /**
494      * Gets priority of the RenderEngine in SurfaceFlinger.
495      */
getGpuContextPriority()496     int getGpuContextPriority();
497 
498     /**
499      * Gets the number of buffers SurfaceFlinger would need acquire. This number
500      * would be propagated to the client via MIN_UNDEQUEUED_BUFFERS so that the
501      * client could allocate enough buffers to match SF expectations of the
502      * pipeline depth. SurfaceFlinger will make sure that it will give the app at
503      * least the time configured as the 'appDuration' before trying to latch
504      * the buffer.
505      *
506      * The total buffers needed for a given configuration is basically the
507      * numbers of vsyncs a single buffer is used across the stack. For the default
508      * configuration a buffer is held ~1 vsync by the app, ~1 vsync by SurfaceFlinger
509      * and 1 vsync by the display. The extra buffers are calculated as the
510      * number of additional buffers on top of the 2 buffers already present
511      * in MIN_UNDEQUEUED_BUFFERS.
512      */
getMaxAcquiredBufferCount()513     int getMaxAcquiredBufferCount();
514 
addWindowInfosListener(IWindowInfosListener windowInfosListener)515     WindowInfosListenerInfo addWindowInfosListener(IWindowInfosListener windowInfosListener);
516 
removeWindowInfosListener(IWindowInfosListener windowInfosListener)517     void removeWindowInfosListener(IWindowInfosListener windowInfosListener);
518 
getOverlaySupport()519     OverlayProperties getOverlaySupport();
520 
521     /**
522      * Returns an instance of StalledTransaction if a transaction from the passed pid has not been
523      * applied in SurfaceFlinger due to an unsignaled fence. Otherwise, null is returned.
524      */
getStalledTransactionInfo(int pid)525     @nullable StalledTransactionInfo getStalledTransactionInfo(int pid);
526 }
527