1 /*
2  * Copyright (c) 2024 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 "params/rs_display_render_params.h"
17 
18 #include "platform/common/rs_log.h"
19 namespace OHOS::Rosen {
20 using RSRenderNodeDrawableAdapterSharedPtr = DrawableV2::RSRenderNodeDrawableAdapter::SharedPtr;
RSDisplayRenderParams(NodeId id)21 RSDisplayRenderParams::RSDisplayRenderParams(NodeId id) : RSRenderParams(id) {}
22 
GetAllMainAndLeashSurfaces()23 std::vector<RSBaseRenderNode::SharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaces()
24 {
25     return allMainAndLeashSurfaces_;
26 }
27 
GetAllMainAndLeashSurfaceDrawables()28 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaceDrawables()
29 {
30     return allMainAndLeashSurfaceDrawables_;
31 }
32 
SetAllMainAndLeashSurfaces(std::vector<RSBaseRenderNode::SharedPtr> & allMainAndLeashSurfaces)33 void RSDisplayRenderParams::SetAllMainAndLeashSurfaces(
34     std::vector<RSBaseRenderNode::SharedPtr>& allMainAndLeashSurfaces)
35 {
36     std::swap(allMainAndLeashSurfaces_, allMainAndLeashSurfaces);
37 }
38 
SetAllMainAndLeashSurfaceDrawables(std::vector<RSRenderNodeDrawableAdapterSharedPtr> & allMainAndLeashSurfaceDrawables)39 void RSDisplayRenderParams::SetAllMainAndLeashSurfaceDrawables(
40     std::vector<RSRenderNodeDrawableAdapterSharedPtr>& allMainAndLeashSurfaceDrawables)
41 {
42     std::swap(allMainAndLeashSurfaceDrawables_, allMainAndLeashSurfaceDrawables);
43 }
44 
SetMainAndLeashSurfaceDirty(bool isDirty)45 void RSDisplayRenderParams::SetMainAndLeashSurfaceDirty(bool isDirty)
46 {
47     if (isMainAndLeashSurfaceDirty_ == isDirty) {
48         return;
49     }
50     isMainAndLeashSurfaceDirty_ = isDirty;
51     needSync_ = true;
52 }
53 
GetMainAndLeashSurfaceDirty() const54 bool RSDisplayRenderParams::GetMainAndLeashSurfaceDirty() const
55 {
56     return isMainAndLeashSurfaceDirty_;
57 }
58 
SetRotationChanged(bool changed)59 void RSDisplayRenderParams::SetRotationChanged(bool changed)
60 {
61     if (isRotationChanged_ == changed) {
62         return;
63     }
64     isRotationChanged_ = changed;
65     needSync_ = true;
66 }
67 
SetGlobalZOrder(float zOrder)68 void RSDisplayRenderParams::SetGlobalZOrder(float zOrder)
69 {
70     zOrder_ = zOrder;
71     needSync_ = true;
72 }
73 
GetGlobalZOrder() const74 float RSDisplayRenderParams::GetGlobalZOrder() const
75 {
76     return zOrder_;
77 }
78 
IsRotationChanged() const79 bool RSDisplayRenderParams::IsRotationChanged() const
80 {
81     return isRotationChanged_;
82 }
83 
SetHDRPresent(bool hasHdrPresent)84 void RSDisplayRenderParams::SetHDRPresent(bool hasHdrPresent)
85 {
86     if (hasHdrPresent_ == hasHdrPresent) {
87         return;
88     }
89     hasHdrPresent_ = hasHdrPresent;
90     needSync_ = true;
91 }
92 
GetHDRPresent() const93 bool RSDisplayRenderParams::GetHDRPresent() const
94 {
95     return hasHdrPresent_;
96 }
97 
SetBrightnessRatio(float brightnessRatio)98 void RSDisplayRenderParams::SetBrightnessRatio(float brightnessRatio)
99 {
100     if (ROSEN_EQ(brightnessRatio_, brightnessRatio)) {
101         return;
102     }
103     brightnessRatio_ = brightnessRatio;
104     needSync_ = true;
105 }
106 
GetBrightnessRatio() const107 float RSDisplayRenderParams::GetBrightnessRatio() const
108 {
109     return brightnessRatio_;
110 }
111 
SetNewColorSpace(const GraphicColorGamut & newColorSpace)112 void RSDisplayRenderParams::SetNewColorSpace(const GraphicColorGamut& newColorSpace)
113 {
114     if (newColorSpace_ == newColorSpace) {
115         return;
116     }
117     needSync_ = true;
118     newColorSpace_ = newColorSpace;
119 }
120 
GetNewColorSpace() const121 GraphicColorGamut RSDisplayRenderParams::GetNewColorSpace() const
122 {
123     return newColorSpace_;
124 }
125 
SetNewPixelFormat(const GraphicPixelFormat & newPixelFormat)126 void RSDisplayRenderParams::SetNewPixelFormat(const GraphicPixelFormat& newPixelFormat)
127 {
128     if (newPixelFormat_ == newPixelFormat) {
129         return;
130     }
131     needSync_ = true;
132     newPixelFormat_ = newPixelFormat;
133 }
134 
GetNewPixelFormat() const135 GraphicPixelFormat RSDisplayRenderParams::GetNewPixelFormat() const
136 {
137     return newPixelFormat_;
138 }
139 
SetZoomed(bool isZoomed)140 void RSDisplayRenderParams::SetZoomed(bool isZoomed)
141 {
142     if (isZoomed_ == isZoomed) {
143         return;
144     }
145     needSync_ = true;
146     isZoomed_ = isZoomed;
147 }
148 
GetZoomed() const149 bool RSDisplayRenderParams::GetZoomed() const
150 {
151     return isZoomed_;
152 }
153 
OnSync(const std::unique_ptr<RSRenderParams> & target)154 void RSDisplayRenderParams::OnSync(const std::unique_ptr<RSRenderParams>& target)
155 {
156     auto targetDisplayParams = static_cast<RSDisplayRenderParams*>(target.get());
157     if (targetDisplayParams == nullptr) {
158         RS_LOGE("RSDisplayRenderParams::OnSync targetDisplayParams is nullptr");
159         return;
160     }
161     allMainAndLeashSurfaceDrawables_.clear();
162     for (auto& surfaceNode : allMainAndLeashSurfaces_) {
163         auto ptr = DrawableV2::RSRenderNodeDrawableAdapter::GetDrawableById(surfaceNode->GetId());
164         if (ptr == nullptr || ptr->GetNodeType() != RSRenderNodeType::SURFACE_NODE) {
165             continue;
166         }
167         allMainAndLeashSurfaceDrawables_.push_back(ptr);
168     }
169     targetDisplayParams->allMainAndLeashSurfaceDrawables_ = allMainAndLeashSurfaceDrawables_;
170     targetDisplayParams->displayHasSecSurface_ = displayHasSecSurface_;
171     targetDisplayParams->displayHasSkipSurface_ = displayHasSkipSurface_;
172     targetDisplayParams->displayHasProtectedSurface_ = displayHasProtectedSurface_;
173     targetDisplayParams->displaySpecailSurfaceChanged_ = displaySpecailSurfaceChanged_;
174     targetDisplayParams->hasCaptureWindow_ = hasCaptureWindow_;
175     targetDisplayParams->offsetX_ = offsetX_;
176     targetDisplayParams->offsetY_ = offsetY_;
177     targetDisplayParams->nodeRotation_ = nodeRotation_;
178     targetDisplayParams->screenRotation_ = screenRotation_;
179     targetDisplayParams->screenId_ = screenId_;
180     targetDisplayParams->isSecurityDisplay_ = isSecurityDisplay_;
181     targetDisplayParams->isSecurityExemption_ = isSecurityExemption_;
182     targetDisplayParams->mirroredId_ = mirroredId_;
183     targetDisplayParams->compositeType_ = compositeType_;
184     targetDisplayParams->isMirrorScreen_ = isMirrorScreen_;
185     targetDisplayParams->mirrorSourceDrawable_ = mirrorSourceDrawable_;
186     targetDisplayParams->mirrorSourceId_ = mirrorSourceId_;
187     targetDisplayParams->screenInfo_ = std::move(screenInfo_);
188     targetDisplayParams->isMainAndLeashSurfaceDirty_ = isMainAndLeashSurfaceDirty_;
189     targetDisplayParams->needOffscreen_ = needOffscreen_;
190     targetDisplayParams->isRotationChanged_ = isRotationChanged_;
191     targetDisplayParams->newColorSpace_ = newColorSpace_;
192     targetDisplayParams->newPixelFormat_ = newPixelFormat_;
193     targetDisplayParams->hasHdrPresent_ = hasHdrPresent_;
194     targetDisplayParams->brightnessRatio_ = brightnessRatio_;
195     targetDisplayParams->zOrder_ = zOrder_;
196     targetDisplayParams->isZoomed_ = isZoomed_;
197     RSRenderParams::OnSync(target);
198 }
199 
ToString() const200 std::string RSDisplayRenderParams::ToString() const
201 {
202     std::string ret = RSRenderParams::ToString() + ", RSDisplayRenderParams: {";
203     ret += RENDER_BASIC_PARAM_TO_STRING(offsetX_);
204     ret += RENDER_BASIC_PARAM_TO_STRING(offsetY_);
205     ret += RENDER_BASIC_PARAM_TO_STRING(int(nodeRotation_));
206     ret += RENDER_BASIC_PARAM_TO_STRING(int(screenRotation_));
207     ret += RENDER_BASIC_PARAM_TO_STRING(screenId_);
208     ret += RENDER_BASIC_PARAM_TO_STRING(mirroredId_);
209     ret += RENDER_BASIC_PARAM_TO_STRING(compositeType_);
210     ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaces_.size());
211     ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaceDrawables_.size());
212     ret += RENDER_PARAM_TO_STRING(screenInfo_);
213     ret += "}";
214     return ret;
215 }
216 
GetMirrorSourceDrawable()217 DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSDisplayRenderParams::GetMirrorSourceDrawable()
218 {
219     return mirrorSourceDrawable_;
220 }
221 
HasSecurityLayer() const222 bool RSDisplayRenderParams::HasSecurityLayer() const
223 {
224     bool hasSecLayerFlag = false;
225     auto iter = displayHasSecSurface_.find(screenId_);
226     if (iter != displayHasSecSurface_.end()) {
227         hasSecLayerFlag = iter->second;
228     }
229     return hasSecLayerFlag;
230 }
231 
HasSkipLayer() const232 bool RSDisplayRenderParams::HasSkipLayer() const
233 {
234     bool hasSkipLayerFlag = false;
235     auto iter = displayHasSkipSurface_.find(screenId_);
236     if (iter != displayHasSkipSurface_.end()) {
237         hasSkipLayerFlag = iter->second;
238     }
239     return hasSkipLayerFlag;
240 }
241 
HasProtectedLayer() const242 bool RSDisplayRenderParams::HasProtectedLayer() const
243 {
244     bool hasProtectedLayerFlag = false;
245     auto iter = displayHasProtectedSurface_.find(screenId_);
246     if (iter != displayHasProtectedSurface_.end()) {
247         hasProtectedLayerFlag = iter->second;
248     }
249     return hasProtectedLayerFlag;
250 }
251 
HasCaptureWindow() const252 bool RSDisplayRenderParams::HasCaptureWindow() const
253 {
254     bool hasCaptureWindow = false;
255     auto iter = hasCaptureWindow_.find(screenId_);
256     if (iter != hasCaptureWindow_.end()) {
257         hasCaptureWindow = iter->second;
258     }
259     return hasCaptureWindow;
260 }
261 
SetNeedOffscreen(bool needOffscreen)262 void RSDisplayRenderParams::SetNeedOffscreen(bool needOffscreen)
263 {
264     if (needOffscreen_ == needOffscreen) {
265         return;
266     }
267     needOffscreen_ = needOffscreen;
268     needSync_ = true;
269 }
270 
GetNeedOffscreen() const271 bool RSDisplayRenderParams::GetNeedOffscreen() const
272 {
273     return needOffscreen_;
274 }
275 
276 } // namespace OHOS::Rosen
277