Loading services/surfaceflinger/BufferQueueLayer.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "BufferQueueLayer.h" #include "BufferQueueLayer.h" #include "LayerRejecter.h" #include "LayerRejecter.h" #include "SurfaceInterceptor.h" #include "TimeStats/TimeStats.h" #include "TimeStats/TimeStats.h" Loading services/surfaceflinger/SurfaceFlinger.cpp +21 −59 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,7 @@ #include "BufferLayer.h" #include "BufferLayer.h" #include "BufferQueueLayer.h" #include "BufferQueueLayer.h" #include "BufferStateLayer.h" #include "BufferStateLayer.h" #include "BufferStateLayerCache.h" #include "Client.h" #include "Client.h" #include "ColorLayer.h" #include "ColorLayer.h" #include "Colorizer.h" #include "Colorizer.h" Loading @@ -95,12 +96,14 @@ #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/VirtualDisplaySurface.h" #include "DisplayHardware/VirtualDisplaySurface.h" #include "Effects/Daltonizer.h" #include "Effects/Daltonizer.h" #include "RegionSamplingThread.h" #include "Scheduler/DispSync.h" #include "Scheduler/DispSync.h" #include "Scheduler/DispSyncSource.h" #include "Scheduler/DispSyncSource.h" #include "Scheduler/EventControlThread.h" #include "Scheduler/EventControlThread.h" #include "Scheduler/EventThread.h" #include "Scheduler/EventThread.h" #include "Scheduler/InjectVSyncSource.h" #include "Scheduler/InjectVSyncSource.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/PhaseOffsets.h" #include "Scheduler/Scheduler.h" #include "Scheduler/Scheduler.h" #include "TimeStats/TimeStats.h" #include "TimeStats/TimeStats.h" Loading Loading @@ -266,49 +269,17 @@ std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { } } } } SurfaceFlingerBE::SurfaceFlingerBE() SurfaceFlingerBE::SurfaceFlingerBE() : mHwcServiceName(getHwcServiceName()) {} : mHwcServiceName(getHwcServiceName()), mFrameBuckets(), SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) mTotalTime(0), : mFactory(factory), mLastSwapTime(0), mPhaseOffsets(mFactory.createPhaseOffsets()), mComposerSequenceId(0) { mInterceptor(mFactory.createSurfaceInterceptor(this)), } mTimeStats(mFactory.createTimeStats()), mEventQueue(mFactory.createMessageQueue()), SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory, mCompositionEngine(mFactory.createCompositionEngine()) {} SurfaceFlinger::SkipInitializationTag) : BnSurfaceComposer(), SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { mFactory(factory), mTransactionPending(false), mAnimTransactionPending(false), mTraversalNeededMainThread(false), mLayersRemoved(false), mLayersAdded(false), mBootTime(systemTime()), mPhaseOffsets{getFactory().createPhaseOffsets()}, mVisibleRegionsDirty(false), mGeometryInvalid(false), mAnimCompositionPending(false), mBootStage(BootStage::BOOTLOADER), mDebugRegion(0), mDebugDisableHWC(0), mDebugDisableTransformHint(0), mDebugEnableProtectedContent(false), mDebugInTransaction(0), mLastTransactionTime(0), mForceFullDamage(false), mTracing(*this), mTimeStats(factory.createTimeStats()), mRefreshStartTime(0), mHasPoweredOff(false), mNumLayers(0), mVrFlingerRequestsDisplay(false), mMainThreadId(std::this_thread::get_id()), mCompositionEngine{getFactory().createCompositionEngine()} { mSetInputWindowsListener = new SetInputWindowsListener(this); } SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { ALOGI("SurfaceFlinger is starting"); ALOGI("SurfaceFlinger is starting"); hasSyncFramework = running_without_sync_framework(true); hasSyncFramework = running_without_sync_framework(true); Loading Loading @@ -427,9 +398,7 @@ void SurfaceFlinger::onFirstRef() mEventQueue->init(this); mEventQueue->init(this); } } SurfaceFlinger::~SurfaceFlinger() SurfaceFlinger::~SurfaceFlinger() = default; { } void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */) void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */) { { Loading Loading @@ -2417,8 +2386,6 @@ void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) { const auto& displayState = display->getState(); const auto& displayState = display->getState(); const auto displayId = display->getId(); const auto displayId = display->getId(); mPostFramebufferTime = systemTime(); if (displayState.isEnabled) { if (displayState.isEnabled) { if (displayId) { if (displayId) { getHwComposer().presentAndGetReleaseFences(*displayId); getHwComposer().presentAndGetReleaseFences(*displayId); Loading Loading @@ -2481,8 +2448,7 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) State drawingState(mDrawingState); State drawingState(mDrawingState); Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock); const nsecs_t now = systemTime(); mDebugInTransaction = systemTime(); mDebugInTransaction = now; // Here we're guaranteed that some transaction flags are set // Here we're guaranteed that some transaction flags are set // so we can call handleTransactionLocked() unconditionally. // so we can call handleTransactionLocked() unconditionally. Loading @@ -2494,7 +2460,6 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) transactionFlags = getTransactionFlags(eTransactionMask); transactionFlags = getTransactionFlags(eTransactionMask); handleTransactionLocked(transactionFlags); handleTransactionLocked(transactionFlags); mLastTransactionTime = systemTime() - now; mDebugInTransaction = 0; mDebugInTransaction = 0; invalidateHwcGeometry(); invalidateHwcGeometry(); // here the transaction has been committed // here the transaction has been committed Loading Loading @@ -5111,13 +5076,13 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } } case 1008: // toggle use of hw composer case 1008: // toggle use of hw composer n = data.readInt32(); n = data.readInt32(); mDebugDisableHWC = n ? 1 : 0; mDebugDisableHWC = n != 0; invalidateHwcGeometry(); invalidateHwcGeometry(); repaintEverything(); repaintEverything(); return NO_ERROR; return NO_ERROR; case 1009: // toggle use of transform hint case 1009: // toggle use of transform hint n = data.readInt32(); n = data.readInt32(); mDebugDisableTransformHint = n ? 1 : 0; mDebugDisableTransformHint = n != 0; invalidateHwcGeometry(); invalidateHwcGeometry(); repaintEverything(); repaintEverything(); return NO_ERROR; return NO_ERROR; Loading Loading @@ -5199,7 +5164,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } } case 1017: { case 1017: { n = data.readInt32(); n = data.readInt32(); mForceFullDamage = static_cast<bool>(n); mForceFullDamage = n != 0; return NO_ERROR; return NO_ERROR; } } case 1018: { // Modify Choreographer's phase offset case 1018: { // Modify Choreographer's phase offset Loading Loading @@ -5926,14 +5891,11 @@ status_t SurfaceFlinger::getAllowedDisplayConfigs(const android::sp<android::IBi return NO_ERROR; return NO_ERROR; } } // ---------------------------------------------------------------------------- void SurfaceFlinger::SetInputWindowsListener::onSetInputWindowsFinished() { void SetInputWindowsListener::onSetInputWindowsFinished() { mFlinger->setInputWindowsFinished(); mFlinger->setInputWindowsFinished(); } } }; // namespace android } // namespace android #if defined(__gl_h_) #if defined(__gl_h_) #error "don't include gl/gl.h in this file" #error "don't include gl/gl.h in this file" Loading services/surfaceflinger/SurfaceFlinger.h +72 −114 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,7 @@ * limitations under the License. * limitations under the License. */ */ #ifndef ANDROID_SURFACE_FLINGER_H #pragma once #define ANDROID_SURFACE_FLINGER_H #include <sys/types.h> #include <sys/types.h> Loading Loading @@ -48,27 +47,18 @@ #include <utils/threads.h> #include <utils/threads.h> #include "AllowedDisplayConfigs.h" #include "AllowedDisplayConfigs.h" #include "Barrier.h" #include "BufferStateLayerCache.h" #include "DisplayDevice.h" #include "DisplayDevice.h" #include "DisplayHardware/HWC2.h" #include "DisplayHardware/HWC2.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/PowerAdvisor.h" #include "DisplayHardware/PowerAdvisor.h" #include "Effects/Daltonizer.h" #include "Effects/Daltonizer.h" #include "FrameTracker.h" #include "FrameTracker.h" #include "LayerStats.h" #include "LayerStats.h" #include "LayerVector.h" #include "LayerVector.h" #include "RegionSamplingThread.h" #include "Scheduler/DispSync.h" #include "Scheduler/EventThread.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/PhaseOffsets.h" #include "Scheduler/RefreshRateConfigs.h" #include "Scheduler/RefreshRateConfigs.h" #include "Scheduler/RefreshRateStats.h" #include "Scheduler/RefreshRateStats.h" #include "Scheduler/Scheduler.h" #include "Scheduler/Scheduler.h" #include "Scheduler/VSyncModulator.h" #include "Scheduler/VSyncModulator.h" #include "SurfaceFlingerFactory.h" #include "SurfaceFlingerFactory.h" #include "SurfaceInterceptor.h" #include "SurfaceTracing.h" #include "SurfaceTracing.h" #include "TransactionCompletedThread.h" #include "TransactionCompletedThread.h" Loading @@ -90,50 +80,30 @@ using namespace android::surfaceflinger; namespace android { namespace android { using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; // --------------------------------------------------------------------------- class Client; class Client; class ColorLayer; class DisplayEventConnection; class EventControlThread; class EventThread; class EventThread; class IGraphicBufferConsumer; class HWComposer; class IGraphicBufferProducer; class IGraphicBufferProducer; class IInputFlinger; class IInputFlinger; class InjectVSyncSource; class InjectVSyncSource; class Layer; class Layer; class MessageBase; class RefreshRateOverlay; class RefreshRateOverlay; class Surface; class RegionSamplingThread; class SurfaceFlingerBE; class TimeStats; class TimeStats; class VSyncSource; namespace compositionengine { namespace compositionengine { class DisplaySurface; class DisplaySurface; } // namespace compositionengine } // namespace compositionengine namespace impl { class EventThread; } // namespace impl namespace renderengine { namespace renderengine { class RenderEngine; class RenderEngine; } } // namespace renderengine typedef std::function<void(const LayerVector::Visitor&)> TraverseLayersFunction; namespace dvr { namespace dvr { class VrFlinger; class VrFlinger; } // namespace dvr } // namespace dvr namespace surfaceflinger { class NativeWindowSurface; } // namespace surfaceflinger // --------------------------------------------------------------------------- enum { enum { eTransactionNeeded = 0x01, eTransactionNeeded = 0x01, eTraversalNeeded = 0x02, eTraversalNeeded = 0x02, Loading Loading @@ -165,35 +135,28 @@ public: // Only accessed from the main thread. // Only accessed from the main thread. struct CompositePresentTime { struct CompositePresentTime { nsecs_t composite { -1 }; nsecs_t composite = -1; std::shared_ptr<FenceTime> display { FenceTime::NO_FENCE }; std::shared_ptr<FenceTime> display = FenceTime::NO_FENCE; }; }; std::queue<CompositePresentTime> mCompositePresentTimes; std::queue<CompositePresentTime> mCompositePresentTimes; static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ nsecs_t mFrameBuckets[NUM_BUCKETS]; nsecs_t mFrameBuckets[NUM_BUCKETS] = {}; nsecs_t mTotalTime; nsecs_t mTotalTime = 0; std::atomic<nsecs_t> mLastSwapTime; std::atomic<nsecs_t> mLastSwapTime = 0; // Double- vs. triple-buffering stats // Double- vs. triple-buffering stats struct BufferingStats { struct BufferingStats { BufferingStats() size_t numSegments = 0; : numSegments(0), nsecs_t totalTime = 0; totalTime(0), twoBufferTime(0), doubleBufferedTime(0), tripleBufferedTime(0) {} size_t numSegments; nsecs_t totalTime; // "Two buffer" means that a third buffer was never used, whereas // "Two buffer" means that a third buffer was never used, whereas // "double-buffered" means that on average the segment only used two // "double-buffered" means that on average the segment only used two // buffers (though it may have used a third for some part of the // buffers (though it may have used a third for some part of the // segment) // segment) nsecs_t twoBufferTime; nsecs_t twoBufferTime = 0; nsecs_t doubleBufferedTime; nsecs_t doubleBufferedTime = 0; nsecs_t tripleBufferedTime; nsecs_t tripleBufferedTime = 0; }; }; mutable Mutex mBufferingStatsMutex; mutable Mutex mBufferingStatsMutex; std::unordered_map<std::string, BufferingStats> mBufferingStats; std::unordered_map<std::string, BufferingStats> mBufferingStats; Loading @@ -201,16 +164,7 @@ public: // The composer sequence id is a monotonically increasing integer that we // The composer sequence id is a monotonically increasing integer that we // use to differentiate callbacks from different hardware composer // use to differentiate callbacks from different hardware composer // instances. Each hardware composer instance gets a different sequence id. // instances. Each hardware composer instance gets a different sequence id. int32_t mComposerSequenceId; int32_t mComposerSequenceId = 0; }; class SetInputWindowsListener : public BnSetInputWindowsListener { public: SetInputWindowsListener(const sp<SurfaceFlinger>& flinger) : mFlinger(flinger) {} void onSetInputWindowsFinished() override; private: const sp<SurfaceFlinger> mFlinger; }; }; class SurfaceFlinger : public BnSurfaceComposer, class SurfaceFlinger : public BnSurfaceComposer, Loading Loading @@ -359,16 +313,12 @@ public: return mTransactionCompletedThread; return mTransactionCompletedThread; } } void setInputWindowsFinished(); private: private: friend class Client; friend class DisplayEventConnection; friend class impl::EventThread; friend class Layer; friend class BufferLayer; friend class BufferLayer; friend class BufferQueueLayer; friend class BufferQueueLayer; friend class BufferStateLayer; friend class BufferStateLayer; friend class Client; friend class Layer; friend class MonitoredProducer; friend class MonitoredProducer; friend class RefreshRateOverlay; friend class RefreshRateOverlay; friend class RegionSamplingThread; friend class RegionSamplingThread; Loading Loading @@ -533,6 +483,8 @@ private: void signalLayerUpdate(); void signalLayerUpdate(); void signalRefresh(); void signalRefresh(); using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; struct ActiveConfigInfo { struct ActiveConfigInfo { RefreshRateType type; RefreshRateType type; int configId; int configId; Loading Loading @@ -588,6 +540,7 @@ private: void updateInputWindowInfo(); void updateInputWindowInfo(); void commitInputWindowCommands() REQUIRES(mStateLock); void commitInputWindowCommands() REQUIRES(mStateLock); void executeInputWindowCommands(); void executeInputWindowCommands(); void setInputWindowsFinished(); void updateCursorAsync(); void updateCursorAsync(); /* handlePageFlip - latch a new buffer if available and compute the dirty /* handlePageFlip - latch a new buffer if available and compute the dirty Loading Loading @@ -677,6 +630,8 @@ private: void startBootAnim(); void startBootAnim(); using TraverseLayersFunction = std::function<void(const LayerVector::Visitor&)>; void renderScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, void renderScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, ANativeWindowBuffer* buffer, bool useIdentityTransform, ANativeWindowBuffer* buffer, bool useIdentityTransform, int* outSyncFd); int* outSyncFd); Loading Loading @@ -962,12 +917,12 @@ private: // access must be protected by mStateLock // access must be protected by mStateLock mutable Mutex mStateLock; mutable Mutex mStateLock; State mCurrentState{LayerVector::StateSet::Current}; State mCurrentState{LayerVector::StateSet::Current}; std::atomic<int32_t> mTransactionFlags{0}; std::atomic<int32_t> mTransactionFlags = 0; Condition mTransactionCV; Condition mTransactionCV; bool mTransactionPending; bool mTransactionPending = false; bool mAnimTransactionPending; bool mAnimTransactionPending = false; SortedVector<sp<Layer>> mLayersPendingRemoval; SortedVector<sp<Layer>> mLayersPendingRemoval; bool mTraversalNeededMainThread; bool mTraversalNeededMainThread = false; // guards access to the mDrawing state if tracing is enabled. // guards access to the mDrawing state if tracing is enabled. mutable std::mutex mDrawingStateLock; mutable std::mutex mDrawingStateLock; Loading @@ -982,31 +937,30 @@ private: size_t mMaxGraphicBufferProducerListSize = MAX_LAYERS; size_t mMaxGraphicBufferProducerListSize = MAX_LAYERS; // protected by mStateLock (but we could use another lock) // protected by mStateLock (but we could use another lock) bool mLayersRemoved; bool mLayersRemoved = false; bool mLayersAdded; bool mLayersAdded = false; std::atomic<bool> mRepaintEverything{false}; std::atomic<bool> mRepaintEverything = false; // constant members (no synchronization needed for access) // constant members (no synchronization needed for access) nsecs_t mBootTime; const nsecs_t mBootTime = systemTime(); bool mGpuToCpuSupported; bool mGpuToCpuSupported = false; std::unique_ptr<EventThread> mInjectorEventThread; std::unique_ptr<EventThread> mInjectorEventThread; std::unique_ptr<InjectVSyncSource> mVSyncInjector; std::unique_ptr<InjectVSyncSource> mVSyncInjector; std::unique_ptr<EventControlThread> mEventControlThread; // Calculates correct offsets. // Calculates correct offsets. VSyncModulator mVsyncModulator; VSyncModulator mVsyncModulator; // Keeps track of all available phase offsets for different refresh types. // Keeps track of all available phase offsets for different refresh types. std::unique_ptr<scheduler::PhaseOffsets> mPhaseOffsets; const std::unique_ptr<scheduler::PhaseOffsets> mPhaseOffsets; // Can only accessed from the main thread, these members // Can only accessed from the main thread, these members // don't need synchronization // don't need synchronization State mDrawingState{LayerVector::StateSet::Drawing}; State mDrawingState{LayerVector::StateSet::Drawing}; bool mVisibleRegionsDirty; bool mVisibleRegionsDirty = false; // Set during transaction commit stage to track if the input info for a layer has changed. // Set during transaction commit stage to track if the input info for a layer has changed. bool mInputInfoChanged{false}; bool mInputInfoChanged = false; bool mGeometryInvalid; bool mGeometryInvalid = false; bool mAnimCompositionPending; bool mAnimCompositionPending = false; std::vector<sp<Layer>> mLayersWithQueuedFrames; std::vector<sp<Layer>> mLayersWithQueuedFrames; // Tracks layers that need to update a display's dirty region. // Tracks layers that need to update a display's dirty region. std::vector<sp<Layer>> mLayersPendingRefresh; std::vector<sp<Layer>> mLayersPendingRefresh; Loading @@ -1023,7 +977,7 @@ private: BOOTANIMATION, BOOTANIMATION, FINISHED, FINISHED, }; }; BootStage mBootStage; BootStage mBootStage = BootStage::BOOTLOADER; struct HotplugEvent { struct HotplugEvent { hwc2_display_t hwcDisplayId; hwc2_display_t hwcDisplayId; Loading @@ -1038,26 +992,23 @@ private: std::unordered_map<DisplayId, sp<IBinder>> mPhysicalDisplayTokens; std::unordered_map<DisplayId, sp<IBinder>> mPhysicalDisplayTokens; // don't use a lock for these, we don't care // don't use a lock for these, we don't care int mDebugRegion; int mDebugRegion = 0; int mDebugDisableHWC; bool mDebugDisableHWC = false; int mDebugDisableTransformHint; bool mDebugDisableTransformHint = false; bool mDebugEnableProtectedContent; bool mDebugEnableProtectedContent = false; volatile nsecs_t mDebugInSwapBuffers; volatile nsecs_t mDebugInTransaction = 0; volatile nsecs_t mDebugInTransaction; bool mForceFullDamage = false; nsecs_t mLastTransactionTime; nsecs_t mPostFramebufferTime; bool mForceFullDamage; bool mPropagateBackpressure = true; bool mPropagateBackpressure = true; std::unique_ptr<SurfaceInterceptor> mInterceptor{mFactory.createSurfaceInterceptor(this)}; std::unique_ptr<SurfaceInterceptor> mInterceptor; SurfaceTracing mTracing; SurfaceTracing mTracing{*this}; bool mTracingEnabled = false; bool mTracingEnabled = false; bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false; bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false; LayerStats mLayerStats; LayerStats mLayerStats; std::shared_ptr<TimeStats> mTimeStats; const std::shared_ptr<TimeStats> mTimeStats; bool mUseHwcVirtualDisplays = false; bool mUseHwcVirtualDisplays = false; std::atomic<uint32_t> mFrameMissedCount{0}; std::atomic<uint32_t> mFrameMissedCount = 0; std::atomic<uint32_t> mHwcFrameMissedCount{0}; std::atomic<uint32_t> mHwcFrameMissedCount = 0; std::atomic<uint32_t> mGpuFrameMissedCount{0}; std::atomic<uint32_t> mGpuFrameMissedCount = 0; TransactionCompletedThread mTransactionCompletedThread; TransactionCompletedThread mTransactionCompletedThread; Loading @@ -1065,16 +1016,16 @@ private: bool mLayerTripleBufferingDisabled = false; bool mLayerTripleBufferingDisabled = false; // these are thread safe // these are thread safe mutable std::unique_ptr<MessageQueue> mEventQueue{mFactory.createMessageQueue()}; std::unique_ptr<MessageQueue> mEventQueue; FrameTracker mAnimFrameTracker; FrameTracker mAnimFrameTracker; // protected by mDestroyedLayerLock; // protected by mDestroyedLayerLock; mutable Mutex mDestroyedLayerLock; mutable Mutex mDestroyedLayerLock; Vector<Layer const *> mDestroyedLayers; Vector<Layer const *> mDestroyedLayers; nsecs_t mRefreshStartTime; nsecs_t mRefreshStartTime = 0; std::atomic<bool> mRefreshPending{false}; std::atomic<bool> mRefreshPending = false; // We maintain a pool of pre-generated texture names to hand out to avoid // We maintain a pool of pre-generated texture names to hand out to avoid // layer creation needing to run on the main thread (which it would // layer creation needing to run on the main thread (which it would Loading Loading @@ -1118,21 +1069,21 @@ private: * Feature prototyping * Feature prototyping */ */ bool mInjectVSyncs; bool mInjectVSyncs = false; // Static screen stats // Static screen stats bool mHasPoweredOff; bool mHasPoweredOff = false; size_t mNumLayers; size_t mNumLayers = 0; // Verify that transaction is being called by an approved process: // Verify that transaction is being called by an approved process: // either AID_GRAPHICS or AID_SYSTEM. // either AID_GRAPHICS or AID_SYSTEM. status_t CheckTransactCodeCredentials(uint32_t code); status_t CheckTransactCodeCredentials(uint32_t code); std::unique_ptr<dvr::VrFlinger> mVrFlinger; std::unique_ptr<dvr::VrFlinger> mVrFlinger; std::atomic<bool> mVrFlingerRequestsDisplay; std::atomic<bool> mVrFlingerRequestsDisplay = false; static bool useVrFlinger; static bool useVrFlinger; std::thread::id mMainThreadId; std::thread::id mMainThreadId = std::this_thread::get_id(); DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED; DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED; Loading Loading @@ -1179,23 +1130,30 @@ private: bool mDesiredActiveConfigChanged GUARDED_BY(mActiveConfigLock) = false; bool mDesiredActiveConfigChanged GUARDED_BY(mActiveConfigLock) = false; bool mCheckPendingFence = false; bool mCheckPendingFence = false; /* ------------------------------------------------------------------------ */ bool mLumaSampling = true; bool mLumaSampling = true; sp<RegionSamplingThread> mRegionSamplingThread; sp<RegionSamplingThread> mRegionSamplingThread; ui::DisplayPrimaries mInternalDisplayPrimaries; sp<IInputFlinger> mInputFlinger; sp<IInputFlinger> mInputFlinger; InputWindowCommands mPendingInputWindowCommands GUARDED_BY(mStateLock); InputWindowCommands mPendingInputWindowCommands GUARDED_BY(mStateLock); // Should only be accessed by the main thread. // Should only be accessed by the main thread. InputWindowCommands mInputWindowCommands; InputWindowCommands mInputWindowCommands; ui::DisplayPrimaries mInternalDisplayPrimaries; sp<SetInputWindowsListener> mSetInputWindowsListener; struct SetInputWindowsListener : BnSetInputWindowsListener { explicit SetInputWindowsListener(sp<SurfaceFlinger> flinger) : mFlinger(std::move(flinger)) {} void onSetInputWindowsFinished() override; const sp<SurfaceFlinger> mFlinger; }; const sp<SetInputWindowsListener> mSetInputWindowsListener = new SetInputWindowsListener(this); bool mPendingSyncInputWindows GUARDED_BY(mStateLock); bool mPendingSyncInputWindows GUARDED_BY(mStateLock); Hwc2::impl::PowerAdvisor mPowerAdvisor; Hwc2::impl::PowerAdvisor mPowerAdvisor; std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; }; }; }; // namespace android #endif // ANDROID_SURFACE_FLINGER_H } // namespace android services/surfaceflinger/SurfaceTracing.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,7 @@ constexpr auto operator""_MB(unsigned long long const num) { */ */ class SurfaceTracing { class SurfaceTracing { public: public: SurfaceTracing(SurfaceFlinger& flinger); explicit SurfaceTracing(SurfaceFlinger& flinger); void enable(); void enable(); bool disable(); bool disable(); status_t writeToFile(); status_t writeToFile(); Loading services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +4 −2 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "FakePhaseOffsets.h" #include "FakePhaseOffsets.h" #include "Layer.h" #include "Layer.h" #include "NativeWindowSurface.h" #include "NativeWindowSurface.h" #include "Scheduler/MessageQueue.h" #include "StartPropertySetThread.h" #include "StartPropertySetThread.h" #include "SurfaceFlinger.h" #include "SurfaceFlinger.h" #include "SurfaceFlingerFactory.h" #include "SurfaceFlingerFactory.h" Loading Loading @@ -276,8 +277,9 @@ public: auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); } auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); } auto captureScreenImplLocked(const RenderArea& renderArea, auto captureScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, ANativeWindowBuffer* buffer, SurfaceFlinger::TraverseLayersFunction traverseLayers, bool useIdentityTransform, bool forSystem, int* outSyncFd) { ANativeWindowBuffer* buffer, bool useIdentityTransform, bool forSystem, int* outSyncFd) { return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer, return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer, useIdentityTransform, forSystem, outSyncFd); useIdentityTransform, forSystem, outSyncFd); } } Loading Loading
services/surfaceflinger/BufferQueueLayer.cpp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "BufferQueueLayer.h" #include "BufferQueueLayer.h" #include "LayerRejecter.h" #include "LayerRejecter.h" #include "SurfaceInterceptor.h" #include "TimeStats/TimeStats.h" #include "TimeStats/TimeStats.h" Loading
services/surfaceflinger/SurfaceFlinger.cpp +21 −59 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,7 @@ #include "BufferLayer.h" #include "BufferLayer.h" #include "BufferQueueLayer.h" #include "BufferQueueLayer.h" #include "BufferStateLayer.h" #include "BufferStateLayer.h" #include "BufferStateLayerCache.h" #include "Client.h" #include "Client.h" #include "ColorLayer.h" #include "ColorLayer.h" #include "Colorizer.h" #include "Colorizer.h" Loading @@ -95,12 +96,14 @@ #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/VirtualDisplaySurface.h" #include "DisplayHardware/VirtualDisplaySurface.h" #include "Effects/Daltonizer.h" #include "Effects/Daltonizer.h" #include "RegionSamplingThread.h" #include "Scheduler/DispSync.h" #include "Scheduler/DispSync.h" #include "Scheduler/DispSyncSource.h" #include "Scheduler/DispSyncSource.h" #include "Scheduler/EventControlThread.h" #include "Scheduler/EventControlThread.h" #include "Scheduler/EventThread.h" #include "Scheduler/EventThread.h" #include "Scheduler/InjectVSyncSource.h" #include "Scheduler/InjectVSyncSource.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/PhaseOffsets.h" #include "Scheduler/Scheduler.h" #include "Scheduler/Scheduler.h" #include "TimeStats/TimeStats.h" #include "TimeStats/TimeStats.h" Loading Loading @@ -266,49 +269,17 @@ std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) { } } } } SurfaceFlingerBE::SurfaceFlingerBE() SurfaceFlingerBE::SurfaceFlingerBE() : mHwcServiceName(getHwcServiceName()) {} : mHwcServiceName(getHwcServiceName()), mFrameBuckets(), SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag) mTotalTime(0), : mFactory(factory), mLastSwapTime(0), mPhaseOffsets(mFactory.createPhaseOffsets()), mComposerSequenceId(0) { mInterceptor(mFactory.createSurfaceInterceptor(this)), } mTimeStats(mFactory.createTimeStats()), mEventQueue(mFactory.createMessageQueue()), SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory, mCompositionEngine(mFactory.createCompositionEngine()) {} SurfaceFlinger::SkipInitializationTag) : BnSurfaceComposer(), SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { mFactory(factory), mTransactionPending(false), mAnimTransactionPending(false), mTraversalNeededMainThread(false), mLayersRemoved(false), mLayersAdded(false), mBootTime(systemTime()), mPhaseOffsets{getFactory().createPhaseOffsets()}, mVisibleRegionsDirty(false), mGeometryInvalid(false), mAnimCompositionPending(false), mBootStage(BootStage::BOOTLOADER), mDebugRegion(0), mDebugDisableHWC(0), mDebugDisableTransformHint(0), mDebugEnableProtectedContent(false), mDebugInTransaction(0), mLastTransactionTime(0), mForceFullDamage(false), mTracing(*this), mTimeStats(factory.createTimeStats()), mRefreshStartTime(0), mHasPoweredOff(false), mNumLayers(0), mVrFlingerRequestsDisplay(false), mMainThreadId(std::this_thread::get_id()), mCompositionEngine{getFactory().createCompositionEngine()} { mSetInputWindowsListener = new SetInputWindowsListener(this); } SurfaceFlinger::SurfaceFlinger(surfaceflinger::Factory& factory) : SurfaceFlinger(factory, SkipInitialization) { ALOGI("SurfaceFlinger is starting"); ALOGI("SurfaceFlinger is starting"); hasSyncFramework = running_without_sync_framework(true); hasSyncFramework = running_without_sync_framework(true); Loading Loading @@ -427,9 +398,7 @@ void SurfaceFlinger::onFirstRef() mEventQueue->init(this); mEventQueue->init(this); } } SurfaceFlinger::~SurfaceFlinger() SurfaceFlinger::~SurfaceFlinger() = default; { } void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */) void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */) { { Loading Loading @@ -2417,8 +2386,6 @@ void SurfaceFlinger::postFramebuffer(const sp<DisplayDevice>& displayDevice) { const auto& displayState = display->getState(); const auto& displayState = display->getState(); const auto displayId = display->getId(); const auto displayId = display->getId(); mPostFramebufferTime = systemTime(); if (displayState.isEnabled) { if (displayState.isEnabled) { if (displayId) { if (displayId) { getHwComposer().presentAndGetReleaseFences(*displayId); getHwComposer().presentAndGetReleaseFences(*displayId); Loading Loading @@ -2481,8 +2448,7 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) State drawingState(mDrawingState); State drawingState(mDrawingState); Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock); const nsecs_t now = systemTime(); mDebugInTransaction = systemTime(); mDebugInTransaction = now; // Here we're guaranteed that some transaction flags are set // Here we're guaranteed that some transaction flags are set // so we can call handleTransactionLocked() unconditionally. // so we can call handleTransactionLocked() unconditionally. Loading @@ -2494,7 +2460,6 @@ void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) transactionFlags = getTransactionFlags(eTransactionMask); transactionFlags = getTransactionFlags(eTransactionMask); handleTransactionLocked(transactionFlags); handleTransactionLocked(transactionFlags); mLastTransactionTime = systemTime() - now; mDebugInTransaction = 0; mDebugInTransaction = 0; invalidateHwcGeometry(); invalidateHwcGeometry(); // here the transaction has been committed // here the transaction has been committed Loading Loading @@ -5111,13 +5076,13 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } } case 1008: // toggle use of hw composer case 1008: // toggle use of hw composer n = data.readInt32(); n = data.readInt32(); mDebugDisableHWC = n ? 1 : 0; mDebugDisableHWC = n != 0; invalidateHwcGeometry(); invalidateHwcGeometry(); repaintEverything(); repaintEverything(); return NO_ERROR; return NO_ERROR; case 1009: // toggle use of transform hint case 1009: // toggle use of transform hint n = data.readInt32(); n = data.readInt32(); mDebugDisableTransformHint = n ? 1 : 0; mDebugDisableTransformHint = n != 0; invalidateHwcGeometry(); invalidateHwcGeometry(); repaintEverything(); repaintEverything(); return NO_ERROR; return NO_ERROR; Loading Loading @@ -5199,7 +5164,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } } case 1017: { case 1017: { n = data.readInt32(); n = data.readInt32(); mForceFullDamage = static_cast<bool>(n); mForceFullDamage = n != 0; return NO_ERROR; return NO_ERROR; } } case 1018: { // Modify Choreographer's phase offset case 1018: { // Modify Choreographer's phase offset Loading Loading @@ -5926,14 +5891,11 @@ status_t SurfaceFlinger::getAllowedDisplayConfigs(const android::sp<android::IBi return NO_ERROR; return NO_ERROR; } } // ---------------------------------------------------------------------------- void SurfaceFlinger::SetInputWindowsListener::onSetInputWindowsFinished() { void SetInputWindowsListener::onSetInputWindowsFinished() { mFlinger->setInputWindowsFinished(); mFlinger->setInputWindowsFinished(); } } }; // namespace android } // namespace android #if defined(__gl_h_) #if defined(__gl_h_) #error "don't include gl/gl.h in this file" #error "don't include gl/gl.h in this file" Loading
services/surfaceflinger/SurfaceFlinger.h +72 −114 Original line number Original line Diff line number Diff line Loading @@ -14,8 +14,7 @@ * limitations under the License. * limitations under the License. */ */ #ifndef ANDROID_SURFACE_FLINGER_H #pragma once #define ANDROID_SURFACE_FLINGER_H #include <sys/types.h> #include <sys/types.h> Loading Loading @@ -48,27 +47,18 @@ #include <utils/threads.h> #include <utils/threads.h> #include "AllowedDisplayConfigs.h" #include "AllowedDisplayConfigs.h" #include "Barrier.h" #include "BufferStateLayerCache.h" #include "DisplayDevice.h" #include "DisplayDevice.h" #include "DisplayHardware/HWC2.h" #include "DisplayHardware/HWC2.h" #include "DisplayHardware/HWComposer.h" #include "DisplayHardware/PowerAdvisor.h" #include "DisplayHardware/PowerAdvisor.h" #include "Effects/Daltonizer.h" #include "Effects/Daltonizer.h" #include "FrameTracker.h" #include "FrameTracker.h" #include "LayerStats.h" #include "LayerStats.h" #include "LayerVector.h" #include "LayerVector.h" #include "RegionSamplingThread.h" #include "Scheduler/DispSync.h" #include "Scheduler/EventThread.h" #include "Scheduler/MessageQueue.h" #include "Scheduler/PhaseOffsets.h" #include "Scheduler/RefreshRateConfigs.h" #include "Scheduler/RefreshRateConfigs.h" #include "Scheduler/RefreshRateStats.h" #include "Scheduler/RefreshRateStats.h" #include "Scheduler/Scheduler.h" #include "Scheduler/Scheduler.h" #include "Scheduler/VSyncModulator.h" #include "Scheduler/VSyncModulator.h" #include "SurfaceFlingerFactory.h" #include "SurfaceFlingerFactory.h" #include "SurfaceInterceptor.h" #include "SurfaceTracing.h" #include "SurfaceTracing.h" #include "TransactionCompletedThread.h" #include "TransactionCompletedThread.h" Loading @@ -90,50 +80,30 @@ using namespace android::surfaceflinger; namespace android { namespace android { using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; // --------------------------------------------------------------------------- class Client; class Client; class ColorLayer; class DisplayEventConnection; class EventControlThread; class EventThread; class EventThread; class IGraphicBufferConsumer; class HWComposer; class IGraphicBufferProducer; class IGraphicBufferProducer; class IInputFlinger; class IInputFlinger; class InjectVSyncSource; class InjectVSyncSource; class Layer; class Layer; class MessageBase; class RefreshRateOverlay; class RefreshRateOverlay; class Surface; class RegionSamplingThread; class SurfaceFlingerBE; class TimeStats; class TimeStats; class VSyncSource; namespace compositionengine { namespace compositionengine { class DisplaySurface; class DisplaySurface; } // namespace compositionengine } // namespace compositionengine namespace impl { class EventThread; } // namespace impl namespace renderengine { namespace renderengine { class RenderEngine; class RenderEngine; } } // namespace renderengine typedef std::function<void(const LayerVector::Visitor&)> TraverseLayersFunction; namespace dvr { namespace dvr { class VrFlinger; class VrFlinger; } // namespace dvr } // namespace dvr namespace surfaceflinger { class NativeWindowSurface; } // namespace surfaceflinger // --------------------------------------------------------------------------- enum { enum { eTransactionNeeded = 0x01, eTransactionNeeded = 0x01, eTraversalNeeded = 0x02, eTraversalNeeded = 0x02, Loading Loading @@ -165,35 +135,28 @@ public: // Only accessed from the main thread. // Only accessed from the main thread. struct CompositePresentTime { struct CompositePresentTime { nsecs_t composite { -1 }; nsecs_t composite = -1; std::shared_ptr<FenceTime> display { FenceTime::NO_FENCE }; std::shared_ptr<FenceTime> display = FenceTime::NO_FENCE; }; }; std::queue<CompositePresentTime> mCompositePresentTimes; std::queue<CompositePresentTime> mCompositePresentTimes; static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ nsecs_t mFrameBuckets[NUM_BUCKETS]; nsecs_t mFrameBuckets[NUM_BUCKETS] = {}; nsecs_t mTotalTime; nsecs_t mTotalTime = 0; std::atomic<nsecs_t> mLastSwapTime; std::atomic<nsecs_t> mLastSwapTime = 0; // Double- vs. triple-buffering stats // Double- vs. triple-buffering stats struct BufferingStats { struct BufferingStats { BufferingStats() size_t numSegments = 0; : numSegments(0), nsecs_t totalTime = 0; totalTime(0), twoBufferTime(0), doubleBufferedTime(0), tripleBufferedTime(0) {} size_t numSegments; nsecs_t totalTime; // "Two buffer" means that a third buffer was never used, whereas // "Two buffer" means that a third buffer was never used, whereas // "double-buffered" means that on average the segment only used two // "double-buffered" means that on average the segment only used two // buffers (though it may have used a third for some part of the // buffers (though it may have used a third for some part of the // segment) // segment) nsecs_t twoBufferTime; nsecs_t twoBufferTime = 0; nsecs_t doubleBufferedTime; nsecs_t doubleBufferedTime = 0; nsecs_t tripleBufferedTime; nsecs_t tripleBufferedTime = 0; }; }; mutable Mutex mBufferingStatsMutex; mutable Mutex mBufferingStatsMutex; std::unordered_map<std::string, BufferingStats> mBufferingStats; std::unordered_map<std::string, BufferingStats> mBufferingStats; Loading @@ -201,16 +164,7 @@ public: // The composer sequence id is a monotonically increasing integer that we // The composer sequence id is a monotonically increasing integer that we // use to differentiate callbacks from different hardware composer // use to differentiate callbacks from different hardware composer // instances. Each hardware composer instance gets a different sequence id. // instances. Each hardware composer instance gets a different sequence id. int32_t mComposerSequenceId; int32_t mComposerSequenceId = 0; }; class SetInputWindowsListener : public BnSetInputWindowsListener { public: SetInputWindowsListener(const sp<SurfaceFlinger>& flinger) : mFlinger(flinger) {} void onSetInputWindowsFinished() override; private: const sp<SurfaceFlinger> mFlinger; }; }; class SurfaceFlinger : public BnSurfaceComposer, class SurfaceFlinger : public BnSurfaceComposer, Loading Loading @@ -359,16 +313,12 @@ public: return mTransactionCompletedThread; return mTransactionCompletedThread; } } void setInputWindowsFinished(); private: private: friend class Client; friend class DisplayEventConnection; friend class impl::EventThread; friend class Layer; friend class BufferLayer; friend class BufferLayer; friend class BufferQueueLayer; friend class BufferQueueLayer; friend class BufferStateLayer; friend class BufferStateLayer; friend class Client; friend class Layer; friend class MonitoredProducer; friend class MonitoredProducer; friend class RefreshRateOverlay; friend class RefreshRateOverlay; friend class RegionSamplingThread; friend class RegionSamplingThread; Loading Loading @@ -533,6 +483,8 @@ private: void signalLayerUpdate(); void signalLayerUpdate(); void signalRefresh(); void signalRefresh(); using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType; struct ActiveConfigInfo { struct ActiveConfigInfo { RefreshRateType type; RefreshRateType type; int configId; int configId; Loading Loading @@ -588,6 +540,7 @@ private: void updateInputWindowInfo(); void updateInputWindowInfo(); void commitInputWindowCommands() REQUIRES(mStateLock); void commitInputWindowCommands() REQUIRES(mStateLock); void executeInputWindowCommands(); void executeInputWindowCommands(); void setInputWindowsFinished(); void updateCursorAsync(); void updateCursorAsync(); /* handlePageFlip - latch a new buffer if available and compute the dirty /* handlePageFlip - latch a new buffer if available and compute the dirty Loading Loading @@ -677,6 +630,8 @@ private: void startBootAnim(); void startBootAnim(); using TraverseLayersFunction = std::function<void(const LayerVector::Visitor&)>; void renderScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, void renderScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, ANativeWindowBuffer* buffer, bool useIdentityTransform, ANativeWindowBuffer* buffer, bool useIdentityTransform, int* outSyncFd); int* outSyncFd); Loading Loading @@ -962,12 +917,12 @@ private: // access must be protected by mStateLock // access must be protected by mStateLock mutable Mutex mStateLock; mutable Mutex mStateLock; State mCurrentState{LayerVector::StateSet::Current}; State mCurrentState{LayerVector::StateSet::Current}; std::atomic<int32_t> mTransactionFlags{0}; std::atomic<int32_t> mTransactionFlags = 0; Condition mTransactionCV; Condition mTransactionCV; bool mTransactionPending; bool mTransactionPending = false; bool mAnimTransactionPending; bool mAnimTransactionPending = false; SortedVector<sp<Layer>> mLayersPendingRemoval; SortedVector<sp<Layer>> mLayersPendingRemoval; bool mTraversalNeededMainThread; bool mTraversalNeededMainThread = false; // guards access to the mDrawing state if tracing is enabled. // guards access to the mDrawing state if tracing is enabled. mutable std::mutex mDrawingStateLock; mutable std::mutex mDrawingStateLock; Loading @@ -982,31 +937,30 @@ private: size_t mMaxGraphicBufferProducerListSize = MAX_LAYERS; size_t mMaxGraphicBufferProducerListSize = MAX_LAYERS; // protected by mStateLock (but we could use another lock) // protected by mStateLock (but we could use another lock) bool mLayersRemoved; bool mLayersRemoved = false; bool mLayersAdded; bool mLayersAdded = false; std::atomic<bool> mRepaintEverything{false}; std::atomic<bool> mRepaintEverything = false; // constant members (no synchronization needed for access) // constant members (no synchronization needed for access) nsecs_t mBootTime; const nsecs_t mBootTime = systemTime(); bool mGpuToCpuSupported; bool mGpuToCpuSupported = false; std::unique_ptr<EventThread> mInjectorEventThread; std::unique_ptr<EventThread> mInjectorEventThread; std::unique_ptr<InjectVSyncSource> mVSyncInjector; std::unique_ptr<InjectVSyncSource> mVSyncInjector; std::unique_ptr<EventControlThread> mEventControlThread; // Calculates correct offsets. // Calculates correct offsets. VSyncModulator mVsyncModulator; VSyncModulator mVsyncModulator; // Keeps track of all available phase offsets for different refresh types. // Keeps track of all available phase offsets for different refresh types. std::unique_ptr<scheduler::PhaseOffsets> mPhaseOffsets; const std::unique_ptr<scheduler::PhaseOffsets> mPhaseOffsets; // Can only accessed from the main thread, these members // Can only accessed from the main thread, these members // don't need synchronization // don't need synchronization State mDrawingState{LayerVector::StateSet::Drawing}; State mDrawingState{LayerVector::StateSet::Drawing}; bool mVisibleRegionsDirty; bool mVisibleRegionsDirty = false; // Set during transaction commit stage to track if the input info for a layer has changed. // Set during transaction commit stage to track if the input info for a layer has changed. bool mInputInfoChanged{false}; bool mInputInfoChanged = false; bool mGeometryInvalid; bool mGeometryInvalid = false; bool mAnimCompositionPending; bool mAnimCompositionPending = false; std::vector<sp<Layer>> mLayersWithQueuedFrames; std::vector<sp<Layer>> mLayersWithQueuedFrames; // Tracks layers that need to update a display's dirty region. // Tracks layers that need to update a display's dirty region. std::vector<sp<Layer>> mLayersPendingRefresh; std::vector<sp<Layer>> mLayersPendingRefresh; Loading @@ -1023,7 +977,7 @@ private: BOOTANIMATION, BOOTANIMATION, FINISHED, FINISHED, }; }; BootStage mBootStage; BootStage mBootStage = BootStage::BOOTLOADER; struct HotplugEvent { struct HotplugEvent { hwc2_display_t hwcDisplayId; hwc2_display_t hwcDisplayId; Loading @@ -1038,26 +992,23 @@ private: std::unordered_map<DisplayId, sp<IBinder>> mPhysicalDisplayTokens; std::unordered_map<DisplayId, sp<IBinder>> mPhysicalDisplayTokens; // don't use a lock for these, we don't care // don't use a lock for these, we don't care int mDebugRegion; int mDebugRegion = 0; int mDebugDisableHWC; bool mDebugDisableHWC = false; int mDebugDisableTransformHint; bool mDebugDisableTransformHint = false; bool mDebugEnableProtectedContent; bool mDebugEnableProtectedContent = false; volatile nsecs_t mDebugInSwapBuffers; volatile nsecs_t mDebugInTransaction = 0; volatile nsecs_t mDebugInTransaction; bool mForceFullDamage = false; nsecs_t mLastTransactionTime; nsecs_t mPostFramebufferTime; bool mForceFullDamage; bool mPropagateBackpressure = true; bool mPropagateBackpressure = true; std::unique_ptr<SurfaceInterceptor> mInterceptor{mFactory.createSurfaceInterceptor(this)}; std::unique_ptr<SurfaceInterceptor> mInterceptor; SurfaceTracing mTracing; SurfaceTracing mTracing{*this}; bool mTracingEnabled = false; bool mTracingEnabled = false; bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false; bool mTracingEnabledChanged GUARDED_BY(mStateLock) = false; LayerStats mLayerStats; LayerStats mLayerStats; std::shared_ptr<TimeStats> mTimeStats; const std::shared_ptr<TimeStats> mTimeStats; bool mUseHwcVirtualDisplays = false; bool mUseHwcVirtualDisplays = false; std::atomic<uint32_t> mFrameMissedCount{0}; std::atomic<uint32_t> mFrameMissedCount = 0; std::atomic<uint32_t> mHwcFrameMissedCount{0}; std::atomic<uint32_t> mHwcFrameMissedCount = 0; std::atomic<uint32_t> mGpuFrameMissedCount{0}; std::atomic<uint32_t> mGpuFrameMissedCount = 0; TransactionCompletedThread mTransactionCompletedThread; TransactionCompletedThread mTransactionCompletedThread; Loading @@ -1065,16 +1016,16 @@ private: bool mLayerTripleBufferingDisabled = false; bool mLayerTripleBufferingDisabled = false; // these are thread safe // these are thread safe mutable std::unique_ptr<MessageQueue> mEventQueue{mFactory.createMessageQueue()}; std::unique_ptr<MessageQueue> mEventQueue; FrameTracker mAnimFrameTracker; FrameTracker mAnimFrameTracker; // protected by mDestroyedLayerLock; // protected by mDestroyedLayerLock; mutable Mutex mDestroyedLayerLock; mutable Mutex mDestroyedLayerLock; Vector<Layer const *> mDestroyedLayers; Vector<Layer const *> mDestroyedLayers; nsecs_t mRefreshStartTime; nsecs_t mRefreshStartTime = 0; std::atomic<bool> mRefreshPending{false}; std::atomic<bool> mRefreshPending = false; // We maintain a pool of pre-generated texture names to hand out to avoid // We maintain a pool of pre-generated texture names to hand out to avoid // layer creation needing to run on the main thread (which it would // layer creation needing to run on the main thread (which it would Loading Loading @@ -1118,21 +1069,21 @@ private: * Feature prototyping * Feature prototyping */ */ bool mInjectVSyncs; bool mInjectVSyncs = false; // Static screen stats // Static screen stats bool mHasPoweredOff; bool mHasPoweredOff = false; size_t mNumLayers; size_t mNumLayers = 0; // Verify that transaction is being called by an approved process: // Verify that transaction is being called by an approved process: // either AID_GRAPHICS or AID_SYSTEM. // either AID_GRAPHICS or AID_SYSTEM. status_t CheckTransactCodeCredentials(uint32_t code); status_t CheckTransactCodeCredentials(uint32_t code); std::unique_ptr<dvr::VrFlinger> mVrFlinger; std::unique_ptr<dvr::VrFlinger> mVrFlinger; std::atomic<bool> mVrFlingerRequestsDisplay; std::atomic<bool> mVrFlingerRequestsDisplay = false; static bool useVrFlinger; static bool useVrFlinger; std::thread::id mMainThreadId; std::thread::id mMainThreadId = std::this_thread::get_id(); DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED; DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED; Loading Loading @@ -1179,23 +1130,30 @@ private: bool mDesiredActiveConfigChanged GUARDED_BY(mActiveConfigLock) = false; bool mDesiredActiveConfigChanged GUARDED_BY(mActiveConfigLock) = false; bool mCheckPendingFence = false; bool mCheckPendingFence = false; /* ------------------------------------------------------------------------ */ bool mLumaSampling = true; bool mLumaSampling = true; sp<RegionSamplingThread> mRegionSamplingThread; sp<RegionSamplingThread> mRegionSamplingThread; ui::DisplayPrimaries mInternalDisplayPrimaries; sp<IInputFlinger> mInputFlinger; sp<IInputFlinger> mInputFlinger; InputWindowCommands mPendingInputWindowCommands GUARDED_BY(mStateLock); InputWindowCommands mPendingInputWindowCommands GUARDED_BY(mStateLock); // Should only be accessed by the main thread. // Should only be accessed by the main thread. InputWindowCommands mInputWindowCommands; InputWindowCommands mInputWindowCommands; ui::DisplayPrimaries mInternalDisplayPrimaries; sp<SetInputWindowsListener> mSetInputWindowsListener; struct SetInputWindowsListener : BnSetInputWindowsListener { explicit SetInputWindowsListener(sp<SurfaceFlinger> flinger) : mFlinger(std::move(flinger)) {} void onSetInputWindowsFinished() override; const sp<SurfaceFlinger> mFlinger; }; const sp<SetInputWindowsListener> mSetInputWindowsListener = new SetInputWindowsListener(this); bool mPendingSyncInputWindows GUARDED_BY(mStateLock); bool mPendingSyncInputWindows GUARDED_BY(mStateLock); Hwc2::impl::PowerAdvisor mPowerAdvisor; Hwc2::impl::PowerAdvisor mPowerAdvisor; std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; }; }; }; // namespace android #endif // ANDROID_SURFACE_FLINGER_H } // namespace android
services/surfaceflinger/SurfaceTracing.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -41,7 +41,7 @@ constexpr auto operator""_MB(unsigned long long const num) { */ */ class SurfaceTracing { class SurfaceTracing { public: public: SurfaceTracing(SurfaceFlinger& flinger); explicit SurfaceTracing(SurfaceFlinger& flinger); void enable(); void enable(); bool disable(); bool disable(); status_t writeToFile(); status_t writeToFile(); Loading
services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +4 −2 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "FakePhaseOffsets.h" #include "FakePhaseOffsets.h" #include "Layer.h" #include "Layer.h" #include "NativeWindowSurface.h" #include "NativeWindowSurface.h" #include "Scheduler/MessageQueue.h" #include "StartPropertySetThread.h" #include "StartPropertySetThread.h" #include "SurfaceFlinger.h" #include "SurfaceFlinger.h" #include "SurfaceFlingerFactory.h" #include "SurfaceFlingerFactory.h" Loading Loading @@ -276,8 +277,9 @@ public: auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); } auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); } auto captureScreenImplLocked(const RenderArea& renderArea, auto captureScreenImplLocked(const RenderArea& renderArea, TraverseLayersFunction traverseLayers, ANativeWindowBuffer* buffer, SurfaceFlinger::TraverseLayersFunction traverseLayers, bool useIdentityTransform, bool forSystem, int* outSyncFd) { ANativeWindowBuffer* buffer, bool useIdentityTransform, bool forSystem, int* outSyncFd) { return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer, return mFlinger->captureScreenImplLocked(renderArea, traverseLayers, buffer, useIdentityTransform, forSystem, outSyncFd); useIdentityTransform, forSystem, outSyncFd); } } Loading