From 562c2718fcf8f465fe54a88c7ac948cd21a77ce5 Mon Sep 17 00:00:00 2001 From: Ady Abraham Date: Fri, 7 May 2021 15:10:42 -0700 Subject: SF: region sampling scheduling optimization Schedule the region sampling thread more wisely by estimating when the next invalidate is going to happen. This makes the region sampling to be scheduled often at times where the main thread is idle, without eating the budget in an invalidate message. Bug: 181983990 Test: SF unit tests Test: observe systrace Change-Id: I1faca3aa7f882ed7c69e77e6a0877c10d57f0f1c --- services/surfaceflinger/RegionSamplingThread.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'services/surfaceflinger/RegionSamplingThread.h') diff --git a/services/surfaceflinger/RegionSamplingThread.h b/services/surfaceflinger/RegionSamplingThread.h index 86632db490..2231853fcb 100644 --- a/services/surfaceflinger/RegionSamplingThread.h +++ b/services/surfaceflinger/RegionSamplingThread.h @@ -63,9 +63,8 @@ public: struct EnvironmentTimingTunables : TimingTunables { EnvironmentTimingTunables(); }; - explicit RegionSamplingThread(SurfaceFlinger& flinger, Scheduler& scheduler, - const TimingTunables& tunables); - explicit RegionSamplingThread(SurfaceFlinger& flinger, Scheduler& scheduler); + explicit RegionSamplingThread(SurfaceFlinger& flinger, const TimingTunables& tunables); + explicit RegionSamplingThread(SurfaceFlinger& flinger); ~RegionSamplingThread(); @@ -76,12 +75,11 @@ public: // Remove the listener to stop receiving median luma notifications. void removeListener(const sp& listener); - // Notifies sampling engine that new content is available. This will trigger a sampling - // pass at some point in the future. - void notifyNewContent(); - - // Notifies the sampling engine that it has a good timing window in which to sample. - void notifySamplingOffset(); + // Notifies sampling engine that composition is done and new content is + // available, and the deadline for the sampling work on the main thread to + // be completed without eating the budget of another frame. + void onCompositionComplete( + std::optional samplingDeadline); private: struct Descriptor { @@ -99,7 +97,7 @@ private: const sp& buffer, const Point& leftTop, const std::vector& descriptors, uint32_t orientation); - void doSample(); + void doSample(std::optional samplingDeadline); void binderDied(const wp& who) override; void checkForStaleLuma(); @@ -107,20 +105,18 @@ private: void threadMain(); SurfaceFlinger& mFlinger; - Scheduler& mScheduler; const TimingTunables mTunables; scheduler::OneShotTimer mIdleTimer; - std::unique_ptr const mPhaseCallback; - std::thread mThread; std::mutex mThreadControlMutex; std::condition_variable_any mCondition; bool mRunning GUARDED_BY(mThreadControlMutex) = true; bool mSampleRequested GUARDED_BY(mThreadControlMutex) = false; - uint32_t mDiscardedFrames GUARDED_BY(mThreadControlMutex) = 0; - std::chrono::nanoseconds lastSampleTime GUARDED_BY(mThreadControlMutex); + std::optional mSampleRequestTime + GUARDED_BY(mThreadControlMutex); + std::chrono::steady_clock::time_point mLastSampleTime GUARDED_BY(mThreadControlMutex); std::mutex mSamplingMutex; std::unordered_map, Descriptor, WpHash> mDescriptors GUARDED_BY(mSamplingMutex); -- cgit v1.2.3-59-g8ed1b