Loading libs/ui/include/ui/FenceTime.h +4 −12 Original line number Diff line number Diff line Loading @@ -142,8 +142,6 @@ private: std::atomic<nsecs_t> mSignalTime{Fence::SIGNAL_TIME_INVALID}; }; using FenceTimePtr = std::shared_ptr<FenceTime>; // A queue of FenceTimes that are expected to signal in FIFO order. // Only maintains a queue of weak pointers so it doesn't keep references // to Fences on its own. Loading Loading @@ -192,15 +190,8 @@ private: // before the new one is added. class FenceToFenceTimeMap { public: using FencePair = std::pair<sp<Fence>, FenceTimePtr>; FencePair makePendingFenceForTest() { const auto fence = sp<Fence>::make(); return {fence, createFenceTimeForTest(fence)}; } // Create a new FenceTime that wraps the provided Fence. FenceTimePtr createFenceTimeForTest(const sp<Fence>&); // Create a new FenceTime with that wraps the provided Fence. std::shared_ptr<FenceTime> createFenceTimeForTest(const sp<Fence>& fence); // Signals all FenceTimes created through this class that are wrappers // around |fence|. Loading @@ -214,6 +205,7 @@ private: std::unordered_map<Fence*, std::vector<std::weak_ptr<FenceTime>>> mMap; }; } // namespace android }; // namespace android #endif // ANDROID_FENCE_TIME_H services/surfaceflinger/Scheduler/Android.bp +0 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ cc_library_static { name: "libscheduler", defaults: ["libscheduler_defaults"], srcs: [ "src/FrameTargeter.cpp", "src/PresentLatencyTracker.cpp", "src/Timer.cpp", ], Loading @@ -53,7 +52,6 @@ cc_test { test_suites: ["device-tests"], defaults: ["libscheduler_defaults"], srcs: [ "tests/FrameTargeterTest.cpp", "tests/PresentLatencyTrackerTest.cpp", "tests/TimerTest.cpp", ], Loading services/surfaceflinger/Scheduler/Scheduler.cpp +10 −19 Original line number Diff line number Diff line Loading @@ -171,21 +171,14 @@ void Scheduler::run() { void Scheduler::onFrameSignal(ICompositor& compositor, VsyncId vsyncId, TimePoint expectedVsyncTime) { mPacesetterFrameTargeter.beginFrame({.frameBeginTime = SchedulerClock::now(), .vsyncId = vsyncId, .expectedVsyncTime = expectedVsyncTime, .sfWorkDuration = mVsyncModulator->getVsyncConfig().sfWorkDuration}, *getVsyncSchedule()); if (!compositor.commit(mPacesetterFrameTargeter.target())) { const TimePoint frameTime = SchedulerClock::now(); if (!compositor.commit(frameTime, vsyncId, expectedVsyncTime)) { return; } const auto compositeResult = compositor.composite(mPacesetterFrameTargeter); compositor.composite(frameTime, vsyncId); compositor.sample(); mPacesetterFrameTargeter.endFrame(compositeResult); } std::optional<Fps> Scheduler::getFrameRateOverride(uid_t uid) const { Loading @@ -195,23 +188,23 @@ std::optional<Fps> Scheduler::getFrameRateOverride(uid_t uid) const { .getFrameRateOverrideForUid(uid, supportsFrameRateOverrideByContent); } bool Scheduler::isVsyncValid(TimePoint expectedVsyncTime, uid_t uid) const { bool Scheduler::isVsyncValid(TimePoint expectedVsyncTimestamp, uid_t uid) const { const auto frameRate = getFrameRateOverride(uid); if (!frameRate.has_value()) { return true; } ATRACE_FORMAT("%s uid: %d frameRate: %s", __func__, uid, to_string(*frameRate).c_str()); return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTime.ns(), *frameRate); return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTimestamp.ns(), *frameRate); } bool Scheduler::isVsyncInPhase(TimePoint expectedVsyncTime, Fps frameRate) const { return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTime.ns(), frameRate); bool Scheduler::isVsyncInPhase(TimePoint timePoint, const Fps frameRate) const { return getVsyncSchedule()->getTracker().isVSyncInPhase(timePoint.ns(), frameRate); } impl::EventThread::ThrottleVsyncCallback Scheduler::makeThrottleVsyncCallback() const { return [this](nsecs_t expectedVsyncTime, uid_t uid) { return !isVsyncValid(TimePoint::fromNs(expectedVsyncTime), uid); return [this](nsecs_t expectedVsyncTimestamp, uid_t uid) { return !isVsyncValid(TimePoint::fromNs(expectedVsyncTimestamp), uid); }; } Loading Loading @@ -723,8 +716,6 @@ void Scheduler::dump(utils::Dumper& dumper) const { mFrameRateOverrideMappings.dump(dumper); dumper.eol(); mPacesetterFrameTargeter.dump(dumper); } void Scheduler::dumpVsync(std::string& out) const { Loading services/surfaceflinger/Scheduler/Scheduler.h +1 −6 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ #include <ftl/fake_guard.h> #include <ftl/optional.h> #include <scheduler/Features.h> #include <scheduler/FrameTargeter.h> #include <scheduler/Time.h> #include <scheduler/VsyncConfig.h> #include <ui/DisplayId.h> Loading Loading @@ -250,11 +249,9 @@ public: return std::const_pointer_cast<VsyncSchedule>(std::as_const(*this).getVsyncSchedule(idOpt)); } const FrameTarget& pacesetterFrameTarget() { return mPacesetterFrameTargeter.target(); } // Returns true if a given vsync timestamp is considered valid vsync // for a given uid bool isVsyncValid(TimePoint expectedVsyncTime, uid_t uid) const; bool isVsyncValid(TimePoint expectedVsyncTimestamp, uid_t uid) const; bool isVsyncInPhase(TimePoint expectedVsyncTime, Fps frameRate) const; Loading Loading @@ -449,8 +446,6 @@ private: ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); FrameTargeter mPacesetterFrameTargeter{mFeatures.test(Feature::kBackpressureGpuComposition)}; ftl::Optional<DisplayRef> pacesetterDisplayLocked() REQUIRES(mDisplayLock) { return static_cast<const Scheduler*>(this)->pacesetterDisplayLocked().transform( [](const Display& display) { return std::ref(const_cast<Display&>(display)); }); Loading services/surfaceflinger/Scheduler/VsyncSchedule.h +5 −9 Original line number Diff line number Diff line Loading @@ -20,16 +20,13 @@ #include <memory> #include <string> #include <ThreadContext.h> #include <android-base/thread_annotations.h> #include <ftl/enum.h> #include <ftl/optional.h> #include <ui/DisplayId.h> #include <scheduler/Features.h> #include <scheduler/IVsyncSource.h> #include <scheduler/Time.h> #include "ThreadContext.h" #include <ui/DisplayId.h> namespace android { class EventThreadTest; Loading @@ -51,16 +48,15 @@ using VsyncDispatch = VSyncDispatch; using VsyncTracker = VSyncTracker; // Schedule that synchronizes to hardware VSYNC of a physical display. class VsyncSchedule final : public IVsyncSource { class VsyncSchedule { public: using RequestHardwareVsync = std::function<void(PhysicalDisplayId, bool enabled)>; VsyncSchedule(PhysicalDisplayId, FeatureFlags, RequestHardwareVsync); ~VsyncSchedule(); // IVsyncSource overrides: Period period() const override; TimePoint vsyncDeadlineAfter(TimePoint) const override; Period period() const; TimePoint vsyncDeadlineAfter(TimePoint) const; // Inform the schedule that the period is changing and the schedule needs to recalibrate // itself. The schedule will end the period transition internally. This will Loading Loading
libs/ui/include/ui/FenceTime.h +4 −12 Original line number Diff line number Diff line Loading @@ -142,8 +142,6 @@ private: std::atomic<nsecs_t> mSignalTime{Fence::SIGNAL_TIME_INVALID}; }; using FenceTimePtr = std::shared_ptr<FenceTime>; // A queue of FenceTimes that are expected to signal in FIFO order. // Only maintains a queue of weak pointers so it doesn't keep references // to Fences on its own. Loading Loading @@ -192,15 +190,8 @@ private: // before the new one is added. class FenceToFenceTimeMap { public: using FencePair = std::pair<sp<Fence>, FenceTimePtr>; FencePair makePendingFenceForTest() { const auto fence = sp<Fence>::make(); return {fence, createFenceTimeForTest(fence)}; } // Create a new FenceTime that wraps the provided Fence. FenceTimePtr createFenceTimeForTest(const sp<Fence>&); // Create a new FenceTime with that wraps the provided Fence. std::shared_ptr<FenceTime> createFenceTimeForTest(const sp<Fence>& fence); // Signals all FenceTimes created through this class that are wrappers // around |fence|. Loading @@ -214,6 +205,7 @@ private: std::unordered_map<Fence*, std::vector<std::weak_ptr<FenceTime>>> mMap; }; } // namespace android }; // namespace android #endif // ANDROID_FENCE_TIME_H
services/surfaceflinger/Scheduler/Android.bp +0 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ cc_library_static { name: "libscheduler", defaults: ["libscheduler_defaults"], srcs: [ "src/FrameTargeter.cpp", "src/PresentLatencyTracker.cpp", "src/Timer.cpp", ], Loading @@ -53,7 +52,6 @@ cc_test { test_suites: ["device-tests"], defaults: ["libscheduler_defaults"], srcs: [ "tests/FrameTargeterTest.cpp", "tests/PresentLatencyTrackerTest.cpp", "tests/TimerTest.cpp", ], Loading
services/surfaceflinger/Scheduler/Scheduler.cpp +10 −19 Original line number Diff line number Diff line Loading @@ -171,21 +171,14 @@ void Scheduler::run() { void Scheduler::onFrameSignal(ICompositor& compositor, VsyncId vsyncId, TimePoint expectedVsyncTime) { mPacesetterFrameTargeter.beginFrame({.frameBeginTime = SchedulerClock::now(), .vsyncId = vsyncId, .expectedVsyncTime = expectedVsyncTime, .sfWorkDuration = mVsyncModulator->getVsyncConfig().sfWorkDuration}, *getVsyncSchedule()); if (!compositor.commit(mPacesetterFrameTargeter.target())) { const TimePoint frameTime = SchedulerClock::now(); if (!compositor.commit(frameTime, vsyncId, expectedVsyncTime)) { return; } const auto compositeResult = compositor.composite(mPacesetterFrameTargeter); compositor.composite(frameTime, vsyncId); compositor.sample(); mPacesetterFrameTargeter.endFrame(compositeResult); } std::optional<Fps> Scheduler::getFrameRateOverride(uid_t uid) const { Loading @@ -195,23 +188,23 @@ std::optional<Fps> Scheduler::getFrameRateOverride(uid_t uid) const { .getFrameRateOverrideForUid(uid, supportsFrameRateOverrideByContent); } bool Scheduler::isVsyncValid(TimePoint expectedVsyncTime, uid_t uid) const { bool Scheduler::isVsyncValid(TimePoint expectedVsyncTimestamp, uid_t uid) const { const auto frameRate = getFrameRateOverride(uid); if (!frameRate.has_value()) { return true; } ATRACE_FORMAT("%s uid: %d frameRate: %s", __func__, uid, to_string(*frameRate).c_str()); return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTime.ns(), *frameRate); return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTimestamp.ns(), *frameRate); } bool Scheduler::isVsyncInPhase(TimePoint expectedVsyncTime, Fps frameRate) const { return getVsyncSchedule()->getTracker().isVSyncInPhase(expectedVsyncTime.ns(), frameRate); bool Scheduler::isVsyncInPhase(TimePoint timePoint, const Fps frameRate) const { return getVsyncSchedule()->getTracker().isVSyncInPhase(timePoint.ns(), frameRate); } impl::EventThread::ThrottleVsyncCallback Scheduler::makeThrottleVsyncCallback() const { return [this](nsecs_t expectedVsyncTime, uid_t uid) { return !isVsyncValid(TimePoint::fromNs(expectedVsyncTime), uid); return [this](nsecs_t expectedVsyncTimestamp, uid_t uid) { return !isVsyncValid(TimePoint::fromNs(expectedVsyncTimestamp), uid); }; } Loading Loading @@ -723,8 +716,6 @@ void Scheduler::dump(utils::Dumper& dumper) const { mFrameRateOverrideMappings.dump(dumper); dumper.eol(); mPacesetterFrameTargeter.dump(dumper); } void Scheduler::dumpVsync(std::string& out) const { Loading
services/surfaceflinger/Scheduler/Scheduler.h +1 −6 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ #include <ftl/fake_guard.h> #include <ftl/optional.h> #include <scheduler/Features.h> #include <scheduler/FrameTargeter.h> #include <scheduler/Time.h> #include <scheduler/VsyncConfig.h> #include <ui/DisplayId.h> Loading Loading @@ -250,11 +249,9 @@ public: return std::const_pointer_cast<VsyncSchedule>(std::as_const(*this).getVsyncSchedule(idOpt)); } const FrameTarget& pacesetterFrameTarget() { return mPacesetterFrameTargeter.target(); } // Returns true if a given vsync timestamp is considered valid vsync // for a given uid bool isVsyncValid(TimePoint expectedVsyncTime, uid_t uid) const; bool isVsyncValid(TimePoint expectedVsyncTimestamp, uid_t uid) const; bool isVsyncInPhase(TimePoint expectedVsyncTime, Fps frameRate) const; Loading Loading @@ -449,8 +446,6 @@ private: ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); FrameTargeter mPacesetterFrameTargeter{mFeatures.test(Feature::kBackpressureGpuComposition)}; ftl::Optional<DisplayRef> pacesetterDisplayLocked() REQUIRES(mDisplayLock) { return static_cast<const Scheduler*>(this)->pacesetterDisplayLocked().transform( [](const Display& display) { return std::ref(const_cast<Display&>(display)); }); Loading
services/surfaceflinger/Scheduler/VsyncSchedule.h +5 −9 Original line number Diff line number Diff line Loading @@ -20,16 +20,13 @@ #include <memory> #include <string> #include <ThreadContext.h> #include <android-base/thread_annotations.h> #include <ftl/enum.h> #include <ftl/optional.h> #include <ui/DisplayId.h> #include <scheduler/Features.h> #include <scheduler/IVsyncSource.h> #include <scheduler/Time.h> #include "ThreadContext.h" #include <ui/DisplayId.h> namespace android { class EventThreadTest; Loading @@ -51,16 +48,15 @@ using VsyncDispatch = VSyncDispatch; using VsyncTracker = VSyncTracker; // Schedule that synchronizes to hardware VSYNC of a physical display. class VsyncSchedule final : public IVsyncSource { class VsyncSchedule { public: using RequestHardwareVsync = std::function<void(PhysicalDisplayId, bool enabled)>; VsyncSchedule(PhysicalDisplayId, FeatureFlags, RequestHardwareVsync); ~VsyncSchedule(); // IVsyncSource overrides: Period period() const override; TimePoint vsyncDeadlineAfter(TimePoint) const override; Period period() const; TimePoint vsyncDeadlineAfter(TimePoint) const; // Inform the schedule that the period is changing and the schedule needs to recalibrate // itself. The schedule will end the period transition internally. This will Loading