From ba23643ff3ec6b50d8dbbcf2ccbc3ebac05bf22f Mon Sep 17 00:00:00 2001 From: xingyanan Date: Mon, 24 Jan 2022 18:01:32 +0800 Subject: [PATCH] split screen bugfix Signed-off-by: xingyanan Change-Id: I71b59f426d058fc9d7dadce86857040041840785 --- wmserver/include/window_inner_manager.h | 9 +-- wmserver/src/window_inner_manager.cpp | 87 ++++++++++++++----------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/wmserver/include/window_inner_manager.h b/wmserver/include/window_inner_manager.h index 386d5489..4dc13984 100644 --- a/wmserver/include/window_inner_manager.h +++ b/wmserver/include/window_inner_manager.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef ACE_ENABLE_GL #include "render_context/render_context.h" #endif @@ -53,9 +54,9 @@ private: static inline SingletonDelegator delegator; sptr CreateWindow(uint32_t displayId, const WindowType& type, const Rect& rect); - void CreateAndShowDivider(); - void HideAndDestroyDivider(); - void DestroyThread(); + void CreateAndShowDivider(std::unique_ptr msg); + void HideAndDestroyDivider(std::unique_ptr msg); + void DestroyThread(std::unique_ptr msg); void DrawSurface(const sptr& window, uint32_t color); sptr GetDividerWindow(uint32_t displayId) const; @@ -66,7 +67,7 @@ private: RenderContext* rc_ = nullptr; #endif std::map> dividerMap_; - std::unique_ptr winMsg_; + std::vector> messages_; bool hasInitThread_ = false; bool needDestroyThread_ = false; }; diff --git a/wmserver/src/window_inner_manager.cpp b/wmserver/src/window_inner_manager.cpp index 43ff3144..591db984 100644 --- a/wmserver/src/window_inner_manager.cpp +++ b/wmserver/src/window_inner_manager.cpp @@ -109,9 +109,9 @@ sptr WindowInnerManager::CreateWindow(uint32_t displayId, const WindowTy return window; } -void WindowInnerManager::CreateAndShowDivider() +void WindowInnerManager::CreateAndShowDivider(std::unique_ptr msg) { - auto window = CreateWindow(winMsg_->displayId, WindowType::WINDOW_TYPE_DOCK_SLICE, winMsg_->dividerRect); + auto window = CreateWindow(msg->displayId, WindowType::WINDOW_TYPE_DOCK_SLICE, msg->dividerRect); if (window == nullptr) { return; } @@ -142,9 +142,9 @@ void WindowInnerManager::CreateAndShowDivider() WLOGFI("CreateAndShowDivider success"); } -void WindowInnerManager::HideAndDestroyDivider() +void WindowInnerManager::HideAndDestroyDivider(std::unique_ptr msg) { - sptr window = GetDividerWindow(winMsg_->displayId); + sptr window = GetDividerWindow(msg->displayId); if (window == nullptr) { WLOGFE("Window is nullptr"); return; @@ -154,11 +154,11 @@ void WindowInnerManager::HideAndDestroyDivider() WLOGFE("Destroy window failed"); return; } - dividerMap_.erase(winMsg_->displayId); + dividerMap_.erase(msg->displayId); WLOGFI("HideAndDestroyDivider success"); } -void WindowInnerManager::DestroyThread() +void WindowInnerManager::DestroyThread(std::unique_ptr msg) { hasInitThread_ = false; needDestroyThread_ = true; @@ -168,68 +168,77 @@ void WindowInnerManager::DestroyThread() void WindowInnerManager::HandleMessage() { WLOGFI("HandleMessage"); + std::vector> handleMsgs; while (!needDestroyThread_) { - std::unique_lock lk(mutex_); - conVar_.wait(lk, [this] { return ready_; }); - - auto cmdType = winMsg_->cmdType; - using Func_t = void(WindowInnerManager::*)(); - static const std::map funcMap = { - std::make_pair(INNER_WM_CREATE_DIVIDER, &WindowInnerManager::CreateAndShowDivider), - std::make_pair(INNER_WM_DESTROY_DIVIDER, &WindowInnerManager::HideAndDestroyDivider), - std::make_pair(INNER_WM_DESTROY_THREAD, &WindowInnerManager::DestroyThread) - }; - auto it = funcMap.find(cmdType); - if (it != funcMap.end()) { - (this->*(it->second))(); + // lock to store massages + { + std::unique_lock lk(mutex_); + conVar_.wait(lk, [this] { return ready_; }); + for (auto& iter: messages_) { + handleMsgs.push_back(std::move(iter)); + } + messages_.clear(); + ready_ = false; } - ready_ = false; + // loop to handle massages + for (auto& msg : handleMsgs) { + auto cmdType = msg->cmdType; + using Func_t = void(WindowInnerManager::*)(std::unique_ptr winMsg); + static const std::map funcMap = { + std::make_pair(INNER_WM_CREATE_DIVIDER, &WindowInnerManager::CreateAndShowDivider), + std::make_pair(INNER_WM_DESTROY_DIVIDER, &WindowInnerManager::HideAndDestroyDivider), + std::make_pair(INNER_WM_DESTROY_THREAD, &WindowInnerManager::DestroyThread)}; + auto it = funcMap.find(cmdType); + if (it != funcMap.end()) { + (this->*(it->second))(std::move(msg)); + } + } + handleMsgs.clear(); } } void WindowInnerManager::SendMessage(InnerWMCmd cmdType, uint32_t displayId) { + std::unique_lock lk(mutex_); if (!hasInitThread_) { WLOGFI("Inner window manager thread has not been created"); return; } - winMsg_->cmdType = cmdType; - winMsg_->displayId = displayId; - + std::unique_ptr winMsg = std::make_unique(); + winMsg->cmdType = cmdType; + winMsg->displayId = displayId; + WLOGFI("SendMessage : displayId = %{public}d, type = %{public}d", + winMsg->displayId, static_cast(cmdType)); + messages_.push_back(std::move(winMsg)); ready_ = true; conVar_.notify_one(); - - WLOGFI("SendMessage : displayId = %{public}d, type = %{public}d", - winMsg_->displayId, static_cast(cmdType)); } void WindowInnerManager::SendMessage(InnerWMCmd cmdType, uint32_t displayId, const Rect& dividerRect) { + std::unique_lock lk(mutex_); if (!hasInitThread_) { WLOGFI("Inner window manager thread has not been created"); return; } - winMsg_->cmdType = cmdType; - winMsg_->displayId = displayId; - winMsg_->dividerRect = dividerRect; - - ready_ = true; - conVar_.notify_one(); - + std::unique_ptr winMsg = std::make_unique(); + winMsg->cmdType = cmdType; + winMsg->displayId = displayId; + winMsg->dividerRect = dividerRect; WLOGFI("SendMessage : displayId = %{public}d, type = %{public}d" \ " Rect = [%{public}d %{public}d %{public}d %{public}d]", - winMsg_->displayId, static_cast(cmdType), - winMsg_->dividerRect.posX_, winMsg_->dividerRect.posY_, - winMsg_->dividerRect.width_, winMsg_->dividerRect.height_); + winMsg->displayId, static_cast(cmdType), + winMsg->dividerRect.posX_, winMsg->dividerRect.posY_, + winMsg->dividerRect.width_, winMsg->dividerRect.height_); + messages_.push_back(std::move(winMsg)); + ready_ = true; + conVar_.notify_one(); } - void WindowInnerManager::Init() { std::unique_lock lk(mutex_); needDestroyThread_ = false; - winMsg_ = std::make_unique(); - // create inner thread std::thread innerWMThread(&WindowInnerManager::HandleMessage, this); innerWMThread.detach();