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