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