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