add vsync offset

Signed-off-by: shegangbin <shegangbin1@huawei.com>
This commit is contained in:
shegangbin 2024-11-21 17:23:35 +08:00
parent 409a7af450
commit 233c123582
5 changed files with 24 additions and 4 deletions

View File

@ -89,7 +89,10 @@ ohos_unittest("hdioutput_unit_test") {
"mock_hdi_device.cpp",
]
deps = [ ":hdibackend_test_common" ]
deps = [
":hdibackend_test_common",
"../../../vsync:libvsync",
]
}
## UnitTest hdioutput_unit_test }}}

View File

@ -247,6 +247,7 @@ HWTEST_F(HdiBackendTest, StartSample001, Function | MediumTest | Level3)
OutputPtr output = HdiOutput::CreateHdiOutput(0);
hdiBackend_->SetPendingMode(output, 0, 0);
output->sampler_->SetHardwareVSyncStatus(false);
output->sampler_->SetVsyncSamplerEnabled(true);
hdiBackend_->StartSample(output);
EXPECT_TRUE(output->sampler_->GetHardwareVSyncStatus());
}

View File

@ -528,11 +528,11 @@ HWTEST_F(HdiOutputTest, GetBufferCacheSize001, Function | MediumTest | Level1)
HWTEST_F(HdiOutputTest, StartVSyncSampler001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
hdiOutput->SetVsyncSamplerEnabled(false);
CreateVSyncSampler()->SetVsyncSamplerEnabled(false);
int32_t res = hdiOutput->StartVSyncSampler(true);
EXPECT_EQ(res, GRAPHIC_DISPLAY_FAILURE);
hdiOutput->SetVsyncSamplerEnabled(true);
CreateVSyncSampler()->SetVsyncSamplerEnabled(true);
hdiOutput->sampler_ = nullptr;
res = hdiOutput->StartVSyncSampler(false);
EXPECT_EQ(res, GRAPHIC_DISPLAY_SUCCESS);

View File

@ -80,6 +80,7 @@ public:
virtual void SetRSDistributor(sptr<VSyncDistributor> &rsVSyncDistributor) = 0;
virtual void SetFrameRateChangingStatus(bool frameRateChanging) = 0;
virtual void SetAppDistributor(sptr<VSyncDistributor> &appVSyncDistributor) = 0;
virtual int64_t GetVSyncOffset() = 0;
};
sptr<VSyncGenerator> CreateVSyncGenerator();
@ -122,6 +123,7 @@ public:
void SetRSDistributor(sptr<VSyncDistributor> &rsVSyncDistributor) override;
void SetFrameRateChangingStatus(bool frameRateChanging) override;
void SetAppDistributor(sptr<VSyncDistributor> &appVSyncDistributor) override;
int64_t GetVSyncOffset() override;
private:
friend class OHOS::Rosen::VSyncGenerator;
@ -207,6 +209,7 @@ private:
int64_t targetPeriod_ = 0;
bool clearAllSamplesFlag_ = false;
uint32_t vsyncMaxRefreshRate_ = 360; // default max TE
int64_t vsyncOffset_ = 0;
};
} // impl
} // namespace Rosen

View File

@ -90,8 +90,10 @@ uint32_t CalculateRefreshRate(int64_t period)
} rateSections[] = {
{30000000, 35000000, 30}, // 30000000ns, 35000000ns
{15000000, 18000000, 60}, // 15000000ns, 18000000ns
{13000000, 15000000, 72}, // 13000000ns, 15000000ns
{10000000, 12000000, 90}, // 10000000ns, 12000000ns
{7500000, 9000000, 120}}; // 7500000ns, 9000000ns
{7500000, 9000000, 120}, // 7500000ns, 9000000ns
{6000000, 7500000, 144}}; // 6000000ns, 7500000ns
for (const auto& rateSection : rateSections) {
if (period > rateSection.min && period < rateSection.max) {
return rateSection.refreshRate;
@ -828,6 +830,12 @@ void VSyncGenerator::CalculateReferenceTimeOffsetPulseNumLocked(int64_t referenc
startRefresh_, pendingPeriod_);
}
int64_t VSyncGenerator::GetVSyncOffset()
{
std::lock_guard<std::mutex> locker(mutex_);
return vsyncOffset_;
}
VsyncError VSyncGenerator::CheckAndUpdateReferenceTime(int64_t hardwareVsyncInterval, int64_t referenceTime)
{
if (hardwareVsyncInterval < 0 || referenceTime < 0) {
@ -855,6 +863,11 @@ VsyncError VSyncGenerator::CheckAndUpdateReferenceTime(int64_t hardwareVsyncInte
bool needNotify = true;
uint32_t periodRefreshRate = CalculateRefreshRate(period_);
uint32_t pendingPeriodRefreshRate = CalculateRefreshRate(pendingPeriod_);
if (pendingPeriodRefreshRate != 0) {
int32_t periodPulseNum = vsyncMaxRefreshRate_ / pendingPeriodRefreshRate;
vsyncOffset_ = (referenceTimeOffsetPulseNum_ % periodPulseNum) * pulse_;
RS_TRACE_NAME_FMT("vsyncOffset_:%ld", vsyncOffset_);
}
// 120hz, 90hz, 60hz
if (((periodRefreshRate == 120) || (periodRefreshRate == 90)) && (pendingPeriodRefreshRate == 60)) {
needNotify = false;