• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "core/components_ng/pattern/ui_extension/surface_proxy_node.h"
17 
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/render/adapter/rosen_render_context.h"
20 #include "core/components_ng/property/safe_area_insets.h"
21 #include "core/pipeline/base/element_register.h"
22 
23 namespace OHOS::Ace::NG {
SetHostNode(const WeakPtr<FrameNode> & host)24 void SurfaceProxyNode::SetHostNode(const WeakPtr<FrameNode>& host)
25 {
26     host_ = host;
27 }
28 
AddSurfaceNode(const std::shared_ptr<Rosen::RSSurfaceNode> & surfaceNode)29 bool SurfaceProxyNode::AddSurfaceNode(
30     const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode)
31 {
32     TAG_LOGI(aceLogTag_, "AddSurfaceNode Start");
33     CHECK_NULL_RETURN(surfaceNode, false);
34     auto host = host_.Upgrade();
35     CHECK_NULL_RETURN(host, false);
36     GetRSUIContext();
37     if (rsUIContext_) {
38         TAG_LOGI(aceLogTag_, "SetRSUIContext rsUIContext_");
39         surfaceNode->SetRSUIContext(rsUIContext_);
40     }
41 
42     if (surfaceProxyNode_ == nullptr) {
43         CreateSurfaceProxyNode();
44         CHECK_NULL_RETURN(surfaceProxyNode_, false);
45     }
46 
47     auto context = AceType::DynamicCast<NG::RosenRenderContext>(surfaceProxyNode_->GetRenderContext());
48     CHECK_NULL_RETURN(context, false);
49     context->SetRSNode(surfaceNode);
50     host->AddChild(surfaceProxyNode_, 0);
51     host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
52     surfaceNode->CreateNodeInRenderThread();
53     OnAddSurfaceNode();
54     TAG_LOGI(aceLogTag_, "AddSurfaceNode Success");
55     return true;
56 }
57 
CreateSurfaceProxyNode()58 void SurfaceProxyNode::CreateSurfaceProxyNode()
59 {
60     auto host = host_.Upgrade();
61     CHECK_NULL_VOID(host);
62     surfaceProxyNode_ = FrameNode::CreateFrameNode(V2::UI_EXTENSION_SURFACE_TAG,
63         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
64     surfaceProxyNode_->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_PARENT);
65     surfaceProxyNode_->SetHitTestMode(HitTestMode::HTMNONE);
66     auto&& opts = host->GetLayoutProperty()->GetSafeAreaExpandOpts();
67     if (opts && opts->Expansive()) {
68         surfaceProxyNode_->GetLayoutProperty()->UpdateSafeAreaExpandOpts(*opts);
69         surfaceProxyNode_->MarkModifyDone();
70     }
71 }
72 
OnAddSurfaceNode()73 void SurfaceProxyNode::OnAddSurfaceNode()
74 {
75     TAG_LOGI(aceLogTag_, "OnAddSurfaceNode");
76 }
77 
GetSurfaceProxyNode()78 RefPtr<FrameNode> SurfaceProxyNode::GetSurfaceProxyNode()
79 {
80     return surfaceProxyNode_;
81 }
82 
GetRSUIContext()83 void SurfaceProxyNode::GetRSUIContext()
84 {
85     auto host = host_.Upgrade();
86     CHECK_NULL_VOID(host);
87     NG::PipelineContext* pipeline = host->GetContext();
88     if (!pipeline) {
89         TAG_LOGE(aceLogTag_, "pipeline is nullptr");
90         return;
91     }
92     std::shared_ptr<Rosen::RSUIDirector> rsUIDirector = pipeline->GetRSUIDirector();
93     if (!rsUIDirector) {
94         TAG_LOGE(aceLogTag_, "rsUIDirector is nullptr");
95         return;
96     }
97     rsUIContext_ = rsUIDirector->GetRSUIContext();
98     if (!rsUIContext_) {
99         TAG_LOGE(aceLogTag_, "rsUIContext_ is nullptr");
100     }
101 }
102 } // namespace OHOS::Ace::NG
103