!14759 VSyncGenerator maxTE改为函数形参

Merge pull request !14759 from hsc/master
This commit is contained in:
openharmony_ci 2024-09-11 04:17:13 +00:00 committed by Gitee
commit 2338f1a54a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 48 additions and 36 deletions

View File

@ -29,7 +29,8 @@ class VSyncController : public VSyncGenerator::Callback {
public:
class Callback {
public:
virtual void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode) = 0;
virtual void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) = 0;
virtual ~Callback() = default;
/* std::pair<id, refresh rate> */
virtual void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) = 0;
@ -48,7 +49,8 @@ public:
private:
void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode);
void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate);
void OnPhaseOffsetChanged(int64_t phaseOffset);
/* std::pair<id, refresh rate> */
void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates);

View File

@ -152,13 +152,14 @@ private:
void ThreadMain();
void EnableVSync();
void DisableVSync();
void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode);
void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate);
void CollectConnections(bool &waitForVSync, int64_t timestamp,
std::vector<sptr<VSyncConnection>> &conns, int64_t vsyncCount, bool isDvsyncThread = false);
VsyncError QosGetPidByName(const std::string& name, uint32_t& pid);
constexpr pid_t ExtractPid(uint64_t id);
void PostVSyncEvent(const std::vector<sptr<VSyncConnection>> &conns, int64_t timestamp, bool isDvsyncThread);
void ChangeConnsRateLocked();
void ChangeConnsRateLocked(uint32_t vsyncMaxRefreshRate);
void CollectConnectionsLTPO(bool &waitForVSync, int64_t timestamp,
std::vector<sptr<VSyncConnection>> &conns, int64_t vsyncCount, bool isDvsyncThread = false);
/* std::pair<id, refresh rate> */
@ -174,7 +175,8 @@ private:
std::vector<sptr<VSyncConnection>> &conns, bool isDvsyncThread);
bool PostVSyncEventPreProcess(int64_t &timestamp, std::vector<sptr<VSyncConnection>> &conns);
void CheckNeedDisableDvsync(int64_t now, int64_t period);
void OnVSyncTrigger(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode);
void OnVSyncTrigger(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate);
sptr<VSyncSystemAbilityListener> saStatusChangeListener_ = nullptr;
std::thread threadLoop_;
@ -197,7 +199,8 @@ private:
int32_t GetUIDVsyncPid();
void SendConnectionsToVSyncWindow(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode,
std::unique_lock<std::mutex> &locker);
void OnDVSyncTrigger(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode);
void OnDVSyncTrigger(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate);
sptr<DVsync> dvsync_ = nullptr;
bool pendingRNVInVsync_ = false; // for vsync switch to dvsync
std::atomic<int64_t> lastDVsyncTS_ = 0; // for dvsync switch to vsync

View File

@ -37,7 +37,8 @@ class VSyncGenerator : public RefBase {
public:
class Callback : public RefBase {
public:
virtual void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode) = 0;
virtual void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) = 0;
virtual void OnPhaseOffsetChanged(int64_t phaseOffset) = 0;
/* std::pair<id, refresh rate> */
virtual void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) = 0;
@ -203,7 +204,7 @@ private:
bool expectTimeFlag_ = false;
int64_t targetPeriod_ = 0;
bool clearAllSamplesFlag_ = false;
std::atomic<uint32_t> vsyncMaxRefreshRate_ = 360; // default max TE
uint32_t vsyncMaxRefreshRate_ = 360; // default max TE
};
} // impl
} // namespace Rosen

View File

@ -88,7 +88,8 @@ VsyncError VSyncController::SetPhaseOffset(int64_t offset)
return generator->ChangePhaseOffset(this, offset);
}
void VSyncController::OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode)
void VSyncController::OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate)
{
Callback *cb = nullptr;
{
@ -96,7 +97,7 @@ void VSyncController::OnVSyncEvent(int64_t now, int64_t period, uint32_t refresh
cb = callback_;
}
if (cb != nullptr) {
cb->OnVSyncEvent(now, period, refreshRate, vsyncMode);
cb->OnVSyncEvent(now, period, refreshRate, vsyncMode, vsyncMaxRefreshRate);
}
}

View File

@ -559,7 +559,8 @@ void VSyncDistributor::DisableVSync()
}
#if defined(RS_ENABLE_DVSYNC)
void VSyncDistributor::OnDVSyncTrigger(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode)
void VSyncDistributor::OnDVSyncTrigger(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate)
{
std::unique_lock<std::mutex> locker(mutex_);
vsyncMode_ = vsyncMode;
@ -587,12 +588,11 @@ void VSyncDistributor::OnDVSyncTrigger(int64_t now, int64_t period, uint32_t ref
}
if (refreshRate > 0) {
uint32_t maxRefreshRate = CreateVSyncGenerator()->GetVSyncMaxRefreshRate();
event_.vsyncPulseCount += static_cast<int64_t>(maxRefreshRate / refreshRate);
event_.vsyncPulseCount += static_cast<int64_t>(vsyncMaxRefreshRate / refreshRate);
generatorRefreshRate_ = refreshRate;
}
ChangeConnsRateLocked();
ChangeConnsRateLocked(vsyncMaxRefreshRate);
RS_TRACE_NAME_FMT("pendingRNVInVsync: %d DVSyncOn: %d isRS:%d", pendingRNVInVsync_, IsDVsyncOn(), isRs_);
if (dvsync_->WaitCond() || pendingRNVInVsync_) {
con_.notify_all();
@ -602,7 +602,8 @@ void VSyncDistributor::OnDVSyncTrigger(int64_t now, int64_t period, uint32_t ref
}
#endif
void VSyncDistributor::OnVSyncTrigger(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode)
void VSyncDistributor::OnVSyncTrigger(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate)
{
std::vector<sptr<VSyncConnection>> conns;
uint32_t generatorRefreshRate;
@ -615,12 +616,11 @@ void VSyncDistributor::OnVSyncTrigger(int64_t now, int64_t period, uint32_t refr
vsyncCount = event_.vsyncCount;
if (refreshRate > 0) {
uint32_t maxRefreshRate = CreateVSyncGenerator()->GetVSyncMaxRefreshRate();
event_.vsyncPulseCount += static_cast<int64_t>(maxRefreshRate / refreshRate);
event_.vsyncPulseCount += static_cast<int64_t>(vsyncMaxRefreshRate / refreshRate);
generatorRefreshRate_ = refreshRate;
}
vsyncMode_ = vsyncMode;
ChangeConnsRateLocked();
ChangeConnsRateLocked(vsyncMaxRefreshRate);
if (vsyncMode_ == VSYNC_MODE_LTPO) {
CollectConnectionsLTPO(waitForVSync, now, conns, event_.vsyncPulseCount);
@ -661,15 +661,16 @@ void VSyncDistributor::OnVSyncTrigger(int64_t now, int64_t period, uint32_t refr
}
}
void VSyncDistributor::OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode)
void VSyncDistributor::OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate)
{
#if defined(RS_ENABLE_DVSYNC)
if (dvsync_->IsFeatureEnabled()) {
OnDVSyncTrigger(now, period, refreshRate, vsyncMode);
OnDVSyncTrigger(now, period, refreshRate, vsyncMode, vsyncMaxRefreshRate);
} else
#endif
{
OnVSyncTrigger(now, period, refreshRate, vsyncMode);
OnVSyncTrigger(now, period, refreshRate, vsyncMode, vsyncMaxRefreshRate);
}
}
@ -1088,10 +1089,9 @@ VsyncError VSyncDistributor::SetQosVSyncRate(uint64_t windowNodeId, int32_t rate
return VSYNC_ERROR_OK;
}
void VSyncDistributor::ChangeConnsRateLocked()
void VSyncDistributor::ChangeConnsRateLocked(uint32_t vsyncMaxRefreshRate)
{
std::lock_guard<std::mutex> locker(changingConnsRefreshRatesMtx_);
uint32_t maxRefreshRate = CreateVSyncGenerator()->GetVSyncMaxRefreshRate();
for (auto connRefreshRate : changingConnsRefreshRates_) {
for (auto conn : connections_) {
if (conn->id_ != connRefreshRate.first) {
@ -1099,13 +1099,13 @@ void VSyncDistributor::ChangeConnsRateLocked()
}
uint32_t refreshRate = connRefreshRate.second;
if ((generatorRefreshRate_ == 0) || (refreshRate == 0) ||
(maxRefreshRate % refreshRate != 0) || (generatorRefreshRate_ % refreshRate != 0)) {
(vsyncMaxRefreshRate % refreshRate != 0) || (generatorRefreshRate_ % refreshRate != 0)) {
conn->refreshRate_ = 0;
conn->vsyncPulseFreq_ = 1;
continue;
}
conn->refreshRate_ = refreshRate;
conn->vsyncPulseFreq_ = maxRefreshRate / refreshRate;
conn->vsyncPulseFreq_ = vsyncMaxRefreshRate / refreshRate;
conn->referencePulseCount_ = event_.vsyncPulseCount;
}
}

View File

@ -127,9 +127,6 @@ VSyncGenerator::~VSyncGenerator()
std::unique_lock<std::mutex> locker(mutex_);
vsyncThreadRunning_ = false;
}
if (std::this_thread::get_id() == thread_.get_id()) {
return;
}
if (thread_.joinable()) {
con_.notify_all();
@ -142,8 +139,10 @@ void VSyncGenerator::ListenerVsyncEventCB(int64_t occurTimestamp, int64_t nextTi
{
SCOPED_DEBUG_TRACE_FMT("occurTimestamp:%ld, nextTimeStamp:%ld", occurTimestamp, nextTimeStamp);
std::vector<Listener> listeners;
uint32_t vsyncMaxRefreshRate = 360;
{
std::unique_lock<std::mutex> locker(mutex_);
vsyncMaxRefreshRate = vsyncMaxRefreshRate_;
int64_t newOccurTimestamp = SystemTime();
if (isWakeup) {
UpdateWakeupDelay(newOccurTimestamp, nextTimeStamp);
@ -160,7 +159,8 @@ void VSyncGenerator::ListenerVsyncEventCB(int64_t occurTimestamp, int64_t nextTi
for (uint32_t i = 0; i < listeners.size(); i++) {
RS_TRACE_NAME_FMT("listener phase is %ld", listeners[i].phase_);
if (listeners[i].callback_ != nullptr) {
listeners[i].callback_->OnVSyncEvent(listeners[i].lastTime_, periodRecord_, currRefreshRate_, vsyncMode_);
listeners[i].callback_->OnVSyncEvent(listeners[i].lastTime_,
periodRecord_, currRefreshRate_, vsyncMode_, vsyncMaxRefreshRate);
}
}
}
@ -736,6 +736,7 @@ uint32_t VSyncGenerator::GetVSyncMaxRefreshRate()
VsyncError VSyncGenerator::SetVSyncMaxRefreshRate(uint32_t refreshRate)
{
std::lock_guard<std::mutex> locker(mutex_);
if (refreshRate < VSYNC_MAX_REFRESHRATE_RANGE_MIN ||
refreshRate > VSYNC_MAX_REFRESHRATE_RANGE_MAX) {
VLOGE("Not support max refresh rate: %{public}u", refreshRate);

View File

@ -30,7 +30,8 @@ public:
class VSyncControllerCallback : public VSyncController::Callback {
public:
void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode) override;
void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) override;
void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) override;
};
@ -48,7 +49,8 @@ void VSyncControllerTest::TearDownTestCase()
vsyncController_ = nullptr;
}
void VSyncControllerCallback::OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode) {}
void VSyncControllerCallback::OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) {}
void VSyncControllerCallback::OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates)
{

View File

@ -437,7 +437,7 @@ HWTEST_F(VSyncDistributorTest, OnVSyncTriggerTest001, Function | MediumTest| Lev
ASSERT_EQ(vsyncDistributor->AddConnection(conn, 1), VSYNC_ERROR_OK);
conns.emplace_back(conn);
}
vsyncDistributor->OnVSyncTrigger(1000000000, 8333333, 120, VSYNC_MODE_LTPO);
vsyncDistributor->OnVSyncTrigger(1000000000, 8333333, 120, VSYNC_MODE_LTPO, 360);
for (int i = 0; i < conns.size(); i++) {
ASSERT_EQ(vsyncDistributor->RemoveConnection(conns[i]), VSYNC_ERROR_OK);
}
@ -458,7 +458,7 @@ HWTEST_F(VSyncDistributorTest, OnVSyncTriggerTest002, Function | MediumTest| Lev
ASSERT_EQ(vsyncDistributor->AddConnection(conn, 1), VSYNC_ERROR_OK);
conns.emplace_back(conn);
}
vsyncDistributor->OnVSyncTrigger(1000000000, -8333333, 120, VSYNC_MODE_LTPO);
vsyncDistributor->OnVSyncTrigger(1000000000, -8333333, 120, VSYNC_MODE_LTPO, 360);
for (int i = 0; i < conns.size(); i++) {
ASSERT_EQ(vsyncDistributor->RemoveConnection(conns[i]), VSYNC_ERROR_OK);
}
@ -479,7 +479,7 @@ HWTEST_F(VSyncDistributorTest, OnVSyncTriggerTest003, Function | MediumTest| Lev
ASSERT_EQ(vsyncDistributor->AddConnection(conn, 1), VSYNC_ERROR_OK);
conns.emplace_back(conn);
}
vsyncDistributor->OnVSyncTrigger(1000000000, 8333333, 120, VSYNC_MODE_LTPS);
vsyncDistributor->OnVSyncTrigger(1000000000, 8333333, 120, VSYNC_MODE_LTPS, 360);
for (int i = 0; i < conns.size(); i++) {
ASSERT_EQ(vsyncDistributor->RemoveConnection(conns[i]), VSYNC_ERROR_OK);
}

View File

@ -78,12 +78,14 @@ void VSyncGeneratorTest::TearDownTestCase()
class VSyncGeneratorTestCallback : public VSyncGenerator::Callback {
public:
void OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode) override;
void OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate) override;
void OnPhaseOffsetChanged(int64_t phaseOffset) override;
void OnConnsRefreshRateChanged(const std::vector<std::pair<uint64_t, uint32_t>> &refreshRates) override;
};
void VSyncGeneratorTestCallback::OnVSyncEvent(int64_t now, int64_t period, uint32_t refreshRate, VSyncMode vsyncMode)
void VSyncGeneratorTestCallback::OnVSyncEvent(int64_t now, int64_t period,
uint32_t refreshRate, VSyncMode vsyncMode, uint32_t vsyncMaxRefreshRate)
{
}