SurfaceFlinger.h revision e7f8dde3f3c398c1ea1bec14e76725a760f71d31
1d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi/* 2d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Copyright (C) 2007 The Android Open Source Project 3d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 4d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Licensed under the Apache License, Version 2.0 (the "License"); 5d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * you may not use this file except in compliance with the License. 6d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * You may obtain a copy of the License at 7d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 8d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * http://www.apache.org/licenses/LICENSE-2.0 9d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * 10d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Unless required by applicable law or agreed to in writing, software 11d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * distributed under the License is distributed on an "AS IS" BASIS, 12d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * See the License for the specific language governing permissions and 14d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * limitations under the License. 15d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi */ 16d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 17d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#ifndef ANDROID_SURFACE_FLINGER_H 18d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#define ANDROID_SURFACE_FLINGER_H 19d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 20d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <stdint.h> 21d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <sys/types.h> 22d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 230e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber#include <EGL/egl.h> 240e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 250e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber/* 260e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber * NOTE: Make sure this file doesn't include anything from <gl/ > or <gl2/ > 270e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber */ 28d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 29d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <cutils/compiler.h> 30d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 31d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <utils/Atomic.h> 32d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <utils/Errors.h> 33d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <utils/KeyedVector.h> 34d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <utils/RefBase.h> 35d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <utils/SortedVector.h> 360e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber#include <utils/threads.h> 37d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 380e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber#include <binder/IMemory.h> 3952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 40d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <ui/PixelFormat.h> 41d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include <ui/mat4.h> 4252cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 4352cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include <gui/ISurfaceComposer.h> 4452cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include <gui/ISurfaceComposerClient.h> 4552cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 4652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include <hardware/hwcomposer_defs.h> 4752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 4852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include <private/gui/LayerState.h> 49d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 50d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include "Barrier.h" 51d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include "DisplayDevice.h" 52d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include "DispSync.h" 530e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber#include "FrameTracker.h" 54d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi#include "MessageQueue.h" 550e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 5652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include "DisplayHardware/HWComposer.h" 5752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong#include "Effects/Daltonizer.h" 58d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 59d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshinamespace android { 6052cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 6152cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong// --------------------------------------------------------------------------- 6252cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 6352cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dongclass Client; 64d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass DisplayEventConnection; 65d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass EventThread; 66d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass IGraphicBufferAlloc; 67d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass Layer; 680e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruberclass LayerDim; 690e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruberclass Surface; 70d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass RenderEngine; 710e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruberclass EventControlThread; 72d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 73d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi// --------------------------------------------------------------------------- 74d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 75d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshienum { 76d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi eTransactionNeeded = 0x01, 77d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi eTraversalNeeded = 0x02, 780e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber eDisplayTransactionNeeded = 0x04, 790e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber eTransactionMask = 0x07 80d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi}; 810e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 82d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshiclass SurfaceFlinger : public BnSurfaceComposer, 83d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi private IBinder::DeathRecipient, 84d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi private HWComposer::EventHandler 85d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi{ 86d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshipublic: 87d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi static char const* getServiceName() ANDROID_API { 880e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber return "SurfaceFlinger"; 89d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi } 9052cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 9152cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong SurfaceFlinger() ANDROID_API; 92d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 93d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // must be called before clients can connect 9452cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong void init() ANDROID_API; 9552cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 9652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong // starts SurfaceFlinger main loop in the current thread 9752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong void run() ANDROID_API; 9852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 99d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi enum { 10052cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong EVENT_VSYNC = HWC_EVENT_VSYNC 10152cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong }; 102d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 103d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // post an asynchronous message to the main thread 104d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); 1050e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 106d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // post a synchronous message to the main thread 1070e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); 108c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong 109c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // force full composition on all displays 110d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi void repaintEverything(); 111d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 112d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // returns the default Display 113d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi sp<const DisplayDevice> getDefaultDisplayDevice() const { 114d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi return getDisplayDevice(mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY]); 115d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi } 11652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 11752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong // utility function to delete a texture on the main thread 11852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong void deleteTextureAsync(uint32_t texture); 11952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 120c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // enable/disable h/w composer event 121c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // TODO: this should be made accessible only to EventThread 122c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong void eventControl(int disp, int event, int enabled); 123c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong 124c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // called on the main thread by MessageQueue when an internal message 125c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // is received 126c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong // TODO: this should be made accessible only to MessageQueue 127c4a9976aa15929a73ab7c0979d8b2e1e9eeadcc7James Dong void onMessageReceived(int32_t what); 1280e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 129d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // for debugging only 1300e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber // TODO: this should be made accessible only to HWComposer 131d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi const Vector< sp<Layer> >& getLayerSortedByZForHwcDisplay(int id); 132d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 133d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi RenderEngine& getRenderEngine() const { 134d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi return *mRenderEngine; 135d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi } 136d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 13752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dongprivate: 13852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong friend class Client; 13952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong friend class DisplayEventConnection; 140d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi friend class Layer; 1410e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber friend class MonitoredProducer; 1420e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 143d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // This value is specified in number of frames. Log frame stats at most 144d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi // every half hour. 145d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; 14652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 14752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong static const size_t MAX_LAYERS = 4096; 14852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 14952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong // We're reference counted, never destroy SurfaceFlinger directly 150d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi virtual ~SurfaceFlinger(); 15152cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong 152d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi /* ------------------------------------------------------------------------ 153d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * Internal data structures 154d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi */ 1550e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 156d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi class LayerVector : public SortedVector< sp<Layer> > { 1570e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber public: 1580e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber LayerVector(); 15952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong LayerVector(const LayerVector& rhs); 160d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi virtual int do_compare(const void* lhs, const void* rhs) const; 161d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi }; 162d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 163d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi struct DisplayDeviceState { 164d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi DisplayDeviceState(); 16552cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong DisplayDeviceState(DisplayDevice::DisplayType type); 16652cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong bool isValid() const { return type >= 0; } 16752cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong bool isMainDisplay() const { return type == DisplayDevice::DISPLAY_PRIMARY; } 16852cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong bool isVirtualDisplay() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; } 16952cb1e5988a8a97c668b935fb5d8d358cb3c635aJames Dong DisplayDevice::DisplayType type; 170d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi sp<IGraphicBufferProducer> surface; 171d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi uint32_t layerStack; 172d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi Rect viewport; 173d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi Rect frame; 174d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi uint8_t orientation; 175d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi uint32_t width, height; 176d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi String8 displayName; 177d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi bool isSecure; 178d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi }; 1790e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber 180d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi struct State { 1810e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber LayerVector layersSortedByZ; 1820e092f806b0a4b81785a52da8ba22d2d47087de5Bill Gruber DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays; 183d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi }; 184d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi 185d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi /* ------------------------------------------------------------------------ 186d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi * IBinder interface 187d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi */ 188d074e30ce44b9e33da43b67a4515b8986ca72b26aimitakeshi virtual status_t onTransact(uint32_t code, const Parcel& data, 189 Parcel* reply, uint32_t flags); 190 virtual status_t dump(int fd, const Vector<String16>& args); 191 192 /* ------------------------------------------------------------------------ 193 * ISurfaceComposer interface 194 */ 195 virtual sp<ISurfaceComposerClient> createConnection(); 196 virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc(); 197 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure); 198 virtual void destroyDisplay(const sp<IBinder>& display); 199 virtual sp<IBinder> getBuiltInDisplay(int32_t id); 200 virtual void setTransactionState(const Vector<ComposerState>& state, 201 const Vector<DisplayState>& displays, uint32_t flags); 202 virtual void bootFinished(); 203 virtual bool authenticateSurfaceTexture( 204 const sp<IGraphicBufferProducer>& bufferProducer) const; 205 virtual sp<IDisplayEventConnection> createDisplayEventConnection(); 206 virtual status_t captureScreen(const sp<IBinder>& display, 207 const sp<IGraphicBufferProducer>& producer, 208 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 209 uint32_t minLayerZ, uint32_t maxLayerZ, 210 bool useIdentityTransform, ISurfaceComposer::Rotation rotation); 211 virtual status_t getDisplayStats(const sp<IBinder>& display, 212 DisplayStatInfo* stats); 213 virtual status_t getDisplayConfigs(const sp<IBinder>& display, 214 Vector<DisplayInfo>* configs); 215 virtual int getActiveConfig(const sp<IBinder>& display); 216 virtual void setPowerMode(const sp<IBinder>& display, int mode); 217 virtual status_t setActiveConfig(const sp<IBinder>& display, int id); 218 virtual status_t clearAnimationFrameStats(); 219 virtual status_t getAnimationFrameStats(FrameStats* outStats) const; 220 221 /* ------------------------------------------------------------------------ 222 * DeathRecipient interface 223 */ 224 virtual void binderDied(const wp<IBinder>& who); 225 226 /* ------------------------------------------------------------------------ 227 * RefBase interface 228 */ 229 virtual void onFirstRef(); 230 231 /* ------------------------------------------------------------------------ 232 * HWComposer::EventHandler interface 233 */ 234 virtual void onVSyncReceived(int type, nsecs_t timestamp); 235 virtual void onHotplugReceived(int disp, bool connected); 236 237 /* ------------------------------------------------------------------------ 238 * Message handling 239 */ 240 void waitForEvent(); 241 void signalTransaction(); 242 void signalLayerUpdate(); 243 void signalRefresh(); 244 245 // called on the main thread in response to initializeDisplays() 246 void onInitializeDisplays(); 247 // called on the main thread in response to setActiveConfig() 248 void setActiveConfigInternal(const sp<DisplayDevice>& hw, int mode); 249 // called on the main thread in response to setPowerMode() 250 void setPowerModeInternal(const sp<DisplayDevice>& hw, int mode); 251 252 // Returns whether the transaction actually modified any state 253 bool handleMessageTransaction(); 254 255 // Returns whether a new buffer has been latched (see handlePageFlip()) 256 bool handleMessageInvalidate(); 257 258 void handleMessageRefresh(); 259 260 void handleTransaction(uint32_t transactionFlags); 261 void handleTransactionLocked(uint32_t transactionFlags); 262 263 void updateCursorAsync(); 264 265 /* handlePageFlip - latch a new buffer if available and compute the dirty 266 * region. Returns whether a new buffer has been latched, i.e., whether it 267 * is necessary to perform a refresh during this vsync. 268 */ 269 bool handlePageFlip(); 270 271 /* ------------------------------------------------------------------------ 272 * Transactions 273 */ 274 uint32_t getTransactionFlags(uint32_t flags); 275 uint32_t peekTransactionFlags(uint32_t flags); 276 uint32_t setTransactionFlags(uint32_t flags); 277 void commitTransaction(); 278 uint32_t setClientStateLocked(const sp<Client>& client, const layer_state_t& s); 279 uint32_t setDisplayStateLocked(const DisplayState& s); 280 281 /* ------------------------------------------------------------------------ 282 * Layer management 283 */ 284 status_t createLayer(const String8& name, const sp<Client>& client, 285 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, 286 sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp); 287 288 status_t createNormalLayer(const sp<Client>& client, const String8& name, 289 uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, 290 sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* outGbp, 291 sp<Layer>* outLayer); 292 293 status_t createDimLayer(const sp<Client>& client, const String8& name, 294 uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle, 295 sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer); 296 297 // called in response to the window-manager calling 298 // ISurfaceComposerClient::destroySurface() 299 status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle); 300 301 // called when all clients have released all their references to 302 // this layer meaning it is entirely safe to destroy all 303 // resources associated to this layer. 304 status_t onLayerDestroyed(const wp<Layer>& layer); 305 306 // remove a layer from SurfaceFlinger immediately 307 status_t removeLayer(const sp<Layer>& layer); 308 309 // add a layer to SurfaceFlinger 310 status_t addClientLayer(const sp<Client>& client, 311 const sp<IBinder>& handle, 312 const sp<IGraphicBufferProducer>& gbc, 313 const sp<Layer>& lbc); 314 315 /* ------------------------------------------------------------------------ 316 * Boot animation, on/off animations and screen capture 317 */ 318 319 void startBootAnim(); 320 321 void renderScreenImplLocked( 322 const sp<const DisplayDevice>& hw, 323 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 324 uint32_t minLayerZ, uint32_t maxLayerZ, 325 bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation); 326 327 status_t captureScreenImplLocked( 328 const sp<const DisplayDevice>& hw, 329 const sp<IGraphicBufferProducer>& producer, 330 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 331 uint32_t minLayerZ, uint32_t maxLayerZ, 332 bool useIdentityTransform, Transform::orientation_flags rotation); 333 334 /* ------------------------------------------------------------------------ 335 * EGL 336 */ 337 size_t getMaxTextureSize() const; 338 size_t getMaxViewportDims() const; 339 340 /* ------------------------------------------------------------------------ 341 * Display and layer stack management 342 */ 343 // called when starting, or restarting after system_server death 344 void initializeDisplays(); 345 346 // Create an IBinder for a builtin display and add it to current state 347 void createBuiltinDisplayLocked(DisplayDevice::DisplayType type); 348 349 // NOTE: can only be called from the main thread or with mStateLock held 350 sp<const DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) const { 351 return mDisplays.valueFor(dpy); 352 } 353 354 // NOTE: can only be called from the main thread or with mStateLock held 355 sp<DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) { 356 return mDisplays.valueFor(dpy); 357 } 358 359 // mark a region of a layer stack dirty. this updates the dirty 360 // region of all screens presenting this layer stack. 361 void invalidateLayerStack(uint32_t layerStack, const Region& dirty); 362 363 // allocate a h/w composer display id 364 int32_t allocateHwcDisplayId(DisplayDevice::DisplayType type); 365 366 /* ------------------------------------------------------------------------ 367 * H/W composer 368 */ 369 370 HWComposer& getHwComposer() const { return *mHwc; } 371 372 /* ------------------------------------------------------------------------ 373 * Compositing 374 */ 375 void invalidateHwcGeometry(); 376 static void computeVisibleRegions( 377 const LayerVector& currentLayers, uint32_t layerStack, 378 Region& dirtyRegion, Region& opaqueRegion); 379 380 void preComposition(); 381 void postComposition(); 382 void rebuildLayerStacks(); 383 void setUpHWComposer(); 384 void doComposition(); 385 void doDebugFlashRegions(); 386 void doDisplayComposition(const sp<const DisplayDevice>& hw, const Region& dirtyRegion); 387 388 // compose surfaces for display hw. this fails if using GL and the surface 389 // has been destroyed and is no longer valid. 390 bool doComposeSurfaces(const sp<const DisplayDevice>& hw, const Region& dirty); 391 392 void postFramebuffer(); 393 void drawWormhole(const sp<const DisplayDevice>& hw, const Region& region) const; 394 395 /* ------------------------------------------------------------------------ 396 * Display management 397 */ 398 399 /* ------------------------------------------------------------------------ 400 * VSync 401 */ 402 void enableHardwareVsync(); 403 void disableHardwareVsync(bool makeUnavailable); 404 void resyncToHardwareVsync(bool makeAvailable); 405 406 /* ------------------------------------------------------------------------ 407 * Debugging & dumpsys 408 */ 409 void listLayersLocked(const Vector<String16>& args, size_t& index, String8& result) const; 410 void dumpStatsLocked(const Vector<String16>& args, size_t& index, String8& result) const; 411 void clearStatsLocked(const Vector<String16>& args, size_t& index, String8& result); 412 void dumpAllLocked(const Vector<String16>& args, size_t& index, String8& result) const; 413 bool startDdmConnection(); 414 static void appendSfConfigString(String8& result); 415 void checkScreenshot(size_t w, size_t s, size_t h, void const* vaddr, 416 const sp<const DisplayDevice>& hw, 417 uint32_t minLayerZ, uint32_t maxLayerZ); 418 419 void logFrameStats(); 420 421 /* ------------------------------------------------------------------------ 422 * Attributes 423 */ 424 425 // access must be protected by mStateLock 426 mutable Mutex mStateLock; 427 State mCurrentState; 428 volatile int32_t mTransactionFlags; 429 Condition mTransactionCV; 430 bool mTransactionPending; 431 bool mAnimTransactionPending; 432 Vector< sp<Layer> > mLayersPendingRemoval; 433 SortedVector< wp<IBinder> > mGraphicBufferProducerList; 434 435 // protected by mStateLock (but we could use another lock) 436 bool mLayersRemoved; 437 438 // access must be protected by mInvalidateLock 439 volatile int32_t mRepaintEverything; 440 441 // constant members (no synchronization needed for access) 442 HWComposer* mHwc; 443 RenderEngine* mRenderEngine; 444 nsecs_t mBootTime; 445 bool mGpuToCpuSupported; 446 sp<EventThread> mEventThread; 447 sp<EventThread> mSFEventThread; 448 sp<EventControlThread> mEventControlThread; 449 EGLContext mEGLContext; 450 EGLDisplay mEGLDisplay; 451 sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES]; 452 453 // Can only accessed from the main thread, these members 454 // don't need synchronization 455 State mDrawingState; 456 bool mVisibleRegionsDirty; 457 bool mHwWorkListDirty; 458 bool mAnimCompositionPending; 459 460 // this may only be written from the main thread with mStateLock held 461 // it may be read from other threads with mStateLock held 462 DefaultKeyedVector< wp<IBinder>, sp<DisplayDevice> > mDisplays; 463 464 // don't use a lock for these, we don't care 465 int mDebugRegion; 466 int mDebugDDMS; 467 int mDebugDisableHWC; 468 int mDebugDisableTransformHint; 469 volatile nsecs_t mDebugInSwapBuffers; 470 nsecs_t mLastSwapBufferTime; 471 volatile nsecs_t mDebugInTransaction; 472 nsecs_t mLastTransactionTime; 473 bool mBootFinished; 474 bool mForceFullDamage; 475 476 // these are thread safe 477 mutable MessageQueue mEventQueue; 478 FrameTracker mAnimFrameTracker; 479 DispSync mPrimaryDispSync; 480 481 // protected by mDestroyedLayerLock; 482 mutable Mutex mDestroyedLayerLock; 483 Vector<Layer const *> mDestroyedLayers; 484 485 // protected by mHWVsyncLock 486 Mutex mHWVsyncLock; 487 bool mPrimaryHWVsyncEnabled; 488 bool mHWVsyncAvailable; 489 490 /* ------------------------------------------------------------------------ 491 * Feature prototyping 492 */ 493 494 Daltonizer mDaltonizer; 495 bool mDaltonize; 496 497 mat4 mColorMatrix; 498 bool mHasColorMatrix; 499}; 500 501}; // namespace android 502 503#endif // ANDROID_SURFACE_FLINGER_H 504