SurfaceComposerClient.h revision c18790018be5d7ea7061ccbc81f3044e74adc823
1/* 2 * Copyright (C) 2007 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_SURFACE_COMPOSER_CLIENT_H 18#define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H 19 20#include <stdint.h> 21#include <sys/types.h> 22 23#include <binder/IBinder.h> 24#include <binder/IMemory.h> 25 26#include <utils/RefBase.h> 27#include <utils/Singleton.h> 28#include <utils/SortedVector.h> 29#include <utils/threads.h> 30 31#include <ui/FrameStats.h> 32#include <ui/PixelFormat.h> 33 34#include <gui/CpuConsumer.h> 35#include <gui/SurfaceControl.h> 36 37namespace android { 38 39// --------------------------------------------------------------------------- 40 41class DisplayInfo; 42class Composer; 43class ISurfaceComposerClient; 44class IGraphicBufferProducer; 45class Region; 46 47// --------------------------------------------------------------------------- 48 49class SurfaceComposerClient : public RefBase 50{ 51 friend class Composer; 52public: 53 SurfaceComposerClient(); 54 virtual ~SurfaceComposerClient(); 55 56 // Always make sure we could initialize 57 status_t initCheck() const; 58 59 // Return the connection of this client 60 sp<IBinder> connection() const; 61 62 // Forcibly remove connection before all references have gone away. 63 void dispose(); 64 65 // callback when the composer is dies 66 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, 67 void* cookie = NULL, uint32_t flags = 0); 68 69 // Get a list of supported configurations for a given display 70 static status_t getDisplayConfigs(const sp<IBinder>& display, 71 Vector<DisplayInfo>* configs); 72 73 // Get the DisplayInfo for the currently-active configuration 74 static status_t getDisplayInfo(const sp<IBinder>& display, 75 DisplayInfo* info); 76 77 // Get the index of the current active configuration (relative to the list 78 // returned by getDisplayInfo) 79 static int getActiveConfig(const sp<IBinder>& display); 80 81 // Set a new active configuration using an index relative to the list 82 // returned by getDisplayInfo 83 static status_t setActiveConfig(const sp<IBinder>& display, int id); 84 85 /* triggers screen off and waits for it to complete */ 86 static void blankDisplay(const sp<IBinder>& display); 87 88 /* triggers screen on and waits for it to complete */ 89 static void unblankDisplay(const sp<IBinder>& display); 90 91 // ------------------------------------------------------------------------ 92 // surface creation / destruction 93 94 //! Create a surface 95 sp<SurfaceControl> createSurface( 96 const String8& name,// name of the surface 97 uint32_t w, // width in pixel 98 uint32_t h, // height in pixel 99 PixelFormat format, // pixel-format desired 100 uint32_t flags = 0 // usage flags 101 ); 102 103 //! Create a virtual display 104 static sp<IBinder> createDisplay(const String8& displayName, bool secure); 105 106 //! Destroy a virtual display 107 static void destroyDisplay(const sp<IBinder>& display); 108 109 //! Get the token for the existing default displays. 110 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi. 111 static sp<IBinder> getBuiltInDisplay(int32_t id); 112 113 // ------------------------------------------------------------------------ 114 // Composer parameters 115 // All composer parameters must be changed within a transaction 116 // several surfaces can be updated in one transaction, all changes are 117 // committed at once when the transaction is closed. 118 // closeGlobalTransaction() requires an IPC with the server. 119 120 //! Open a composer transaction on all active SurfaceComposerClients. 121 static void openGlobalTransaction(); 122 123 //! Close a composer transaction on all active SurfaceComposerClients. 124 static void closeGlobalTransaction(bool synchronous = false); 125 126 //! Flag the currently open transaction as an animation transaction. 127 static void setAnimationTransaction(); 128 129 status_t hide(const sp<IBinder>& id); 130 status_t show(const sp<IBinder>& id); 131 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask); 132 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent); 133 status_t setLayer(const sp<IBinder>& id, int32_t layer); 134 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f); 135 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy); 136 status_t setPosition(const sp<IBinder>& id, float x, float y); 137 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h); 138 status_t setCrop(const sp<IBinder>& id, const Rect& crop); 139 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack); 140 status_t destroySurface(const sp<IBinder>& id); 141 142 status_t clearLayerFrameStats(const sp<IBinder>& token) const; 143 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const; 144 145 static status_t clearAnimationFrameStats(); 146 static status_t getAnimationFrameStats(FrameStats* outStats); 147 148 static void setDisplaySurface(const sp<IBinder>& token, 149 const sp<IGraphicBufferProducer>& bufferProducer); 150 static void setDisplayLayerStack(const sp<IBinder>& token, 151 uint32_t layerStack); 152 153 /* setDisplayProjection() defines the projection of layer stacks 154 * to a given display. 155 * 156 * - orientation defines the display's orientation. 157 * - layerStackRect defines which area of the window manager coordinate 158 * space will be used. 159 * - displayRect defines where on the display will layerStackRect be 160 * mapped to. displayRect is specified post-orientation, that is 161 * it uses the orientation seen by the end-user. 162 */ 163 static void setDisplayProjection(const sp<IBinder>& token, 164 uint32_t orientation, 165 const Rect& layerStackRect, 166 const Rect& displayRect); 167 168private: 169 virtual void onFirstRef(); 170 Composer& getComposer(); 171 172 mutable Mutex mLock; 173 status_t mStatus; 174 sp<ISurfaceComposerClient> mClient; 175 Composer& mComposer; 176}; 177 178// --------------------------------------------------------------------------- 179 180class ScreenshotClient 181{ 182public: 183 // if cropping isn't required, callers may pass in a default Rect, e.g.: 184 // capture(display, producer, Rect(), reqWidth, ...); 185 static status_t capture( 186 const sp<IBinder>& display, 187 const sp<IGraphicBufferProducer>& producer, 188 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 189 uint32_t minLayerZ, uint32_t maxLayerZ, 190 bool useIdentityTransform); 191 192private: 193 mutable sp<CpuConsumer> mCpuConsumer; 194 mutable sp<IGraphicBufferProducer> mProducer; 195 CpuConsumer::LockedBuffer mBuffer; 196 bool mHaveBuffer; 197 198public: 199 ScreenshotClient(); 200 ~ScreenshotClient(); 201 202 // frees the previous screenshot and captures a new one 203 // if cropping isn't required, callers may pass in a default Rect, e.g.: 204 // update(display, Rect(), useIdentityTransform); 205 status_t update(const sp<IBinder>& display, 206 Rect sourceCrop, bool useIdentityTransform); 207 status_t update(const sp<IBinder>& display, 208 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 209 bool useIdentityTransform); 210 status_t update(const sp<IBinder>& display, 211 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 212 uint32_t minLayerZ, uint32_t maxLayerZ, 213 bool useIdentityTransform); 214 215 sp<CpuConsumer> getCpuConsumer() const; 216 217 // release memory occupied by the screenshot 218 void release(); 219 220 // pixels are valid until this object is freed or 221 // release() or update() is called 222 void const* getPixels() const; 223 224 uint32_t getWidth() const; 225 uint32_t getHeight() const; 226 PixelFormat getFormat() const; 227 uint32_t getStride() const; 228 // size of allocated memory in bytes 229 size_t getSize() const; 230}; 231 232// --------------------------------------------------------------------------- 233}; // namespace android 234 235#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H 236