• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UI_RS_CANVAS_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H
17 
18 #include "ui/rs_node.h"
19 
20 
21 namespace OHOS {
22 namespace Rosen {
23 class RSNodeMap;
24 
25 class RSC_EXPORT RSCanvasNode : public RSNode {
26 public:
27     using WeakPtr = std::weak_ptr<RSCanvasNode>;
28     using SharedPtr = std::shared_ptr<RSCanvasNode>;
29     static inline constexpr RSUINodeType Type = RSUINodeType::CANVAS_NODE;
GetType()30     RSUINodeType GetType() const override
31     {
32         return Type;
33     }
34 
35     ~RSCanvasNode() override;
36 
37     static SharedPtr Create(bool isRenderServiceNode = false, bool isTextureExportNode = false,
38         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
39 
40     ExtendRecordingCanvas* BeginRecording(int width, int height);
41     bool IsRecording() const;
42     void FinishRecording();
43     float GetPaintWidth() const;
44     float GetPaintHeight() const;
45     void DrawOnNode(RSModifierType type, DrawFunc func) override;
46 
47     void SetFreeze(bool isFreeze) override;
48 
49     void SetHDRPresent(bool hdrPresent);
50 
51     void SetBoundsChangedCallback(BoundsChangedCallback callback) override;
52 
53     void CheckThread();
54 
55     /**
56      * @brief Set linked node id in PC window resize scenario.
57      * @param rootNodeId source RSRootNode id.
58      */
59     void SetLinkedRootNodeId(NodeId rootNodeId);
60     NodeId GetLinkedRootNodeId();
61 
62     bool Marshalling(Parcel& parcel) const;
63     static SharedPtr Unmarshalling(Parcel& parcel);
64 protected:
65     RSCanvasNode(
66         bool isRenderServiceNode, bool isTextureExportNode = false, std::shared_ptr<RSUIContext> rsUIContext = nullptr);
67     RSCanvasNode(bool isRenderServiceNode, NodeId id, bool isTextureExportNode = false,
68         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
69     RSCanvasNode(const RSCanvasNode&) = delete;
70     RSCanvasNode(const RSCanvasNode&&) = delete;
71     RSCanvasNode& operator=(const RSCanvasNode&) = delete;
72     RSCanvasNode& operator=(const RSCanvasNode&&) = delete;
73     BoundsChangedCallback boundsChangedCallback_;
74 
75 private:
76     ExtendRecordingCanvas* recordingCanvas_ = nullptr;
77     bool recordingUpdated_ = false;
78     mutable std::mutex mutex_;
79 
80     friend class RSUIDirector;
81     friend class RSAnimation;
82     friend class RSPathAnimation;
83     friend class RSPropertyAnimation;
84     friend class RSNodeMap;
85     friend class RSNodeMapV2;
86     void OnBoundsSizeChanged() const override;
87     void CreateRenderNodeForTextureExportSwitch() override;
88     void RegisterNodeMap() override;
89     pid_t tid_;
90 
91     // [Attention] Only used in PC window resize scene now
92     NodeId linkedRootNodeId_ = INVALID_NODEID;
93 };
94 } // namespace Rosen
95 } // namespace OHOS
96 
97 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H
98