1/*
2 * Copyright (C) 2006 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#ifndef ANDROID_GUI_ISURFACE_COMPOSER_H
18#define ANDROID_GUI_ISURFACE_COMPOSER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/RefBase.h>
24#include <utils/Errors.h>
25#include <utils/Timers.h>
26#include <utils/Vector.h>
27
28#include <binder/IInterface.h>
29
30#include <ui/FrameStats.h>
31#include <ui/PixelFormat.h>
32
33#include <vector>
34
35namespace android {
36// ----------------------------------------------------------------------------
37
38struct ComposerState;
39struct DisplayState;
40struct DisplayInfo;
41struct DisplayStatInfo;
42class HdrCapabilities;
43class IDisplayEventConnection;
44class IGraphicBufferProducer;
45class ISurfaceComposerClient;
46class Rect;
47enum class FrameEvent;
48
49/*
50 * This class defines the Binder IPC interface for accessing various
51 * SurfaceFlinger features.
52 */
53class ISurfaceComposer: public IInterface {
54public:
55    DECLARE_META_INTERFACE(SurfaceComposer)
56
57    // flags for setTransactionState()
58    enum {
59        eSynchronous = 0x01,
60        eAnimation   = 0x02,
61    };
62
63    enum {
64        eDisplayIdMain = 0,
65        eDisplayIdHdmi = 1
66    };
67
68    enum Rotation {
69        eRotateNone = 0,
70        eRotate90   = 1,
71        eRotate180  = 2,
72        eRotate270  = 3
73    };
74
75    enum VsyncSource {
76        eVsyncSourceApp = 0,
77        eVsyncSourceSurfaceFlinger = 1
78    };
79
80    /* create connection with surface flinger, requires
81     * ACCESS_SURFACE_FLINGER permission
82     */
83    virtual sp<ISurfaceComposerClient> createConnection() = 0;
84
85    /** create a scoped connection with surface flinger.
86     * Surfaces produced with this connection will act
87     * as children of the passed in GBP. That is to say
88     * SurfaceFlinger will draw them relative and confined to
89     * drawing of buffers from the layer associated with parent.
90     * As this is graphically equivalent in reach to just drawing
91     * pixels into the parent buffers, it requires no special permission.
92     */
93    virtual sp<ISurfaceComposerClient> createScopedConnection(
94            const sp<IGraphicBufferProducer>& parent) = 0;
95
96    /* return an IDisplayEventConnection */
97    virtual sp<IDisplayEventConnection> createDisplayEventConnection(
98            VsyncSource vsyncSource = eVsyncSourceApp) = 0;
99
100    /* create a virtual display
101     * requires ACCESS_SURFACE_FLINGER permission.
102     */
103    virtual sp<IBinder> createDisplay(const String8& displayName,
104            bool secure) = 0;
105
106    /* destroy a virtual display
107     * requires ACCESS_SURFACE_FLINGER permission.
108     */
109    virtual void destroyDisplay(const sp<IBinder>& display) = 0;
110
111    /* get the token for the existing default displays. possible values
112     * for id are eDisplayIdMain and eDisplayIdHdmi.
113     */
114    virtual sp<IBinder> getBuiltInDisplay(int32_t id) = 0;
115
116    /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
117    virtual void setTransactionState(const Vector<ComposerState>& state,
118            const Vector<DisplayState>& displays, uint32_t flags) = 0;
119
120    /* signal that we're done booting.
121     * Requires ACCESS_SURFACE_FLINGER permission
122     */
123    virtual void bootFinished() = 0;
124
125    /* verify that an IGraphicBufferProducer was created by SurfaceFlinger.
126     */
127    virtual bool authenticateSurfaceTexture(
128            const sp<IGraphicBufferProducer>& surface) const = 0;
129
130    /* Returns the frame timestamps supported by SurfaceFlinger.
131     */
132    virtual status_t getSupportedFrameTimestamps(
133            std::vector<FrameEvent>* outSupported) const = 0;
134
135    /* set display power mode. depending on the mode, it can either trigger
136     * screen on, off or low power mode and wait for it to complete.
137     * requires ACCESS_SURFACE_FLINGER permission.
138     */
139    virtual void setPowerMode(const sp<IBinder>& display, int mode) = 0;
140
141    /* returns information for each configuration of the given display
142     * intended to be used to get information about built-in displays */
143    virtual status_t getDisplayConfigs(const sp<IBinder>& display,
144            Vector<DisplayInfo>* configs) = 0;
145
146    /* returns display statistics for a given display
147     * intended to be used by the media framework to properly schedule
148     * video frames */
149    virtual status_t getDisplayStats(const sp<IBinder>& display,
150            DisplayStatInfo* stats) = 0;
151
152    /* indicates which of the configurations returned by getDisplayInfo is
153     * currently active */
154    virtual int getActiveConfig(const sp<IBinder>& display) = 0;
155
156    /* specifies which configuration (of those returned by getDisplayInfo)
157     * should be used */
158    virtual status_t setActiveConfig(const sp<IBinder>& display, int id) = 0;
159
160    virtual status_t getDisplayColorModes(const sp<IBinder>& display,
161            Vector<android_color_mode_t>* outColorModes) = 0;
162    virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) = 0;
163    virtual status_t setActiveColorMode(const sp<IBinder>& display,
164            android_color_mode_t colorMode) = 0;
165
166    /* Capture the specified screen. requires READ_FRAME_BUFFER permission
167     * This function will fail if there is a secure window on screen.
168     */
169    virtual status_t captureScreen(const sp<IBinder>& display,
170            const sp<IGraphicBufferProducer>& producer,
171            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
172            int32_t minLayerZ, int32_t maxLayerZ,
173            bool useIdentityTransform,
174            Rotation rotation = eRotateNone) = 0;
175
176    /* Clears the frame statistics for animations.
177     *
178     * Requires the ACCESS_SURFACE_FLINGER permission.
179     */
180    virtual status_t clearAnimationFrameStats() = 0;
181
182    /* Gets the frame statistics for animations.
183     *
184     * Requires the ACCESS_SURFACE_FLINGER permission.
185     */
186    virtual status_t getAnimationFrameStats(FrameStats* outStats) const = 0;
187
188    /* Gets the supported HDR capabilities of the given display.
189     *
190     * Requires the ACCESS_SURFACE_FLINGER permission.
191     */
192    virtual status_t getHdrCapabilities(const sp<IBinder>& display,
193            HdrCapabilities* outCapabilities) const = 0;
194
195    virtual status_t enableVSyncInjections(bool enable) = 0;
196
197    virtual status_t injectVSync(nsecs_t when) = 0;
198};
199
200// ----------------------------------------------------------------------------
201
202class BnSurfaceComposer: public BnInterface<ISurfaceComposer> {
203public:
204    enum {
205        // Note: BOOT_FINISHED must remain this value, it is called from
206        // Java by ActivityManagerService.
207        BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
208        CREATE_CONNECTION,
209        UNUSED, // formerly CREATE_GRAPHIC_BUFFER_ALLOC
210        CREATE_DISPLAY_EVENT_CONNECTION,
211        CREATE_DISPLAY,
212        DESTROY_DISPLAY,
213        GET_BUILT_IN_DISPLAY,
214        SET_TRANSACTION_STATE,
215        AUTHENTICATE_SURFACE,
216        GET_SUPPORTED_FRAME_TIMESTAMPS,
217        GET_DISPLAY_CONFIGS,
218        GET_ACTIVE_CONFIG,
219        SET_ACTIVE_CONFIG,
220        CONNECT_DISPLAY,
221        CAPTURE_SCREEN,
222        CLEAR_ANIMATION_FRAME_STATS,
223        GET_ANIMATION_FRAME_STATS,
224        SET_POWER_MODE,
225        GET_DISPLAY_STATS,
226        GET_HDR_CAPABILITIES,
227        GET_DISPLAY_COLOR_MODES,
228        GET_ACTIVE_COLOR_MODE,
229        SET_ACTIVE_COLOR_MODE,
230        ENABLE_VSYNC_INJECTIONS,
231        INJECT_VSYNC,
232        CREATE_SCOPED_CONNECTION
233    };
234
235    virtual status_t onTransact(uint32_t code, const Parcel& data,
236            Parcel* reply, uint32_t flags = 0);
237};
238
239// ----------------------------------------------------------------------------
240
241}; // namespace android
242
243#endif // ANDROID_GUI_ISURFACE_COMPOSER_H
244