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