From e1e91b24799d183831aebef786138c94b13a7bf3 Mon Sep 17 00:00:00 2001 From: zhangjie Date: Mon, 15 Apr 2024 12:32:41 +0800 Subject: [PATCH] =?UTF-8?q?LTPO=E9=80=82=E9=85=8D=E7=AA=97=E5=8F=A3vsync?= =?UTF-8?q?=E5=A4=9A=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjie Change-Id: I4e1603ae491840dd41e2976ebb215afe63533d41 --- wm/BUILD.gn | 2 - wm/include/vsync_station.h | 4 +- wm/include/window_rate_manager.h | 48 ------------- wm/src/root_scene.cpp | 7 +- wm/src/vsync_station.cpp | 28 ++++++-- wm/src/window_rate_manager.cpp | 90 ------------------------- wm/src/window_session_impl.cpp | 23 +++++-- wm/test/unittest/vsync_station_test.cpp | 54 +++++++++++++++ 8 files changed, 104 insertions(+), 152 deletions(-) delete mode 100644 wm/include/window_rate_manager.h delete mode 100644 wm/src/window_rate_manager.cpp diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 32443cc4fe..bd22007281 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -75,7 +75,6 @@ ohos_static_library("libwm_static") { "src/window_manager_agent.cpp", "src/window_option.cpp", "src/window_prepare_terminate.cpp", - "src/window_rate_manager.cpp", "src/window_scene.cpp", "src/window_scene_session_impl.cpp", "src/window_session_impl.cpp", @@ -219,7 +218,6 @@ ohos_shared_library("libwm") { "src/window_manager_agent.cpp", "src/window_option.cpp", "src/window_prepare_terminate.cpp", - "src/window_rate_manager.cpp", "src/window_scene.cpp", "src/window_scene_session_impl.cpp", "src/window_session_impl.cpp", diff --git a/wm/include/vsync_station.h b/wm/include/vsync_station.h index 9fade4026a..058fffc19f 100644 --- a/wm/include/vsync_station.h +++ b/wm/include/vsync_station.h @@ -43,7 +43,9 @@ public: } void RequestVsync(const std::shared_ptr& vsyncCallback); int64_t GetVSyncPeriod(); - void FlushFrameRate(uint32_t rate, bool immediate); + FrameRateLinkerId GetFrameRateLinkerId(); + void FlushFrameRate(uint32_t rate); + void SetFrameRateLinkerEnable(bool enabled); void RemoveCallback(); void SetIsMainHandlerAvailable(bool available) { diff --git a/wm/include/window_rate_manager.h b/wm/include/window_rate_manager.h deleted file mode 100644 index db86dc9969..0000000000 --- a/wm/include/window_rate_manager.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_WINDOW_RATE_MANAGER_H -#define OHOS_WINDOW_RATE_MANAGER_H - -#include -#include -#include -#include - -#include "vsync_station.h" -#include "wm_single_instance.h" - -namespace OHOS { -namespace Rosen { -class WindowRateManager { -WM_DECLARE_SINGLE_INSTANCE_BASE(WindowRateManager); -public: - WindowRateManager() = default; - ~WindowRateManager() = default; - void FlushFrameRate(int32_t id, uint32_t rate, const std::shared_ptr& vsyncStation); - void FlushFrameRateForRootWindow(uint32_t rate, const std::shared_ptr& vsyncStation); - void AddWindowRate(int32_t windowId, uint32_t rate = 0); - void RemoveWindowRate(int32_t windowId, const std::shared_ptr& vsyncStation); - uint32_t GetExpectedRate(); - -private: - std::mutex mtx_; - std::unordered_map windowRateMap_; - uint32_t expectedRate_ = 0; - uint32_t rootWindowRate_ = 0; -}; -} // namespace Rosen -} // namespace OHOS -#endif // OHOS_WINDOW_RATE_MANAGER_H \ No newline at end of file diff --git a/wm/src/root_scene.cpp b/wm/src/root_scene.cpp index ded9e1e33d..deaea14eff 100644 --- a/wm/src/root_scene.cpp +++ b/wm/src/root_scene.cpp @@ -30,7 +30,6 @@ #include "anr_manager.h" #include "intention_event_manager.h" #include "window_manager_hilog.h" -#include "window_rate_manager.h" namespace OHOS { namespace Rosen { @@ -202,7 +201,11 @@ int64_t RootScene::GetVSyncPeriod() void RootScene::FlushFrameRate(uint32_t rate) { std::lock_guard lock(mutex_); - WindowRateManager::GetInstance().FlushFrameRateForRootWindow(rate, vsyncStation_); + if (vsyncStation_ == nullptr) { + TLOGE(WmsLogTag::WMS_MAIN, "FlushFrameRate failed, vsyncStation is nullptr"); + return; + } + vsyncStation_->FlushFrameRate(rate); } void RootScene::OnBundleUpdated(const std::string& bundleName) diff --git a/wm/src/vsync_station.cpp b/wm/src/vsync_station.cpp index 8e6f2115e7..af130373d4 100644 --- a/wm/src/vsync_station.cpp +++ b/wm/src/vsync_station.cpp @@ -72,16 +72,34 @@ int64_t VsyncStation::GetVSyncPeriod() return period; } -void VsyncStation::FlushFrameRate(uint32_t rate, bool immediate) +FrameRateLinkerId VsyncStation::GetFrameRateLinkerId() { if (frameRateLinker_) { - WLOGD("VsyncStation::FlushFrameRate %{public}d", rate); + return frameRateLinker_->GetId(); + } + return 0; +} + +void VsyncStation::FlushFrameRate(uint32_t rate) +{ + if (frameRateLinker_ && frameRateLinker_->IsEnable()) { + WLOGD("VsyncStation::FlushFrameRate %{public}d, linkerID = %{public}" PRIu64, rate, frameRateLinker_->GetId()); FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, rate}; - if (immediate) { - frameRateLinker_->UpdateFrameRateRangeImme(range); - } else { + frameRateLinker_->UpdateFrameRateRange(range); + } +} + +void VsyncStation::SetFrameRateLinkerEnable(bool enabled) +{ + if (frameRateLinker_) { + if (!enabled) { + FrameRateRange range = {0, RANGE_MAX_REFRESHRATE, 0}; + WLOGI("VsyncStation::FlushFrameRateImme %{public}d, linkerID = %{public}" PRIu64, + range.preferred_, frameRateLinker_->GetId()); frameRateLinker_->UpdateFrameRateRange(range); + frameRateLinker_->UpdateFrameRateRangeImme(range); } + frameRateLinker_->SetEnable(enabled); } } diff --git a/wm/src/window_rate_manager.cpp b/wm/src/window_rate_manager.cpp deleted file mode 100644 index 4d11ff4df1..0000000000 --- a/wm/src/window_rate_manager.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "window_rate_manager.h" - -#include "window_frame_trace.h" -#include "window_manager_hilog.h" -#include "ui/rs_frame_rate_linker.h" - -using namespace FRAME_TRACE; - -namespace OHOS { -namespace Rosen { -namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowRateManager"}; -} -WM_IMPLEMENT_SINGLE_INSTANCE(WindowRateManager) - -void WindowRateManager::FlushFrameRate(int32_t windowId, uint32_t rate, - const std::shared_ptr& vsyncStation) -{ - std::lock_guard lock(mtx_); - if (auto iter = windowRateMap_.find(windowId); iter != windowRateMap_.end() && iter->second != rate) { - iter->second = rate; - expectedRate_ = GetExpectedRate(); - if (vsyncStation != nullptr) { - vsyncStation->FlushFrameRate(expectedRate_, false); - } - } -} - -void WindowRateManager::FlushFrameRateForRootWindow(uint32_t rate, const std::shared_ptr& vsyncStation) -{ - std::lock_guard lock(mtx_); - if (rate != rootWindowRate_ && vsyncStation != nullptr) { - rootWindowRate_ = rate; - expectedRate_ = GetExpectedRate(); - vsyncStation->FlushFrameRate(expectedRate_, false); - } -} - -void WindowRateManager::AddWindowRate(int32_t windowId, uint32_t rate) -{ - std::lock_guard lock(mtx_); - if (windowRateMap_.count(windowId)) { - return; - } - windowRateMap_.emplace(windowId, rate); - WLOGD("WindowRateManager::AddWindowRate id: %{public}d", windowId); -} - -void WindowRateManager::RemoveWindowRate(int32_t windowId, const std::shared_ptr& vsyncStation) -{ - std::lock_guard lock(mtx_); - if (auto iter = windowRateMap_.find(windowId); iter != windowRateMap_.end()) { - auto rate = iter->second; - windowRateMap_.erase(iter); - WLOGD("WindowRateManager::RemoveWindowRate id: %{public}d", windowId); - if (rate == expectedRate_ && vsyncStation != nullptr) { - expectedRate_ = GetExpectedRate(); - vsyncStation->FlushFrameRate(expectedRate_, true); - } - } -} - -uint32_t WindowRateManager::GetExpectedRate() -{ - uint32_t expectedRate = 0; - if (!windowRateMap_.empty()) { - auto iter = std::max_element( - windowRateMap_.begin(), windowRateMap_.end(), [](auto a, auto b) { return a.second < b.second; }); - expectedRate = iter->second; - } - expectedRate = std::max(expectedRate, rootWindowRate_); - return expectedRate; -} -} // namespace Rosen -} // namespace OHOS diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 54a2314ce0..ce4030cf4e 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -44,7 +44,6 @@ #include "window_adapter.h" #include "window_manager_hilog.h" #include "window_helper.h" -#include "window_rate_manager.h" #include "color_parser.h" #include "singleton_container.h" #include "perform_reporter.h" @@ -1638,7 +1637,13 @@ void WindowSessionImpl::NotifyAfterForeground(bool needNotifyListeners, bool nee if (needNotifyUiContent) { CALL_UI_CONTENT(Foreground); } - WindowRateManager::GetInstance().AddWindowRate(GetPersistentId()); + if (vsyncStation_ == nullptr) { + TLOGE(WmsLogTag::WMS_MAIN, "SetFrameRateLinkerEnable ture failed, vsyncStation is nullptr"); + return; + } + TLOGD(WmsLogTag::WMS_MAIN, "SetFrameRateLinkerEnable: ture, linkerId = %{public}" PRIu64, + vsyncStation_->GetFrameRateLinkerId()); + vsyncStation_->SetFrameRateLinkerEnable(true); } void WindowSessionImpl::NotifyAfterBackground(bool needNotifyListeners, bool needNotifyUiContent) @@ -1651,7 +1656,13 @@ void WindowSessionImpl::NotifyAfterBackground(bool needNotifyListeners, bool nee if (needNotifyUiContent) { CALL_UI_CONTENT(Background); } - WindowRateManager::GetInstance().RemoveWindowRate(GetPersistentId(), vsyncStation_); + if (vsyncStation_ == nullptr) { + TLOGE(WmsLogTag::WMS_MAIN, "SetFrameRateLinkerEnable false failed, vsyncStation is nullptr"); + return; + } + TLOGD(WmsLogTag::WMS_MAIN, "SetFrameRateLinkerEnable: false, linkerId = %{public}" PRIu64, + vsyncStation_->GetFrameRateLinkerId()); + vsyncStation_->SetFrameRateLinkerEnable(false); } static void RequestInputMethodCloseKeyboard(bool isNeedKeyboard, bool keepKeyboardFlag) @@ -2497,7 +2508,11 @@ int64_t WindowSessionImpl::GetVSyncPeriod() void WindowSessionImpl::FlushFrameRate(uint32_t rate) { std::lock_guard lock(mutex_); - WindowRateManager::GetInstance().FlushFrameRate(GetPersistentId(), rate, vsyncStation_); + if (vsyncStation_ == nullptr) { + TLOGE(WmsLogTag::WMS_MAIN, "FlushFrameRate failed, vsyncStation is nullptr"); + return; + } + vsyncStation_->FlushFrameRate(rate); } WMError WindowSessionImpl::UpdateProperty(WSPropertyChangeAction action) diff --git a/wm/test/unittest/vsync_station_test.cpp b/wm/test/unittest/vsync_station_test.cpp index bb3f8835b5..5200f77c6d 100644 --- a/wm/test/unittest/vsync_station_test.cpp +++ b/wm/test/unittest/vsync_station_test.cpp @@ -79,6 +79,60 @@ HWTEST_F(VsyncStationTest, RequestVsyncMultiWindow, Function | SmallTest | Level vsyncStation1->RequestVsync(vsyncCallback1); } +/** + * @tc.name: GetFrameRateLinkerId + * @tc.desc: GetFrameRateLinkerId Test + * @tc.type: FUNC + */ +HWTEST_F(VsyncStationTest, GetFrameRateLinkerId, Function | SmallTest | Level3) +{ + NodeId nodeId0 = 0; + std::shared_ptr vsyncStation0 = std::make_shared(nodeId0); + ASSERT_NE(vsyncStation0, nullptr); + ASSERT_NE(-1, vsyncStation0->GetFrameRateLinkerId()); + NodeId nodeId1 = 1; + std::shared_ptr vsyncStation1 = std::make_shared(nodeId1); + ASSERT_NE(vsyncStation1, nullptr); + ASSERT_NE(-1, vsyncStation1->GetFrameRateLinkerId()); +} + +/** + * @tc.name: FlushFrameRate + * @tc.desc: FlushFrameRate Test + * @tc.type: FUNC + */ +HWTEST_F(VsyncStationTest, FlushFrameRate, Function | SmallTest | Level3) +{ + NodeId nodeId0 = 0; + std::shared_ptr vsyncStation0 = std::make_shared(nodeId0); + ASSERT_NE(vsyncStation0, nullptr); + uint32_t rate0 = 60; + vsyncStation0->FlushFrameRate(rate0); + NodeId nodeId1 = 1; + std::shared_ptr vsyncStation1 = std::make_shared(nodeId1); + ASSERT_NE(vsyncStation1, nullptr); + uint32_t rate1 = 120; + vsyncStation1->FlushFrameRate(rate1); +} + +/** + * @tc.name: SetFrameRateLinkerEnable + * @tc.desc: SetFrameRateLinkerEnable Test + * @tc.type: FUNC + */ +HWTEST_F(VsyncStationTest, SetFrameRateLinkerEnable, Function | SmallTest | Level3) +{ + NodeId nodeId0 = 0; + std::shared_ptr vsyncStation0 = std::make_shared(nodeId0); + ASSERT_NE(vsyncStation0, nullptr); + bool enable0 = false; + vsyncStation0->SetFrameRateLinkerEnable(enable0); + NodeId nodeId1 = 1; + std::shared_ptr vsyncStation1 = std::make_shared(nodeId1); + ASSERT_NE(vsyncStation1, nullptr); + bool enable1 = true; + vsyncStation1->SetFrameRateLinkerEnable(enable1); +} } } // namespace Rosen } // namespace OHOS \ No newline at end of file -- Gitee