From 28bfe80818b8a397b8208a45efe9c51bc989b79e Mon Sep 17 00:00:00 2001 From: wlj Date: Wed, 13 Jul 2022 09:47:43 +0800 Subject: [PATCH] add watchdog Signed-off-by: wlj Change-Id: I57ea5b503d91ad119667b5c52afcddab409fac77 --- utils/include/wm_common_inner.h | 1 + wm/BUILD.gn | 1 + wm/src/window_impl.cpp | 6 + wm/src/window_manager.cpp | 7 + wmserver/BUILD.gn | 2 +- wmserver/include/window_common_event.h | 1 - wmserver/include/window_manager_service.h | 20 ++- wmserver/include/window_task_looper.h | 87 ------------ wmserver/src/window_manager_service.cpp | 161 +++++++++++++--------- wmserver/src/window_task_looper.cpp | 95 ------------- 10 files changed, 128 insertions(+), 253 deletions(-) delete mode 100644 wmserver/include/window_task_looper.h delete mode 100644 wmserver/src/window_task_looper.cpp diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 7995abbd..31dd1396 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -143,6 +143,7 @@ namespace { constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240; constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320; constexpr uint32_t MAX_FLOATING_SIZE = 2560; + constexpr unsigned int WMS_WATCHDOG_CHECK_INTERVAL = 6; // actual check interval is 3000ms(6 * 500) const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0}; const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512}; } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index ea7d7bea..4d7ba260 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -76,6 +76,7 @@ ohos_shared_library("libwm") { "bundle_framework:appexecfwk_core", "graphic_standard:surface", "graphic_standard:window_animation", + "hicollie_native:libhicollie", "hilog_native:libhilog", "hisysevent_native:libhisysevent", "input:libmmi-client", diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 5acbbbd9..4b14f3c9 100755 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "xcollie/watchdog.h" #include "color_parser.h" #include "display_manager.h" @@ -100,6 +101,11 @@ void WindowImpl::InitListenerHandler() return; } isListenerHandlerRunning_ = true; + int ret = HiviewDFX::Watchdog::GetInstance().AddThread(WM_CALLBACK_THREAD_NAME, + eventHandler_, WMS_WATCHDOG_CHECK_INTERVAL); + if (ret != 0) { + WLOGFE("Add watchdog thread failed"); + } WLOGFD("init window callback runner success."); } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index b196add2..7bc769c5 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -21,6 +21,8 @@ #include "event_handler.h" #include "event_runner.h" #include "marshalling_helper.h" +#include "xcollie/watchdog.h" + #include "window_adapter.h" #include "window_manager_agent.h" #include "window_manager_hilog.h" @@ -199,6 +201,11 @@ void WindowManager::Impl::InitListenerHandler() return; } isHandlerRunning_ = true; + int ret = HiviewDFX::Watchdog::GetInstance().AddThread(WINDOW_MANAGER_CALLBACK_THREAD_NAME, + listenerHandler_, WMS_WATCHDOG_CHECK_INTERVAL); + if (ret != 0) { + WLOGFE("Add watchdog thread failed"); + } WLOGFD("init window manager callback runner success."); } diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index a834d99f..3fbff3d4 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -59,7 +59,6 @@ ohos_shared_library("libwms") { "src/window_snapshot/snapshot_controller.cpp", "src/window_snapshot/snapshot_proxy.cpp", "src/window_snapshot/snapshot_stub.cpp", - "src/window_task_looper.cpp", "src/window_zorder_policy.cpp", "src/zidl/window_manager_stub.cpp", ] @@ -84,6 +83,7 @@ ohos_shared_library("libwms") { "display_manager:displaymgr", "graphic_standard:surface", "graphic_standard:window_animation", + "hicollie_native:libhicollie", "hilog_native:libhilog", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", diff --git a/wmserver/include/window_common_event.h b/wmserver/include/window_common_event.h index 273a1170..abc82187 100644 --- a/wmserver/include/window_common_event.h +++ b/wmserver/include/window_common_event.h @@ -22,7 +22,6 @@ #include #include "window_root.h" -#include "window_task_looper.h" namespace OHOS { namespace Rosen { diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 5b214eb6..4dd7f2fd 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -18,6 +18,7 @@ #include #include +#include "event_handler.h" #include #include @@ -35,7 +36,6 @@ #include "zidl/window_manager_stub.h" #include "window_dumper.h" #include "window_root.h" -#include "window_task_looper.h" #include "snapshot_controller.h" namespace OHOS { @@ -67,6 +67,7 @@ DECLARE_SYSTEM_ABILITY(WindowManagerService); WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService); public: + using Task = std::function; void OnStart() override; void OnStop() override; void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; @@ -110,7 +111,7 @@ public: void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation); WMError UpdateRsTree(uint32_t windowId, bool isAdd) override; void OnScreenshot(DisplayId displayId); - void OnAccountSwitched(int accountId) const; + void OnAccountSwitched(int accountId); protected: WindowManagerService(); virtual ~WindowManagerService() = default; @@ -126,6 +127,18 @@ private: const std::map>& displayInfoMap, DisplayStateChangeType type); WMError GetFocusWindowInfo(sptr& abilityToken); void ConfigureWindowManagerService(); + void PostAsyncTask(Task task); + void PostVoidSyncTask(Task task); + template> + Return PostSyncTask(SyncTask&& task) + { + Return ret; + std::function syncTask([&ret, &task]() {ret = task();}); + if (handler_) { + handler_->PostSyncTask(syncTask, AppExecFwk::EventQueue::Priority::IMMEDIATE); + } + return ret; + } static inline SingletonDelegator delegator; AtomicMap accessTokenIdMaps_; @@ -139,8 +152,9 @@ private: sptr windowDumper_; SystemConfig systemConfig_; ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 }; - std::unique_ptr wmsTaskLooper_; std::shared_ptr windowCommonEvent_; + std::shared_ptr runner_ = nullptr; + std::shared_ptr handler_ = nullptr; RSInterfaces& rsInterface_; bool startingOpen_ = true; std::shared_ptr rsUiDirector_; diff --git a/wmserver/include/window_task_looper.h b/wmserver/include/window_task_looper.h deleted file mode 100644 index 9a85f948..00000000 --- a/wmserver/include/window_task_looper.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2022 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_ROSEN_WINDOW_TASK_LOOPER_H -#define OHOS_ROSEN_WINDOW_TASK_LOOPER_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace Rosen { -template -class ScheduledTask : public RefBase { -public: - static auto Create(SyncTask&& task) - { - sptr> t(new ScheduledTask(std::forward(task))); - return std::make_pair(t, t->task_.get_future()); - } - - void Run() - { - task_(); - } - -private: - explicit ScheduledTask(SyncTask&& task) : task_(std::move(task)) {} - ~ScheduledTask() {} - - using Return = std::invoke_result_t; - std::packaged_task task_; -}; - -class WindowTaskLooper { -public: - using Task = std::function; - WindowTaskLooper() = default; - ~WindowTaskLooper(); - - template> - std::future ScheduleTask(SyncTask&& task) - { - auto [scheduledTask, taskFuture] = ScheduledTask::Create(std::forward(task)); - PostTask([t(std::move(scheduledTask))]() { t->Run(); }); - return std::move(taskFuture); - } - void PostTask(const Task& task); - void WakeUp(); - void Start() noexcept; - bool IsRunning(); - -private: - void WaitTask(); - void TaskProcessThread(); - void ExecuteAllTask(); - -private: - mutable std::mutex mtx_; - bool wakeUp_ = false; - std::condition_variable taskCond_; - mutable std::atomic running_ { false }; - std::vector taskQ_; - std::unique_ptr taskProcessThread_; -}; -} // namespace Rosen -} // namespace OHOS -#endif \ No newline at end of file diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index c6d1abef..92b606cc 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -15,6 +15,8 @@ #include "window_manager_service.h" +#include + #include #include #include @@ -22,6 +24,7 @@ #include #include #include +#include "xcollie/watchdog.h" #include "display_manager_service_inner.h" #include "dm_common.h" @@ -42,6 +45,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerService"}; + const std::string WMS_NAME = "WindowManagerSevice"; } WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService) @@ -59,12 +63,17 @@ WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERV windowDumper_ = new WindowDumper(windowRoot_); freezeDisplayController_ = new FreezeController(); windowCommonEvent_ = std::make_shared(); - wmsTaskLooper_ = std::make_unique(); startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled + runner_ = AppExecFwk::EventRunner::Create(WMS_NAME); + handler_ = std::make_shared(runner_); + int ret = HiviewDFX::Watchdog::GetInstance().AddThread(WMS_NAME, handler_, WMS_WATCHDOG_CHECK_INTERVAL); + if (ret != 0) { + WLOGFE("Add watchdog thread failed"); + } // init RSUIDirector, it will handle animation callback rsUiDirector_ = RSUIDirector::Create(); - rsUiDirector_->SetUITaskRunner([this](const std::function& task) { wmsTaskLooper_->PostTask(task); }); + rsUiDirector_->SetUITaskRunner([this](const std::function& task) { PostAsyncTask(task); }); rsUiDirector_->Init(false); } @@ -80,10 +89,29 @@ void WindowManagerService::OnStart() RegisterSnapshotHandler(); RegisterWindowManagerServiceHandler(); RegisterWindowVisibilityChangeCallback(); - wmsTaskLooper_->Start(); AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); } +void WindowManagerService::PostAsyncTask(Task task) +{ + if (handler_) { + bool ret = handler_->PostTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); + if (!ret) { + WLOGFE("EventHandler PostTask Failed"); + } + } +} + +void WindowManagerService::PostVoidSyncTask(Task task) +{ + if (handler_) { + bool ret = handler_->PostSyncTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE); + if (!ret) { + WLOGFE("EventHandler PostVoidSyncTask Failed"); + } + } +} + void WindowManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { @@ -93,9 +121,9 @@ void WindowManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std } } -void WindowManagerService::OnAccountSwitched(int accountId) const +void WindowManagerService::OnAccountSwitched(int accountId) { - wmsTaskLooper_->PostTask([this, accountId]() { + PostAsyncTask([this, accountId]() { windowRoot_->RemoveSingleUserWindowNodes(accountId); }); WLOGFI("called"); @@ -105,14 +133,14 @@ void WindowManagerService::WindowVisibilityChangeCallback(std::shared_ptr weak(occlusionData); - return wmsTaskLooper_->ScheduleTask([this, weak]() { + PostVoidSyncTask([this, weak]() { auto weakOcclusionData = weak.lock(); if (weakOcclusionData == nullptr) { WLOGFE("weak occlusionData is nullptr"); return; } windowRoot_->NotifyWindowVisibilityChange(weakOcclusionData); - }).wait(); + }); } void WindowManagerService::RegisterWindowVisibilityChangeCallback() @@ -256,9 +284,10 @@ int WindowManagerService::Dump(int fd, const std::vector& args) if (windowDumper_ == nullptr) { windowDumper_ = new WindowDumper(windowRoot_); } - return wmsTaskLooper_->ScheduleTask([this, fd, &args]() { + + return PostSyncTask([this, fd, &args]() { return static_cast(windowDumper_->Dump(fd, args)); - }).get(); + }); } void WindowManagerService::ConfigureWindowManagerService() @@ -319,23 +348,23 @@ WMError WindowManagerService::NotifyWindowTransition( { if (!isFromClient) { WLOGFI("NotifyWindowTransition asynchronously."); - wmsTaskLooper_->PostTask([this, fromInfo, toInfo]() mutable { + PostAsyncTask([this, fromInfo, toInfo]() mutable { return windowController_->NotifyWindowTransition(fromInfo, toInfo); }); return WMError::WM_OK; } else { WLOGFI("NotifyWindowTransition synchronously."); - return wmsTaskLooper_->ScheduleTask([this, &fromInfo, &toInfo]() { + return PostSyncTask([this, &fromInfo, &toInfo]() { return windowController_->NotifyWindowTransition(fromInfo, toInfo); - }).get(); + }); } } WMError WindowManagerService::GetFocusWindowInfo(sptr& abilityToken) { - return wmsTaskLooper_->ScheduleTask([this, &abilityToken]() { + return PostSyncTask([this, &abilityToken]() { return windowController_->GetFocusWindowInfo(abilityToken); - }).get(); + }); } void WindowManagerService::StartingWindow(sptr info, sptr pixelMap, @@ -345,8 +374,8 @@ void WindowManagerService::StartingWindow(sptr info, sptr< WLOGFI("startingWindow not open!"); return; } - return wmsTaskLooper_->PostTask([this, info, pixelMap, isColdStart, bkgColor]() { - return windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart); + PostAsyncTask([this, info, pixelMap, isColdStart, bkgColor]() { + windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart); }); } @@ -357,8 +386,8 @@ void WindowManagerService::CancelStartingWindow(sptr abilityToken WLOGFI("startingWindow not open!"); return; } - return wmsTaskLooper_->PostTask([this, abilityToken]() { - return windowController_->CancelStartingWindow(abilityToken); + PostAsyncTask([this, abilityToken]() { + windowController_->CancelStartingWindow(abilityToken); }); } @@ -375,19 +404,19 @@ WMError WindowManagerService::CreateWindow(sptr& window, sptrScheduleTask([this, pid, uid, &window, &property, &surfaceNode, &windowId, &token]() { + WMError ret = PostSyncTask([this, pid, uid, &window, &property, &surfaceNode, &windowId, &token]() { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:CreateWindow(%u)", windowId); return windowController_->CreateWindow(window, property, surfaceNode, windowId, token, pid, uid); - }).get(); + }); accessTokenIdMaps_.insert(std::pair(windowId, IPCSkeleton::GetCallingTokenID())); return ret; } WMError WindowManagerService::AddWindow(sptr& property) { - return wmsTaskLooper_->ScheduleTask([this, &property]() { + return PostSyncTask([this, &property]() { return HandleAddWindow(property); - }).get(); + }); } WMError WindowManagerService::HandleAddWindow(sptr& property) @@ -411,11 +440,11 @@ WMError WindowManagerService::HandleAddWindow(sptr& property) WMError WindowManagerService::RemoveWindow(uint32_t windowId) { - return wmsTaskLooper_->ScheduleTask([this, windowId]() { + return PostSyncTask([this, windowId]() { WLOGFI("[WMS] Remove: %{public}u", windowId); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:RemoveWindow(%u)", windowId); return windowController_->RemoveWindowNode(windowId); - }).get(); + }); } WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf) @@ -424,7 +453,7 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf) WLOGFI("Operation rejected"); return WMError::WM_ERROR_INVALID_OPERATION; } - return wmsTaskLooper_->ScheduleTask([this, windowId, onlySelf]() { + return PostSyncTask([this, windowId, onlySelf]() { WLOGFI("[WMS] Destroy: %{public}u", windowId); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:DestroyWindow(%u)", windowId); auto node = windowRoot_->GetWindowNode(windowId); @@ -432,31 +461,31 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf) dragController_->FinishDrag(windowId); } return windowController_->DestroyWindow(windowId, onlySelf); - }).get(); + }); } WMError WindowManagerService::RequestFocus(uint32_t windowId) { - return wmsTaskLooper_->ScheduleTask([this, windowId]() { + return PostSyncTask([this, windowId]() { WLOGFI("[WMS] RequestFocus: %{public}u", windowId); return windowController_->RequestFocus(windowId); - }).get(); + }); } WMError WindowManagerService::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) { - return wmsTaskLooper_->ScheduleTask([this, windowId, level]() { + return PostSyncTask([this, windowId, level]() { return windowController_->SetWindowBackgroundBlur(windowId, level); - }).get(); + }); } AvoidArea WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { - return wmsTaskLooper_->ScheduleTask([this, windowId, avoidAreaType]() { + return PostSyncTask([this, windowId, avoidAreaType]() { WLOGFI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId, static_cast(avoidAreaType)); return windowController_->GetAvoidAreaByType(windowId, avoidAreaType); - }).get(); + }); } void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type, @@ -466,12 +495,12 @@ void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType typ WLOGFE("windowManagerAgent is null"); return; } - return wmsTaskLooper_->ScheduleTask([this, &windowManagerAgent, type]() { + PostVoidSyncTask([this, &windowManagerAgent, type]() { WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type); if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR) { // if system bar, notify once windowController_->NotifySystemBarTints(); } - }).wait(); + }); } void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, @@ -481,9 +510,9 @@ void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType t WLOGFE("windowManagerAgent is null"); return; } - return wmsTaskLooper_->ScheduleTask([this, &windowManagerAgent, type]() { + PostVoidSyncTask([this, &windowManagerAgent, type]() { WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type); - }).wait(); + }); } WMError WindowManagerService::SetWindowAnimationController(const sptr& controller) @@ -495,28 +524,28 @@ WMError WindowManagerService::SetWindowAnimationController(const sptr deathRecipient = new AgentDeathRecipient( [this](sptr& remoteObject) { - wmsTaskLooper_->ScheduleTask([&remoteObject]() { + PostVoidSyncTask([&remoteObject]() { RemoteAnimation::OnRemoteDie(remoteObject); - }).wait(); + }); } ); controller->AsObject()->AddDeathRecipient(deathRecipient); - return wmsTaskLooper_->ScheduleTask([this, &controller]() { + return PostSyncTask([this, &controller]() { return windowController_->SetWindowAnimationController(controller); - }).get(); + }); } void WindowManagerService::OnWindowEvent(Event event, const sptr& remoteObject) { if (event == Event::REMOTE_DIED) { - return wmsTaskLooper_->ScheduleTask([this, &remoteObject, event]() { + PostVoidSyncTask([this, &remoteObject, event]() { uint32_t windowId = windowRoot_->GetWindowIdByObject(remoteObject); auto node = windowRoot_->GetWindowNode(windowId); if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { dragController_->FinishDrag(windowId); } windowController_->DestroyWindow(windowId, true); - }).wait(); + }); } } @@ -530,7 +559,7 @@ void WindowManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, } else if (type == DisplayStateChangeType::UNFREEZE) { freezeDisplayController_->UnfreezeDisplay(displayId); } else { - wmsTaskLooper_->PostTask([this, defaultDisplayId, displayInfo, displayInfoMap, type]() mutable { + PostAsyncTask([this, defaultDisplayId, displayInfo, displayInfoMap, type]() mutable { windowController_->NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); }); } @@ -554,21 +583,21 @@ void DisplayChangeListener::OnScreenshot(DisplayId displayId) void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isStartDrag) { - return wmsTaskLooper_->PostTask([this, windowId, isStartDrag]() { + PostAsyncTask([this, windowId, isStartDrag]() { windowController_->ProcessPointDown(windowId, isStartDrag); }); } void WindowManagerService::ProcessPointUp(uint32_t windowId) { - return wmsTaskLooper_->PostTask([this, windowId]() { + PostAsyncTask([this, windowId]() { windowController_->ProcessPointUp(windowId); }); } void WindowManagerService::MinimizeAllAppWindows(DisplayId displayId) { - return wmsTaskLooper_->PostTask([this, displayId]() { + PostAsyncTask([this, displayId]() { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:MinimizeAllAppWindows(%" PRIu64")", displayId); WLOGFI("displayId %{public}" PRIu64"", displayId); windowController_->MinimizeAllAppWindows(displayId); @@ -577,7 +606,7 @@ void WindowManagerService::MinimizeAllAppWindows(DisplayId displayId) WMError WindowManagerService::ToggleShownStateForAllAppWindows() { - wmsTaskLooper_->PostTask([this]() { + PostAsyncTask([this]() { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:ToggleShownStateForAllAppWindows"); return windowController_->ToggleShownStateForAllAppWindows(); }); @@ -586,18 +615,18 @@ WMError WindowManagerService::ToggleShownStateForAllAppWindows() WMError WindowManagerService::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) { - return wmsTaskLooper_->ScheduleTask([this, &topWinId, mainWinId]() { + return PostSyncTask([this, &topWinId, mainWinId]() { return windowController_->GetTopWindowId(mainWinId, topWinId); - }).get(); + }); } WMError WindowManagerService::SetWindowLayoutMode(WindowLayoutMode mode) { - return wmsTaskLooper_->ScheduleTask([this, mode]() { + return PostSyncTask([this, mode]() { WLOGFI("layoutMode: %{public}u", mode); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:SetWindowLayoutMode"); return windowController_->SetWindowLayoutMode(mode); - }).get(); + }); } WMError WindowManagerService::UpdateProperty(sptr& windowProperty, PropertyChangeAction action) @@ -607,12 +636,12 @@ WMError WindowManagerService::UpdateProperty(sptr& windowPropert return WMError::WM_ERROR_NULLPTR; } if (action == PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY) { - wmsTaskLooper_->PostTask([this, windowProperty, action]() mutable { + PostAsyncTask([this, windowProperty, action]() mutable { windowController_->UpdateProperty(windowProperty, action); }); return WMError::WM_OK; } - return wmsTaskLooper_->ScheduleTask([this, &windowProperty, action]() { + return PostSyncTask([this, &windowProperty, action]() { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:UpdateProperty"); WMError res = windowController_->UpdateProperty(windowProperty, action); if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK && @@ -620,7 +649,7 @@ WMError WindowManagerService::UpdateProperty(sptr& windowPropert dragController_->UpdateDragInfo(windowProperty->GetWindowId()); } return res; - }).get(); + }); } WMError WindowManagerService::GetAccessibilityWindowInfo(sptr& windowInfo) @@ -629,9 +658,9 @@ WMError WindowManagerService::GetAccessibilityWindowInfo(sptrScheduleTask([this, &windowInfo]() { + return PostSyncTask([this, &windowInfo]() { return windowRoot_->GetAccessibilityWindowInfo(windowInfo); - }).get(); + }); } WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig) @@ -653,21 +682,21 @@ WMError WindowManagerService::GetModeChangeHotZones(DisplayId displayId, ModeCha void WindowManagerService::MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback) { - return wmsTaskLooper_->ScheduleTask([this, windowIds, isAnimated, &finishCallback]() mutable { - return windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback); - }).get(); + PostVoidSyncTask([this, windowIds, isAnimated, &finishCallback]() mutable { + windowController_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback); + }); } void WindowManagerService::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) { - wmsTaskLooper_->ScheduleTask([this, displayId, &orientation]() mutable { + PostVoidSyncTask([this, displayId, &orientation]() mutable { orientation = windowController_->GetWindowPreferredOrientation(displayId); - }).wait(); + }); } WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool haveAvoidAreaListener) { - return wmsTaskLooper_->ScheduleTask([this, windowId, haveAvoidAreaListener]() { + return PostSyncTask([this, windowId, haveAvoidAreaListener]() { sptr node = windowRoot_->GetWindowNode(windowId); if (node == nullptr) { WLOGFE("get window node failed. win %{public}u", windowId); @@ -680,19 +709,19 @@ WMError WindowManagerService::UpdateAvoidAreaListener(uint32_t windowId, bool ha } container->UpdateAvoidAreaListener(node, haveAvoidAreaListener); return WMError::WM_OK; - }).get(); + }); } WMError WindowManagerService::UpdateRsTree(uint32_t windowId, bool isAdd) { - return wmsTaskLooper_->ScheduleTask([this, windowId, isAdd]() { + return PostSyncTask([this, windowId, isAdd]() { return windowRoot_->UpdateRsTree(windowId, isAdd); - }).get(); + }); } void WindowManagerService::OnScreenshot(DisplayId displayId) { - wmsTaskLooper_->PostTask([this, displayId]() { + PostAsyncTask([this, displayId]() { windowController_->OnScreenshot(displayId); }); } diff --git a/wmserver/src/window_task_looper.cpp b/wmserver/src/window_task_looper.cpp deleted file mode 100644 index 914185e1..00000000 --- a/wmserver/src/window_task_looper.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2022 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_task_looper.h" - -namespace OHOS { -namespace Rosen { -void WindowTaskLooper::PostTask(const Task& task) -{ - { - std::lock_guard lock(mtx_); - taskQ_.emplace_back(task); - } - WakeUp(); -} - -void WindowTaskLooper::WaitTask() -{ - std::unique_lock lock(mtx_); - if (!wakeUp_ && taskQ_.empty()) { - taskCond_.wait( - lock, - [this] () { - return !taskQ_.empty() || wakeUp_; - }); - } - wakeUp_ = false; -} - -void WindowTaskLooper::WakeUp() -{ - std::lock_guard lock(mtx_); - wakeUp_ = true; - taskCond_.notify_one(); -} - -void WindowTaskLooper::Start() noexcept -{ - taskProcessThread_ = std::make_unique([this]() { - TaskProcessThread(); - }); - taskProcessThread_->detach(); -} - -void WindowTaskLooper::TaskProcessThread() -{ - if (running_) { - return; - } - running_ = true; - while (running_) { - WaitTask(); - ExecuteAllTask(); - } -} - -void WindowTaskLooper::ExecuteAllTask() -{ - std::vector tasks; - { - std::lock_guard lock(mtx_); - tasks.swap(taskQ_); - } - for (const auto& task : tasks) { - if (task != nullptr) { - task(); - } - } -} - -bool WindowTaskLooper::IsRunning() -{ - return running_; -} - -WindowTaskLooper::~WindowTaskLooper() -{ - std::lock_guard lock(mtx_); - running_ = false; - taskQ_.clear(); -} -} // namespace Rosen -} // namespace OHOS \ No newline at end of file