diff --git a/adapter/ohos/entrance/rs_adapter.cpp b/adapter/ohos/entrance/rs_adapter.cpp index e754e72e05a41ec50604e9c3ab0a756ea97cc93c..93ac9c7cf7188a4165cfcd080afd1d763a7f295e 100644 --- a/adapter/ohos/entrance/rs_adapter.cpp +++ b/adapter/ohos/entrance/rs_adapter.cpp @@ -36,7 +36,9 @@ void RsAdapter::RsUIDirectorInit( } rsUiDirector->SetRSSurfaceNode(window->GetSurfaceNode()); rsUiDirector->SetCacheDir(cacheDir); - rsUiDirector->Init(true, true); + if (!rsUiDirector->GetRSUIContext()) { + rsUiDirector->Init(true, true); + } } } @@ -57,7 +59,9 @@ void RsAdapter::RsFlushImplicitTransaction( if (!rsUiDirector) { rsUiDirector = Rosen::RSUIDirector::Create(); } - rsUiDirector->Init(true, true); + if (!rsUiDirector->GetRSUIContext()) { + rsUiDirector->Init(true, true); + } auto surfaceNode = dragWindow->GetSurfaceNode(); if (surfaceNode) { auto rsUiContext = surfaceNode->GetRSUIContext(); @@ -93,7 +97,9 @@ void RsAdapter::RsFlushImplicitTransactionWithRoot( if (!rsUiDirector) { rsUiDirector = Rosen::RSUIDirector::Create(); } - rsUiDirector->Init(true, true); + if (!rsUiDirector->GetRSUIContext()) { + rsUiDirector->Init(true, true); + } auto surfaceNode = dragWindow->GetSurfaceNode(); std::shared_ptr rsUiContext; if (surfaceNode) { diff --git a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp index a449265c2aea9315ebc64e2d8f9e0d735aaa5523..1766d0c706c23084f56ec010ab1189bd8930bc02 100644 --- a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp +++ b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp @@ -250,7 +250,17 @@ void SubwindowOhos::InitWindowRSUIDirector(const RefPtr& if (context != nullptr) { context->SetRSUIDirector(rsUiDirector); } - rsUiDirector->Init(true, true); + if (!rsUiDirector->GetRSUIContext()) { + rsUiDirector->Init(true, true); + } + auto id = container->GetInstanceId(); + rsUiDirector->SetUITaskRunner( + [taskExecutor = container->GetTaskExecutor(), id]( + const std::function& task, uint32_t delay) { + ContainerScope scope(id); + taskExecutor->PostDelayedTask( + task, TaskExecutor::TaskType::UI, delay, "ArkUIRenderServiceTask", PriorityType::HIGH); + }, 0, true); TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "UIContent Init Rosen Backend"); } #endif @@ -1508,7 +1518,17 @@ void SubwindowOhos::InitDialogWindowRSUIDirector(const RefPtrSetRSUIDirector(rsUiDirector); } - rsUiDirector->Init(true, true); + if (!rsUiDirector->GetRSUIContext()) { + rsUiDirector->Init(true, true); + } + auto id = container->GetInstanceId(); + rsUiDirector->SetUITaskRunner( + [taskExecutor = container->GetTaskExecutor(), id]( + const std::function& task, uint32_t delay) { + ContainerScope scope(id); + taskExecutor->PostDelayedTask( + task, TaskExecutor::TaskType::UI, delay, "ArkUIRenderServiceTask", PriorityType::HIGH); + }, 0, true); } #endif } diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 15e32df39e7c8e45b3a7574a9567f99a9159ec85..0572c4b477973b1e59278f0f5d1b7bab34a2f7dd 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -279,7 +279,7 @@ bool IsContainerDeleteFlag() bool IsMultiInstanceEnabled() { - return (system::GetParameter("persist.rosen.rsclientmultiinstance.enabled", "0") != "0"); + return (system::GetParameter("persist.rosen.rsclientmultiinstance.enabled", "1") != "0"); } bool IsLayoutDetectEnabled() diff --git a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp index cd4c3b890d5abfc6dee665ee89c45792263432fd..eb6ba124ad69e94f3d26de6c10b73fae9eed7e79 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp @@ -330,8 +330,10 @@ std::shared_ptr AnimationUtils::CreateInte auto wrappedOnFinish = GetWrappedCallback(callback); Rosen::RSAnimationTimingProtocol timingProtocol; Rosen::RSAnimationTimingCurve curve; + auto context = PipelineBase::GetCurrentContext(); + auto rsUIContext = GetRSUIContext(context); interactiveAnimation->interactiveAnimation_ = - Rosen::RSInteractiveImplictAnimator::Create(timingProtocol, curve); + Rosen::RSInteractiveImplictAnimator::Create(rsUIContext, timingProtocol, curve); CHECK_NULL_RETURN(interactiveAnimation->interactiveAnimation_, nullptr); if (addCallback) { interactiveAnimation->interactiveAnimation_->AddAnimation(addCallback); diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp index a8e336351c0a7e17a502b199495813cb0f643a35..52756fa6fd448c457844559a7e09812c368351c9 100755 --- a/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_context.cpp @@ -7350,7 +7350,7 @@ void RosenRenderContext::UpdateWindowBlur() CHECK_NULL_VOID(rsWindow); auto surfaceNode = rsWindow->GetSurfaceNode(); CHECK_NULL_VOID(surfaceNode); - auto rsUIContext = rsNode_->GetRSUIContext(); + auto rsUIContext = surfaceNode->GetRSUIContext(); auto rsNodeTmp = rsUIContext ? rsUIContext->GetNodeMap().GetNode(surfaceNode->GetId()) : Rosen::RSNodeMap::Instance().GetNode(surfaceNode->GetId()); AnimationOption option; @@ -7363,7 +7363,7 @@ void RosenRenderContext::UpdateWindowBlur() windowBlurModifier_->SetBehindWindowFilterSaturation(blurParam->saturation); windowBlurModifier_->SetBehindWindowFilterBrightness(blurParam->brightness); windowBlurModifier_->SetBehindWindowFilterMaskColor(Rosen::RSColor(rgbaColor)); - if (needAddModifier) { + if (needAddModifier && rsNodeTmp) { rsNodeTmp->AddModifier(windowBlurModifier_); } #else diff --git a/frameworks/core/components_ng/render/adapter/rosen_window.cpp b/frameworks/core/components_ng/render/adapter/rosen_window.cpp index bfc027c7af08c99cd15e1bc9691f4451c7078323..27b556f4be15d8214ea6af372fbfbf144bf5d8fa 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_window.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_window.cpp @@ -104,7 +104,9 @@ RosenWindow::RosenWindow(const OHOS::sptr& window, RefPtrSetRSSurfaceNode(window->GetSurfaceNode()); } rsUIDirector_->SetCacheDir(AceApplicationInfo::GetInstance().GetDataFileDirPath()); - rsUIDirector_->Init(true, true); + if (!rsUIDirector_->GetRSUIContext()) { + rsUIDirector_->Init(true, true); + } } rsUIDirector_->SetUITaskRunner( diff --git a/test/unittest/core/base/frame_node_test_ng.cpp b/test/unittest/core/base/frame_node_test_ng.cpp index 471e216044ca8b5d970d7ec2e89f0c14c59b3099..6c36250a87357c6c33e36d7fa717754aaea4cda8 100644 --- a/test/unittest/core/base/frame_node_test_ng.cpp +++ b/test/unittest/core/base/frame_node_test_ng.cpp @@ -2801,4 +2801,25 @@ HWTEST_F(FrameNodeTestNg, FrameNodeTestNg311, TestSize.Level1) EXPECT_EQ(result, false); pattern_ = nullptr; } + +/** + * @tc.name: AttachContext001 + * @tc.desc: Test frame node method + * @tc.type: FUNC + */ +HWTEST_F(FrameNodeTestNg, AttachContext001, TestSize.Level1) +{ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + auto node = FrameNode::CreateFrameNode("main", 1, AceType::MakeRefPtr(), true); + ASSERT_NE(node, nullptr); + node->GetOrCreateGestureEventHub(); + SystemProperties::multiInstanceEnabled_ = true; + node->AttachContext(AceType::RawPtr(context)); + auto mockRenderContext = AceType::MakeRefPtr(); + node->renderContext_ = mockRenderContext; + EXPECT_EQ(node->context_, AceType::RawPtr(context)); + node->DetachContext(true); + EXPECT_EQ(node->context_, nullptr); +} } // namespace OHOS::Ace::NG