From 498147608533c9ccc4085009d62b96e59861946a Mon Sep 17 00:00:00 2001 From: liuanguang Date: Tue, 27 May 2025 16:01:20 +0800 Subject: [PATCH] refactor: RS client multi-instance code optimization Signed-off-by: liuanguang Change-Id: I2aaeb84f8ee134f566640074cf4ba1b246e01b6a --- .../helper/window_scene_helper.cpp | 61 +++++++++++++------ .../window_scene/helper/window_scene_helper.h | 7 ++- .../window_scene/scene/input_scene.cpp | 1 + .../window_scene/scene/panel_scene.cpp | 1 + .../window_scene/scene/transform_scene.cpp | 1 + .../window_scene/scene/window_scene.cpp | 1 + .../core/pattern/window_scene/BUILD.gn | 1 + 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.cpp b/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.cpp index 577ce20024e..1cbc551cada 100644 --- a/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.cpp +++ b/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.cpp @@ -26,6 +26,7 @@ #include "core/components_ng/pattern/text_field/text_field_pattern.h" #include "core/components_ng/pattern/search/search_pattern.h" #include "core/pipeline_ng/pipeline_context.h" +#include "parameters.h" #include "session/host/include/session.h" #include "transaction/rs_transaction.h" #include "transaction/rs_transaction_handler.h" @@ -355,8 +356,21 @@ bool WindowSceneHelper::IsNodeInKeyGuardWindow(const RefPtr& node) return sessionWindowType == Rosen::WindowType::WINDOW_TYPE_KEYGUARD; } +bool WindowSceneHelper::IsRSClientMultiInstanceEnabled() +{ + static bool enabled = [] { + bool value = system::GetParameter("persist.rosen.rsclientmultiinstance.enabled", "0") != "0"; + TAG_LOGD(AceLogTag::ACE_WINDOW, "RS multi-instance enabled: %{public}d", value); + return value; + }(); + return enabled; +} + std::shared_ptr WindowSceneHelper::GetRSUIContext(const RefPtr& frameNode) { + if (!IsRSClientMultiInstanceEnabled()) { + return nullptr; + } CHECK_NULL_RETURN(frameNode, nullptr); auto pipeline = frameNode->GetContext(); CHECK_NULL_RETURN(pipeline, nullptr); @@ -371,32 +385,39 @@ std::shared_ptr WindowSceneHelper::GetRSUIContext(const RefP std::shared_ptr WindowSceneHelper::GetRSTransaction(const sptr& session) { - auto rsUIContext = session->GetRSUIContext(__func__); - if (rsUIContext) { - if (auto rsSyncTransHandler = rsUIContext->GetSyncTransactionHandler()) { - return rsSyncTransHandler->GetRSTransaction(); - } + CHECK_NULL_RETURN(session, nullptr); + if (IsRSClientMultiInstanceEnabled()) { + auto rsUIContext = session->GetRSUIContext(); + TAG_LOGD(AceLogTag::ACE_WINDOW, "Use RSSyncTransactionHandler: %{public}s", + RSUIContextToStr(rsUIContext).c_str()); + CHECK_NULL_RETURN(rsUIContext, nullptr); + auto rsSyncTransHandler = rsUIContext->GetSyncTransactionHandler(); + CHECK_NULL_RETURN(rsSyncTransHandler, nullptr); + return rsSyncTransHandler->GetRSTransaction(); + } else { + TAG_LOGD(AceLogTag::ACE_WINDOW, "Fallback to RSSyncTransactionController"); + auto rsSyncTransController = Rosen::RSSyncTransactionController::GetInstance(); + CHECK_NULL_RETURN(rsSyncTransController, nullptr); + return rsSyncTransController->GetRSTransaction(); } - TAG_LOGD(AceLogTag::ACE_WINDOW, "Use RSSyncTransactionController"); - return Rosen::RSSyncTransactionController::GetInstance()->GetRSTransaction(); -} - - -std::shared_ptr WindowSceneHelper::GetRSTransactionHandler( - const RefPtr& frameNode) -{ - auto rsUIContext = GetRSUIContext(frameNode); - CHECK_NULL_RETURN(rsUIContext, nullptr); - return rsUIContext->GetRSTransaction(); } void WindowSceneHelper::FlushImplicitTransaction(const RefPtr& frameNode) { - if (auto transactionHandler = GetRSTransactionHandler(frameNode)) { - transactionHandler->FlushImplicitTransaction(); + CHECK_NULL_VOID(frameNode); + if (IsRSClientMultiInstanceEnabled()) { + auto rsUIContext = GetRSUIContext(frameNode); + TAG_LOGD(AceLogTag::ACE_WINDOW, "Use RSTransactionHandler: %{public}s", + RSUIContextToStr(rsUIContext).c_str()); + CHECK_NULL_VOID(rsUIContext); + auto rsTransHandler = rsUIContext->GetRSTransaction(); + CHECK_NULL_VOID(rsTransHandler); + rsTransHandler->FlushImplicitTransaction(); } else { - TAG_LOGD(AceLogTag::ACE_WINDOW, "RSTransactionHandler is null, use RSTransactionProxy"); - Rosen::RSTransactionProxy::GetInstance()->FlushImplicitTransaction(); + TAG_LOGD(AceLogTag::ACE_WINDOW, "Fallback to RSTransactionProxy"); + auto rsTransProxy = Rosen::RSTransactionProxy::GetInstance(); + CHECK_NULL_VOID(rsTransProxy); + rsTransProxy->FlushImplicitTransaction(); } } diff --git a/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.h b/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.h index 4cd2e77c82c..12bcd289a8c 100644 --- a/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.h +++ b/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.h @@ -95,12 +95,15 @@ public: static bool IsNodeInKeyGuardWindow(const RefPtr& node); + /* + * RS Client Multi Instance + */ + static bool IsRSClientMultiInstanceEnabled(); + static std::shared_ptr GetRSUIContext(const RefPtr& frameNode); static std::shared_ptr GetRSTransaction(const sptr& session); - static std::shared_ptr GetRSTransactionHandler(const RefPtr& frameNode); - static void FlushImplicitTransaction(const RefPtr& frameNode); static std::string RSNodeToStr(const std::shared_ptr& rsNode); diff --git a/frameworks/core/components_ng/pattern/window_scene/scene/input_scene.cpp b/frameworks/core/components_ng/pattern/window_scene/scene/input_scene.cpp index 51abe50abaa..4aa81099f67 100644 --- a/frameworks/core/components_ng/pattern/window_scene/scene/input_scene.cpp +++ b/frameworks/core/components_ng/pattern/window_scene/scene/input_scene.cpp @@ -33,6 +33,7 @@ void InputScene::OnAttachToFrameNode() TAG_LOGD(AceLogTag::ACE_WINDOW, "Create RSCanvasNode: %{public}s", WindowSceneHelper::RSNodeToStr(rsNode).c_str()); CHECK_NULL_VOID(rsNode); + rsNode->SetSkipCheckInMultiInstance(true); context->SetRSNode(rsNode); rsNode->SetBoundsChangedCallback(boundsChangedCallback_); } diff --git a/frameworks/core/components_ng/pattern/window_scene/scene/panel_scene.cpp b/frameworks/core/components_ng/pattern/window_scene/scene/panel_scene.cpp index ed4164faa8b..4cdca9d54ed 100644 --- a/frameworks/core/components_ng/pattern/window_scene/scene/panel_scene.cpp +++ b/frameworks/core/components_ng/pattern/window_scene/scene/panel_scene.cpp @@ -33,6 +33,7 @@ void PanelScene::OnAttachToFrameNode() TAG_LOGD(AceLogTag::ACE_WINDOW, "Create RSCanvasNode: %{public}s", WindowSceneHelper::RSNodeToStr(rsNode).c_str()); CHECK_NULL_VOID(rsNode); + rsNode->SetSkipCheckInMultiInstance(true); context->SetRSNode(rsNode); rsNode->SetBoundsChangedCallback(boundsChangedCallback_); } diff --git a/frameworks/core/components_ng/pattern/window_scene/scene/transform_scene.cpp b/frameworks/core/components_ng/pattern/window_scene/scene/transform_scene.cpp index 5574b99a248..c6e4fc48a8c 100644 --- a/frameworks/core/components_ng/pattern/window_scene/scene/transform_scene.cpp +++ b/frameworks/core/components_ng/pattern/window_scene/scene/transform_scene.cpp @@ -29,6 +29,7 @@ void TransformScene::OnAttachToFrameNode() TAG_LOGD(AceLogTag::ACE_WINDOW, "Create RSCanvasNode: %{public}s", WindowSceneHelper::RSNodeToStr(rsNode).c_str()); CHECK_NULL_VOID(rsNode); + rsNode->SetSkipCheckInMultiInstance(true); context->SetRSNode(rsNode); } diff --git a/frameworks/core/components_ng/pattern/window_scene/scene/window_scene.cpp b/frameworks/core/components_ng/pattern/window_scene/scene/window_scene.cpp index 874a6da1450..39257cc411f 100644 --- a/frameworks/core/components_ng/pattern/window_scene/scene/window_scene.cpp +++ b/frameworks/core/components_ng/pattern/window_scene/scene/window_scene.cpp @@ -99,6 +99,7 @@ std::shared_ptr WindowScene::CreateLeashWindowNode() TAG_LOGD(AceLogTag::ACE_WINDOW, "Create RSSurfaceNode: %{public}s", WindowSceneHelper::RSNodeToStr(surfaceNode).c_str()); CHECK_NULL_RETURN(surfaceNode, nullptr); + surfaceNode->SetSkipCheckInMultiInstance(true); surfaceNode->SetLeashPersistentId(static_cast(session_->GetPersistentId())); return surfaceNode; } diff --git a/test/unittest/core/pattern/window_scene/BUILD.gn b/test/unittest/core/pattern/window_scene/BUILD.gn index add774cabe8..4dad1426a11 100644 --- a/test/unittest/core/pattern/window_scene/BUILD.gn +++ b/test/unittest/core/pattern/window_scene/BUILD.gn @@ -51,6 +51,7 @@ ace_unittest("window_scene_test") { "cJSON:cjson", "c_utils:utils", "ffrt:libffrt", + "init:libbegetutil", "input:libmmi-client", "ipc:ipc_single", "napi:ace_napi", -- Gitee