• 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 
32 RSDisplayRenderNode::~RSDisplayRenderNode() = default;
33 
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender)34 void RSDisplayRenderNode::CollectSurface(
35     const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender)
36 {
37     ResetSortedChildren();
38     for (auto& child : node->GetSortedChildren()) {
39         child->CollectSurface(child, vec, isUniRender);
40     }
41 }
42 
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)43 void RSDisplayRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
44 {
45     if (!visitor) {
46         return;
47     }
48     visitor->PrepareDisplayRenderNode(*this);
49 }
50 
Process(const std::shared_ptr<RSNodeVisitor> & visitor)51 void RSDisplayRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
52 {
53     if (!visitor) {
54         return;
55     }
56     RSRenderNode::RenderTraceDebug();
57     visitor->ProcessDisplayRenderNode(*this);
58 }
59 
GetCompositeType() const60 RSDisplayRenderNode::CompositeType RSDisplayRenderNode::GetCompositeType() const
61 {
62     return compositeType_;
63 }
64 
SetCompositeType(RSDisplayRenderNode::CompositeType type)65 void RSDisplayRenderNode::SetCompositeType(RSDisplayRenderNode::CompositeType type)
66 {
67     compositeType_ = type;
68 }
69 
SetForceSoftComposite(bool flag)70 void RSDisplayRenderNode::SetForceSoftComposite(bool flag)
71 {
72     forceSoftComposite_ = flag;
73 }
74 
IsForceSoftComposite() const75 bool RSDisplayRenderNode::IsForceSoftComposite() const
76 {
77     return forceSoftComposite_;
78 }
79 
SetMirrorSource(SharedPtr node)80 void RSDisplayRenderNode::SetMirrorSource(SharedPtr node)
81 {
82     if (!isMirroredDisplay_ || node == nullptr) {
83         return;
84     }
85     mirrorSource_ = node;
86 }
87 
ResetMirrorSource()88 void RSDisplayRenderNode::ResetMirrorSource()
89 {
90     mirrorSource_.reset();
91 }
92 
IsMirrorDisplay() const93 bool RSDisplayRenderNode::IsMirrorDisplay() const
94 {
95     return isMirroredDisplay_;
96 }
97 
SetSecurityDisplay(bool isSecurityDisplay)98 void RSDisplayRenderNode::SetSecurityDisplay(bool isSecurityDisplay)
99 {
100     isSecurityDisplay_ = isSecurityDisplay;
101 }
102 
GetSecurityDisplay() const103 bool RSDisplayRenderNode::GetSecurityDisplay() const
104 {
105     return isSecurityDisplay_;
106 }
107 
SetIsMirrorDisplay(bool isMirror)108 void RSDisplayRenderNode::SetIsMirrorDisplay(bool isMirror)
109 {
110     isMirroredDisplay_ = isMirror;
111     RS_LOGD("RSDisplayRenderNode::SetIsMirrorDisplay, node id:[%" PRIu64 "], isMirrorDisplay: [%s]", GetId(),
112         IsMirrorDisplay() ? "true" : "false");
113 }
114 
115 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__)
CreateSurface(sptr<IBufferConsumerListener> listener)116 bool RSDisplayRenderNode::CreateSurface(sptr<IBufferConsumerListener> listener)
117 {
118     if (consumer_ != nullptr && surface_ != nullptr) {
119         RS_LOGI("RSDisplayRenderNode::CreateSurface already created, return");
120         return true;
121     }
122     consumer_ = Surface::CreateSurfaceAsConsumer("DisplayNode");
123     if (consumer_ == nullptr) {
124         RS_LOGE("RSDisplayRenderNode::CreateSurface get consumer surface fail");
125         return false;
126     }
127     SurfaceError ret = consumer_->RegisterConsumerListener(listener);
128     if (ret != SURFACE_ERROR_OK) {
129         RS_LOGE("RSDisplayRenderNode::CreateSurface RegisterConsumerListener fail");
130         return false;
131     }
132     consumerListener_ = listener;
133     auto producer = consumer_->GetProducer();
134     sptr<Surface> surface = Surface::CreateSurfaceAsProducer(producer);
135     auto client = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
136     surface_ = client->CreateRSSurface(surface);
137     RS_LOGI("RSDisplayRenderNode::CreateSurface end");
138     surfaceCreated_ = true;
139     return true;
140 }
141 #endif
142 
SkipFrame(uint32_t skipFrameInterval)143 bool RSDisplayRenderNode::SkipFrame(uint32_t skipFrameInterval)
144 {
145     frameCount_++;
146     // ensure skipFrameInterval is not 0
147     if (skipFrameInterval == 0) {
148         return false;
149     }
150     if ((frameCount_ - 1) % skipFrameInterval == 0) {
151         return false;
152     }
153     return true;
154 }
155 
GetRotation() const156 ScreenRotation RSDisplayRenderNode::GetRotation() const
157 {
158     auto boundsGeoPtr = std::static_pointer_cast<RSObjAbsGeometry>(GetRenderProperties().GetBoundsGeometry());
159     if (boundsGeoPtr == nullptr) {
160         return ScreenRotation::ROTATION_0;
161     }
162     // -90.0f: convert rotation degree to 4 enum values
163     return static_cast<ScreenRotation>(static_cast<int32_t>(std::roundf(boundsGeoPtr->GetRotation() / -90.0f)) % 4);
164 }
165 
IsRotationChanged() const166 bool RSDisplayRenderNode::IsRotationChanged() const
167 {
168     auto boundsGeoPtr = std::static_pointer_cast<RSObjAbsGeometry>(GetRenderProperties().GetBoundsGeometry());
169     if (boundsGeoPtr == nullptr) {
170         return false;
171     }
172     // boundsGeoPtr->IsNeedClientCompose() return false if rotation degree is times of 90
173     // which means rotation is end.
174     bool isRotationEnd = !boundsGeoPtr->IsNeedClientCompose();
175     return !(ROSEN_EQ(boundsGeoPtr->GetRotation(), lastRotation_) && isRotationEnd);
176 }
177 
UpdateRotation()178 void RSDisplayRenderNode::UpdateRotation()
179 {
180     auto boundsGeoPtr = std::static_pointer_cast<RSObjAbsGeometry>(GetRenderProperties().GetBoundsGeometry());
181     if (boundsGeoPtr == nullptr) {
182         return;
183     }
184     lastRotation_ = boundsGeoPtr->GetRotation();
185 }
186 
UpdateDisplayDirtyManager(int32_t bufferage)187 void RSDisplayRenderNode::UpdateDisplayDirtyManager(int32_t bufferage)
188 {
189     dirtyManager_->SetBufferAge(bufferage);
190     dirtyManager_->UpdateDirty();
191 }
192 
ClearCurrentSurfacePos()193 void RSDisplayRenderNode::ClearCurrentSurfacePos()
194 {
195     lastFrameSurfacePos_.clear();
196     lastFrameSurfacePos_.swap(currentFrameSurfacePos_);
197 }
198 
199 } // namespace Rosen
200 } // namespace OHOS
201