SurfaceFlinger.h revision 7d3dcb9235ec149af2f5139a8a9c6eac859d92e2
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_SURFACE_FLINGER_H 18#define ANDROID_SURFACE_FLINGER_H 19 20#include <memory> 21#include <stdint.h> 22#include <sys/types.h> 23 24#include <EGL/egl.h> 25 26/* 27 * NOTE: Make sure this file doesn't include anything from <gl/ > or <gl2/ > 28 */ 29 30#include <cutils/compiler.h> 31 32#include <utils/Atomic.h> 33#include <utils/Errors.h> 34#include <utils/KeyedVector.h> 35#include <utils/RefBase.h> 36#include <utils/SortedVector.h> 37#include <utils/threads.h> 38 39#include <ui/FenceTime.h> 40#include <ui/PixelFormat.h> 41#include <math/mat4.h> 42 43#include <gui/FrameTimestamps.h> 44#include <gui/ISurfaceComposer.h> 45#include <gui/ISurfaceComposerClient.h> 46#include <gui/OccupancyTracker.h> 47 48#include <hardware/hwcomposer_defs.h> 49 50#include <system/graphics.h> 51 52#include <private/gui/LayerState.h> 53 54#include "Barrier.h" 55#include "DisplayDevice.h" 56#include "DispSync.h" 57#include "FrameTracker.h" 58#include "LayerVector.h" 59#include "MessageQueue.h" 60#include "SurfaceInterceptor.h" 61#include "StartBootAnimThread.h" 62 63#include "DisplayHardware/HWComposer.h" 64#include "Effects/Daltonizer.h" 65 66#include <map> 67#include <mutex> 68#include <queue> 69#include <string> 70#include <utility> 71 72namespace android { 73 74// --------------------------------------------------------------------------- 75 76class Client; 77class DisplayEventConnection; 78class EventThread; 79class Layer; 80class LayerDim; 81class Surface; 82class RenderEngine; 83class EventControlThread; 84class VSyncSource; 85class InjectVSyncSource; 86 87namespace dvr { 88class VrFlinger; 89} // namespace dvr 90 91// --------------------------------------------------------------------------- 92 93enum { 94 eTransactionNeeded = 0x01, 95 eTraversalNeeded = 0x02, 96 eDisplayTransactionNeeded = 0x04, 97 eTransactionMask = 0x07 98}; 99 100class SurfaceFlinger : public BnSurfaceComposer, 101 private IBinder::DeathRecipient, 102 private HWComposer::EventHandler 103{ 104public: 105 106 // This is the phase offset in nanoseconds of the software vsync event 107 // relative to the vsync event reported by HWComposer. The software vsync 108 // event is when SurfaceFlinger and Choreographer-based applications run each 109 // frame. 110 // 111 // This phase offset allows adjustment of the minimum latency from application 112 // wake-up time (by Choreographer) to the time at which the resulting window 113 // image is displayed. This value may be either positive (after the HW vsync) 114 // or negative (before the HW vsync). Setting it to 0 will result in a lower 115 // latency bound of two vsync periods because the app and SurfaceFlinger 116 // will run just after the HW vsync. Setting it to a positive number will 117 // result in the minimum latency being: 118 // 119 // (2 * VSYNC_PERIOD - (vsyncPhaseOffsetNs % VSYNC_PERIOD)) 120 // 121 // Note that reducing this latency makes it more likely for the applications 122 // to not have their window content image ready in time. When this happens 123 // the latency will end up being an additional vsync period, and animations 124 // will hiccup. Therefore, this latency should be tuned somewhat 125 // conservatively (or at least with awareness of the trade-off being made). 126 static int64_t vsyncPhaseOffsetNs; 127 static int64_t sfVsyncPhaseOffsetNs; 128 129 // If fences from sync Framework are supported. 130 static bool hasSyncFramework; 131 132 // Instruct the Render Engine to use EGL_IMG_context_priority is available. 133 static bool useContextPriority; 134 135 // The offset in nanoseconds to use when DispSync timestamps present fence 136 // signaling time. 137 static int64_t dispSyncPresentTimeOffset; 138 139 // Some hardware can do RGB->YUV conversion more efficiently in hardware 140 // controlled by HWC than in hardware controlled by the video encoder. 141 // This instruct VirtualDisplaySurface to use HWC for such conversion on 142 // GL composition. 143 static bool useHwcForRgbToYuv; 144 145 // Maximum dimension supported by HWC for virtual display. 146 // Equal to min(max_height, max_width). 147 static uint64_t maxVirtualDisplaySize; 148 149 // Controls the number of buffers SurfaceFlinger will allocate for use in 150 // FramebufferSurface 151 static int64_t maxFrameBufferAcquiredBuffers; 152 153 // Indicate if platform supports color management on its 154 // wide-color display. This is typically found on devices 155 // with wide gamut (e.g. Display-P3) display. 156 // This also allows devices with wide-color displays that don't 157 // want to support color management to disable color management. 158 static bool hasWideColorDisplay; 159 160 static char const* getServiceName() ANDROID_API { 161 return "SurfaceFlinger"; 162 } 163 164 SurfaceFlinger() ANDROID_API; 165 166 // must be called before clients can connect 167 void init() ANDROID_API; 168 169 // starts SurfaceFlinger main loop in the current thread 170 void run() ANDROID_API; 171 172 enum { 173 EVENT_VSYNC = HWC_EVENT_VSYNC 174 }; 175 176 // post an asynchronous message to the main thread 177 status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); 178 179 // post a synchronous message to the main thread 180 status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); 181 182 // force full composition on all displays 183 void repaintEverything(); 184 185 // returns the default Display 186 sp<const DisplayDevice> getDefaultDisplayDevice() const { 187 Mutex::Autolock _l(mStateLock); 188 return getDefaultDisplayDeviceLocked(); 189 } 190 191 // utility function to delete a texture on the main thread 192 void deleteTextureAsync(uint32_t texture); 193 194 // enable/disable h/w composer event 195 // TODO: this should be made accessible only to EventThread 196#ifdef USE_HWC2 197 void setVsyncEnabled(int disp, int enabled); 198#else 199 void eventControl(int disp, int event, int enabled); 200#endif 201 202 // called on the main thread by MessageQueue when an internal message 203 // is received 204 // TODO: this should be made accessible only to MessageQueue 205 void onMessageReceived(int32_t what); 206 207 // for debugging only 208 // TODO: this should be made accessible only to HWComposer 209 const Vector< sp<Layer> >& getLayerSortedByZForHwcDisplay(int id); 210 211 RenderEngine& getRenderEngine() const { 212 return *mRenderEngine; 213 } 214 215 bool authenticateSurfaceTextureLocked( 216 const sp<IGraphicBufferProducer>& bufferProducer) const; 217 218private: 219 friend class Client; 220 friend class DisplayEventConnection; 221 friend class EventThread; 222 friend class Layer; 223 friend class MonitoredProducer; 224 225 // This value is specified in number of frames. Log frame stats at most 226 // every half hour. 227 enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; 228 229 static const size_t MAX_LAYERS = 4096; 230 static constexpr const char* kTimestampProperty = "service.sf.present_timestamp"; 231 232 // We're reference counted, never destroy SurfaceFlinger directly 233 virtual ~SurfaceFlinger(); 234 235 /* ------------------------------------------------------------------------ 236 * Internal data structures 237 */ 238 239 class State { 240 public: 241 LayerVector layersSortedByZ; 242 DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays; 243 244 void traverseInZOrder(const std::function<void(Layer*)>& consume) const; 245 void traverseInReverseZOrder(const std::function<void(Layer*)>& consume) const; 246 }; 247 248 /* ------------------------------------------------------------------------ 249 * IBinder interface 250 */ 251 virtual status_t onTransact(uint32_t code, const Parcel& data, 252 Parcel* reply, uint32_t flags); 253 virtual status_t dump(int fd, const Vector<String16>& args); 254 255 /* ------------------------------------------------------------------------ 256 * ISurfaceComposer interface 257 */ 258 virtual sp<ISurfaceComposerClient> createConnection(); 259 virtual sp<ISurfaceComposerClient> createScopedConnection(const sp<IGraphicBufferProducer>& gbp); 260 virtual sp<IBinder> createDisplay(const String8& displayName, bool secure); 261 virtual void destroyDisplay(const sp<IBinder>& display); 262 virtual sp<IBinder> getBuiltInDisplay(int32_t id); 263 virtual void setTransactionState(const Vector<ComposerState>& state, 264 const Vector<DisplayState>& displays, uint32_t flags); 265 virtual void bootFinished(); 266 virtual bool authenticateSurfaceTexture( 267 const sp<IGraphicBufferProducer>& bufferProducer) const; 268 virtual status_t getSupportedFrameTimestamps( 269 std::vector<FrameEvent>* outSupported) const; 270 virtual sp<IDisplayEventConnection> createDisplayEventConnection(); 271 virtual status_t captureScreen(const sp<IBinder>& display, 272 const sp<IGraphicBufferProducer>& producer, 273 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 274 int32_t minLayerZ, int32_t maxLayerZ, 275 bool useIdentityTransform, ISurfaceComposer::Rotation rotation); 276 virtual status_t getDisplayStats(const sp<IBinder>& display, 277 DisplayStatInfo* stats); 278 virtual status_t getDisplayConfigs(const sp<IBinder>& display, 279 Vector<DisplayInfo>* configs); 280 virtual int getActiveConfig(const sp<IBinder>& display); 281 virtual status_t getDisplayColorModes(const sp<IBinder>& display, 282 Vector<android_color_mode_t>* configs); 283 virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display); 284 virtual status_t setActiveColorMode(const sp<IBinder>& display, android_color_mode_t colorMode); 285 virtual void setPowerMode(const sp<IBinder>& display, int mode); 286 virtual status_t setActiveConfig(const sp<IBinder>& display, int id); 287 virtual status_t clearAnimationFrameStats(); 288 virtual status_t getAnimationFrameStats(FrameStats* outStats) const; 289 virtual status_t getHdrCapabilities(const sp<IBinder>& display, 290 HdrCapabilities* outCapabilities) const; 291 virtual status_t enableVSyncInjections(bool enable); 292 virtual status_t injectVSync(nsecs_t when); 293 294 295 /* ------------------------------------------------------------------------ 296 * DeathRecipient interface 297 */ 298 virtual void binderDied(const wp<IBinder>& who); 299 300 /* ------------------------------------------------------------------------ 301 * RefBase interface 302 */ 303 virtual void onFirstRef(); 304 305 /* ------------------------------------------------------------------------ 306 * HWComposer::EventHandler interface 307 */ 308 virtual void onVSyncReceived(HWComposer* composer, int type, nsecs_t timestamp); 309 virtual void onHotplugReceived(HWComposer* composer, int disp, bool connected); 310 virtual void onInvalidateReceived(HWComposer* composer); 311 312 /* ------------------------------------------------------------------------ 313 * Message handling 314 */ 315 void waitForEvent(); 316 void signalTransaction(); 317 void signalLayerUpdate(); 318 void signalRefresh(); 319 320 // called on the main thread in response to initializeDisplays() 321 void onInitializeDisplays(); 322 // called on the main thread in response to setActiveConfig() 323 void setActiveConfigInternal(const sp<DisplayDevice>& hw, int mode); 324 // called on the main thread in response to setPowerMode() 325 void setPowerModeInternal(const sp<DisplayDevice>& hw, int mode); 326 327 // Called on the main thread in response to setActiveColorMode() 328 void setActiveColorModeInternal(const sp<DisplayDevice>& hw, android_color_mode_t colorMode); 329 330 // Returns whether the transaction actually modified any state 331 bool handleMessageTransaction(); 332 333 // Returns whether a new buffer has been latched (see handlePageFlip()) 334 bool handleMessageInvalidate(); 335 336 void handleMessageRefresh(); 337 338 void handleTransaction(uint32_t transactionFlags); 339 void handleTransactionLocked(uint32_t transactionFlags); 340 341 void updateCursorAsync(); 342 343 /* handlePageFlip - latch a new buffer if available and compute the dirty 344 * region. Returns whether a new buffer has been latched, i.e., whether it 345 * is necessary to perform a refresh during this vsync. 346 */ 347 bool handlePageFlip(); 348 349 /* ------------------------------------------------------------------------ 350 * Transactions 351 */ 352 uint32_t getTransactionFlags(uint32_t flags); 353 uint32_t peekTransactionFlags(); 354 uint32_t setTransactionFlags(uint32_t flags); 355 void commitTransaction(); 356 uint32_t setClientStateLocked(const sp<Client>& client, const layer_state_t& s); 357 uint32_t setDisplayStateLocked(const DisplayState& s); 358 359 /* ------------------------------------------------------------------------ 360 * Layer management 361 */ 362 status_t createLayer(const String8& name, const sp<Client>& client, 363 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, 364 uint32_t windowType, uint32_t ownerUid, sp<IBinder>* handle, 365 sp<IGraphicBufferProducer>* gbp, sp<Layer>* parent); 366 367 status_t createNormalLayer(const sp<Client>& client, const String8& name, 368 uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, 369 sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* outGbp, 370 sp<Layer>* outLayer); 371 372 status_t createDimLayer(const sp<Client>& client, const String8& name, 373 uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle, 374 sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer); 375 376 String8 getUniqueLayerName(const String8& name); 377 378 // called in response to the window-manager calling 379 // ISurfaceComposerClient::destroySurface() 380 status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle); 381 382 // called when all clients have released all their references to 383 // this layer meaning it is entirely safe to destroy all 384 // resources associated to this layer. 385 status_t onLayerDestroyed(const wp<Layer>& layer); 386 387 // remove a layer from SurfaceFlinger immediately 388 status_t removeLayer(const sp<Layer>& layer); 389 390 // add a layer to SurfaceFlinger 391 status_t addClientLayer(const sp<Client>& client, 392 const sp<IBinder>& handle, 393 const sp<IGraphicBufferProducer>& gbc, 394 const sp<Layer>& lbc, 395 const sp<Layer>& parent); 396 397 /* ------------------------------------------------------------------------ 398 * Boot animation, on/off animations and screen capture 399 */ 400 401 void startBootAnim(); 402 403 void renderScreenImplLocked( 404 const sp<const DisplayDevice>& hw, 405 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 406 int32_t minLayerZ, int32_t maxLayerZ, 407 bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation); 408 409 status_t captureScreenImplLocked( 410 const sp<const DisplayDevice>& hw, 411 const sp<IGraphicBufferProducer>& producer, 412 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, 413 int32_t minLayerZ, int32_t maxLayerZ, 414 bool useIdentityTransform, Transform::orientation_flags rotation, 415 bool isLocalScreenshot); 416 417 sp<StartBootAnimThread> mStartBootAnimThread = nullptr; 418 419 /* ------------------------------------------------------------------------ 420 * EGL 421 */ 422 size_t getMaxTextureSize() const; 423 size_t getMaxViewportDims() const; 424 425 /* ------------------------------------------------------------------------ 426 * Display and layer stack management 427 */ 428 // called when starting, or restarting after system_server death 429 void initializeDisplays(); 430 431 // Create an IBinder for a builtin display and add it to current state 432 void createBuiltinDisplayLocked(DisplayDevice::DisplayType type); 433 434 435 sp<const DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) const { 436 Mutex::Autolock _l(mStateLock); 437 return getDisplayDeviceLocked(dpy); 438 } 439 440 sp<DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) { 441 Mutex::Autolock _l(mStateLock); 442 return getDisplayDeviceLocked(dpy); 443 } 444 445 // NOTE: can only be called from the main thread or with mStateLock held 446 sp<const DisplayDevice> getDisplayDeviceLocked(const wp<IBinder>& dpy) const { 447 return mDisplays.valueFor(dpy); 448 } 449 450 // NOTE: can only be called from the main thread or with mStateLock held 451 sp<DisplayDevice> getDisplayDeviceLocked(const wp<IBinder>& dpy) { 452 return mDisplays.valueFor(dpy); 453 } 454 455 sp<const DisplayDevice> getDefaultDisplayDeviceLocked() const { 456 return getDisplayDeviceLocked(mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY]); 457 } 458 459 void createDefaultDisplayDevice(); 460 461 int32_t getDisplayType(const sp<IBinder>& display) { 462 if (!display.get()) return NAME_NOT_FOUND; 463 for (int i = 0; i < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES; ++i) { 464 if (display == mBuiltinDisplays[i]) { 465 return i; 466 } 467 } 468 return NAME_NOT_FOUND; 469 } 470 471 // mark a region of a layer stack dirty. this updates the dirty 472 // region of all screens presenting this layer stack. 473 void invalidateLayerStack(uint32_t layerStack, const Region& dirty); 474 475#ifndef USE_HWC2 476 int32_t allocateHwcDisplayId(DisplayDevice::DisplayType type); 477#endif 478 479 /* ------------------------------------------------------------------------ 480 * H/W composer 481 */ 482 483 HWComposer& getHwComposer() const { return *mHwc; } 484 485 /* ------------------------------------------------------------------------ 486 * Compositing 487 */ 488 void invalidateHwcGeometry(); 489 void computeVisibleRegions(uint32_t layerStack, 490 Region& dirtyRegion, Region& opaqueRegion); 491 492 void preComposition(nsecs_t refreshStartTime); 493 void postComposition(nsecs_t refreshStartTime); 494 void updateCompositorTiming( 495 nsecs_t vsyncPhase, nsecs_t vsyncInterval, nsecs_t compositeTime, 496 std::shared_ptr<FenceTime>& presentFenceTime); 497 void setCompositorTimingSnapped( 498 nsecs_t vsyncPhase, nsecs_t vsyncInterval, 499 nsecs_t compositeToPresentLatency); 500 void rebuildLayerStacks(); 501 502 // Given a dataSpace, returns the appropriate color_mode to use 503 // to display that dataSpace. 504 android_color_mode pickColorMode(android_dataspace dataSpace); 505 android_dataspace bestTargetDataSpace(android_dataspace a, android_dataspace b); 506 507 void setUpHWComposer(); 508 void doComposition(); 509 void doDebugFlashRegions(); 510 void doDisplayComposition(const sp<const DisplayDevice>& displayDevice, const Region& dirtyRegion); 511 512 // compose surfaces for display hw. this fails if using GL and the surface 513 // has been destroyed and is no longer valid. 514 bool doComposeSurfaces(const sp<const DisplayDevice>& displayDevice, const Region& dirty); 515 516 void postFramebuffer(); 517 void drawWormhole(const sp<const DisplayDevice>& displayDevice, const Region& region) const; 518 519 /* ------------------------------------------------------------------------ 520 * Display management 521 */ 522 523 /* ------------------------------------------------------------------------ 524 * VSync 525 */ 526 void enableHardwareVsync(); 527 void resyncToHardwareVsync(bool makeAvailable); 528 void disableHardwareVsync(bool makeUnavailable); 529 530public: 531 void resyncWithRateLimit(); 532 void getCompositorTiming(CompositorTiming* compositorTiming); 533private: 534 535 /* ------------------------------------------------------------------------ 536 * Debugging & dumpsys 537 */ 538 void listLayersLocked(const Vector<String16>& args, size_t& index, String8& result) const; 539 void dumpStatsLocked(const Vector<String16>& args, size_t& index, String8& result) const; 540 void clearStatsLocked(const Vector<String16>& args, size_t& index, String8& result); 541 void dumpAllLocked(const Vector<String16>& args, size_t& index, String8& result) const; 542 bool startDdmConnection(); 543 void appendSfConfigString(String8& result) const; 544 void checkScreenshot(size_t w, size_t s, size_t h, void const* vaddr, 545 const sp<const DisplayDevice>& hw, 546 int32_t minLayerZ, int32_t maxLayerZ); 547 548 void logFrameStats(); 549 550 void dumpStaticScreenStats(String8& result) const; 551 // Not const because each Layer needs to query Fences and cache timestamps. 552 void dumpFrameEventsLocked(String8& result); 553 554 void recordBufferingStats(const char* layerName, 555 std::vector<OccupancyTracker::Segment>&& history); 556 void dumpBufferingStats(String8& result) const; 557 void dumpWideColorInfo(String8& result) const; 558 559 bool isLayerTripleBufferingDisabled() const { 560 return this->mLayerTripleBufferingDisabled; 561 } 562 563#ifdef USE_HWC2 564 /* ------------------------------------------------------------------------ 565 * VrFlinger 566 */ 567 void clearHwcLayers(const LayerVector& layers); 568 void resetHwcLocked(); 569 570 // Check to see if we should handoff to vr flinger. 571 void updateVrFlinger(); 572#endif 573 574 /* ------------------------------------------------------------------------ 575 * Attributes 576 */ 577 578 // access must be protected by mStateLock 579 mutable Mutex mStateLock; 580 State mCurrentState; 581 volatile int32_t mTransactionFlags; 582 Condition mTransactionCV; 583 bool mTransactionPending; 584 bool mAnimTransactionPending; 585 SortedVector< sp<Layer> > mLayersPendingRemoval; 586 SortedVector< wp<IBinder> > mGraphicBufferProducerList; 587 588 // protected by mStateLock (but we could use another lock) 589 bool mLayersRemoved; 590 bool mLayersAdded; 591 592 // access must be protected by mInvalidateLock 593 volatile int32_t mRepaintEverything; 594 595 // current, real and vr hardware composers. 596 HWComposer* mHwc; 597#ifdef USE_HWC2 598 HWComposer* mRealHwc; 599 HWComposer* mVrHwc; 600#endif 601 // constant members (no synchronization needed for access) 602 RenderEngine* mRenderEngine; 603 nsecs_t mBootTime; 604 bool mGpuToCpuSupported; 605 sp<EventThread> mEventThread; 606 sp<EventThread> mSFEventThread; 607 sp<EventThread> mInjectorEventThread; 608 sp<InjectVSyncSource> mVSyncInjector; 609 sp<EventControlThread> mEventControlThread; 610 EGLContext mEGLContext; 611 EGLDisplay mEGLDisplay; 612 sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES]; 613 614#ifdef USE_HWC2 615 std::unique_ptr<dvr::VrFlinger> mVrFlinger; 616#endif 617 618 // Can only accessed from the main thread, these members 619 // don't need synchronization 620 State mDrawingState; 621 bool mVisibleRegionsDirty; 622#ifndef USE_HWC2 623 bool mHwWorkListDirty; 624#else 625 bool mGeometryInvalid; 626#endif 627 bool mAnimCompositionPending; 628#ifdef USE_HWC2 629 std::vector<sp<Layer>> mLayersWithQueuedFrames; 630 sp<Fence> mPreviousPresentFence = Fence::NO_FENCE; 631 bool mHadClientComposition = false; 632#endif 633 FenceTimeline mGlCompositionDoneTimeline; 634 FenceTimeline mDisplayTimeline; 635 636 // this may only be written from the main thread with mStateLock held 637 // it may be read from other threads with mStateLock held 638 DefaultKeyedVector< wp<IBinder>, sp<DisplayDevice> > mDisplays; 639 640 // don't use a lock for these, we don't care 641 int mDebugRegion; 642 int mDebugDDMS; 643 int mDebugDisableHWC; 644 int mDebugDisableTransformHint; 645 volatile nsecs_t mDebugInSwapBuffers; 646 nsecs_t mLastSwapBufferTime; 647 volatile nsecs_t mDebugInTransaction; 648 nsecs_t mLastTransactionTime; 649 bool mBootFinished; 650 bool mForceFullDamage; 651#ifdef USE_HWC2 652 bool mPropagateBackpressure = true; 653#endif 654 SurfaceInterceptor mInterceptor; 655 bool mUseHwcVirtualDisplays = false; 656 657 // Restrict layers to use two buffers in their bufferqueues. 658 bool mLayerTripleBufferingDisabled = false; 659 660 // these are thread safe 661 mutable MessageQueue mEventQueue; 662 FrameTracker mAnimFrameTracker; 663 DispSync mPrimaryDispSync; 664 665 // protected by mDestroyedLayerLock; 666 mutable Mutex mDestroyedLayerLock; 667 Vector<Layer const *> mDestroyedLayers; 668 669 // protected by mHWVsyncLock 670 Mutex mHWVsyncLock; 671 bool mPrimaryHWVsyncEnabled; 672 bool mHWVsyncAvailable; 673 674 // protected by mCompositorTimingLock; 675 mutable std::mutex mCompositorTimingLock; 676 CompositorTiming mCompositorTiming; 677 678 // Only accessed from the main thread. 679 struct CompositePresentTime { 680 nsecs_t composite { -1 }; 681 std::shared_ptr<FenceTime> display { FenceTime::NO_FENCE }; 682 }; 683 std::queue<CompositePresentTime> mCompositePresentTimes; 684 685 /* ------------------------------------------------------------------------ 686 * Feature prototyping 687 */ 688 689 bool mInjectVSyncs; 690 691 Daltonizer mDaltonizer; 692#ifndef USE_HWC2 693 bool mDaltonize; 694#endif 695 696 mat4 mPreviousColorMatrix; 697 mat4 mColorMatrix; 698 bool mHasColorMatrix; 699 700 // Static screen stats 701 bool mHasPoweredOff; 702 static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ 703 nsecs_t mFrameBuckets[NUM_BUCKETS]; 704 nsecs_t mTotalTime; 705 std::atomic<nsecs_t> mLastSwapTime; 706 707 size_t mNumLayers; 708 709 // Double- vs. triple-buffering stats 710 struct BufferingStats { 711 BufferingStats() 712 : numSegments(0), 713 totalTime(0), 714 twoBufferTime(0), 715 doubleBufferedTime(0), 716 tripleBufferedTime(0) {} 717 718 size_t numSegments; 719 nsecs_t totalTime; 720 721 // "Two buffer" means that a third buffer was never used, whereas 722 // "double-buffered" means that on average the segment only used two 723 // buffers (though it may have used a third for some part of the 724 // segment) 725 nsecs_t twoBufferTime; 726 nsecs_t doubleBufferedTime; 727 nsecs_t tripleBufferedTime; 728 }; 729 mutable Mutex mBufferingStatsMutex; 730 std::unordered_map<std::string, BufferingStats> mBufferingStats; 731 732 // Verify that transaction is being called by an approved process: 733 // either AID_GRAPHICS or AID_SYSTEM. 734 status_t CheckTransactCodeCredentials(uint32_t code); 735 736#ifdef USE_HWC2 737 std::atomic<bool> mVrFlingerRequestsDisplay; 738 static bool useVrFlinger; 739#endif 740 }; 741}; // namespace android 742 743#endif // ANDROID_SURFACE_FLINGER_H 744