• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "pipeline/rs_display_render_node.h"
17 
18 #include "common/rs_obj_abs_geometry.h"
19 #include "platform/common/rs_log.h"
20 #include "screen_manager/screen_types.h"
21 #include "visitor/rs_node_visitor.h"
22 #include "transaction/rs_render_service_client.h"
23 
24 namespace OHOS {
25 namespace Rosen {
RSDisplayRenderNode(NodeId id,const RSDisplayNodeConfig & config,std::weak_ptr<RSContext> context)26 RSDisplayRenderNode::RSDisplayRenderNode(NodeId id, const RSDisplayNodeConfig& config, std::weak_ptr<RSContext> context)
27     : RSRenderNode(id, context), RSSurfaceHandler(id), screenId_(config.screenId), offsetX_(0), offsetY_(0),
28       isMirroredDisplay_(config.isMirrored),
29       dirtyManager_(std::make_shared<RSDirtyRegionManager>())
30 {
31     MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
32     MemoryTrack::Instance().AddNodeRecord(id, info);
33 }
34 
~RSDisplayRenderNode()35 RSDisplayRenderNode::~RSDisplayRenderNode()
36 {
37     MemoryTrack::Instance().RemoveNodeRecord(GetId());
38 }
39 
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender,bool onlyFirstLevel)40 void RSDisplayRenderNode::CollectSurface(
41     const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender,
42     bool onlyFirstLevel)
43 {
44     for (auto& child : node->GetSortedChildren()) {
45         child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
46     }
47 }
48 
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)49 void RSDisplayRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
50 {
51     if (!visitor) {
52         return;
53     }
54     visitor->PrepareDisplayRenderNode(*this);
55 }
56 
Process(const std::shared_ptr<RSNodeVisitor> & visitor)57 void RSDisplayRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
58 {
59     if (!visitor) {
60         return;
61     }
62     RSRenderNode::RenderTraceDebug();
63     visitor->ProcessDisplayRenderNode(*this);
64 }
65 
SetIsOnTheTree(bool flag,NodeId instanceRootNodeId)66 void RSDisplayRenderNode::SetIsOnTheTree(bool flag, NodeId instanceRootNodeId)
67 {
68     RSRenderNode::SetIsOnTheTree(flag, GetId());
69 }
70 
GetCompositeType() const71 RSDisplayRenderNode::CompositeType RSDisplayRenderNode::GetCompositeType() const
72 {
73     return compositeType_;
74 }
75 
SetCompositeType(RSDisplayRenderNode::CompositeType type)76 void RSDisplayRenderNode::SetCompositeType(RSDisplayRenderNode::CompositeType type)
77 {
78     compositeType_ = type;
79 }
80 
SetForceSoftComposite(bool flag)81 void RSDisplayRenderNode::SetForceSoftComposite(bool flag)
82 {
83     forceSoftComposite_ = flag;
84 }
85 
IsForceSoftComposite() const86 bool RSDisplayRenderNode::IsForceSoftComposite() const
87 {
88     return forceSoftComposite_;
89 }
90 
SetMirrorSource(SharedPtr node)91 void RSDisplayRenderNode::SetMirrorSource(SharedPtr node)
92 {
93     if (!isMirroredDisplay_ || node == nullptr) {
94         return;
95     }
96     mirrorSource_ = node;
97 }
98 
ResetMirrorSource()99 void RSDisplayRenderNode::ResetMirrorSource()
100 {
101     mirrorSource_.reset();
102 }
103 
IsMirrorDisplay() const104 bool RSDisplayRenderNode::IsMirrorDisplay() const
105 {
106     return isMirroredDisplay_;
107 }
108 
SetSecurityDisplay(bool isSecurityDisplay)109 void RSDisplayRenderNode::SetSecurityDisplay(bool isSecurityDisplay)
110 {
111     isSecurityDisplay_ = isSecurityDisplay;
112 }
113 
GetSecurityDisplay() const114 bool RSDisplayRenderNode::GetSecurityDisplay() const
115 {
116     return isSecurityDisplay_;
117 }
118 
SetIsMirrorDisplay(bool isMirror)119 void RSDisplayRenderNode::SetIsMirrorDisplay(bool isMirror)
120 {
121     isMirroredDisplay_ = isMirror;
122     RS_LOGD("RSDisplayRenderNode::SetIsMirrorDisplay, node id:[%" PRIu64 "], isMirrorDisplay: [%s]", GetId(),
123         IsMirrorDisplay() ? "true" : "false");
124 }
125 
126 #ifndef ROSEN_CROSS_PLATFORM
CreateSurface(sptr<IBufferConsumerListener> listener)127 bool RSDisplayRenderNode::CreateSurface(sptr<IBufferConsumerListener> listener)
128 {
129     if (consumer_ != nullptr && surface_ != nullptr) {
130         RS_LOGI("RSDisplayRenderNode::CreateSurface already created, return");
131         return true;
132     }
133     consumer_ = IConsumerSurface::Create("DisplayNode");
134     if (consumer_ == nullptr) {
135         RS_LOGE("RSDisplayRenderNode::CreateSurface get consumer surface fail");
136         return false;
137     }
138     SurfaceError ret = consumer_->RegisterConsumerListener(listener);
139     if (ret != SURFACE_ERROR_OK) {
140         RS_LOGE("RSDisplayRenderNode::CreateSurface RegisterConsumerListener fail");
141         return false;
142     }
143     consumerListener_ = listener;
144     auto producer = consumer_->GetProducer();
145     sptr<Surface> surface = Surface::CreateSurfaceAsProducer(producer);
146     surface->SetQueueSize(4); // 4 Buffer rotation
147     auto client = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
148     surface_ = client->CreateRSSurface(surface);
149     RS_LOGI("RSDisplayRenderNode::CreateSurface end");
150     surfaceCreated_ = true;
151     return true;
152 }
153 #endif
154 
SkipFrame(uint32_t skipFrameInterval)155 bool RSDisplayRenderNode::SkipFrame(uint32_t skipFrameInterval)
156 {
157     frameCount_++;
158     // ensure skipFrameInterval is not 0
159     if (skipFrameInterval == 0) {
160         return false;
161     }
162     if ((frameCount_ - 1) % skipFrameInterval == 0) {
163         return false;
164     }
165     return true;
166 }
167 
GetRotation() const168 ScreenRotation RSDisplayRenderNode::GetRotation() const
169 {
170     auto boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
171     if (boundsGeoPtr == nullptr) {
172         return ScreenRotation::ROTATION_0;
173     }
174     // -90.0f: convert rotation degree to 4 enum values
175     return static_cast<ScreenRotation>(static_cast<int32_t>(std::roundf(boundsGeoPtr->GetRotation() / -90.0f)) % 4);
176 }
177 
IsRotationChanged() const178 bool RSDisplayRenderNode::IsRotationChanged() const
179 {
180     auto boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
181     if (boundsGeoPtr == nullptr) {
182         return false;
183     }
184     // boundsGeoPtr->IsNeedClientCompose() return false if rotation degree is times of 90
185     // which means rotation is end.
186     bool isRotationEnd = !boundsGeoPtr->IsNeedClientCompose();
187     return !(ROSEN_EQ(boundsGeoPtr->GetRotation(), lastRotation_) && isRotationEnd);
188 }
189 
UpdateRotation()190 void RSDisplayRenderNode::UpdateRotation()
191 {
192     auto boundsGeoPtr = (GetRenderProperties().GetBoundsGeometry());
193     if (boundsGeoPtr == nullptr) {
194         return;
195     }
196     lastRotation_ = boundsGeoPtr->GetRotation();
197 }
198 
UpdateDisplayDirtyManager(int32_t bufferage,bool useAlignedDirtyRegion)199 void RSDisplayRenderNode::UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion)
200 {
201     dirtyManager_->SetBufferAge(bufferage);
202     dirtyManager_->UpdateDirty(useAlignedDirtyRegion);
203 }
204 
ClearCurrentSurfacePos()205 void RSDisplayRenderNode::ClearCurrentSurfacePos()
206 {
207     lastFrameSurfacePos_.clear();
208     lastFrameSurfacePos_.swap(currentFrameSurfacePos_);
209 }
210 
211 } // namespace Rosen
212 } // namespace OHOS
213