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