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
32#include <gui/IGraphicBufferAlloc.h>
33#include <gui/ISurfaceComposerClient.h>
34
35namespace android {
36// ----------------------------------------------------------------------------
37
38class ComposerState;
39class DisplayState;
40struct DisplayInfo;
41struct DisplayStatInfo;
42class HdrCapabilities;
43class IDisplayEventConnection;
44class IMemoryHeap;
45class Rect;
46
47/*
48 * This class defines the Binder IPC interface for accessing various
49 * SurfaceFlinger features.
50 */
51class ISurfaceComposer: public IInterface {
52public:
53    DECLARE_META_INTERFACE(SurfaceComposer);
54
55    // flags for setTransactionState()
56    enum {
57        eSynchronous = 0x01,
58        eAnimation   = 0x02,
59    };
60
61    enum {
62        eDisplayIdMain = 0,
63        eDisplayIdHdmi = 1
64    };
65
66    enum Rotation {
67        eRotateNone = 0,
68        eRotate90   = 1,
69        eRotate180  = 2,
70        eRotate270  = 3
71    };
72
73    /* create connection with surface flinger, requires
74     * ACCESS_SURFACE_FLINGER permission
75     */
76    virtual sp<ISurfaceComposerClient> createConnection() = 0;
77
78    /* create a graphic buffer allocator
79     */
80    virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc() = 0;
81
82    /* return an IDisplayEventConnection */
83    virtual sp<IDisplayEventConnection> createDisplayEventConnection() = 0;
84
85    /* create a virtual display
86     * requires ACCESS_SURFACE_FLINGER permission.
87     */
88    virtual sp<IBinder> createDisplay(const String8& displayName,
89            bool secure) = 0;
90
91    /* destroy a virtual display
92     * requires ACCESS_SURFACE_FLINGER permission.
93     */
94    virtual void destroyDisplay(const sp<IBinder>& display) = 0;
95
96    /* get the token for the existing default displays. possible values
97     * for id are eDisplayIdMain and eDisplayIdHdmi.
98     */
99    virtual sp<IBinder> getBuiltInDisplay(int32_t id) = 0;
100
101    /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */
102    virtual void setTransactionState(const Vector<ComposerState>& state,
103            const Vector<DisplayState>& displays, uint32_t flags) = 0;
104
105    /* signal that we're done booting.
106     * Requires ACCESS_SURFACE_FLINGER permission
107     */
108    virtual void bootFinished() = 0;
109
110    /* verify that an IGraphicBufferProducer was created by SurfaceFlinger.
111     */
112    virtual bool authenticateSurfaceTexture(
113            const sp<IGraphicBufferProducer>& surface) const = 0;
114
115    /* set display power mode. depending on the mode, it can either trigger
116     * screen on, off or low power mode and wait for it to complete.
117     * requires ACCESS_SURFACE_FLINGER permission.
118     */
119    virtual void setPowerMode(const sp<IBinder>& display, int mode) = 0;
120
121    /* returns information for each configuration of the given display
122     * intended to be used to get information about built-in displays */
123    virtual status_t getDisplayConfigs(const sp<IBinder>& display,
124            Vector<DisplayInfo>* configs) = 0;
125
126    /* returns display statistics for a given display
127     * intended to be used by the media framework to properly schedule
128     * video frames */
129    virtual status_t getDisplayStats(const sp<IBinder>& display,
130            DisplayStatInfo* stats) = 0;
131
132    /* indicates which of the configurations returned by getDisplayInfo is
133     * currently active */
134    virtual int getActiveConfig(const sp<IBinder>& display) = 0;
135
136    /* specifies which configuration (of those returned by getDisplayInfo)
137     * should be used */
138    virtual status_t setActiveConfig(const sp<IBinder>& display, int id) = 0;
139
140    /* Capture the specified screen. requires READ_FRAME_BUFFER permission
141     * This function will fail if there is a secure window on screen.
142     */
143    virtual status_t captureScreen(const sp<IBinder>& display,
144            const sp<IGraphicBufferProducer>& producer,
145            Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
146            uint32_t minLayerZ, uint32_t maxLayerZ,
147            bool useIdentityTransform,
148            Rotation rotation = eRotateNone) = 0;
149
150    /* Clears the frame statistics for animations.
151     *
152     * Requires the ACCESS_SURFACE_FLINGER permission.
153     */
154    virtual status_t clearAnimationFrameStats() = 0;
155
156    /* Gets the frame statistics for animations.
157     *
158     * Requires the ACCESS_SURFACE_FLINGER permission.
159     */
160    virtual status_t getAnimationFrameStats(FrameStats* outStats) const = 0;
161
162    /* Gets the supported HDR capabilities of the given display.
163     *
164     * Requires the ACCESS_SURFACE_FLINGER permission.
165     */
166    virtual status_t getHdrCapabilities(const sp<IBinder>& display,
167            HdrCapabilities* outCapabilities) const = 0;
168};
169
170// ----------------------------------------------------------------------------
171
172class BnSurfaceComposer: public BnInterface<ISurfaceComposer> {
173public:
174    enum {
175        // Note: BOOT_FINISHED must remain this value, it is called from
176        // Java by ActivityManagerService.
177        BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
178        CREATE_CONNECTION,
179        CREATE_GRAPHIC_BUFFER_ALLOC,
180        CREATE_DISPLAY_EVENT_CONNECTION,
181        CREATE_DISPLAY,
182        DESTROY_DISPLAY,
183        GET_BUILT_IN_DISPLAY,
184        SET_TRANSACTION_STATE,
185        AUTHENTICATE_SURFACE,
186        GET_DISPLAY_CONFIGS,
187        GET_ACTIVE_CONFIG,
188        SET_ACTIVE_CONFIG,
189        CONNECT_DISPLAY,
190        CAPTURE_SCREEN,
191        CLEAR_ANIMATION_FRAME_STATS,
192        GET_ANIMATION_FRAME_STATS,
193        SET_POWER_MODE,
194        GET_DISPLAY_STATS,
195        GET_HDR_CAPABILITIES,
196    };
197
198    virtual status_t onTransact(uint32_t code, const Parcel& data,
199            Parcel* reply, uint32_t flags = 0);
200};
201
202// ----------------------------------------------------------------------------
203
204}; // namespace android
205
206#endif // ANDROID_GUI_ISURFACE_COMPOSER_H
207