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 #ifndef ROSEN_CROSS_PLATFORM 20 #include <ibuffer_consumer_listener.h> 21 #include <surface.h> 22 #include "sync_fence.h" 23 #endif 24 25 #include "common/rs_macros.h" 26 #include "pipeline/rs_render_node.h" 27 #include "pipeline/rs_surface_handler.h" 28 #include "platform/drawing/rs_surface.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 enum class ScreenRotation : uint32_t; 33 class RSB_EXPORT RSDisplayRenderNode : public RSRenderNode, public RSSurfaceHandler { 34 public: 35 enum CompositeType { 36 UNI_RENDER_COMPOSITE = 0, 37 UNI_RENDER_MIRROR_COMPOSITE, 38 HARDWARE_COMPOSITE, 39 SOFTWARE_COMPOSITE 40 }; 41 using WeakPtr = std::weak_ptr<RSDisplayRenderNode>; 42 using SharedPtr = std::shared_ptr<RSDisplayRenderNode>; 43 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::DISPLAY_NODE; 44 45 explicit RSDisplayRenderNode(NodeId id, const RSDisplayNodeConfig& config, std::weak_ptr<RSContext> context = {}); 46 ~RSDisplayRenderNode() override; 47 SetScreenId(uint64_t screenId)48 void SetScreenId(uint64_t screenId) 49 { 50 screenId_ = screenId; 51 } 52 GetScreenId()53 uint64_t GetScreenId() const 54 { 55 return screenId_; 56 } 57 SetDisplayOffset(int32_t offsetX,int32_t offsetY)58 void SetDisplayOffset(int32_t offsetX, int32_t offsetY) 59 { 60 offsetX_ = offsetX; 61 offsetY_ = offsetY; 62 } 63 GetDisplayOffsetX()64 int32_t GetDisplayOffsetX() const 65 { 66 return offsetX_; 67 } 68 GetDisplayOffsetY()69 int32_t GetDisplayOffsetY() const 70 { 71 return offsetY_; 72 } 73 74 void CollectSurface( 75 const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, 76 bool isUniRender) override; 77 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 78 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 79 GetType()80 RSRenderNodeType GetType() const override 81 { 82 return RSRenderNodeType::DISPLAY_NODE; 83 } 84 85 bool IsMirrorDisplay() const; 86 87 void SetCompositeType(CompositeType type); 88 CompositeType GetCompositeType() const; 89 void SetForceSoftComposite(bool flag); 90 bool IsForceSoftComposite() const; 91 void SetMirrorSource(SharedPtr node); 92 void ResetMirrorSource(); 93 void SetIsMirrorDisplay(bool isMirror); 94 void SetSecurityDisplay(bool isSecurityDisplay); 95 bool GetSecurityDisplay() const; 96 bool SkipFrame(uint32_t skipFrameInterval); 97 GetMirrorSource()98 WeakPtr GetMirrorSource() const 99 { 100 return mirrorSource_; 101 } 102 HasDisappearingTransition(bool)103 bool HasDisappearingTransition(bool) const override 104 { 105 return false; 106 } 107 GetRSSurface()108 std::shared_ptr<RSSurface> GetRSSurface() const 109 { 110 return surface_; 111 } 112 113 #ifndef ROSEN_CROSS_PLATFORM 114 bool CreateSurface(sptr<IBufferConsumerListener> listener); GetConsumerListener()115 sptr<IBufferConsumerListener> GetConsumerListener() const 116 { 117 return consumerListener_; 118 } 119 #endif 120 IsSurfaceCreated()121 bool IsSurfaceCreated() const 122 { 123 return surfaceCreated_; 124 } 125 126 ScreenRotation GetRotation() const; 127 GetDirtyManager()128 std::shared_ptr<RSDirtyRegionManager> GetDirtyManager() 129 { 130 return dirtyManager_; 131 } 132 void UpdateDisplayDirtyManager(int32_t bufferage); 133 void ClearCurrentSurfacePos(); UpdateSurfaceNodePos(NodeId id,RectI rect)134 void UpdateSurfaceNodePos(NodeId id, RectI rect) 135 { 136 currentFrameSurfacePos_[id] = rect; 137 } 138 GetLastFrameSurfacePos(NodeId id)139 RectI GetLastFrameSurfacePos(NodeId id) 140 { 141 return lastFrameSurfacePos_[id]; 142 } 143 GetCurrentFrameSurfacePos(NodeId id)144 RectI GetCurrentFrameSurfacePos(NodeId id) 145 { 146 return currentFrameSurfacePos_[id]; 147 } 148 GetSurfaceChangedRects()149 const std::vector<RectI> GetSurfaceChangedRects() const 150 { 151 std::vector<RectI> rects; 152 for (auto iter = lastFrameSurfacePos_.begin(); iter != lastFrameSurfacePos_.end(); iter++) { 153 if (currentFrameSurfacePos_.find(iter->first) == currentFrameSurfacePos_.end()) { 154 rects.emplace_back(iter->second); 155 } 156 } 157 for (auto iter = currentFrameSurfacePos_.begin(); iter != currentFrameSurfacePos_.end(); iter++) { 158 if (lastFrameSurfacePos_.find(iter->first) == lastFrameSurfacePos_.end()) { 159 rects.emplace_back(iter->second); 160 } 161 } 162 return rects; 163 } 164 GetCurAllSurfaces()165 std::vector<RSBaseRenderNode::SharedPtr>& GetCurAllSurfaces() 166 { 167 return curAllSurfaces_; 168 } 169 170 void UpdateRotation(); 171 bool IsRotationChanged() const; 172 private: 173 CompositeType compositeType_ { HARDWARE_COMPOSITE }; 174 uint64_t screenId_; 175 int32_t offsetX_; 176 int32_t offsetY_; 177 bool forceSoftComposite_ { false }; 178 bool isMirroredDisplay_ = false; 179 bool isSecurityDisplay_ = false; 180 WeakPtr mirrorSource_; 181 float lastRotation_ = 0.f; 182 183 std::shared_ptr<RSSurface> surface_; 184 bool surfaceCreated_ { false }; 185 #ifndef ROSEN_CROSS_PLATFORM 186 sptr<IBufferConsumerListener> consumerListener_; 187 #endif 188 uint64_t frameCount_ = 0; 189 190 std::map<NodeId, RectI> lastFrameSurfacePos_; 191 std::map<NodeId, RectI> currentFrameSurfacePos_; 192 std::shared_ptr<RSDirtyRegionManager> dirtyManager_ = nullptr; 193 194 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces_; 195 }; 196 } // namespace Rosen 197 } // namespace OHOS 198 199 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DISPLAY_RENDER_NODE_H 200