From eba1024dee02cba23bfde77d5ce34a0fe37648aa Mon Sep 17 00:00:00 2001 From: qianlf Date: Tue, 1 Mar 2022 14:18:21 +0800 Subject: [PATCH] notify ace before window destroy Signed-off-by: qianlf Change-Id: I8135b09145e4a830264f9ab151cb8ddcaf57ad38 --- interfaces/innerkits/wm/window.h | 5 +++++ wm/include/window_impl.h | 8 ++++++++ wm/src/window_impl.cpp | 14 +++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index b89c3299..75f425e6 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -38,6 +38,10 @@ namespace OHOS::AbilityRuntime { class Context; } +namespace OHOS::Ace { + class UIContent; +} + namespace OHOS { namespace Rosen { class RSSurfaceNode; @@ -125,6 +129,7 @@ public: virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual std::string GetContentInfo() = 0; + virtual Ace::UIContent* GetUIContent() const = 0; virtual bool IsDecorEnable() const = 0; virtual WMError Maximize() = 0; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 0e4fac89..30c5c63d 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -127,6 +127,7 @@ public: NativeValue* storage, bool isdistributed) override; virtual std::string GetContentInfo() override; virtual const std::shared_ptr GetContext() const override; + virtual Ace::UIContent* GetUIContent() const override; // colorspace, gamut virtual bool IsSupportWideGamut() override; @@ -158,6 +159,13 @@ private: uiContent_->Destroy(); } } + inline void NotifyBeforeSubWindowDestroy(sptr& window) const + { + auto uiContent = window->GetUIContent(); + if (uiContent != nullptr) { + uiContent->Destroy(); + } + } void SetDefaultOption(); // for api7 bool IsWindowValid() const; void OnVsync(int64_t timeStamp); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 8f401138..721ab646 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -365,6 +365,11 @@ WMError WindowImpl::SetUIContent(const std::string& contentInfo, return WMError::WM_OK; } +Ace::UIContent* WindowImpl::GetUIContent() const +{ + return uiContent_.get(); +} + std::string WindowImpl::GetContentInfo() { WLOGFI("GetContentInfo"); @@ -586,7 +591,13 @@ WMError WindowImpl::Destroy() WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId()); - // FixMe: Remove "NotifyBeforeDestroy()" because of ACE bug, add when fixed + NotifyBeforeDestroy(); + if (subWindowMap_.count(GetWindowId()) > 0) { + for (auto& subWindow : subWindowMap_.at(GetWindowId())) { + NotifyBeforeSubWindowDestroy(subWindow); + } + } + WMError ret = SingletonContainer::Get().DestroyWindow(property_->GetWindowId()); if (ret != WMError::WM_OK) { WLOGFE("destroy window failed with errCode:%{public}d", static_cast(ret)); @@ -607,6 +618,7 @@ WMError WindowImpl::Destroy() // Destroy app floating window if exist if (appFloatingWindowMap_.count(GetWindowId()) > 0) { for (auto& floatingWindow : appFloatingWindowMap_.at(GetWindowId())) { + NotifyBeforeSubWindowDestroy(floatingWindow); WMError fltRet = SingletonContainer::Get().DestroyWindow(floatingWindow->GetWindowId()); if (fltRet == WMError::WM_OK) { WLOGFI("Destroy App %{public}d FltWindow %{public}d", GetWindowId(), floatingWindow->GetWindowId());