diff options
Diffstat (limited to 'services/surfaceflinger/RegionSamplingThread.h')
-rw-r--r-- | services/surfaceflinger/RegionSamplingThread.h | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/services/surfaceflinger/RegionSamplingThread.h b/services/surfaceflinger/RegionSamplingThread.h index 2231853fcb..b9b7a3c436 100644 --- a/services/surfaceflinger/RegionSamplingThread.h +++ b/services/surfaceflinger/RegionSamplingThread.h @@ -16,19 +16,17 @@ #pragma once -#include <android-base/thread_annotations.h> -#include <binder/IBinder.h> -#include <renderengine/ExternalTexture.h> -#include <ui/GraphicBuffer.h> -#include <ui/Rect.h> -#include <utils/StrongPointer.h> - #include <chrono> #include <condition_variable> #include <mutex> #include <thread> #include <unordered_map> +#include <android-base/thread_annotations.h> +#include <binder/IBinder.h> +#include <ui/GraphicBuffer.h> +#include <ui/Rect.h> +#include <utils/StrongPointer.h> #include "Scheduler/OneShotTimer.h" namespace android { @@ -45,10 +43,10 @@ float sampleArea(const uint32_t* data, int32_t width, int32_t height, int32_t st class RegionSamplingThread : public IBinder::DeathRecipient { public: struct TimingTunables { - // debug.sf.sampling_duration_ns - // When asynchronously collecting sample, the duration, at which the sampling should start - // before a vsync - std::chrono::nanoseconds mSamplingDuration; + // debug.sf.sampling_offset_ns + // When asynchronously collecting sample, the offset, from zero phase in the vsync timeline + // at which the sampling should start. + std::chrono::nanoseconds mSamplingOffset; // debug.sf.sampling_period_ns // This is the maximum amount of time the luma recieving client // should have to wait for a new luma value after a frame is updated. The inverse of this is @@ -63,8 +61,9 @@ public: struct EnvironmentTimingTunables : TimingTunables { EnvironmentTimingTunables(); }; - explicit RegionSamplingThread(SurfaceFlinger& flinger, const TimingTunables& tunables); - explicit RegionSamplingThread(SurfaceFlinger& flinger); + explicit RegionSamplingThread(SurfaceFlinger& flinger, Scheduler& scheduler, + const TimingTunables& tunables); + explicit RegionSamplingThread(SurfaceFlinger& flinger, Scheduler& scheduler); ~RegionSamplingThread(); @@ -75,11 +74,12 @@ public: // Remove the listener to stop receiving median luma notifications. void removeListener(const sp<IRegionSamplingListener>& listener); - // 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<std::chrono::steady_clock::time_point> samplingDeadline); + // 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(); private: struct Descriptor { @@ -97,7 +97,7 @@ private: const sp<GraphicBuffer>& buffer, const Point& leftTop, const std::vector<RegionSamplingThread::Descriptor>& descriptors, uint32_t orientation); - void doSample(std::optional<std::chrono::steady_clock::time_point> samplingDeadline); + void doSample(); void binderDied(const wp<IBinder>& who) override; void checkForStaleLuma(); @@ -105,23 +105,24 @@ private: void threadMain(); SurfaceFlinger& mFlinger; + Scheduler& mScheduler; const TimingTunables mTunables; scheduler::OneShotTimer mIdleTimer; + std::unique_ptr<SamplingOffsetCallback> 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; - std::optional<std::chrono::steady_clock::time_point> mSampleRequestTime - GUARDED_BY(mThreadControlMutex); - std::chrono::steady_clock::time_point mLastSampleTime GUARDED_BY(mThreadControlMutex); + uint32_t mDiscardedFrames GUARDED_BY(mThreadControlMutex) = 0; + std::chrono::nanoseconds lastSampleTime GUARDED_BY(mThreadControlMutex); std::mutex mSamplingMutex; std::unordered_map<wp<IBinder>, Descriptor, WpHash> mDescriptors GUARDED_BY(mSamplingMutex); - std::shared_ptr<renderengine::ExternalTexture> mCachedBuffer GUARDED_BY(mSamplingMutex) = - nullptr; + sp<GraphicBuffer> mCachedBuffer GUARDED_BY(mSamplingMutex) = nullptr; }; } // namespace android |