1 /* 2 * Copyright (c) 2022-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_PROXY_RENDER_NODE_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PROXY_RENDER_NODE_H 17 18 #include "common/rs_macros.h" 19 #include "pipeline/rs_render_node.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 class RSSurfaceRenderNode; 24 class RSB_EXPORT RSProxyRenderNode : public RSRenderNode { 25 public: 26 using WeakPtr = std::weak_ptr<RSProxyRenderNode>; 27 using SharedPtr = std::shared_ptr<RSProxyRenderNode>; 28 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::PROXY_NODE; GetType()29 RSRenderNodeType GetType() const override 30 { 31 return Type; 32 } 33 GetUifirstSupportFlag()34 bool GetUifirstSupportFlag() override 35 { 36 return false; 37 } 38 39 ~RSProxyRenderNode() override; 40 41 void Prepare(const std::shared_ptr<RSNodeVisitor>& visitor) override; 42 void Process(const std::shared_ptr<RSNodeVisitor>& visitor) override; 43 44 // Transfer the rendering context variables (matrix/alpha/clip) from the proxy node to the target node, usually a 45 // surface node. Note that: 46 // 1. All three variables (alpha, matrix, and clipRegion) are RELATIVE to its parent node. 47 // 2. Alpha can be processed as an absolute value, as its parent (surface) node's alpha should always be 1.0f. 48 // 3. The matrix and clipRegion should be applied according to the parent node's matrix. 49 void SetContextMatrix(const std::optional<Drawing::Matrix>& transform); 50 void SetContextAlpha(float alpha); 51 void SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion); 52 53 void ResetContextVariableCache(); 54 protected: 55 void OnTreeStateChanged() override; 56 57 private: 58 explicit RSProxyRenderNode(NodeId id, std::weak_ptr<RSSurfaceRenderNode> target, NodeId targetId, 59 const std::weak_ptr<RSContext>& context = {}); 60 std::weak_ptr<RSSurfaceRenderNode> target_; 61 NodeId targetId_; 62 63 std::optional<Drawing::Matrix> contextMatrix_; 64 float contextAlpha_ = 0.0f; 65 std::optional<Drawing::Rect> contextClipRect_; 66 67 void CleanUp(bool removeModifiers); 68 69 friend class ProxyNodeCommandHelper; 70 friend class RSUniRenderVisitor; 71 }; 72 } // namespace Rosen 73 } // namespace OHOS 74 75 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_PROXY_RENDER_NODE_H 76