From c56b92b8fdc32e3ef8a91ae3c26e39f5dc6a1738 Mon Sep 17 00:00:00 2001 From: sunbees Date: Wed, 20 Nov 2024 21:53:50 +0800 Subject: [PATCH] =?UTF-8?q?xcomponent=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunbees --- .../arkts_native_xcomponent_bridge.cpp | 112 +++++++++++------- .../jsview/js_xcomponent.cpp | 40 ++++++- .../jsview/js_xcomponent_controller.cpp | 1 + .../jsview/models/xcomponent_model_impl.cpp | 2 +- .../pattern/xcomponent/xcomponent_event_hub.h | 18 +-- .../pattern/xcomponent/xcomponent_model.h | 6 +- .../pattern/xcomponent/xcomponent_pattern.cpp | 61 ++++++---- .../render/adapter/rosen_render_surface.cpp | 19 ++- .../xcomponent_property_test_ng.cpp | 20 ++-- .../pattern/xcomponent/xcomponent_test_ng.cpp | 26 ++-- .../xcomponent/xcomponent_testtwo_ng.cpp | 10 +- 11 files changed, 198 insertions(+), 117 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp index 98e8358317c..cf58cc929da 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp @@ -23,6 +23,60 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" namespace OHOS::Ace::NG { +namespace { +void SetControllerOnCreatedCallback(EcmaVM* vm, FrameNode* frameNode, const Local& createdFunc) +{ + if (createdFunc->IsFunction(vm)) { + panda::Local func = createdFunc; + auto onSurfaceCreated = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( + const std::string& surfaceId, const std::string& /* xcomponentId */) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; + func->Call(vm, func.ToLocal(), para, 1); + }; + XComponentModelNG::SetControllerOnCreated(frameNode, std::move(onSurfaceCreated)); + } +} + +void SetControllerOnChangedCallback(EcmaVM* vm, FrameNode* frameNode, const Local& changedFunc) +{ + if (changedFunc->IsFunction(vm)) { + panda::Local func = changedFunc; + auto onSurfaceChanged = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( + const std::string& surfaceId, const NG::RectF& rect) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + const char* keys[] = { "offsetX", "offsetY", "surfaceWidth", "surfaceHeight" }; + Local rectValues[] = { panda::NumberRef::New(vm, rect.Left()), + panda::NumberRef::New(vm, rect.Top()), panda::NumberRef::New(vm, rect.Width()), + panda::NumberRef::New(vm, rect.Height()) }; + auto rectObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, rectValues); + panda::Local para[2] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()), rectObj }; + func->Call(vm, func.ToLocal(), para, 2); + }; + XComponentModelNG::SetControllerOnChanged(frameNode, std::move(onSurfaceChanged)); + } +} + +void SetControllerOnDestroyedCallback(EcmaVM* vm, FrameNode* frameNode, const Local& destroyedFunc) +{ + if (destroyedFunc->IsFunction(vm)) { + panda::Local func = destroyedFunc; + auto ondestroyed = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( + const std::string& surfaceId, const std::string& /* xcomponentId */) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; + func->Call(vm, func.ToLocal(), para, 1); + }; + XComponentModelNG::SetControllerOnDestroyed(frameNode, std::move(ondestroyed)); + } +} +} // namespace enum ArgIndices { ARG_FIRST = 0, @@ -115,12 +169,15 @@ void XComponentBridge::SetControllerOnCreated(ArkUIRuntimeCallInfo* runtimeCallI auto createdFunc = object->Get(vm, panda::StringRef::NewFromUtf8(vm, "onSurfaceCreated")); if (createdFunc->IsFunction(vm)) { panda::Local func = createdFunc; - auto onSurfaceCreated = [vm, func = panda::CopyableGlobal(vm, func), frameNode](const std::string& surfaceId) { + auto onSurfaceCreated = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( + const std::string& surfaceId, const std::string& xcomponentId) { panda::LocalScope pandaScope(vm); panda::TryCatch trycatch(vm); PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; func->Call(vm, func.ToLocal(), para, 1); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponentNode[%{public}s] ControllerOnCreated surfaceId:%{public}s", + xcomponentId.c_str(), surfaceId.c_str()); }; XComponentModelNG::SetControllerOnCreated(frameNode, std::move(onSurfaceCreated)); } @@ -171,14 +228,17 @@ void XComponentBridge::SetControllerOnDestroyed(ArkUIRuntimeCallInfo* runtimeCal auto destroyedFunc = object->Get(vm, panda::StringRef::NewFromUtf8(vm, "onSurfaceDestroyed")); if (destroyedFunc->IsFunction(vm)) { panda::Local func = destroyedFunc; - auto ondestroyed = [vm, func = panda::CopyableGlobal(vm, func), frameNode](const std::string& surfaceId) { + auto onDestroyed = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( + const std::string& surfaceId, const std::string& xcomponentId) { panda::LocalScope pandaScope(vm); panda::TryCatch trycatch(vm); PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; func->Call(vm, func.ToLocal(), para, 1); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponentNode[%{public}s] ControllerOnDestroyed surfaceId:%{public}s", + xcomponentId.c_str(), surfaceId.c_str()); }; - XComponentModelNG::SetControllerOnDestroyed(frameNode, std::move(ondestroyed)); + XComponentModelNG::SetControllerOnDestroyed(frameNode, std::move(onDestroyed)); } } @@ -197,47 +257,11 @@ void XComponentBridge::SetControllerCallback(ArkUIRuntimeCallInfo* runtimeCallIn auto* frameNode = reinterpret_cast(firstArg->ToNativePointer(vm)->Value()); auto object = controllerArg->ToObject(vm); auto createdFunc = object->Get(vm, panda::StringRef::NewFromUtf8(vm, "onSurfaceCreated")); - if (createdFunc->IsFunction(vm)) { - panda::Local func = createdFunc; - auto onSurfaceCreated = [vm, func = panda::CopyableGlobal(vm, func), frameNode](const std::string& surfaceId) { - panda::LocalScope pandaScope(vm); - panda::TryCatch trycatch(vm); - PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); - panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; - func->Call(vm, func.ToLocal(), para, 1); - }; - XComponentModelNG::SetControllerOnCreated(frameNode, std::move(onSurfaceCreated)); - } + SetControllerOnCreatedCallback(vm, frameNode, createdFunc); auto changedFunc = object->Get(vm, panda::StringRef::NewFromUtf8(vm, "onSurfaceChanged")); - if (changedFunc->IsFunction(vm)) { - panda::Local func = changedFunc; - auto onSurfaceChanged = [vm, func = panda::CopyableGlobal(vm, func), frameNode]( - const std::string& surfaceId, const NG::RectF& rect) { - panda::LocalScope pandaScope(vm); - panda::TryCatch trycatch(vm); - PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); - const char* keys[] = { "offsetX", "offsetY", "surfaceWidth", "surfaceHeight" }; - Local rectValues[] = { panda::NumberRef::New(vm, rect.Left()), - panda::NumberRef::New(vm, rect.Top()), panda::NumberRef::New(vm, rect.Width()), - panda::NumberRef::New(vm, rect.Height()) }; - auto rectObj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, rectValues); - panda::Local para[2] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()), rectObj }; - func->Call(vm, func.ToLocal(), para, 2); - }; - XComponentModelNG::SetControllerOnChanged(frameNode, std::move(onSurfaceChanged)); - } + SetControllerOnChangedCallback(vm, frameNode, changedFunc); auto destroyedFunc = object->Get(vm, panda::StringRef::NewFromUtf8(vm, "onSurfaceDestroyed")); - if (destroyedFunc->IsFunction(vm)) { - panda::Local func = destroyedFunc; - auto ondestroyed = [vm, func = panda::CopyableGlobal(vm, func), frameNode](const std::string& surfaceId) { - panda::LocalScope pandaScope(vm); - panda::TryCatch trycatch(vm); - PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); - panda::Local para[1] = { panda::StringRef::NewFromUtf8(vm, surfaceId.c_str()) }; - func->Call(vm, func.ToLocal(), para, 1); - }; - XComponentModelNG::SetControllerOnDestroyed(frameNode, std::move(ondestroyed)); - } + SetControllerOnDestroyedCallback(vm, frameNode, destroyedFunc); } ArkUINativeModuleValue XComponentBridge::SetXComponentInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo) @@ -605,6 +629,7 @@ ArkUINativeModuleValue XComponentBridge::SetOnLoad(ArkUIRuntimeCallInfo *runtime argv.emplace_back(jsVal->GetLocalHandle()); } func->Call(vm, func.ToLocal(), argv.data(), argv.size()); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponentNode[%{public}s] onLoad", xcomponentId.c_str()); }; XComponentModelNG::SetOnLoad(frameNode, std::move(onLoad)); return panda::JSValueRef::Undefined(vm); @@ -627,11 +652,12 @@ ArkUINativeModuleValue XComponentBridge::SetOnDestroy(ArkUIRuntimeCallInfo *runt CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); auto obj = secondArg->ToObject(vm); panda::Local func = obj; - auto onDestroy = [vm, func = panda::CopyableGlobal(vm, func), frameNode]() { + auto onDestroy = [vm, func = panda::CopyableGlobal(vm, func), frameNode](const std::string& xcomponentId) { panda::LocalScope pandaScope(vm); panda::TryCatch trycatch(vm); PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); func->Call(vm, func.ToLocal(), nullptr, 0); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponentNode[%{public}s] onDestroy", xcomponentId.c_str()); }; XComponentModelNG::SetOnDestroy(frameNode, std::move(onDestroy)); return panda::JSValueRef::Undefined(vm); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp index d68767674f7..f151d4b8246 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent.cpp @@ -66,21 +66,29 @@ XComponentModel* XComponentModel::GetInstance() } // namespace OHOS::Ace namespace OHOS::Ace::Framework { -void SetControllerCallback(const JSRef& object, const JsiExecutionContext& execCtx) +void SetControllerOnCreated( + const WeakPtr& targetNode, const JSRef& object, const JsiExecutionContext& execCtx) { - WeakPtr targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); auto jsCreatedFunc = object->GetProperty("onSurfaceCreated"); if (jsCreatedFunc->IsFunction()) { auto jsFunc = AceType::MakeRefPtr(JSRef(object), JSRef::Cast(jsCreatedFunc)); - auto onSurfaceCreated = [execCtx, func = std::move(jsFunc), node = targetNode](const std::string& surfaceId) { + auto onSurfaceCreated = [execCtx, func = std::move(jsFunc), node = targetNode]( + const std::string& surfaceId, const std::string& xcomponentId) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("XComponentController.onSurfaceCreated"); PipelineContext::SetCallBackNode(node); auto jsVal = JSRef::Make(ToJSValue(surfaceId)); func->ExecuteJS(1, &jsVal); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] ControllerOnCreated surfaceId:%{public}s", + xcomponentId.c_str(), surfaceId.c_str()); }; XComponentModel::GetInstance()->SetControllerOnCreated(std::move(onSurfaceCreated)); } +} + +void SetControllerOnChanged( + const WeakPtr& targetNode, const JSRef& object, const JsiExecutionContext& execCtx) +{ auto jsChangedFunc = object->GetProperty("onSurfaceChanged"); if (jsChangedFunc->IsFunction()) { auto jsFunc = AceType::MakeRefPtr(JSRef(object), JSRef::Cast(jsChangedFunc)); @@ -100,20 +108,36 @@ void SetControllerCallback(const JSRef& object, const JsiExecutionCont }; XComponentModel::GetInstance()->SetControllerOnChanged(std::move(onSurfaceChanged)); } +} + +void SetControllerOnDestroyed( + const WeakPtr& targetNode, const JSRef& object, const JsiExecutionContext& execCtx) +{ auto jsDestroyedFunc = object->GetProperty("onSurfaceDestroyed"); if (jsDestroyedFunc->IsFunction()) { auto jsFunc = AceType::MakeRefPtr(JSRef(object), JSRef::Cast(jsDestroyedFunc)); - auto onSurfaceDestroyed = [execCtx, func = std::move(jsFunc), node = targetNode](const std::string& surfaceId) { + auto onSurfaceDestroyed = [execCtx, func = std::move(jsFunc), node = targetNode]( + const std::string& surfaceId, const std::string& xcomponentId) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("XComponentController.onSurfaceDestroyed"); PipelineContext::SetCallBackNode(node); auto jsVal = JSRef::Make(ToJSValue(surfaceId)); func->ExecuteJS(1, &jsVal); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] ControllerOnDestroyed surfaceId:%{public}s", + xcomponentId.c_str(), surfaceId.c_str()); }; XComponentModel::GetInstance()->SetControllerOnDestroyed(std::move(onSurfaceDestroyed)); } } +void SetControllerCallback(const JSRef& object, const JsiExecutionContext& execCtx) +{ + WeakPtr targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); + SetControllerOnCreated(targetNode, object, execCtx); + SetControllerOnChanged(targetNode, object, execCtx); + SetControllerOnDestroyed(targetNode, object, execCtx); +} + std::shared_ptr GetXComponentController( const JSRef& controller, std::optional& id, const JsiExecutionContext& execCtx) { @@ -297,6 +321,7 @@ void JSXComponent::JsOnLoad(const JSCallbackInfo& args) PipelineContext::SetCallBackNode(node); std::vector keys = { "load", xcomponentId }; func->ExecuteNew(keys, ""); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] onLoad triggers", xcomponentId.c_str()); }; XComponentModel::GetInstance()->SetOnLoad(std::move(onLoad)); } @@ -336,7 +361,8 @@ void JSXComponent::RegisterOnDestroy(const JsiExecutionContext& execCtx, const L } auto jsFunc = panda::Global(execCtx.vm_, Local(func)); - auto onDestroy = [execCtx, funcRef = std::move(jsFunc), node = AceType::WeakClaim(AceType::RawPtr(frameNode))]() { + auto onDestroy = [execCtx, funcRef = std::move(jsFunc), node = AceType::WeakClaim(AceType::RawPtr(frameNode))]( + const std::string& xcomponentId) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("XComponentNode.onDestroy"); PipelineContext::SetCallBackNode(node); @@ -352,12 +378,14 @@ void JSXComponent::JsOnDestroy(const JSCallbackInfo& args) } auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(args[0])); WeakPtr targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); - auto onDestroy = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = targetNode]() { + auto onDestroy = [execCtx = args.GetExecutionContext(), func = std::move(jsFunc), node = targetNode]( + const std::string& xcomponentId) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); ACE_SCORING_EVENT("XComponent.onDestroy"); PipelineContext::SetCallBackNode(node); std::vector keys = { "destroy" }; func->Execute(keys, ""); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] onDestroy", xcomponentId.c_str()); }; XComponentModel::GetInstance()->SetOnDestroy(std::move(onDestroy)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp index d7caff561df..bae02d37521 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp @@ -155,6 +155,7 @@ void JSXComponentController::GetSurfaceId(const JSCallbackInfo& args) auto surfaceId = xcomponentController_->GetSurfaceId(); auto returnValue = JSVal(ToJSValue(surfaceId)); auto returnPtr = JSRef::Make(returnValue); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "Controller GetSurfaceId:%{public}s", surfaceId.c_str()); args.SetReturnValue(returnPtr); } } diff --git a/frameworks/bridge/declarative_frontend/jsview/models/xcomponent_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/xcomponent_model_impl.cpp index b814c95cb2c..7d9e4c7497b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/xcomponent_model_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/models/xcomponent_model_impl.cpp @@ -73,6 +73,6 @@ void XComponentModelImpl::SetOnDestroy(DestroyEvent&& onDestroy) return; } xcomponentComponent->SetXComponentDestroyEventId( - EventMarker([func = std::move(onDestroy)](const std::string& param) { func(); })); + EventMarker([func = std::move(onDestroy)](const std::string& param) { func(""); })); } } // namespace OHOS::Ace::Framework diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_event_hub.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_event_hub.h index a77cf63fb08..c8d9d99fa84 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_event_hub.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_event_hub.h @@ -22,12 +22,12 @@ namespace OHOS::Ace::NG { using LoadEvent = std::function; -using DestroyEvent = std::function; +using DestroyEvent = std::function; using ExternalEvent = std::function; using DetachEvent = std::function; -using SurfaceCreatedEvent = std::function; +using SurfaceCreatedEvent = std::function; using SurfaceChangedEvent = std::function; -using SurfaceDestroyedEvent = std::function; +using SurfaceDestroyedEvent = std::function; class XComponentEventHub : public EventHub { DECLARE_ACE_TYPE(XComponentEventHub, EventHub) @@ -53,10 +53,10 @@ public: destroyEvent_ = std::move(destroyEvent); } - void FireDestroyEvent() const + void FireDestroyEvent(const std::string& xcomponentId) const { if (destroyEvent_) { - destroyEvent_(); + destroyEvent_(xcomponentId); } } @@ -89,10 +89,10 @@ public: controllerCreatedEvent_ = std::move(controllerCreatedEvent); } - void FireControllerCreatedEvent(const std::string& surfaceId) const + void FireControllerCreatedEvent(const std::string& surfaceId, const std::string& xcomponentId) const { if (controllerCreatedEvent_) { - controllerCreatedEvent_(surfaceId); + controllerCreatedEvent_(surfaceId, xcomponentId); } } @@ -113,10 +113,10 @@ public: controllerDestroyedEvent_ = std::move(controllerDestroyedEvent); } - void FireControllerDestroyedEvent(const std::string& surfaceId) const + void FireControllerDestroyedEvent(const std::string& surfaceId, const std::string& xcomponentId) const { if (controllerDestroyedEvent_) { - controllerDestroyedEvent_(surfaceId); + controllerDestroyedEvent_(surfaceId, xcomponentId); } } diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model.h index cd2bb0dc11e..1768d34ff34 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model.h @@ -26,11 +26,11 @@ namespace OHOS::Ace { using LoadEvent = std::function; -using DestroyEvent = std::function; +using DestroyEvent = std::function; using DetachCallback = std::function; -using SurfaceCreatedEvent = std::function; +using SurfaceCreatedEvent = std::function; using SurfaceChangedEvent = std::function; -using SurfaceDestroyedEvent = std::function; +using SurfaceDestroyedEvent = std::function; class XComponentModel { public: diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp index bdda88c94a6..c5c5ff8361f 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp @@ -281,6 +281,8 @@ void XComponentPattern::Initialize() void XComponentPattern::OnAttachToMainTree() { + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] AttachToMainTree", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] AttachToMainTree", GetId().c_str()); if (isTypedNode_ && surfaceCallbackMode_ == SurfaceCallbackMode::DEFAULT) { HandleSurfaceCreated(); } @@ -288,6 +290,8 @@ void XComponentPattern::OnAttachToMainTree() void XComponentPattern::OnDetachFromMainTree() { + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] DetachFromMainTree", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] DetachFromMainTree", GetId().c_str()); if (isTypedNode_ && surfaceCallbackMode_ == SurfaceCallbackMode::DEFAULT) { HandleSurfaceDestroyed(); } @@ -474,15 +478,15 @@ void XComponentPattern::OnDetachFromFrameNode(FrameNode* frameNode) auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); - eventHub->FireDestroyEvent(); + ACE_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); + eventHub->FireDestroyEvent(GetId()); } if (id_.has_value()) { eventHub->FireDetachEvent(id_.value()); } { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); - eventHub->FireControllerDestroyedEvent(surfaceId_); + ACE_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); + eventHub->FireControllerDestroyedEvent(surfaceId_, GetId()); } #ifdef RENDER_EXTRACT_SUPPORTED if (renderContextForSurface_) { @@ -626,11 +630,12 @@ void XComponentPattern::DumpInfo() DumpLog::GetInstance().AddDesc(std::string("xcomponentId: ").append(id_.value_or("no id"))); DumpLog::GetInstance().AddDesc(std::string("xcomponentType: ").append(XComponentTypeToString(type_))); DumpLog::GetInstance().AddDesc(std::string("libraryName: ").append(libraryname_.value_or("no library name"))); + DumpLog::GetInstance().AddDesc(std::string("surfaceId: ").append(surfaceId_)); + DumpLog::GetInstance().AddDesc(std::string("surfaceRect: ").append(paintRect_.ToString())); } void XComponentPattern::DumpAdvanceInfo() { - DumpLog::GetInstance().AddDesc(std::string("surfaceRect: ").append(paintRect_.ToString())); if (renderSurface_) { renderSurface_->DumpInfo(); } @@ -699,12 +704,12 @@ void XComponentPattern::XComponentSizeInit() eventHub->FireSurfaceInitEvent(id_.value(), host->GetId()); } { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireLoadEvent", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] FireLoadEvent", GetId().c_str()); eventHub->FireLoadEvent(GetId()); } { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerCreatedEvent", GetId().c_str()); - eventHub->FireControllerCreatedEvent(surfaceId_); + ACE_SCOPED_TRACE("XComponent[%s] FireControllerCreatedEvent", GetId().c_str()); + eventHub->FireControllerCreatedEvent(surfaceId_, GetId()); } } @@ -955,6 +960,8 @@ void XComponentPattern::InitFocusEvent(const RefPtr& focusHub) focusHub->SetOnFocusInternal(std::move(onFocusEvent)); auto onKeyEvent = [weak = WeakClaim(this)](const KeyEvent& event) -> bool { + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "HandleKeyEvent[%{public}d,%{public}d,%{public}d,%{public}" PRId64 "]", + event.action, event.code, event.sourceType, event.deviceId); auto pattern = weak.Upgrade(); CHECK_NULL_RETURN(pattern, false); return pattern->HandleKeyEvent(event); @@ -1058,6 +1065,8 @@ void XComponentPattern::InitMouseEvent(const RefPtr& inputHub) CHECK_NULL_VOID(!mouseEvent_); auto mouseTask = [weak = WeakClaim(this)](const MouseInfo& info) { + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "HandleMouseEvent[%{public}f,%{public}f,%{public}d,%{public}d]", + info.GetLocalLocation().GetX(), info.GetLocalLocation().GetY(), info.GetAction(), info.GetButton()); auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); pattern->HandleMouseEvent(info); @@ -1100,11 +1109,9 @@ void XComponentPattern::HandleTouchEvent(const TouchEventInfo& info) touchEventPoint_.timeStamp = timeStamp; auto touchType = touchInfoList.front().GetTouchType(); touchEventPoint_.type = ConvertNativeXComponentTouchEvent(touchType); - TAG_LOGD(AceLogTag::ACE_XCOMPONENT, - "XComponent HandleTouchEvent x = %{public}f, y = %{public}f, id = %{public}d, type = %{public}zu, size = " - "%{public}u", - touchEventPoint_.x, touchEventPoint_.y, touchEventPoint_.id, touchType, - static_cast(info.GetTouches().size())); + TAG_LOGD(AceLogTag::ACE_XCOMPONENT, "HandleTouchEvent[%{public}f,%{public}f,%{public}d,%{public}zu,%{public}u]", + localOffset.GetX(), localOffset.GetY(), touchInfo.GetFingerId(), touchInfoList.front().GetTouchType(), + static_cast(touchInfo.GetSize())); SetTouchPoint(info.GetTouches(), timeStamp, touchType); if (nativeXComponent_ && nativeXComponentImpl_) { @@ -1616,7 +1623,7 @@ void XComponentPattern::OnNativeLoad(FrameNode* frameNode) auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireLoadEvent", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] FireLoadEvent", GetId().c_str()); eventHub->FireLoadEvent(GetId()); } } @@ -1628,8 +1635,8 @@ void XComponentPattern::OnNativeUnload(FrameNode* frameNode) auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); - eventHub->FireDestroyEvent(); + ACE_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); + eventHub->FireDestroyEvent(GetId()); } } @@ -1641,14 +1648,14 @@ void XComponentPattern::OnSurfaceCreated() if (isNativeXComponent_) { CHECK_NULL_VOID(nativeXComponentImpl_); CHECK_NULL_VOID(nativeXComponent_); - TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceCreated", GetId().c_str()); - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] NativeSurfaceCreated", GetId().c_str()); nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); nativeXComponentImpl_->SetSurface(nativeWindow_); const auto* callback = nativeXComponentImpl_->GetCallback(); CHECK_NULL_VOID(callback); CHECK_NULL_VOID(callback->OnSurfaceCreated); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceCreated", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] NativeSurfaceCreated[w:%f,h:%f]", GetId().c_str(), width, height); callback->OnSurfaceCreated(nativeXComponent_.get(), nativeWindow_); } else { auto host = GetHost(); @@ -1656,8 +1663,8 @@ void XComponentPattern::OnSurfaceCreated() auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerCreatedEvent", GetId().c_str()); - eventHub->FireControllerCreatedEvent(surfaceId_); + ACE_SCOPED_TRACE("XComponent[%s] FireControllerCreatedEvent", GetId().c_str()); + eventHub->FireControllerCreatedEvent(surfaceId_, GetId()); } } } @@ -1687,14 +1694,14 @@ void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect, bool needResi CHECK_NULL_VOID(callback); CHECK_NULL_VOID(callback->OnSurfaceChanged); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] native OnSurfaceChanged", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] native OnSurfaceChanged[w:%f,h:%f]", GetId().c_str(), width, height); callback->OnSurfaceChanged(nativeXComponent_.get(), surface); } } else { auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerChangedEvent", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] FireControllerChangedEvent[w:%f,h:%f]", GetId().c_str(), width, height); eventHub->FireControllerChangedEvent(surfaceId_, surfaceRect); } } @@ -1703,7 +1710,6 @@ void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect, bool needResi void XComponentPattern::OnSurfaceDestroyed() { if (isNativeXComponent_) { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] native OnSurfaceDestroyed", GetId().c_str()); CHECK_RUN_ON(UI); CHECK_NULL_VOID(nativeXComponent_); CHECK_NULL_VOID(nativeXComponentImpl_); @@ -1711,6 +1717,8 @@ void XComponentPattern::OnSurfaceDestroyed() const auto* callback = nativeXComponentImpl_->GetCallback(); CHECK_NULL_VOID(callback); CHECK_NULL_VOID(callback->OnSurfaceDestroyed); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceDestroyed", GetId().c_str()); + ACE_SCOPED_TRACE("XComponent[%s] native OnSurfaceDestroyed", GetId().c_str()); callback->OnSurfaceDestroyed(nativeXComponent_.get(), surface); nativeXComponentImpl_->SetSurface(nullptr); } else { @@ -1719,8 +1727,8 @@ void XComponentPattern::OnSurfaceDestroyed() auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); - eventHub->FireControllerDestroyedEvent(surfaceId_); + ACE_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); + eventHub->FireControllerDestroyedEvent(surfaceId_, GetId()); } } } @@ -2023,11 +2031,12 @@ void XComponentPattern::DumpInfo(std::unique_ptr& json) json->Put("xcomponentId", id_.value_or("no id").c_str()); json->Put("xcomponentType", XComponentTypeToString(type_).c_str()); json->Put("libraryName", libraryname_.value_or("no library name").c_str()); + json->Put("surfaceId", surfaceId_.c_str()); + json->Put("surfaceRect", paintRect_.ToString().c_str()); } void XComponentPattern::DumpAdvanceInfo(std::unique_ptr& json) { - json->Put("surfaceRect", paintRect_.ToString().c_str()); if (renderSurface_) { renderSurface_->DumpInfo(json); } diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp index 3242c907443..707ab2f0826 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp @@ -575,10 +575,15 @@ void RosenRenderSurface::DrawBufferForXComponent( if (!isUniRender_.load()) { sendCount_.fetch_add(1); } - ACE_SCOPED_TRACE("DrawXComponentBuffer[id:%u][sendTimes:%d]", surfaceNode->bufferId_, surfaceNode->sendTimes_); + auto uid = GetUniqueIdNum(); + if (uid == 0) { + TAG_LOGW(AceLogTag::ACE_XCOMPONENT, "DrawSurfaceBuffer uid is invalid"); + } + ACE_SCOPED_TRACE("DrawXComponentBuffer[id:%u][sendTimes:%d][uid:%" PRIu64 "]", surfaceNode->bufferId_, + surfaceNode->sendTimes_, uid); auto& recordingCanvas = static_cast(canvas); - auto transform = surfaceNode->buffer_ == nullptr ? - GraphicTransformType::GRAPHIC_ROTATE_NONE : surfaceNode->buffer_->GetSurfaceBufferTransform(); + auto transform = surfaceNode->buffer_ == nullptr ? GraphicTransformType::GRAPHIC_ROTATE_NONE + : surfaceNode->buffer_->GetSurfaceBufferTransform(); Rosen::DrawingSurfaceBufferInfo info { surfaceNode->buffer_, offsetX, offsetY, static_cast(width), static_cast(height), getpid(), GetUniqueIdNum(), surfaceNode->acquireFence_, transform }; recordingCanvas.DrawSurfaceBuffer(info); @@ -589,12 +594,14 @@ void RosenRenderSurface::RegisterBufferCallback() { #ifdef OHOS_PLATFORM CHECK_EQUAL_VOID(isTexture_, false); - auto pid = getpid(); auto uid = GetUniqueIdNum(); if (!bufferCallback_) { bufferCallback_ = std::make_shared(WeakClaim(this)); } - Rosen::RSInterfaces::GetInstance().RegisterSurfaceBufferCallback(pid, uid, bufferCallback_); + if (uid == 0) { + TAG_LOGW(AceLogTag::ACE_XCOMPONENT, "RegisterBufferCallback uid is invalid"); + } + Rosen::RSInterfaces::GetInstance().RegisterSurfaceBufferCallback(getpid(), uid, bufferCallback_); auto rosenRenderContext = DynamicCast(renderContext_.Upgrade()); CHECK_NULL_VOID(rosenRenderContext); auto rsNode = rosenRenderContext->GetRSNode(); @@ -737,6 +744,8 @@ void DrawBufferListener::OnBufferAvailable() #ifdef OHOS_PLATFORM void XComponentSurfaceBufferCallback::OnFinish(const Rosen::FinishCallbackRet& ret) { + ACE_SCOPED_TRACE( + "SurfaceBufferCallback::OnFinish[uid:%" PRIu64 "][size:%zu]", ret.uid, ret.surfaceBufferIds.size()); auto renderSurface = renderSurface_.Upgrade(); CHECK_NULL_VOID(renderSurface); if (ret.uid != renderSurface->GetUniqueIdNum()) { diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp index 81cb6e14c7c..2e45a914036 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_property_test_ng.cpp @@ -1607,13 +1607,15 @@ HWTEST_F(XComponentPropertyTestNg, XComponentModelNGLifeCycleCallbackTest043, Te std::string onSurfaceCreatedSurfaceId = ""; std::string onSurfaceChangedSurfaceId = ""; std::string onSurfaceDestroyedSurfaceId = ""; - auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId]( - const std::string& surfaceId) { onSurfaceCreatedSurfaceId = surfaceId; }; + auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceCreatedSurfaceId = surfaceId; + }; auto onSurfaceChanged = [&onSurfaceChangedSurfaceId](const std::string& surfaceId, const RectF& /* rect */) { onSurfaceChangedSurfaceId = surfaceId; }; - auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId]( - const std::string& surfaceId) { onSurfaceDestroyedSurfaceId = surfaceId; }; + auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceDestroyedSurfaceId = surfaceId; + }; /** * @tc.steps: step2. call CreateFrameNode @@ -1669,13 +1671,15 @@ HWTEST_F(XComponentPropertyTestNg, XComponentModelNGLifeCycleCallbackTest044, Te std::string onSurfaceCreatedSurfaceId = ""; std::string onSurfaceChangedSurfaceId = ""; std::string onSurfaceDestroyedSurfaceId = ""; - auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId]( - const std::string& surfaceId) { onSurfaceCreatedSurfaceId = surfaceId; }; + auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceCreatedSurfaceId = surfaceId; + }; auto onSurfaceChanged = [&onSurfaceChangedSurfaceId](const std::string& surfaceId, const RectF& /* rect */) { onSurfaceChangedSurfaceId = surfaceId; }; - auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId]( - const std::string& surfaceId) { onSurfaceDestroyedSurfaceId = surfaceId; }; + auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceDestroyedSurfaceId = surfaceId; + }; /** * @tc.steps: step2. call CreateFrameNode diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp index 6619bf24b93..33658adee12 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_test_ng.cpp @@ -212,7 +212,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest002, TestSize.Level1) std::string onLoadKey; std::string onDestroyKey; auto onLoad = [&onLoadKey](const std::string& /* xComponentId */) { onLoadKey = CHECK_KEY; }; - auto onDestroy = [&onDestroyKey]() { onDestroyKey = CHECK_KEY; }; + auto onDestroy = [&onDestroyKey](const std::string& /* xComponentId */) { onDestroyKey = CHECK_KEY; }; testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; testProperty.loadEvent = std::move(onLoad); @@ -228,7 +228,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest002, TestSize.Level1) auto xComponentEventHub = frameNode->GetEventHub(); ASSERT_TRUE(xComponentEventHub); xComponentEventHub->FireLoadEvent(XCOMPONENT_ID); - xComponentEventHub->FireDestroyEvent(); + xComponentEventHub->FireDestroyEvent(XCOMPONENT_ID); EXPECT_EQ(onLoadKey, CHECK_KEY); EXPECT_EQ(onDestroyKey, CHECK_KEY); @@ -239,7 +239,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest002, TestSize.Level1) */ auto onLoad2 = [&onLoadKey](const std::string& /* xComponentId */) { onLoadKey = ""; }; - auto onDestroy2 = [&onDestroyKey]() { onDestroyKey = ""; }; + auto onDestroy2 = [&onDestroyKey](const std::string& /* xComponentId */) { onDestroyKey = ""; }; testProperty.xcType = XCOMPONENT_COMPONENT_TYPE_VALUE; testProperty.loadEvent = std::move(onLoad2); testProperty.destroyEvent = std::move(onDestroy2); @@ -249,7 +249,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest002, TestSize.Level1) xComponentEventHub = frameNode2->GetEventHub(); ASSERT_TRUE(xComponentEventHub); xComponentEventHub->FireLoadEvent(XCOMPONENT_ID); - xComponentEventHub->FireDestroyEvent(); + xComponentEventHub->FireDestroyEvent(XCOMPONENT_ID); EXPECT_EQ(onLoadKey, CHECK_KEY); EXPECT_EQ(onDestroyKey, CHECK_KEY); } @@ -611,7 +611,7 @@ HWTEST_F(XComponentTestNg, XComponentOnAreaChangedInnerTest019, TestSize.Level1) std::string onLoadKey; std::string onDestroyKey; auto onLoad = [&onLoadKey](const std::string& /* xComponentId */) { onLoadKey = CHECK_KEY; }; - auto onDestroy = [&onDestroyKey]() { onDestroyKey = CHECK_KEY; }; + auto onDestroy = [&onDestroyKey](const std::string& /* xComponentId */) { onDestroyKey = CHECK_KEY; }; testProperty.xcType = XCOMPONENT_SURFACE_TYPE_VALUE; testProperty.loadEvent = std::move(onLoad); @@ -794,7 +794,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest023, TestSize.Level1) std::string onLoadKey; std::string onDestroyKey; auto onLoad = [&onLoadKey](const std::string& /* xComponentId */) { onLoadKey = CHECK_KEY; }; - auto onDestroy = [&onDestroyKey]() { onDestroyKey = CHECK_KEY; }; + auto onDestroy = [&onDestroyKey](const std::string& /* xComponentId */) { onDestroyKey = CHECK_KEY; }; /** * @tc.steps: step1. set the testProperty and CreateXComponentNode @@ -822,7 +822,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest023, TestSize.Level1) auto xComponentEventHub = frameNode->GetEventHub(); ASSERT_TRUE(xComponentEventHub); xComponentEventHub->FireLoadEvent(XCOMPONENT_ID); - xComponentEventHub->FireDestroyEvent(); + xComponentEventHub->FireDestroyEvent(XCOMPONENT_ID); EXPECT_FALSE(onLoadKey == CHECK_KEY); EXPECT_FALSE(onDestroyKey == CHECK_KEY); @@ -841,7 +841,7 @@ HWTEST_F(XComponentTestNg, XComponentEventTest023, TestSize.Level1) */ ASSERT_TRUE(xComponentEventHub); xComponentEventHub->FireLoadEvent(XCOMPONENT_ID); - xComponentEventHub->FireDestroyEvent(); + xComponentEventHub->FireDestroyEvent(XCOMPONENT_ID); EXPECT_EQ(onLoadKey, CHECK_KEY); EXPECT_EQ(onDestroyKey, CHECK_KEY); } @@ -1320,13 +1320,15 @@ HWTEST_F(XComponentTestNg, XComponentSurfaceLifeCycleCallback, TestSize.Level1) std::string onSurfaceCreatedSurfaceId = ""; std::string onSurfaceChangedSurfaceId = ""; std::string onSurfaceDestroyedSurfaceId = ""; - auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId]( - const std::string& surfaceId) { onSurfaceCreatedSurfaceId = surfaceId; }; + auto onSurfaceCreated = [&onSurfaceCreatedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceCreatedSurfaceId = surfaceId; + }; auto onSurfaceChanged = [&onSurfaceChangedSurfaceId](const std::string& surfaceId, const RectF& /* rect */) { onSurfaceChangedSurfaceId = surfaceId; }; - auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId]( - const std::string& surfaceId) { onSurfaceDestroyedSurfaceId = surfaceId; }; + auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceId](const std::string& surfaceId, const std::string& xcId) { + onSurfaceDestroyedSurfaceId = surfaceId; + }; testProperty.surfaceCreatedEvent = std::move(onSurfaceCreated); testProperty.surfaceChangedEvent = std::move(onSurfaceChanged); testProperty.surfaceDestroyedEvent = std::move(onSurfaceDestroyed); diff --git a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp index c5035a136e5..eb93a69b45e 100644 --- a/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp +++ b/test/unittest/core/pattern/xcomponent/xcomponent_testtwo_ng.cpp @@ -461,10 +461,12 @@ HWTEST_F(XComponentTestTwoNg, XComponentTestTwoNg016, TestSize.Level1) g_testProperty.libraryName = std::nullopt; int32_t onSurfaceCreatedSurfaceCount = 0; int32_t onSurfaceDestroyedSurfaceCount = 0; - auto onSurfaceCreated = [&onSurfaceCreatedSurfaceCount]( - const std::string& surfaceId) { ++onSurfaceCreatedSurfaceCount; }; - auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceCount]( - const std::string& surfaceId) { ++onSurfaceDestroyedSurfaceCount; }; + auto onSurfaceCreated = [&onSurfaceCreatedSurfaceCount](const std::string& surfaceId, const std::string& xcId) { + ++onSurfaceCreatedSurfaceCount; + }; + auto onSurfaceDestroyed = [&onSurfaceDestroyedSurfaceCount](const std::string& surfaceId, const std::string& xcId) { + ++onSurfaceDestroyedSurfaceCount; + }; g_testProperty.surfaceCreatedEvent = std::move(onSurfaceCreated); g_testProperty.surfaceDestroyedEvent = std::move(onSurfaceDestroyed); auto frameNode = CreateXComponentNode(g_testProperty); -- Gitee