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