From abe185d9cdbb3b9fefbcb1b8897b8062784cebdd Mon Sep 17 00:00:00 2001 From: maojiangping Date: Thu, 27 Jan 2022 19:10:53 +0800 Subject: [PATCH] add WindowName for debug Signed-off-by: maojiangping Change-Id: Ic633ded829724b068670348110938451aa5805df Signed-off-by: maojiangping --- interfaces/innerkits/wm/window_scene.h | 1 + utils/include/window_property.h | 3 +++ utils/src/window_property.cpp | 16 ++++++++++++++++ wm/src/window_impl.cpp | 2 ++ wm/src/window_scene.cpp | 14 +++++++++++++- wmserver/include/window_node.h | 1 + wmserver/src/window_node.cpp | 5 +++++ wmserver/src/window_node_container.cpp | 12 ++++++++---- 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/interfaces/innerkits/wm/window_scene.h b/interfaces/innerkits/wm/window_scene.h index 8ce65eff..ec59f9ea 100644 --- a/interfaces/innerkits/wm/window_scene.h +++ b/interfaces/innerkits/wm/window_scene.h @@ -58,6 +58,7 @@ private: DisplayId displayId_ = DEFAULT_DISPLAY_ID; std::shared_ptr context_ = nullptr; + std::string GenerateMainWindowName(const std::shared_ptr& context) const; }; } // namespace Rosen } // namespace OHOS diff --git a/utils/include/window_property.h b/utils/include/window_property.h index ee53f216..192c5b88 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -29,6 +29,7 @@ public: WindowProperty() = default; ~WindowProperty() = default; + void SetWindowName(const std::string& name); void SetWindowRect(const struct Rect& rect); void SetWindowType(WindowType type); void SetWindowMode(WindowMode mode); @@ -46,6 +47,7 @@ public: void SetSystemBarProperty(WindowType type, const SystemBarProperty& state); void SetDecorEnable(bool decorEnable); + const std::string& GetWindowName() const; Rect GetWindowRect() const; WindowType GetWindowType() const; WindowMode GetWindowMode() const; @@ -65,6 +67,7 @@ public: virtual bool Marshalling(Parcel& parcel) const override; static sptr Unmarshalling(Parcel& parcel); private: + std::string windowName_; Rect windowRect_ { 0, 0, 0, 0 }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN }; diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 52c29cf6..233addaf 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -18,6 +18,11 @@ namespace OHOS { namespace Rosen { +void WindowProperty::SetWindowName(const std::string& name) +{ + windowName_ = name; +} + void WindowProperty::SetWindowRect(const struct Rect& rect) { windowRect_ = rect; @@ -96,6 +101,11 @@ void WindowProperty::ResumeLastWindowMode() mode_ = lastMode_; } +const std::string& WindowProperty::GetWindowName() const +{ + return windowName_ ; +} + Rect WindowProperty::GetWindowRect() const { return windowRect_; @@ -212,6 +222,11 @@ void WindowProperty::MapUnmarshalling(Parcel& parcel, sptr& prop bool WindowProperty::Marshalling(Parcel& parcel) const { + // write windowName_ + if (!parcel.WriteString(windowName_)) { + return false; + } + // write windowRect_ if (!(parcel.WriteInt32(windowRect_.posX_) && parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) && parcel.WriteUint32(windowRect_.height_))) { @@ -293,6 +308,7 @@ bool WindowProperty::Marshalling(Parcel& parcel) const sptr WindowProperty::Unmarshalling(Parcel& parcel) { sptr property(new WindowProperty()); + property->SetWindowName(parcel.ReadString()); Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() }; property->SetWindowRect(rect); property->SetWindowType(static_cast(parcel.ReadUint32())); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index fb9b42e3..e6a157a4 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -39,6 +39,7 @@ std::map>> WindowImpl::subWindowMap_; WindowImpl::WindowImpl(const sptr& option) { property_ = new WindowProperty(); + property_->SetWindowName(option->GetWindowName()); property_->SetWindowRect(option->GetWindowRect()); property_->SetWindowType(option->GetWindowType()); property_->SetWindowMode(option->GetWindowMode()); @@ -55,6 +56,7 @@ WindowImpl::WindowImpl(const sptr& option) callback_->onCallback = std::bind(&WindowImpl::OnVsync, this, std::placeholders::_1); struct RSSurfaceNodeConfig rsSurfaceNodeConfig; + rsSurfaceNodeConfig.SurfaceNodeName = property_->GetWindowName(); surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); } diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 4500f30d..96077bd3 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -14,6 +14,7 @@ */ #include "window_scene.h" + #include #include "static_call.h" @@ -47,7 +48,7 @@ WMError WindowScene::Init(DisplayId displayId, const std::shared_ptrSetDisplayId(displayId); mainWindow_ = SingletonContainer::Get().CreateWindow( - MAIN_WINDOW_ID + std::to_string(count++), option, context); + GenerateMainWindowName(context), option, context); if (mainWindow_ == nullptr) { return WMError::WM_ERROR_NULLPTR; } @@ -56,6 +57,17 @@ WMError WindowScene::Init(DisplayId displayId, const std::shared_ptr& context) const +{ + if (context == nullptr) { + return MAIN_WINDOW_ID + std::to_string(count++); + } else { + std::string windowName = context->GetBundleName() + std::to_string(count++); + std::size_t pos = windowName.find_last_of('.'); + return (pos < 0) ? windowName : windowName.substr(pos + 1); // skip '.' + } +} + sptr WindowScene::CreateWindow(const std::string& windowName, sptr& option) const { if (windowName.empty() || mainWindow_ == nullptr || option == nullptr) { diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index cddd197b..18b5a7cd 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -50,6 +50,7 @@ public: const sptr& GetWindowToken() const; uint32_t GetWindowId() const; uint32_t GetParentId() const; + const std::string& GetWindowName() const; DisplayId GetDisplayId() const; const Rect& GetLayoutRect() const; WindowType GetWindowType() const; diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index eb86d456..9b811d0b 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -58,6 +58,11 @@ DisplayId WindowNode::GetDisplayId() const return property_->GetDisplayId(); } +const std::string& WindowNode::GetWindowName() const +{ + return property_->GetWindowName(); +} + uint32_t WindowNode::GetWindowId() const { return property_->GetWindowId(); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index bf8a04a9..0ca3374c 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -30,6 +30,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; + constexpr int WINDOW_NAME_MAX_LENGTH = 10; } WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId) @@ -644,15 +645,18 @@ void WindowNodeContainer::OnAvoidAreaChange(const std::vector& avoidArea) void WindowNodeContainer::DumpScreenWindowTree() { WLOGFI("-------- Screen %{public}" PRIu64" dump window info begin---------", screenId_); - WLOGFI("WinId Type Mode Flag ZOrd [ x y w h]"); + WLOGFI("WindowName WinId Type Mode Flag ZOrd [ x y w h]"); std::vector> windowNodes; TraverseContainer(windowNodes); int zOrder = windowNodes.size(); for (auto node : windowNodes) { Rect rect = node->GetLayoutRect(); - WLOGFI("%{public}5d %{public}4d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ - "%{public}4d %{public}4d]", node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(), - node->GetWindowFlags(), --zOrder, rect.posX_, rect.posY_, rect.width_, rect.height_); + const std::string& windowName = node->GetWindowName().size() < WINDOW_NAME_MAX_LENGTH ? + node->GetWindowName() : node->GetWindowName().substr(0, WINDOW_NAME_MAX_LENGTH); + WLOGFI("%{public}10s %{public}5d %{public}4d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", windowName.c_str(), node->GetWindowId(), node->GetWindowType(), + node->GetWindowMode(), node->GetWindowFlags(), + --zOrder, rect.posX_, rect.posY_, rect.width_, rect.height_); } WLOGFI("-------- Screen %{public}" PRIu64" dump window info end ---------", screenId_); }