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_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_NODE_H 17 18 #include <memory> 19 #include <unordered_set> 20 21 #include "animation/rs_animation_manager.h" 22 #include "common/rs_macros.h" 23 #include "modifier/rs_render_modifier.h" 24 #include "pipeline/rs_base_render_node.h" 25 #include "pipeline/rs_dirty_region_manager.h" 26 #include "property/rs_properties.h" 27 28 class SkCanvas; 29 namespace OHOS { 30 namespace Rosen { 31 class DrawCmdList; 32 class RSPaintFilterCanvas; 33 34 class RSB_EXPORT RSRenderNode : public RSBaseRenderNode { 35 public: 36 using WeakPtr = std::weak_ptr<RSRenderNode>; 37 using SharedPtr = std::shared_ptr<RSRenderNode>; 38 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::RS_NODE; GetType()39 RSRenderNodeType GetType() const override 40 { 41 return Type; 42 } 43 44 ~RSRenderNode() override; 45 46 std::pair<bool, bool> Animate(int64_t timestamp) override; 47 bool Update(RSDirtyRegionManager& dirtyManager, const RSProperties* parent, bool parentDirty); 48 49 RSProperties& GetMutableRenderProperties(); 50 const RSProperties& GetRenderProperties() const; 51 void UpdateRenderStatus(RectI& dirtyRegion, bool isPartialRenderEnabled); IsRenderUpdateIgnored()52 inline bool IsRenderUpdateIgnored() const 53 { 54 return isRenderUpdateIgnored_; 55 } 56 57 // used for animation test GetAnimationManager()58 RSAnimationManager& GetAnimationManager() 59 { 60 return animationManager_; 61 } 62 63 virtual void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas); ProcessRenderContents(RSPaintFilterCanvas & canvas)64 virtual void ProcessRenderContents(RSPaintFilterCanvas& canvas) {} 65 virtual void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas); 66 void RenderTraceDebug() const; HasDisappearingTransition(bool recursive)67 bool HasDisappearingTransition(bool recursive) const override 68 { 69 return (disappearingTransitionCount_ > 0) || RSBaseRenderNode::HasDisappearingTransition(recursive); 70 } 71 bool ShouldPaint() const; 72 GetOldDirty()73 inline RectI GetOldDirty() const 74 { 75 return oldDirty_; 76 } GetOldDirtyInSurface()77 inline RectI GetOldDirtyInSurface() const 78 { 79 return oldDirtyInSurface_; 80 } 81 IsDirtyRegionUpdated()82 inline bool IsDirtyRegionUpdated() const 83 { 84 return isDirtyRegionUpdated_; 85 } 86 void AddModifier(const std::shared_ptr<RSRenderModifier> modifier); 87 void RemoveModifier(const PropertyId& id); 88 89 void ApplyModifiers(); 90 std::shared_ptr<RSRenderModifier> GetModifier(const PropertyId& id); 91 IsShadowValidLastFrame()92 bool IsShadowValidLastFrame() const 93 { 94 return isShadowValidLastFrame_; 95 } SetShadowValidLastFrame(bool isShadowValidLastFrame)96 void SetShadowValidLastFrame(bool isShadowValidLastFrame) 97 { 98 isShadowValidLastFrame_ = isShadowValidLastFrame; 99 } 100 // update parent's children rect including childRect and itself 101 // if not customized, it merge's node's dirtyRect 102 void UpdateParentChildrenRect(std::shared_ptr<RSBaseRenderNode> parentNode, 103 const bool isCustomized = false, const RectI subRect = RectI()) const; 104 105 protected: 106 explicit RSRenderNode(NodeId id, std::weak_ptr<RSContext> context = {}); 107 void UpdateDirtyRegion(RSDirtyRegionManager& dirtyManager, bool geoDirty); 108 bool IsDirty() const override; 109 void AddGeometryModifier(const std::shared_ptr<RSRenderModifier> modifier); 110 std::pair<int, int> renderNodeSaveCount_ = { 0, 0 }; 111 std::map<RSModifierType, std::list<std::shared_ptr<RSRenderModifier>>> drawCmdModifiers_; 112 // if true, it means currently it's in partial render mode and this node is intersect with dirtyRegion 113 bool isRenderUpdateIgnored_ = false; 114 bool isShadowValidLastFrame_ = false; 115 116 private: 117 void FallbackAnimationsToRoot(); 118 void UpdateOverlayBounds(); 119 void FilterModifiersByPid(pid_t pid); 120 bool isDirtyRegionUpdated_ = false; 121 bool isLastVisible_ = false; 122 bool fallbackAnimationOnDestroy_ = true; 123 uint32_t disappearingTransitionCount_ = 0; 124 RectI oldDirty_; 125 RectI oldDirtyInSurface_; 126 RSProperties renderProperties_; 127 RSAnimationManager animationManager_; 128 std::map<PropertyId, std::shared_ptr<RSRenderModifier>> modifiers_; 129 // bounds and frame modifiers must be unique 130 std::shared_ptr<RSRenderModifier> boundsModifier_; 131 std::shared_ptr<RSRenderModifier> frameModifier_; 132 133 friend class RSRenderTransition; 134 friend class RSRenderNodeMap; 135 friend class RSProxyRenderNode; 136 }; 137 } // namespace Rosen 138 } // namespace OHOS 139 140 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RENDER_NODE_H 141