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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H 17 18 #include <memory> 19 #include <mutex> 20 #ifndef ROSEN_CROSS_PLATFORM 21 #include <ibuffer_consumer_listener.h> 22 #include <iconsumer_surface.h> 23 #include <surface.h> 24 #include "sync_fence.h" 25 #endif 26 27 #include "common/rs_macros.h" 28 #include "memory/rs_memory_track.h" 29 #include "pipeline/rs_render_node.h" 30 #include "pipeline/rs_surface_handler.h" 31 #ifdef NEW_RENDER_CONTEXT 32 #include "rs_render_surface.h" 33 #else 34 #include "platform/drawing/rs_surface.h" 35 #endif 36 37 namespace OHOS { 38 namespace Rosen { 39 enum class ScreenRotation : uint32_t; 40 class RSB_EXPORT RSDisplayRenderNode : public RSRenderNode, public RSSurfaceHandler { 41 public: 42 enum CompositeType { 43 UNI_RENDER_COMPOSITE = 0, 44 UNI_RENDER_MIRROR_COMPOSITE, 45 UNI_RENDER_EXPAND_COMPOSITE, 46 HARDWARE_COMPOSITE, 47 SOFTWARE_COMPOSITE 48 }; 49 using WeakPtr = std::weak_ptr<RSDisplayRenderNode>; 50 using SharedPtr = std::shared_ptr<RSDisplayRenderNode>; 51 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::DISPLAY_NODE; 52 53 explicit RSDisplayRenderNode(NodeId id, const RSDisplayNodeConfig& config, std::weak_ptr<RSContext> context = {}); 54 ~RSDisplayRenderNode() override; 55 void SetIsOnTheTree(bool flag, NodeId instanceRootNodeId = INVALID_NODEID) override; 56 SetScreenId(uint64_t screenId)57 void SetScreenId(uint64_t screenId) 58 { 59 screenId_ = screenId; 60 } 61 GetScreenId()62 uint64_t GetScreenId() const 63 { 64 return screenId_; 65 } 66 SetDisplayOffset(int32_t offsetX,int32_t offsetY)67 void SetDisplayOffset(int32_t offsetX, int32_t offsetY) 68 { 69 offsetX_ = offsetX; 70 offsetY_ = offsetY; 71 } 72 GetDisplayOffsetX()73 int32_t GetDisplayOffsetX() const 74 { 75 return offsetX_; 76 } 77 GetDisplayOffsetY()78 int32_t GetDisplayOffsetY() const 79 { 80 return offsetY_; 81 } 82 GetFingerprint()83 bool GetFingerprint() const 84 { 85 return hasFingerprint_; 86 } 87 SetFingerprint(bool hasFingerprint)88 void SetFingerprint(bool hasFingerprint) 89 { 90 hasFingerprint_ = hasFingerprint; 91 } 92 93 void CollectSurface( 94 const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, 95 bool isUniRender, bool onlyFirstLevel) override; 96 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 97 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 98 GetType()99 RSRenderNodeType GetType() const override 100 { 101 return RSRenderNodeType::DISPLAY_NODE; 102 } 103 104 bool IsMirrorDisplay() const; 105 106 void SetCompositeType(CompositeType type); 107 CompositeType GetCompositeType() const; 108 void SetForceSoftComposite(bool flag); 109 bool IsForceSoftComposite() const; 110 void SetMirrorSource(SharedPtr node); 111 void ResetMirrorSource(); 112 void SetIsMirrorDisplay(bool isMirror); 113 void SetSecurityDisplay(bool isSecurityDisplay); 114 bool GetSecurityDisplay() const; 115 bool SkipFrame(uint32_t skipFrameInterval); 116 GetMirrorSource()117 WeakPtr GetMirrorSource() const 118 { 119 return mirrorSource_; 120 } 121 HasDisappearingTransition(bool)122 bool HasDisappearingTransition(bool) const override 123 { 124 return false; 125 } 126 #ifdef NEW_RENDER_CONTEXT GetRSSurface()127 std::shared_ptr<RSRenderSurface> GetRSSurface() const 128 { 129 return surface_; 130 } 131 #else GetRSSurface()132 std::shared_ptr<RSSurface> GetRSSurface() const 133 { 134 return surface_; 135 } 136 #endif 137 // Use in vulkan parallel rendering SetIsParallelDisplayNode(bool isParallelDisplayNode)138 void SetIsParallelDisplayNode(bool isParallelDisplayNode) 139 { 140 isParallelDisplayNode_ = isParallelDisplayNode; 141 } 142 IsParallelDisplayNode()143 bool IsParallelDisplayNode() const 144 { 145 return isParallelDisplayNode_; 146 } 147 148 #ifndef ROSEN_CROSS_PLATFORM 149 bool CreateSurface(sptr<IBufferConsumerListener> listener); GetConsumerListener()150 sptr<IBufferConsumerListener> GetConsumerListener() const 151 { 152 return consumerListener_; 153 } 154 #endif 155 IsSurfaceCreated()156 bool IsSurfaceCreated() const 157 { 158 return surfaceCreated_; 159 } 160 161 ScreenRotation GetRotation() const; 162 GetDirtyManager()163 std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() 164 { 165 return dirtyManager_; 166 } 167 void UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion = false); 168 void ClearCurrentSurfacePos(); UpdateSurfaceNodePos(NodeId id,RectI rect)169 void UpdateSurfaceNodePos(NodeId id, RectI rect) 170 { 171 #if defined(RS_ENABLE_PARALLEL_RENDER) && (defined (RS_ENABLE_GL) || defined (RS_ENABLE_VK)) 172 std::unique_lock<std::mutex> lock(mtx_); 173 currentFrameSurfacePos_[id] = rect; 174 #else 175 currentFrameSurfacePos_[id] = rect; 176 #endif 177 } 178 GetLastFrameSurfacePos(NodeId id)179 RectI GetLastFrameSurfacePos(NodeId id) 180 { 181 if (lastFrameSurfacePos_.count(id) == 0) { 182 return RectI(); 183 } 184 return lastFrameSurfacePos_[id]; 185 } 186 GetCurrentFrameSurfacePos(NodeId id)187 RectI GetCurrentFrameSurfacePos(NodeId id) 188 { 189 if (currentFrameSurfacePos_.count(id) == 0) { 190 return RectI(); 191 } 192 return currentFrameSurfacePos_[id]; 193 } 194 GetSurfaceChangedRects()195 const std::vector<RectI> GetSurfaceChangedRects() const 196 { 197 std::vector<RectI> rects; 198 for (auto iter = lastFrameSurfacePos_.begin(); iter != lastFrameSurfacePos_.end(); iter++) { 199 if (currentFrameSurfacePos_.find(iter->first) == currentFrameSurfacePos_.end()) { 200 rects.emplace_back(iter->second); 201 } 202 } 203 for (auto iter = currentFrameSurfacePos_.begin(); iter != currentFrameSurfacePos_.end(); iter++) { 204 if (lastFrameSurfacePos_.find(iter->first) == lastFrameSurfacePos_.end()) { 205 rects.emplace_back(iter->second); 206 } 207 } 208 return rects; 209 } 210 GetCurAllSurfaces()211 std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces() 212 { 213 return curAllSurfaces_; 214 } 215 216 void UpdateRotation(); 217 bool IsRotationChanged() const; IsFirstTimeToProcessor()218 bool IsFirstTimeToProcessor() const { 219 return isFirstTimeToProcessor_; 220 } 221 222 #ifndef USE_ROSEN_DRAWING SetInitMatrix(const SkMatrix & skMatrix)223 void SetInitMatrix(const SkMatrix& skMatrix) { 224 initMatrix_ = skMatrix; 225 #else 226 void SetInitMatrix(const Drawing::Matrix& matrix) { 227 initMatrix_ = matrix; 228 #endif 229 isFirstTimeToProcessor_ = false; 230 } 231 232 #ifndef USE_ROSEN_DRAWING 233 const SkMatrix& GetInitMatrix() const { 234 #else 235 const Drawing::Matrix& GetInitMatrix() const { 236 #endif 237 return initMatrix_; 238 } 239 private: 240 CompositeType compositeType_ { HARDWARE_COMPOSITE }; 241 uint64_t screenId_; 242 int32_t offsetX_; 243 int32_t offsetY_; 244 bool forceSoftComposite_ { false }; 245 bool isMirroredDisplay_ = false; 246 bool isSecurityDisplay_ = false; 247 WeakPtr mirrorSource_; 248 float lastRotation_ = 0.f; 249 #ifndef USE_ROSEN_DRAWING 250 SkMatrix initMatrix_; 251 #else 252 Drawing::Matrix initMatrix_; 253 #endif 254 bool isFirstTimeToProcessor_ = true; 255 #ifdef NEW_RENDER_CONTEXT 256 std::shared_ptr<RSRenderSurface> surface_; 257 #else 258 std::shared_ptr<RSSurface> surface_; 259 #endif 260 bool surfaceCreated_ { false }; 261 bool hasFingerprint_ = false; 262 #ifndef ROSEN_CROSS_PLATFORM 263 sptr<IBufferConsumerListener> consumerListener_; 264 #endif 265 uint64_t frameCount_ = 0; 266 267 std::map<NodeId, RectI> lastFrameSurfacePos_; 268 std::map<NodeId, RectI> currentFrameSurfacePos_; 269 std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr; 270 271 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces_; 272 std::mutex mtx_; 273 274 // Use in vulkan parallel rendering 275 bool isParallelDisplayNode_ = false; 276 }; 277 } // namespace Rosen 278 } // namespace OHOS 279 280 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H 281