!15386 进入Adaptive Sync提前送显模式需要关闭vsync校准

Merge pull request !15386 from 陶春龙/master
This commit is contained in:
openharmony_ci 2024-10-11 07:55:56 +00:00 committed by Gitee
commit 5e256702c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 98 additions and 13 deletions

View File

@ -62,6 +62,8 @@ public:
void StartSample(const OutputPtr &output);
/* set a temporary period used only for VSyncSampler::GetHardwarePeriod interface */
void SetPendingMode(const OutputPtr &output, int64_t period, int64_t timestamp);
void SetVsyncSamplerEnabled(const OutputPtr &output, bool enabled);
bool GetVsyncSamplerEnabled(const OutputPtr &output);
private:
HdiBackend() = default;
virtual ~HdiBackend() = default;

View File

@ -96,6 +96,8 @@ public:
void SetPendingMode(int64_t period, int64_t timestamp);
void ReleaseLayers(sptr<SyncFence>& releaseFence);
int32_t GetBufferCacheSize();
void SetVsyncSamplerEnabled(bool enabled);
bool GetVsyncSamplerEnabled();
private:
HdiDevice *device_ = nullptr;
@ -149,6 +151,7 @@ private:
void ClearBufferCache();
std::map<LayerInfoPtr, sptr<SyncFence>> GetLayersReleaseFenceLocked();
std::atomic<bool> enableVsyncSample_ = true;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -247,6 +247,24 @@ void HdiBackend::StartSample(const OutputPtr &output)
}
output->StartVSyncSampler(true); // force resample
}
void HdiBackend::SetVsyncSamplerEnabled(const OutputPtr &output, bool enabled)
{
if (output == nullptr) {
HLOGE("output is nullptr.");
return;
}
output->SetVsyncSamplerEnabled(enabled);
}
bool HdiBackend::GetVsyncSamplerEnabled(const OutputPtr &output)
{
if (output == nullptr) {
HLOGE("output is nullptr.");
return false;
}
return output->GetVsyncSamplerEnabled();
}
void HdiBackend::ResetDevice()
{

View File

@ -545,7 +545,7 @@ int32_t HdiOutput::UpdateInfosAfterCommit(sptr<SyncFence> fbFence)
int64_t timestamp = thirdFrameAheadPresentFence_->SyncFileReadTimestamp();
bool startSample = false;
if (timestamp != SyncFence::FENCE_PENDING_TIMESTAMP) {
startSample = sampler_->AddPresentFenceTime(timestamp);
startSample = enableVsyncSample_.load() && sampler_->AddPresentFenceTime(timestamp);
RecordCompositionTime(timestamp);
bool presentTimeUpdated = false;
LayerPtr uniRenderLayer = nullptr;
@ -577,6 +577,18 @@ int32_t HdiOutput::UpdateInfosAfterCommit(sptr<SyncFence> fbFence)
return ret;
}
void HdiOutput::SetVsyncSamplerEnabled(bool enabled)
{
RS_TRACE_NAME_FMT("HdiOutput::SetVsyncSamplerEnabled, enableVsyncSample_:%d", enabled);
HLOGI("Change enableVsyncSample_, value is %{public}d", enabled);
enableVsyncSample_.store(enabled);
}
bool HdiOutput::GetVsyncSamplerEnabled()
{
return enableVsyncSample_.load();
}
int32_t HdiOutput::ReleaseFramebuffer(const sptr<SyncFence>& releaseFence)
{
if (currFrameBuffer_ == nullptr) {
@ -706,6 +718,10 @@ std::map<LayerInfoPtr, sptr<SyncFence>> HdiOutput::GetLayersReleaseFenceLocked()
int32_t HdiOutput::StartVSyncSampler(bool forceReSample)
{
ScopedBytrace func("HdiOutput::StartVSyncSampler, forceReSample:" + std::to_string(forceReSample));
if (!enableVsyncSample_.load()) {
ScopedBytrace func("disabled vsyncSample");
return GRAPHIC_DISPLAY_FAILURE;
}
if (sampler_ == nullptr) {
sampler_ = CreateVSyncSampler();
}

View File

@ -145,6 +145,22 @@ HWTEST_F(HdiBackendTest, RegHwcDeadListener002, Function | MediumTest| Level3)
ASSERT_EQ(ret, ROSEN_ERROR_OK);
}
/*
* Function: SetVsyncSamplerEnabled
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. call SetVsyncSamplerEnabled()
* 2. call GetVsyncSamplerEnabled
* 3. check ret
*/
HWTEST_F(HdiBackendTest, SetVsyncSamplerEnabled, Function | MediumTest| Level3)
{
OutputPtr output = HdiOutput::CreateHdiOutput(0);
hdiBackend_->SetVsyncSamplerEnabled(output, false);
ASSERT_EQ(hdiBackend_->GetVsyncSamplerEnabled(output), false);
}
/*
* Function: ResetDevice
* Type: Function

View File

@ -66,7 +66,7 @@ namespace {
"VOTER_IDLE"
};
constexpr int ADAPTIVE_SYNC_PROPERTY = 2;
constexpr int ADAPTIVE_SYNC_PROPERTY = 3;
constexpr int DISPLAY_SUCCESS = 1;
}

View File

@ -155,7 +155,7 @@ void HgmCore::SetASConfig(PolicyConfigData::ScreenSetting& curScreenSetting)
std::string asConfig = curScreenSetting.ltpoConfig["adaptiveSync"];
if (asConfig == "1" || asConfig == "0") {
adaptiveSync_ = std::stoi(curScreenSetting.ltpoConfig["adaptiveSync"]);
adaptiveSync_ = std::stoi(asConfig);
} else {
adaptiveSync_ = 0;
}

View File

@ -224,17 +224,13 @@ void RSHardwareThread::CommitAndReleaseLayers(OutputPtr output, const std::vecto
if (!hgmCore.GetLtpoEnabled()) {
PostTask(task);
} else {
// if in game adaptive vsync mode and do direct composition,send layer immediately
auto frameRateMgr = hgmCore.GetFrameRateMgr();
if (frameRateMgr != nullptr) {
bool isAdaptive = frameRateMgr->IsAdaptive();
RS_LOGD("RSHardwareThread::CommitAndReleaseLayers send layer isAdaptive: %{public}u", isAdaptive);
if (isAdaptive) {
RS_TRACE_NAME("RSHardwareThread::CommitAndReleaseLayers PostTask in Adaptive Mode");
PostTask(task);
return;
}
if (IsInAdaptiveMode(output)) {
RS_TRACE_NAME("RSHardwareThread::CommitAndReleaseLayers PostTask in Adaptive Mode");
PostTask(task);
isLastAdaptive_ = true;
return;
}
isLastAdaptive_ = false;
auto period = CreateVSyncSampler()->GetHardwarePeriod();
int64_t pipelineOffset = hgmCore.GetPipelineOffset();
uint64_t expectCommitTime = static_cast<uint64_t>(param.frameTimestamp +
@ -256,6 +252,38 @@ void RSHardwareThread::CommitAndReleaseLayers(OutputPtr output, const std::vecto
}
}
bool RSHardwareThread::IsInAdaptiveMode(const OutputPtr &output)
{
if (hdiBackend_ == nullptr) {
RS_LOGE("RSHardwareThread::IsInAdaptiveMode hdiBackend_ is nullptr");
return false;
}
bool isSamplerEnabled = hdiBackend_->GetVsyncSamplerEnabled(output);
auto& hgmCore = OHOS::Rosen::HgmCore::Instance();
// if in game adaptive vsync mode and do direct composition,send layer immediately
auto frameRateMgr = hgmCore.GetFrameRateMgr();
if (frameRateMgr != nullptr) {
bool isAdaptive = frameRateMgr->IsAdaptive();
RS_LOGD("RSHardwareThread::CommitAndReleaseLayers send layer isAdaptive: %{public}u", isAdaptive);
if (isAdaptive) {
if (isSamplerEnabled) {
// when phone enter game adaptive sync mode must disable vsync sampler
hdiBackend_->SetVsyncSamplerEnabled(output, false);
}
return true;
}
}
if (isLastAdaptive_ && !isSamplerEnabled) {
// exit adaptive sync mode must restore vsync sampler, and startSample immediately
hdiBackend_->SetVsyncSamplerEnabled(output, true);
hdiBackend_->StartSample(output);
}
return false;
}
RefreshRateParam RSHardwareThread::GetRefreshRateParam()
{
// need to sync the hgm data from main thread.

View File

@ -73,6 +73,7 @@ private:
void PerformSetActiveMode(OutputPtr output, uint64_t timestamp, uint64_t constraintRelativeTime);
void ExecuteSwitchRefreshRate(uint32_t rate);
void AddRefreshRateCount();
bool IsInAdaptiveMode(const OutputPtr &output);
RefreshRateParam GetRefreshRateParam();
std::shared_ptr<RSSurfaceOhos> CreateFrameBufferSurfaceOhos(const sptr<Surface>& surface);
@ -104,6 +105,7 @@ private:
std::map<uint32_t, uint64_t> refreshRateCounts_;
sptr<SyncFence> releaseFence_ = SyncFence::InvalidFence();
int64_t delayTime_ = 0;
bool isLastAdaptive_ = false;
friend class RSUniRenderThread;
friend class RSUifirstManager;