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->displayHasSnapshotSkipSurface_ = displayHasSnapshotSkipSurface_; 173 targetDisplayParams->displayHasProtectedSurface_ = displayHasProtectedSurface_; 174 targetDisplayParams->displaySpecailSurfaceChanged_ = displaySpecailSurfaceChanged_; 175 targetDisplayParams->hasCaptureWindow_ = hasCaptureWindow_; 176 targetDisplayParams->offsetX_ = offsetX_; 177 targetDisplayParams->offsetY_ = offsetY_; 178 targetDisplayParams->nodeRotation_ = nodeRotation_; 179 targetDisplayParams->screenRotation_ = screenRotation_; 180 targetDisplayParams->screenId_ = screenId_; 181 targetDisplayParams->isSecurityDisplay_ = isSecurityDisplay_; 182 targetDisplayParams->isSecurityExemption_ = isSecurityExemption_; 183 targetDisplayParams->mirroredId_ = mirroredId_; 184 targetDisplayParams->compositeType_ = compositeType_; 185 targetDisplayParams->isMirrorScreen_ = isMirrorScreen_; 186 targetDisplayParams->mirrorSourceDrawable_ = mirrorSourceDrawable_; 187 targetDisplayParams->mirrorSourceId_ = mirrorSourceId_; 188 targetDisplayParams->screenInfo_ = std::move(screenInfo_); 189 targetDisplayParams->isMainAndLeashSurfaceDirty_ = isMainAndLeashSurfaceDirty_; 190 targetDisplayParams->needOffscreen_ = needOffscreen_; 191 targetDisplayParams->isRotationChanged_ = isRotationChanged_; 192 targetDisplayParams->newColorSpace_ = newColorSpace_; 193 targetDisplayParams->newPixelFormat_ = newPixelFormat_; 194 targetDisplayParams->hasHdrPresent_ = hasHdrPresent_; 195 targetDisplayParams->brightnessRatio_ = brightnessRatio_; 196 targetDisplayParams->zOrder_ = zOrder_; 197 targetDisplayParams->isZoomed_ = isZoomed_; 198 RSRenderParams::OnSync(target); 199 } 200 ToString() const201std::string RSDisplayRenderParams::ToString() const 202 { 203 std::string ret = RSRenderParams::ToString() + ", RSDisplayRenderParams: {"; 204 ret += RENDER_BASIC_PARAM_TO_STRING(offsetX_); 205 ret += RENDER_BASIC_PARAM_TO_STRING(offsetY_); 206 ret += RENDER_BASIC_PARAM_TO_STRING(int(nodeRotation_)); 207 ret += RENDER_BASIC_PARAM_TO_STRING(int(screenRotation_)); 208 ret += RENDER_BASIC_PARAM_TO_STRING(screenId_); 209 ret += RENDER_BASIC_PARAM_TO_STRING(mirroredId_); 210 ret += RENDER_BASIC_PARAM_TO_STRING(compositeType_); 211 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaces_.size()); 212 ret += RENDER_BASIC_PARAM_TO_STRING(allMainAndLeashSurfaceDrawables_.size()); 213 ret += RENDER_PARAM_TO_STRING(screenInfo_); 214 ret += "}"; 215 return ret; 216 } 217 GetMirrorSourceDrawable()218DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr RSDisplayRenderParams::GetMirrorSourceDrawable() 219 { 220 return mirrorSourceDrawable_; 221 } 222 HasSecurityLayer() const223bool RSDisplayRenderParams::HasSecurityLayer() const 224 { 225 bool hasSecLayerFlag = false; 226 auto iter = displayHasSecSurface_.find(screenId_); 227 if (iter != displayHasSecSurface_.end()) { 228 hasSecLayerFlag = iter->second; 229 } 230 return hasSecLayerFlag; 231 } 232 HasSkipLayer() const233bool RSDisplayRenderParams::HasSkipLayer() const 234 { 235 bool hasSkipLayerFlag = false; 236 auto iter = displayHasSkipSurface_.find(screenId_); 237 if (iter != displayHasSkipSurface_.end()) { 238 hasSkipLayerFlag = iter->second; 239 } 240 return hasSkipLayerFlag; 241 } 242 HasSnapshotSkipLayer() const243bool RSDisplayRenderParams::HasSnapshotSkipLayer() const 244 { 245 bool hasSnapshotSkipLayerFlag = false; 246 auto iter = displayHasSnapshotSkipSurface_.find(screenId_); 247 if (iter != displayHasSnapshotSkipSurface_.end()) { 248 hasSnapshotSkipLayerFlag = iter->second; 249 } 250 return hasSnapshotSkipLayerFlag; 251 } 252 HasProtectedLayer() const253bool RSDisplayRenderParams::HasProtectedLayer() const 254 { 255 bool hasProtectedLayerFlag = false; 256 auto iter = displayHasProtectedSurface_.find(screenId_); 257 if (iter != displayHasProtectedSurface_.end()) { 258 hasProtectedLayerFlag = iter->second; 259 } 260 return hasProtectedLayerFlag; 261 } 262 HasCaptureWindow() const263bool RSDisplayRenderParams::HasCaptureWindow() const 264 { 265 bool hasCaptureWindow = false; 266 auto iter = hasCaptureWindow_.find(screenId_); 267 if (iter != hasCaptureWindow_.end()) { 268 hasCaptureWindow = iter->second; 269 } 270 return hasCaptureWindow; 271 } 272 SetNeedOffscreen(bool needOffscreen)273void RSDisplayRenderParams::SetNeedOffscreen(bool needOffscreen) 274 { 275 if (needOffscreen_ == needOffscreen) { 276 return; 277 } 278 needOffscreen_ = needOffscreen; 279 needSync_ = true; 280 } 281 GetNeedOffscreen() const282bool RSDisplayRenderParams::GetNeedOffscreen() const 283 { 284 return needOffscreen_; 285 } 286 287 } // namespace OHOS::Rosen 288