Home | History | Annotate | Download | only in gui
      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 <gui/IGraphicBufferAlloc.h>
     34 #include <gui/ISurfaceComposerClient.h>
     35 
     36 namespace android {
     37 // ----------------------------------------------------------------------------
     38 
     39 class ComposerState;
     40 class DisplayState;
     41 struct DisplayInfo;
     42 class DisplayStatInfo;
     43 class IDisplayEventConnection;
     44 class IMemoryHeap;
     45 class Rect;
     46 
     47 /*
     48  * This class defines the Binder IPC interface for accessing various
     49  * SurfaceFlinger features.
     50  */
     51 class ISurfaceComposer: public IInterface {
     52 public:
     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 
    163 // ----------------------------------------------------------------------------
    164 
    165 class BnSurfaceComposer: public BnInterface<ISurfaceComposer> {
    166 public:
    167     enum {
    168         // Note: BOOT_FINISHED must remain this value, it is called from
    169         // Java by ActivityManagerService.
    170         BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
    171         CREATE_CONNECTION,
    172         CREATE_GRAPHIC_BUFFER_ALLOC,
    173         CREATE_DISPLAY_EVENT_CONNECTION,
    174         CREATE_DISPLAY,
    175         DESTROY_DISPLAY,
    176         GET_BUILT_IN_DISPLAY,
    177         SET_TRANSACTION_STATE,
    178         AUTHENTICATE_SURFACE,
    179         GET_DISPLAY_CONFIGS,
    180         GET_ACTIVE_CONFIG,
    181         SET_ACTIVE_CONFIG,
    182         CONNECT_DISPLAY,
    183         CAPTURE_SCREEN,
    184         CLEAR_ANIMATION_FRAME_STATS,
    185         GET_ANIMATION_FRAME_STATS,
    186         SET_POWER_MODE,
    187         GET_DISPLAY_STATS,
    188     };
    189 
    190     virtual status_t onTransact(uint32_t code, const Parcel& data,
    191             Parcel* reply, uint32_t flags = 0);
    192 };
    193 
    194 // ----------------------------------------------------------------------------
    195 
    196 }; // namespace android
    197 
    198 #endif // ANDROID_GUI_ISURFACE_COMPOSER_H
    199