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