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 
39     ExtendRecordingCanvas* BeginRecording(int width, int height);
40     bool IsRecording() const;
41     void FinishRecording();
42     float GetPaintWidth() const;
43     float GetPaintHeight() const;
44     void DrawOnNode(RSModifierType type, DrawFunc func) override;
45 
46     void SetFreeze(bool isFreeze) override;
47 
48     void SetHDRPresent(bool hdrPresent);
49 
50     void SetBoundsChangedCallback(BoundsChangedCallback callback) override;
51 
52 protected:
53     RSCanvasNode(bool isRenderServiceNode, bool isTextureExportNode = false);
54     RSCanvasNode(const RSCanvasNode&) = delete;
55     RSCanvasNode(const RSCanvasNode&&) = delete;
56     RSCanvasNode& operator=(const RSCanvasNode&) = delete;
57     RSCanvasNode& operator=(const RSCanvasNode&&) = delete;
58     BoundsChangedCallback boundsChangedCallback_;
59 
60 private:
61     ExtendRecordingCanvas* recordingCanvas_ = nullptr;
62     bool recordingUpdated_ = false;
63     mutable std::mutex mutex_;
64 
65     friend class RSUIDirector;
66     friend class RSAnimation;
67     friend class RSPathAnimation;
68     friend class RSPropertyAnimation;
69     friend class RSNodeMap;
70     void OnBoundsSizeChanged() const override;
71     void CreateRenderNodeForTextureExportSwitch() override;
72 };
73 } // namespace Rosen
74 } // namespace OHOS
75 
76 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H
77