From 957399a28b2c68cf4ceebb587ff2eb5aa46d897c Mon Sep 17 00:00:00 2001 From: hehao Date: Wed, 28 Aug 2024 11:11:12 +0800 Subject: [PATCH 1/2] pass transform hint Signed-off-by: hehao --- .../pattern/model/model_pattern.cpp | 22 +++++++++++++++++-- .../pattern/model/model_pattern.h | 13 +++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/model/model_pattern.cpp b/frameworks/core/components_ng/pattern/model/model_pattern.cpp index b933793d4b..adcfd19580 100644 --- a/frameworks/core/components_ng/pattern/model/model_pattern.cpp +++ b/frameworks/core/components_ng/pattern/model/model_pattern.cpp @@ -96,7 +96,7 @@ bool ModelPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, contentOffset.GetX(), contentOffset.GetY(), width, height, scale, widthScale, heightScale, - config.contentSizeChange, modelAdapter_->GetSurfaceType() + config.contentSizeChange, modelAdapter_->GetSurfaceType(), rotation_, }; modelAdapter_->OnDirtyLayoutWrapperSwap(windowChangeInfo); host->MarkNeedSyncRenderTree(); @@ -109,10 +109,28 @@ void ModelPattern::OnAttachToFrameNode() auto host = GetHost(); CHECK_NULL_VOID(host); CHECK_NULL_VOID(modelAdapter_); + // hint + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + pipeline->AddWindowStateChangedCallback(host->GetId()); + auto callbackId = pipeline->RegisterTransformHintChangeCallback([weak = WeakClaim(this)](uint32_t rotation) { + auto pattern = weak.Upgrade(); + if (pattern) { + pattern->rotation_ = rotation; + } + }); + UpdateTransformHintChangedCallbackId(callbackId); modelAdapter_->OnAttachToFrameNode(host->GetRenderContext()); } -void ModelPattern::OnDetachFromFrameNode(FrameNode* node) {} +void ModelPattern::OnDetachFromFrameNode(FrameNode* node) +{ + CHECK_NULL_VOID(node); + auto pipeline = AceType::DynamicCast(PipelineBase::GetCurrentContext()); + if (HasTransformHintChangedCallbackId()) { + pipeline->UnregisterTransformHintChangedCallback(transformHintChangedCallbackId_.value_or(-1)); + } +} void ModelPattern::HandleTouchEvent(const TouchEventInfo& info) { diff --git a/frameworks/core/components_ng/pattern/model/model_pattern.h b/frameworks/core/components_ng/pattern/model/model_pattern.h index 777601b705..46149a3a09 100644 --- a/frameworks/core/components_ng/pattern/model/model_pattern.h +++ b/frameworks/core/components_ng/pattern/model/model_pattern.h @@ -57,6 +57,16 @@ public: return MakeRefPtr(WeakClaim(RawPtr(modelAdapter_))); } + void UpdateTransformHintChangedCallbackId(std::optional id) + { + transformHintChangedCallbackId_ = id; + } + + bool HasTransformHintChangedCallbackId() + { + return transformHintChangedCallbackId_.has_value(); + } + void OnModifyDone() override; void OnRebuildFrame() override; void ToJsonValue(std::unique_ptr& json, const InspectorFilter& filter) const override; @@ -75,6 +85,9 @@ private: RefPtr modelAdapter_; RefPtr touchListener_; + std::optional transformHintChangedCallbackId_; + uint32_t rotation_ = 0; // Transform + ACE_DISALLOW_COPY_AND_MOVE(ModelPattern); }; -- Gitee From e7c75d9e32b80829bb458762ef8be20f7ea040ba Mon Sep 17 00:00:00 2001 From: zhaoduo_ustc Date: Wed, 28 Aug 2024 14:38:45 +0000 Subject: [PATCH 2/2] update frameworks/core/components_ng/pattern/model/model_pattern.cpp. Signed-off-by: zhaoduo_ustc --- .../core/components_ng/pattern/model/model_pattern.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/model/model_pattern.cpp b/frameworks/core/components_ng/pattern/model/model_pattern.cpp index adcfd19580..ad948669cd 100644 --- a/frameworks/core/components_ng/pattern/model/model_pattern.cpp +++ b/frameworks/core/components_ng/pattern/model/model_pattern.cpp @@ -110,7 +110,7 @@ void ModelPattern::OnAttachToFrameNode() CHECK_NULL_VOID(host); CHECK_NULL_VOID(modelAdapter_); // hint - auto pipeline = PipelineContext::GetCurrentContext(); + auto pipeline = host->GetContextRefPtr(); CHECK_NULL_VOID(pipeline); pipeline->AddWindowStateChangedCallback(host->GetId()); auto callbackId = pipeline->RegisterTransformHintChangeCallback([weak = WeakClaim(this)](uint32_t rotation) { @@ -126,7 +126,10 @@ void ModelPattern::OnAttachToFrameNode() void ModelPattern::OnDetachFromFrameNode(FrameNode* node) { CHECK_NULL_VOID(node); - auto pipeline = AceType::DynamicCast(PipelineBase::GetCurrentContext()); + auto id = node->GetId(); + auto pipeline = node->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + pipeline->RemoveWindowStateChangedCallback(id); if (HasTransformHintChangedCallbackId()) { pipeline->UnregisterTransformHintChangedCallback(transformHintChangedCallbackId_.value_or(-1)); } -- Gitee