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 
     32 #include <gui/IGraphicBufferAlloc.h>
     33 #include <gui/ISurfaceComposerClient.h>
     34 
     35 namespace android {
     36 // ----------------------------------------------------------------------------
     37 
     38 class ComposerState;
     39 class DisplayState;
     40 struct DisplayInfo;
     41 struct DisplayStatInfo;
     42 class HdrCapabilities;
     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     virtual status_t getDisplayColorModes(const sp<IBinder>& display,
    141             Vector<android_color_mode_t>* outColorModes) = 0;
    142     virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display) = 0;
    143     virtual status_t setActiveColorMode(const sp<IBinder>& display,
    144             android_color_mode_t colorMode) = 0;
    145 
    146     /* Capture the specified screen. requires READ_FRAME_BUFFER permission
    147      * This function will fail if there is a secure window on screen.
    148      */
    149     virtual status_t captureScreen(const sp<IBinder>& display,
    150             const sp<IGraphicBufferProducer>& producer,
    151             Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
    152             uint32_t minLayerZ, uint32_t maxLayerZ,
    153             bool useIdentityTransform,
    154             Rotation rotation = eRotateNone) = 0;
    155 
    156     /* Clears the frame statistics for animations.
    157      *
    158      * Requires the ACCESS_SURFACE_FLINGER permission.
    159      */
    160     virtual status_t clearAnimationFrameStats() = 0;
    161 
    162     /* Gets the frame statistics for animations.
    163      *
    164      * Requires the ACCESS_SURFACE_FLINGER permission.
    165      */
    166     virtual status_t getAnimationFrameStats(FrameStats* outStats) const = 0;
    167 
    168     /* Gets the supported HDR capabilities of the given display.
    169      *
    170      * Requires the ACCESS_SURFACE_FLINGER permission.
    171      */
    172     virtual status_t getHdrCapabilities(const sp<IBinder>& display,
    173             HdrCapabilities* outCapabilities) const = 0;
    174 };
    175 
    176 // ----------------------------------------------------------------------------
    177 
    178 class BnSurfaceComposer: public BnInterface<ISurfaceComposer> {
    179 public:
    180     enum {
    181         // Note: BOOT_FINISHED must remain this value, it is called from
    182         // Java by ActivityManagerService.
    183         BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION,
    184         CREATE_CONNECTION,
    185         CREATE_GRAPHIC_BUFFER_ALLOC,
    186         CREATE_DISPLAY_EVENT_CONNECTION,
    187         CREATE_DISPLAY,
    188         DESTROY_DISPLAY,
    189         GET_BUILT_IN_DISPLAY,
    190         SET_TRANSACTION_STATE,
    191         AUTHENTICATE_SURFACE,
    192         GET_DISPLAY_CONFIGS,
    193         GET_ACTIVE_CONFIG,
    194         SET_ACTIVE_CONFIG,
    195         CONNECT_DISPLAY,
    196         CAPTURE_SCREEN,
    197         CLEAR_ANIMATION_FRAME_STATS,
    198         GET_ANIMATION_FRAME_STATS,
    199         SET_POWER_MODE,
    200         GET_DISPLAY_STATS,
    201         GET_HDR_CAPABILITIES,
    202         GET_DISPLAY_COLOR_MODES,
    203         GET_ACTIVE_COLOR_MODE,
    204         SET_ACTIVE_COLOR_MODE,
    205     };
    206 
    207     virtual status_t onTransact(uint32_t code, const Parcel& data,
    208             Parcel* reply, uint32_t flags = 0);
    209 };
    210 
    211 // ----------------------------------------------------------------------------
    212 
    213 }; // namespace android
    214 
    215 #endif // ANDROID_GUI_ISURFACE_COMPOSER_H
    216