summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/Scheduler/Scheduler.h
diff options
context:
space:
mode:
Diffstat (limited to 'services/surfaceflinger/Scheduler/Scheduler.h')
-rw-r--r--services/surfaceflinger/Scheduler/Scheduler.h192
1 files changed, 74 insertions, 118 deletions
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 30a32537ad..730ea8f0c8 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -26,10 +26,10 @@
// TODO(b/129481165): remove the #pragma below and fix conversion issues
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
-#pragma clang diagnostic ignored "-Wextra"
#include <ui/GraphicTypes.h>
-#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
+#pragma clang diagnostic pop
+#include "EventControlThread.h"
#include "EventThread.h"
#include "LayerHistory.h"
#include "OneShotTimer.h"
@@ -41,72 +41,76 @@ namespace android {
using namespace std::chrono_literals;
using scheduler::LayerHistory;
+class DispSync;
class FenceTime;
class InjectVSyncSource;
-class PredictedVsyncTracer;
+struct DisplayStateInfo;
-namespace scheduler {
-class VsyncController;
-class VSyncDispatch;
-class VSyncTracker;
-} // namespace scheduler
-
-namespace frametimeline {
-class TokenManager;
-} // namespace frametimeline
-
-struct ISchedulerCallback {
- virtual void setVsyncEnabled(bool) = 0;
+class ISchedulerCallback {
+public:
+ virtual ~ISchedulerCallback() = default;
virtual void changeRefreshRate(const scheduler::RefreshRateConfigs::RefreshRate&,
scheduler::RefreshRateConfigEvent) = 0;
virtual void repaintEverythingForHWC() = 0;
virtual void kernelTimerChanged(bool expired) = 0;
- virtual void triggerOnFrameRateOverridesChanged() = 0;
+};
-protected:
- ~ISchedulerCallback() = default;
+class IPhaseOffsetControl {
+public:
+ virtual ~IPhaseOffsetControl() = default;
+ virtual void setPhaseOffset(scheduler::ConnectionHandle, nsecs_t phaseOffset) = 0;
};
-class Scheduler {
+class Scheduler : public IPhaseOffsetControl {
public:
using RefreshRate = scheduler::RefreshRateConfigs::RefreshRate;
- using ModeEvent = scheduler::RefreshRateConfigEvent;
+ using ConfigEvent = scheduler::RefreshRateConfigEvent;
+
+ // Indicates whether to start the transaction early, or at vsync time.
+ enum class TransactionStart {
+ Early, // DEPRECATED. Start the transaction early. Times out on its own
+ EarlyStart, // Start the transaction early and keep this config until EarlyEnd
+ EarlyEnd, // End the early config started at EarlyStart
+ Normal // Start the transaction at the normal time
+ };
+
+ Scheduler(impl::EventControlThread::SetVSyncEnabledFunction,
+ const scheduler::RefreshRateConfigs&, ISchedulerCallback& schedulerCallback,
+ bool useContentDetectionV2, bool useContentDetection);
- Scheduler(const scheduler::RefreshRateConfigs&, ISchedulerCallback&);
- ~Scheduler();
+ virtual ~Scheduler();
+
+ DispSync& getPrimaryDispSync();
using ConnectionHandle = scheduler::ConnectionHandle;
- ConnectionHandle createConnection(const char* connectionName, frametimeline::TokenManager*,
- std::chrono::nanoseconds workDuration,
- std::chrono::nanoseconds readyDuration,
+ ConnectionHandle createConnection(const char* connectionName, nsecs_t phaseOffsetNs,
impl::EventThread::InterceptVSyncsCallback);
- sp<IDisplayEventConnection> createDisplayEventConnection(
- ConnectionHandle, ISurfaceComposer::EventRegistrationFlags eventRegistration = {});
+ sp<IDisplayEventConnection> createDisplayEventConnection(ConnectionHandle,
+ ISurfaceComposer::ConfigChanged);
sp<EventThreadConnection> getEventConnection(ConnectionHandle);
void onHotplugReceived(ConnectionHandle, PhysicalDisplayId, bool connected);
- void onPrimaryDisplayModeChanged(ConnectionHandle, PhysicalDisplayId, DisplayModeId,
- nsecs_t vsyncPeriod) EXCLUDES(mFeatureStateLock);
- void onNonPrimaryDisplayModeChanged(ConnectionHandle, PhysicalDisplayId, DisplayModeId,
- nsecs_t vsyncPeriod);
+ void onPrimaryDisplayConfigChanged(ConnectionHandle, PhysicalDisplayId,
+ HwcConfigIndexType configId, nsecs_t vsyncPeriod)
+ EXCLUDES(mFeatureStateLock);
+ void onNonPrimaryDisplayConfigChanged(ConnectionHandle, PhysicalDisplayId,
+ HwcConfigIndexType configId, nsecs_t vsyncPeriod);
void onScreenAcquired(ConnectionHandle);
void onScreenReleased(ConnectionHandle);
- void onFrameRateOverridesChanged(ConnectionHandle, PhysicalDisplayId)
- EXCLUDES(mFrameRateOverridesMutex) EXCLUDES(mConnectionsLock);
-
- // Modifies work duration in the event thread.
- void setDuration(ConnectionHandle, std::chrono::nanoseconds workDuration,
- std::chrono::nanoseconds readyDuration);
+ // Modifies phase offset in the event thread.
+ void setPhaseOffset(ConnectionHandle, nsecs_t phaseOffset) override;
- DisplayStatInfo getDisplayStatInfo(nsecs_t now);
+ void getDisplayStatInfo(DisplayStatInfo* stats);
// Returns injector handle if injection has toggled, or an invalid handle otherwise.
ConnectionHandle enableVSyncInjection(bool enable);
+
// Returns false if injection is disabled.
- bool injectVSync(nsecs_t when, nsecs_t expectedVSyncTime, nsecs_t deadlineTimestamp);
+ bool injectVSync(nsecs_t when, nsecs_t expectedVSyncTime);
+
void enableHardwareVsync();
void disableHardwareVsync(bool makeUnavailable);
@@ -118,18 +122,18 @@ public:
void resyncToHardwareVsync(bool makeAvailable, nsecs_t period);
void resync();
- // Passes a vsync sample to VsyncController. periodFlushed will be true if
- // VsyncController detected that the vsync period changed, and false otherwise.
+ // Passes a vsync sample to DispSync. periodFlushed will be true if
+ // DispSync detected that the vsync period changed, and false otherwise.
void addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwcVsyncPeriod,
bool* periodFlushed);
void addPresentFence(const std::shared_ptr<FenceTime>&);
void setIgnorePresentFences(bool ignore);
+ nsecs_t getDispSyncExpectedPresentTime(nsecs_t now);
// Layers are registered on creation, and unregistered when the weak reference expires.
void registerLayer(Layer*);
void recordLayerHistory(Layer*, nsecs_t presentTime, LayerHistory::LayerUpdateType updateType);
- void setModeChangePending(bool pending);
- void deregisterLayer(Layer*);
+ void setConfigChangePending(bool pending);
// Detects content using layer history, and selects a matching refresh rate.
void chooseRefreshRateForContent();
@@ -142,21 +146,11 @@ public:
void setDisplayPowerState(bool normal);
- scheduler::VSyncDispatch& getVsyncDispatch() { return *mVsyncSchedule.dispatch; }
-
- // Returns true if a given vsync timestamp is considered valid vsync
- // for a given uid
- bool isVsyncValid(nsecs_t expectedVsyncTimestamp, uid_t uid) const
- EXCLUDES(mFrameRateOverridesMutex);
-
- std::chrono::steady_clock::time_point getPreviousVsyncFrom(nsecs_t expectedPresentTime) const;
-
void dump(std::string&) const;
void dump(ConnectionHandle, std::string&) const;
- void dumpVsync(std::string&) const;
// Get the appropriate refresh for current conditions.
- std::optional<DisplayModeId> getPreferredModeId();
+ std::optional<HwcConfigIndexType> getPreferredConfigId();
// Notifies the scheduler about a refresh rate timeline change.
void onNewVsyncPeriodChangeTimeline(const hal::VsyncPeriodChangeTimeline& timeline);
@@ -169,17 +163,6 @@ public:
size_t getEventThreadConnectionCount(ConnectionHandle handle);
- std::unique_ptr<VSyncSource> makePrimaryDispSyncSource(const char* name,
- std::chrono::nanoseconds workDuration,
- std::chrono::nanoseconds readyDuration,
- bool traceVsync = true);
-
- // Stores the preferred refresh rate that an app should run at.
- // FrameRateOverride.refreshRateHz == 0 means no preference.
- void setPreferredRefreshRateForUid(FrameRateOverride) EXCLUDES(mFrameRateOverridesMutex);
- // Retrieves the overridden refresh rate for a given uid.
- std::optional<Fps> getFrameRateOverride(uid_t uid) const EXCLUDES(mFrameRateOverridesMutex);
-
private:
friend class TestableScheduler;
@@ -189,33 +172,17 @@ private:
enum class TimerState { Reset, Expired };
enum class TouchState { Inactive, Active };
- struct Options {
- // Whether to use idle timer callbacks that support the kernel timer.
- bool supportKernelTimer;
- // Whether to use content detection at all.
- bool useContentDetection;
- };
-
- struct VsyncSchedule {
- std::unique_ptr<scheduler::VsyncController> controller;
- std::unique_ptr<scheduler::VSyncTracker> tracker;
- std::unique_ptr<scheduler::VSyncDispatch> dispatch;
- };
-
- // Unlike the testing constructor, this creates the VsyncSchedule, LayerHistory, and timers.
- Scheduler(const scheduler::RefreshRateConfigs&, ISchedulerCallback&, Options);
-
// Used by tests to inject mocks.
- Scheduler(VsyncSchedule, const scheduler::RefreshRateConfigs&, ISchedulerCallback&,
- std::unique_ptr<LayerHistory>, Options);
+ Scheduler(std::unique_ptr<DispSync>, std::unique_ptr<EventControlThread>,
+ const scheduler::RefreshRateConfigs&, ISchedulerCallback& schedulerCallback,
+ bool useContentDetectionV2, bool useContentDetection);
- static VsyncSchedule createVsyncSchedule(bool supportKernelIdleTimer);
- static std::unique_ptr<LayerHistory> createLayerHistory(const scheduler::RefreshRateConfigs&);
+ std::unique_ptr<VSyncSource> makePrimaryDispSyncSource(const char* name, nsecs_t phaseOffsetNs);
// Create a connection on the given EventThread.
ConnectionHandle createConnection(std::unique_ptr<EventThread>);
- sp<EventThreadConnection> createConnectionInternal(
- EventThread*, ISurfaceComposer::EventRegistrationFlags eventRegistration = {});
+ sp<EventThreadConnection> createConnectionInternal(EventThread*,
+ ISurfaceComposer::ConfigChanged);
// Update feature state machine to given state when corresponding timer resets or expires.
void kernelIdleTimerCallback(TimerState);
@@ -230,19 +197,13 @@ private:
void setVsyncPeriod(nsecs_t period);
// This function checks whether individual features that are affecting the refresh rate
- // selection were initialized, prioritizes them, and calculates the DisplayModeId
+ // selection were initialized, prioritizes them, and calculates the HwcConfigIndexType
// for the suggested refresh rate.
- DisplayModeId calculateRefreshRateModeId(
+ HwcConfigIndexType calculateRefreshRateConfigIndexType(
scheduler::RefreshRateConfigs::GlobalSignals* consideredSignals = nullptr)
REQUIRES(mFeatureStateLock);
- void dispatchCachedReportedMode() REQUIRES(mFeatureStateLock);
- bool updateFrameRateOverrides(scheduler::RefreshRateConfigs::GlobalSignals consideredSignals,
- Fps displayRefreshRate) REQUIRES(mFeatureStateLock)
- EXCLUDES(mFrameRateOverridesMutex);
-
- impl::EventThread::ThrottleVsyncCallback makeThrottleVsyncCallback() const;
- impl::EventThread::GetVsyncPeriodFunction makeGetVsyncPeriodFunction() const;
+ void dispatchCachedReportedConfig() REQUIRES(mFeatureStateLock);
// Stores EventThread associated with a given VSyncSource, and an initial EventThreadConnection.
struct Connection {
@@ -251,8 +212,7 @@ private:
};
ConnectionHandle::Id mNextConnectionHandleId = 0;
- mutable std::mutex mConnectionsLock;
- std::unordered_map<ConnectionHandle, Connection> mConnections GUARDED_BY(mConnectionsLock);
+ std::unordered_map<ConnectionHandle, Connection> mConnections;
bool mInjectVSyncs = false;
InjectVSyncSource* mVSyncInjector = nullptr;
@@ -264,8 +224,11 @@ private:
std::atomic<nsecs_t> mLastResyncTime = 0;
- const Options mOptions;
- VsyncSchedule mVsyncSchedule;
+ // Whether to use idle timer callbacks that support the kernel timer.
+ const bool mSupportKernelTimer;
+
+ std::unique_ptr<DispSync> mPrimaryDispSync;
+ std::unique_ptr<EventControlThread> mEventControlThread;
// Used to choose refresh rate if content detection is enabled.
std::unique_ptr<LayerHistory> mLayerHistory;
@@ -281,27 +244,28 @@ private:
// In order to make sure that the features don't override themselves, we need a state machine
// to keep track which feature requested the config change.
- mutable std::mutex mFeatureStateLock;
+ std::mutex mFeatureStateLock;
struct {
+ ContentDetectionState contentDetectionV1 = ContentDetectionState::Off;
TimerState idleTimer = TimerState::Reset;
TouchState touch = TouchState::Inactive;
TimerState displayPowerTimer = TimerState::Expired;
- std::optional<DisplayModeId> modeId;
+ std::optional<HwcConfigIndexType> configId;
LayerHistory::Summary contentRequirements;
bool isDisplayPowerStateNormal = true;
- // Used to cache the last parameters of onPrimaryDisplayModeChanged
- struct ModeChangedParams {
+ // Used to cache the last parameters of onPrimaryDisplayConfigChanged
+ struct ConfigChangedParams {
ConnectionHandle handle;
PhysicalDisplayId displayId;
- DisplayModeId modeId;
+ HwcConfigIndexType configId;
nsecs_t vsyncPeriod;
};
- std::optional<ModeChangedParams> cachedModeChangedParams;
+ std::optional<ConfigChangedParams> cachedConfigChangedParams;
} mFeatures GUARDED_BY(mFeatureStateLock);
const scheduler::RefreshRateConfigs& mRefreshRateConfigs;
@@ -311,18 +275,10 @@ private:
GUARDED_BY(mVsyncTimelineLock);
static constexpr std::chrono::nanoseconds MAX_VSYNC_APPLIED_TIME = 200ms;
- const std::unique_ptr<PredictedVsyncTracer> mPredictedVsyncTracer;
-
- // The frame rate override lists need their own mutex as they are being read
- // by SurfaceFlinger, Scheduler and EventThread (as a callback) to prevent deadlocks
- mutable std::mutex mFrameRateOverridesMutex;
-
- // mappings between a UID and a preferred refresh rate that this app would
- // run at.
- scheduler::RefreshRateConfigs::UidToFrameRateOverride mFrameRateOverridesByContent
- GUARDED_BY(mFrameRateOverridesMutex);
- scheduler::RefreshRateConfigs::UidToFrameRateOverride mFrameRateOverridesFromBackdoor
- GUARDED_BY(mFrameRateOverridesMutex);
+ // This variable indicates whether to use the content detection feature at all.
+ const bool mUseContentDetection;
+ // This variable indicates whether to use V2 version of the content detection.
+ const bool mUseContentDetectionV2;
};
} // namespace android