diff --git a/rosen/modules/composer/vsync/include/vsync_distributor.h b/rosen/modules/composer/vsync/include/vsync_distributor.h index e3062d8b2b..35ee252981 100644 --- a/rosen/modules/composer/vsync/include/vsync_distributor.h +++ b/rosen/modules/composer/vsync/include/vsync_distributor.h @@ -76,6 +76,7 @@ public: bool rnvTrigger_ = false; private: VsyncError CleanAllLocked(); + VsyncError GetRemoteDistributorLocked(sptr &distributor); class VSyncConnectionDeathRecipient : public IRemoteObject::DeathRecipient { public: explicit VSyncConnectionDeathRecipient(wptr conn); diff --git a/rosen/modules/composer/vsync/src/vsync_distributor.cpp b/rosen/modules/composer/vsync/src/vsync_distributor.cpp index c4deab9852..5a2aed6943 100644 --- a/rosen/modules/composer/vsync/src/vsync_distributor.cpp +++ b/rosen/modules/composer/vsync/src/vsync_distributor.cpp @@ -114,21 +114,30 @@ VsyncError VSyncConnection::RequestNextVSync() return RequestNextVSync("unknown", 0); } +VsyncError VSyncConnection::GetRemoteDistributorLocked(sptr &distributor) +{ + if (distributor_ == nullptr) { + return VSYNC_ERROR_NULLPTR; + } + distributor = distributor_.promote(); + if (distributor == nullptr) { + return VSYNC_ERROR_NULLPTR; + } + return VSYNC_ERROR_OK; +} + VsyncError VSyncConnection::RequestNextVSync(const std::string &fromWhom, int64_t lastVSyncTS) { - sptr distributor; + sptr distributor = nullptr; { std::unique_lock locker(mutex_); if (isDead_) { VLOGE("%{public}s VSync Client Connection is dead, name:%{public}s.", __func__, info_.name_.c_str()); return VSYNC_ERROR_API_FAILED; } - if (distributor_ == nullptr) { - return VSYNC_ERROR_NULLPTR; - } - distributor = distributor_.promote(); - if (distributor == nullptr) { - return VSYNC_ERROR_NULLPTR; + VsyncError ret = GetRemoteDistributorLocked(distributor); + if (ret != VSYNC_ERROR_OK) { + return ret; } } return distributor->RequestNextVSync(this, fromWhom, lastVSyncTS); @@ -189,12 +198,10 @@ VsyncError VSyncConnection::SetVSyncRate(int32_t rate) VLOGE("%{public}s VSync Client Connection is dead, name:%{public}s.", __func__, info_.name_.c_str()); return VSYNC_ERROR_API_FAILED; } - if (distributor_ == nullptr) { - return VSYNC_ERROR_NULLPTR; - } - const sptr distributor = distributor_.promote(); - if (distributor == nullptr) { - return VSYNC_ERROR_NULLPTR; + sptr distributor = nullptr; + VsyncError ret = GetRemoteDistributorLocked(distributor); + if (ret != VSYNC_ERROR_OK) { + return ret; } return distributor->SetVSyncRate(rate, this); } @@ -202,11 +209,12 @@ VsyncError VSyncConnection::SetVSyncRate(int32_t rate) VsyncError VSyncConnection::CleanAllLocked() { socketPair_ = nullptr; - const sptr distributor = distributor_.promote(); - if (distributor == nullptr) { - return VSYNC_ERROR_OK; + sptr distributor = nullptr; + VsyncError ret = GetRemoteDistributorLocked(distributor); + if (ret != VSYNC_ERROR_OK) { + return ret; } - VsyncError ret = distributor->RemoveConnection(this); + ret = distributor->RemoveConnection(this); isDead_ = true; return ret; } @@ -219,19 +227,16 @@ VsyncError VSyncConnection::Destroy() VsyncError VSyncConnection::SetUiDvsyncSwitch(bool dvsyncSwitch) { - sptr distributor; + sptr distributor = nullptr; { std::unique_lock locker(mutex_); if (isDead_) { VLOGE("%{public}s VSync Client Connection is dead, name:%{public}s.", __func__, info_.name_.c_str()); return VSYNC_ERROR_API_FAILED; } - if (distributor_ == nullptr) { - return VSYNC_ERROR_NULLPTR; - } - distributor = distributor_.promote(); - if (distributor == nullptr) { - return VSYNC_ERROR_NULLPTR; + VsyncError ret = GetRemoteDistributorLocked(distributor); + if (ret != VSYNC_ERROR_OK) { + return ret; } } return distributor->SetUiDvsyncSwitch(dvsyncSwitch, this); @@ -312,8 +317,8 @@ VsyncError VSyncDistributor::RemoveConnection(const sptr& conne if (connection == nullptr) { return VSYNC_ERROR_NULLPTR; } - int32_t proxyPid = connection->proxyPid_; std::lock_guard locker(mutex_); + int32_t proxyPid = connection->proxyPid_; auto it = std::find(connections_.begin(), connections_.end(), connection); if (it == connections_.end()) { return VSYNC_ERROR_INVALID_ARGUMENTS; @@ -684,8 +689,8 @@ void VSyncDistributor::CollectConnections(bool &waitForVSync, int64_t timestamp, waitForVSync = true; if (timestamp > 0) { connections_[i]->rate_ = -1; - conns.push_back(connections_[i]); connections_[i]->triggerThisTime_ = false; + conns.push_back(connections_[i]); } continue; } @@ -699,8 +704,8 @@ void VSyncDistributor::CollectConnections(bool &waitForVSync, int64_t timestamp, waitForVSync = true; if (timestamp > 0 && (vsyncCount % rate == 0)) { connections_[i]->rate_ = -1; - conns.push_back(connections_[i]); connections_[i]->triggerThisTime_ = false; + conns.push_back(connections_[i]); } } else if (connections_[i]->rate_ > 0) { // for SetVSyncRate waitForVSync = true; @@ -722,14 +727,16 @@ void VSyncDistributor::CollectConnectionsLTPO(bool &waitForVSync, int64_t timest continue; } waitForVSync = true; + if (timestamp <= 0) { + break; + } int64_t vsyncPulseFreq = static_cast(connections_[i]->vsyncPulseFreq_); - if (timestamp > 0 && - (vsyncCount - connections_[i]->referencePulseCount_) % vsyncPulseFreq == 0) { - conns.push_back(connections_[i]); + if ((vsyncCount - connections_[i]->referencePulseCount_) % vsyncPulseFreq == 0) { connections_[i]->triggerThisTime_ = false; if (connections_[i]->rate_ == 0) { connections_[i]->rate_ = -1; } + conns.push_back(connections_[i]); } } }