From a0ea339d61ec4b5dc58056a3d20138d5f6c5a197 Mon Sep 17 00:00:00 2001 From: sd-wu Date: Wed, 27 Aug 2025 11:06:34 +0800 Subject: [PATCH] =?UTF-8?q?native=20xcomponent=20=E4=BF=9D=E6=8C=81renderC?= =?UTF-8?q?ontext=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sd-wu --- .../pattern/xcomponent/xcomponent_pattern.h | 2 +- .../xcomponent/xcomponent_pattern_v2.cpp | 3 +- .../xcomponent/xcomponent_v2_test_ng.cpp | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index 54f5db001cc..31d486a2720 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -403,6 +403,7 @@ protected: void* nativeWindow_ = nullptr; bool hasReleasedSurface_ = false; RefPtr renderContextForSurface_; + RefPtr handlingSurfaceRenderContext_; std::optional transformHintChangedCallbackId_; std::string surfaceId_; bool isOnTree_ = false; @@ -500,7 +501,6 @@ private: std::optional soPath_; std::optional screenId_; - RefPtr handlingSurfaceRenderContext_; WeakPtr extPattern_; std::shared_ptr nativeXComponent_; diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp index 78daf67d31c..0a527b206c0 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern_v2.cpp @@ -136,7 +136,6 @@ void XComponentPatternV2::BeforeSyncGeometryProperties(const DirtySwapConfig& co } const auto& [offsetChanged, sizeChanged] = UpdateSurfaceRect(); HandleSurfaceChangeEvent(offsetChanged, sizeChanged, config.frameOffsetChange); - AddAfterLayoutTaskForExportTexture(); host->MarkNeedSyncRenderTree(); } @@ -331,6 +330,7 @@ void XComponentPatternV2::DisposeSurface() CHECK_NULL_VOID(renderContextForSurface_); renderContext->RemoveChild(renderContextForSurface_); renderContextForSurface_ = nullptr; + handlingSurfaceRenderContext_ = nullptr; #ifdef ENABLE_ROSEN_BACKEND FlushImplicitTransaction(host); #endif @@ -504,6 +504,7 @@ void XComponentPatternV2::InitializeRenderContext() return; } renderContextForSurface_ = RenderContext::Create(); + handlingSurfaceRenderContext_ = renderContextForSurface_; RenderContext::ContextParam param = { RenderContext::ContextType::HARDWARE_SURFACE, GetId() + "Surface", RenderContext::PatternType::XCOM }; renderContextForSurface_->InitContext(false, param); diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp index 3bcf036500c..d55bd98c654 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_v2_test_ng.cpp @@ -1153,4 +1153,38 @@ HWTEST_F(XComponentV2TestNg, GetSurfaceHolderTest, TestSize.Level1) pattern->SetSurfaceHolder(surfaceHolder); ASSERT_TRUE(pattern->GetSurfaceHolder()); } + +/** + * @tc.name: XComponentV2InitAndDisposeSurfaceTest + * @tc.desc: Test FlushImplicitTransaction method + * @tc.type: FUNC + */ +HWTEST_F(XComponentV2TestNg, XComponentV2InitAndDisposeSurfaceTest, TestSize.Level1) +{ + /** + * @tc.steps: step1. call CreateXComponentNode. + * @tc.expected: xcomponent frameNode create successfully. + */ + auto frameNode = CreateXComponentNode(); + ASSERT_TRUE(frameNode); + ASSERT_EQ(frameNode->GetTag(), V2::XCOMPONENT_ETS_TAG); + auto pattern = frameNode->GetPattern(); + ASSERT_TRUE(pattern); + + /** + * @tc.steps: step2. call InitializeRenderContext. + * @tc.expected: surface renderContext create successfully. + */ + pattern->InitializeRenderContext(); + EXPECT_TRUE(pattern->renderContextForSurface_); + EXPECT_EQ(pattern->renderContextForSurface_, pattern->handlingSurfaceRenderContext_); + + /** + * @tc.steps: step3. call DisposeSurface. + * @tc.expected: surface renderContext dispose successfully. + */ + pattern->DisposeSurface(); + EXPECT_FALSE(pattern->renderContextForSurface_); + EXPECT_EQ(pattern->renderContextForSurface_, pattern->handlingSurfaceRenderContext_); +} } // namespace OHOS::Ace::NG -- Gitee