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)21RSDisplayRenderParams::RSDisplayRenderParams(NodeId id) : RSRenderParams(id) {} 22 GetAllMainAndLeashSurfaces()23std::vector<RSBaseRenderNode::SharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaces() 24 { 25 return allMainAndLeashSurfaces_; 26 } 27 GetAllMainAndLeashSurfaceDrawables()28std::vector<RSRenderNodeDrawableAdapterSharedPtr>& RSDisplayRenderParams::GetAllMainAndLeashSurfaceDrawables() 29 { 30 return allMainAndLeashSurfaceDrawables_; 31 } 32 SetAllMainAndLeashSurfaces(std::vector<RSBaseRenderNode::SharedPtr> & allMainAndLeashSurfaces)33void RSDisplayRenderParams::SetAllMainAndLeashSurfaces( 34 std::vector<RSBaseRenderNode::SharedPtr>& allMainAndLeashSurfaces) 35 { 36 std::swap(allMainAndLeashSurfaces_, allMainAndLeashSurfaces); 37 } 38 SetAllMainAndLeashSurfaceDrawables(std::vector<RSRenderNodeDrawableAdapterSharedPtr> & allMainAndLeashSurfaceDrawables)39void RSDisplayRenderParams::SetAllMainAndLeashSurfaceDrawables( 40 std::vector<RSRenderNodeDrawableAdapterSharedPtr>& allMainAndLeashSurfaceDrawables) 41 { 42 std::swap(allMainAndLeashSurfaceDrawables_, allMainAndLeashSurfaceDrawables); 43 } 44 SetMainAndLeashSurfaceDirty(bool isDirty)45void RSDisplayRenderParams::SetMainAndLeashSurfaceDirty(bool isDirty) 46 { 47 if (isMainAndLeashSurfaceDirty_ == isDirty) { 48 return; 49 } 50 isMainAndLeashSurfaceDirty_ = isDirty; 51 needSync_ = true; 52 } 53 GetMainAndLeashSurfaceDirty() const54bool RSDisplayRenderParams::GetMainAndLeashSurfaceDirty() const 55 { 56 return isMainAndLeashSurfaceDirty_; 57 } 58 SetRotationChanged(bool changed)59void RSDisplayRenderParams::SetRotationChanged(bool changed) 60 { 61 if (isRotationChanged_ == changed) { 62 return; 63 } 64 isRotationChanged_ = changed; 65 needSync_ = true; 66 } 67 SetGlobalZOrder(float zOrder)68void RSDisplayRenderParams::SetGlobalZOrder(float zOrder) 69 { 70 zOrder_ = zOrder; 71 needSync_ = true; 72 } 73 GetGlobalZOrder() const74float RSDisplayRenderParams::GetGlobalZOrder() const 75 { 76 return zOrder_; 77 } 78 IsRotationChanged() const79bool RSDisplayRenderParams::IsRotationChanged() const 80 { 81 return isRotationChanged_; 82 } 83 SetHDRPresent(bool hasHdrPresent)84void RSDisplayRenderParams::SetHDRPresent(bool hasHdrPresent) 85 { 86 if (hasHdrPresent_ == hasHdrPresent) { 87 return; 88 } 89 hasHdrPresent_ = hasHdrPresent; 90 needSync_ = true; 91 } 92 GetHDRPresent() const93bool RSDisplayRenderParams::GetHDRPresent() const 94 { 95 return hasHdrPresent_; 96 } 97 SetBrightnessRatio(float brightnessRatio)98void RSDisplayRenderParams::SetBrightnessRatio(float brightnessRatio) 99 { 100 if (ROSEN_EQ(brightnessRatio_, brightnessRatio)) { 101 return; 102 } 103 brightnessRatio_ = brightnessRatio; 104 needSync_ = true; 105 } 106 GetBrightnessRatio() const107float RSDisplayRenderParams::GetBrightnessRatio() const 108 { 109 return brightnessRatio_; 110 } 111 SetNewColorSpace(const GraphicColorGamut & newColorSpace)112void RSDisplayRenderParams::SetNewColorSpace(const GraphicColorGamut& newColorSpace) 113 { 114 if (newColorSpace_ == newColorSpace) { 115 return; 116 } 117 needSync_ = true; 118 newColorSpace_ = newColorSpace; 119 } 120 GetNewColorSpace() const121GraphicColorGamut RSDisplayRenderParams::GetNewColorSpace() const 122 { 123 return newColorSpace_; 124 } 125 SetNewPixelFormat(const GraphicPixelFormat & newPixelFormat)126void RSDisplayRenderParams::SetNewPixelFormat(const GraphicPixelFormat& newPixelFormat) 127 { 128 if (newPixelFormat_ == newPixelFormat) { 129 return; 130 } 131 needSync_ = true; 132 newPixelFormat_ = newPixelFormat; 133 } 134 GetNewPixelFormat() const135GraphicPixelFormat RSDisplayRenderParams::GetNewPixelFormat() const 136 { 137 return newPixelFormat_; 138 } 139 SetZoomed(bool isZoomed)140void RSDisplayRenderParams::SetZoomed(bool isZoomed) 141 { 142 if (isZoomed_ == isZoomed) { 143 return; 144 } 145 needSync_ = true; 146 isZoomed_ = isZoomed; 147 } 148 GetZoomed() const149bool RSDisplayRenderParams::GetZoomed() const 150 { 151 return isZoomed_; 152 } 153 OnSync(const std::unique_ptr<RSRenderParams> & target)154void 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->mirrorSourceDrawable_ = mirrorSourceDrawable_; 185 targetDisplayParams->mirrorSourceId_ = mirrorSourceId_; 186 targetDisplayParams->screenInfo_ = std::move(screenInfo_); 187 targetDisplayParams->isMainAndLeashSurfaceDirty_ = isMainAndLeashSurfaceDirty_; 188 targetDisplayParams->needOffscreen_ = needOffscreen_; 189 targetDisplayParams->isRotationChanged_ = isRotationChanged_; 190 targetDisplayParams->newColorSpace_ = newColorSpace_; 191 targetDisplayParams->newPixelFormat_ = newPixelFormat_; 192 targetDisplayParams->hasHdrPresent_ = hasHdrPresent_; 193 targetDisplayParams->brightnessRatio_ = brightnessRatio_; 194 targetDisplayParams->zOrder_ = zOrder_; 195 targetDisplayParams->isZoomed_ = isZoomed_; 196 RSRenderParams::OnSync(target); 197 } 198 ToString() const199std::string RSDisplayRenderParams::ToString() const 200 { 201 std::string ret = RSRenderParams::ToString() + ", RSDisplayRenderParams: {"; 202 ret += RENDER_BASIC_PARAM_TO_STRING(offsetX_); 203 ret += RENDER_BASIC_PARAM_TO_STRING(offsetY_); 204 ret += RENDER_BASIC_PARAM_TO_STRING(int(nodeRotation_)); 205 ret += RENDER_BASIC_PARAM_TO_STRING(int(screenRotation_)); 206 ret += RENDER_BASIC_PARAM_TO_STRING(screenId_); 207 ret += RENDER_BASIC_PARAM_TO_STRING(mirroredId_); 208 ret += RENDER_BASIC_PARAM_TO_STRING(compositeType_); 209 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaces_.size()); 210 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaceDrawables_.size()); 211 ret += RENDER_PARAM_TO_STRING(screenInfo_); 212 ret += "}"; 213 return ret; 214 } 215 GetMirrorSourceDrawable()216DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSDisplayRenderParams::GetMirrorSourceDrawable() 217 { 218 return mirrorSourceDrawable_; 219 } 220 HasSecurityLayer() const221bool RSDisplayRenderParams::HasSecurityLayer() const 222 { 223 bool hasSecLayerFlag = false; 224 auto iter = displayHasSecSurface_.find(screenId_); 225 if (iter != displayHasSecSurface_.end()) { 226 hasSecLayerFlag = iter->second; 227 } 228 return hasSecLayerFlag; 229 } 230 HasSkipLayer() const231bool RSDisplayRenderParams::HasSkipLayer() const 232 { 233 bool hasSkipLayerFlag = false; 234 auto iter = displayHasSkipSurface_.find(screenId_); 235 if (iter != displayHasSkipSurface_.end()) { 236 hasSkipLayerFlag = iter->second; 237 } 238 return hasSkipLayerFlag; 239 } 240 HasProtectedLayer() const241bool RSDisplayRenderParams::HasProtectedLayer() const 242 { 243 bool hasProtectedLayerFlag = false; 244 auto iter = displayHasProtectedSurface_.find(screenId_); 245 if (iter != displayHasProtectedSurface_.end()) { 246 hasProtectedLayerFlag = iter->second; 247 } 248 return hasProtectedLayerFlag; 249 } 250 HasCaptureWindow() const251bool RSDisplayRenderParams::HasCaptureWindow() const 252 { 253 bool hasCaptureWindow = false; 254 auto iter = hasCaptureWindow_.find(screenId_); 255 if (iter != hasCaptureWindow_.end()) { 256 hasCaptureWindow = iter->second; 257 } 258 return hasCaptureWindow; 259 } 260 SetNeedOffscreen(bool needOffscreen)261void RSDisplayRenderParams::SetNeedOffscreen(bool needOffscreen) 262 { 263 if (needOffscreen_ == needOffscreen) { 264 return; 265 } 266 needOffscreen_ = needOffscreen; 267 needSync_ = true; 268 } 269 GetNeedOffscreen() const270bool RSDisplayRenderParams::GetNeedOffscreen() const 271 { 272 return needOffscreen_; 273 } 274 275 } // namespace OHOS::Rosen 276