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 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 179 int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform, 180 Rotation rotation = eRotateNone) = 0; 181 182 /** 183 * Capture a subtree of the layer hierarchy, potentially ignoring the root node. 184 */ 185 virtual status_t captureLayers(const sp<IBinder>& layerHandleBinder, 186 sp<GraphicBuffer>* outBuffer, const Rect& sourceCrop, 187 float frameScale = 1.0, bool childrenOnly = false) = 0; 188 189 /* Clears the frame statistics for animations. 190 * 191 * Requires the ACCESS_SURFACE_FLINGER permission. 192 */ 193 virtual status_t clearAnimationFrameStats() = 0; 194 195 /* Gets the frame statistics for animations. 196 * 197 * Requires the ACCESS_SURFACE_FLINGER permission. 198 */ 199 virtual status_t getAnimationFrameStats(FrameStats* outStats) const = 0; 200 201 /* Gets the supported HDR capabilities of the given display. 202 * 203 * Requires the ACCESS_SURFACE_FLINGER permission. 204 */ 205 virtual status_t getHdrCapabilities(const sp<IBinder>& display, 206 HdrCapabilities* outCapabilities) const = 0; 207 208 virtual status_t enableVSyncInjections(bool enable) = 0; 209 210 virtual status_t injectVSync(nsecs_t when) = 0; 211 212 /* Gets the list of active layers in Z order for debugging purposes 213 * 214 * Requires the ACCESS_SURFACE_FLINGER permission. 215 */ 216 virtual status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* outLayers) const = 0; 217 }; 218 219 // ---------------------------------------------------------------------------- 220 221 class BnSurfaceComposer: public BnInterface<ISurfaceComposer> { 222 public: 223 enum { 224 // Note: BOOT_FINISHED must remain this value, it is called from 225 // Java by ActivityManagerService. 226 BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, 227 CREATE_CONNECTION, 228 UNUSED, // formerly CREATE_GRAPHIC_BUFFER_ALLOC 229 CREATE_DISPLAY_EVENT_CONNECTION, 230 CREATE_DISPLAY, 231 DESTROY_DISPLAY, 232 GET_BUILT_IN_DISPLAY, 233 SET_TRANSACTION_STATE, 234 AUTHENTICATE_SURFACE, 235 GET_SUPPORTED_FRAME_TIMESTAMPS, 236 GET_DISPLAY_CONFIGS, 237 GET_ACTIVE_CONFIG, 238 SET_ACTIVE_CONFIG, 239 CONNECT_DISPLAY, 240 CAPTURE_SCREEN, 241 CAPTURE_LAYERS, 242 CLEAR_ANIMATION_FRAME_STATS, 243 GET_ANIMATION_FRAME_STATS, 244 SET_POWER_MODE, 245 GET_DISPLAY_STATS, 246 GET_HDR_CAPABILITIES, 247 GET_DISPLAY_COLOR_MODES, 248 GET_ACTIVE_COLOR_MODE, 249 SET_ACTIVE_COLOR_MODE, 250 ENABLE_VSYNC_INJECTIONS, 251 INJECT_VSYNC, 252 GET_LAYER_DEBUG_INFO, 253 CREATE_SCOPED_CONNECTION 254 }; 255 256 virtual status_t onTransact(uint32_t code, const Parcel& data, 257 Parcel* reply, uint32_t flags = 0); 258 }; 259 260 // ---------------------------------------------------------------------------- 261 262 }; // namespace android 263 264 #endif // ANDROID_GUI_ISURFACE_COMPOSER_H 265