From c8797a1198863d29767304dd233bf8725d0d0070 Mon Sep 17 00:00:00 2001 From: zhangjie Date: Fri, 10 Nov 2023 11:30:56 +0800 Subject: [PATCH] =?UTF-8?q?LTPO=E7=BB=98=E6=98=BE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjie Change-Id: If2ac6fd31d2c825a8ce430c4cf79c5a58aba7158 --- interfaces/innerkits/wm/window.h | 6 ++++++ wm/include/vsync_station.h | 4 ++++ wm/include/window_session_impl.h | 1 + wm/src/vsync_station.cpp | 28 +++++++++++++++++++++++++++- wm/src/window_session_impl.cpp | 8 ++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 7cb8cb19d3..ee207f6acc 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -885,6 +885,12 @@ public: * @return vsync period. */ virtual int64_t GetVSyncPeriod() { return 0; } + /** + * @brief flush frame rate of linker. + * + * @param rate frame rate. + */ + virtual void FlushFrameRate(uint32_t rate) {} /** * @brief Update Configuration. * diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h index 35807103d6..28a5ee965a 100644 --- a/wm/include/vsync_station.h +++ b/wm/include/vsync_station.h @@ -31,6 +31,7 @@ namespace OHOS { namespace Rosen { +class RSFrameRateLinker; class VsyncStation { WM_DECLARE_SINGLE_INSTANCE_BASE(VsyncStation); public: @@ -41,6 +42,8 @@ public: } void RequestVsync(const std::shared_ptr& vsyncCallback); int64_t GetVSyncPeriod(); + void FlushFrameRate(uint32_t rate); + void SetFrameRateLinkerEnable(bool enabled); void RemoveCallback(); void SetIsMainHandlerAvailable(bool available) { @@ -66,6 +69,7 @@ private: bool destroyed_ = false; const std::string VSYNC_THREAD_ID = "VsyncThread"; std::shared_ptr receiver_ = nullptr; + std::shared_ptr frameRateLinker_; std::unordered_set> vsyncCallbacks_; VSyncReceiver::FrameCallback frameCallback_ = { .userData_ = this, diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 64107dc4d5..3320eb73fd 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -87,6 +87,7 @@ public: WMError SetAPPWindowIcon(const std::shared_ptr& icon) override; void RequestVsync(const std::shared_ptr& vsyncCallback) override; int64_t GetVSyncPeriod() override; + void FlushFrameRate(uint32_t rate) override; // inherits from session stage WSError SetActive(bool active) override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp index 0ec7c8c040..d0b7aa8f2f 100644 --- a/wm/src/vsync_station.cpp +++ b/wm/src/vsync_station.cpp @@ -17,6 +17,7 @@ #include "window_frame_trace.h" #include "transaction/rs_interfaces.h" +#include "ui/rs_frame_rate_linker.h" #include "window_manager_hilog.h" using namespace FRAME_TRACE; @@ -66,6 +67,29 @@ int64_t VsyncStation::GetVSyncPeriod() return period; } +void VsyncStation::FlushFrameRate(uint32_t rate) +{ + if (frameRateLinker_ && frameRateLinker_->IsEnable()) { + WLOGI("VsyncStation::FlushFrameRate %{public}d", rate); + FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, rate}; + if (range.IsValid()) { + frameRateLinker_->UpdateFrameRateRange(range); + } + } +} + +void VsyncStation::SetFrameRateLinkerEnable(bool enabled) +{ + if (frameRateLinker_) { + if (!enabled) { + FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, 0}; + WLOGI("VsyncStation::SetFrameRateLinkerEnable false"); + frameRateLinker_->UpdateFrameRateRangeImme(range); + } + frameRateLinker_->SetEnable(enabled); + } +} + void VsyncStation::Init() { if (!hasInitVsyncReceiver_ || !vsyncHandler_) { @@ -81,8 +105,10 @@ void VsyncStation::Init() } } auto& rsClient = OHOS::Rosen::RSInterfaces::GetInstance(); + frameRateLinker_ = OHOS::Rosen::RSFrameRateLinker::Create(); while (receiver_ == nullptr) { - receiver_ = rsClient.CreateVSyncReceiver("WM_" + std::to_string(::getpid()), vsyncHandler_); + receiver_ = rsClient.CreateVSyncReceiver("WM_" + std::to_string(::getpid()), frameRateLinker_->GetId(), + vsyncHandler_); } receiver_->Init(); hasInitVsyncReceiver_ = true; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 3e7226d746..3c3eb29841 100755 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1035,6 +1035,7 @@ void WindowSessionImpl::NotifyAfterForeground(bool needNotifyListeners, bool nee if (needNotifyUiContent) { CALL_UI_CONTENT(Foreground); } + VsyncStation::GetInstance().SetFrameRateLinkerEnable(true); } void WindowSessionImpl::NotifyAfterBackground(bool needNotifyListeners, bool needNotifyUiContent) @@ -1046,6 +1047,7 @@ void WindowSessionImpl::NotifyAfterBackground(bool needNotifyListeners, bool nee if (needNotifyUiContent) { CALL_UI_CONTENT(Background); } + VsyncStation::GetInstance().SetFrameRateLinkerEnable(false); } void WindowSessionImpl::NotifyAfterFocused() @@ -1546,6 +1548,12 @@ int64_t WindowSessionImpl::GetVSyncPeriod() return VsyncStation::GetInstance().GetVSyncPeriod(); } +void WindowSessionImpl::FlushFrameRate(uint32_t rate) +{ + std::lock_guard lock(mutex_); + VsyncStation::GetInstance().FlushFrameRate(rate); +} + WMError WindowSessionImpl::UpdateProperty(WSPropertyChangeAction action) { WLOGFD("UpdateProperty, action:%{public}u", action); -- Gitee