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