• 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 #ifndef USE_ROSEN_DRAWING
21 class SkCanvas;
22 #endif
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSNodeMap;
27 
28 class RSC_EXPORT RSCanvasNode : public RSNode {
29 public:
30     using WeakPtr = std::weak_ptr<RSCanvasNode>;
31     using SharedPtr = std::shared_ptr<RSCanvasNode>;
32     static inline constexpr RSUINodeType Type = RSUINodeType::CANVAS_NODE;
GetType()33     RSUINodeType GetType() const override
34     {
35         return Type;
36     }
37 
38     ~RSCanvasNode() override;
39 
40     static SharedPtr Create(bool isRenderServiceNode = false, bool isTextureExportNode = false);
41 
42 #ifndef USE_ROSEN_DRAWING
43     SkCanvas* BeginRecording(int width, int height);
44 #else
45     ExtendRecordingCanvas* BeginRecording(int width, int height);
46 #endif
47     bool IsRecording() const;
48     void FinishRecording();
49     float GetPaintWidth() const;
50     float GetPaintHeight() const;
51     void DrawOnNode(RSModifierType type, DrawFunc func) override;
52 
53     void SetFreeze(bool isFreeze) override;
54 
55     using BoundsChangedCallback = std::function<void(const Rosen::Vector4f&)>;
56     void SetBoundsChangedCallback(BoundsChangedCallback callback) override;
57 
58 protected:
59     RSCanvasNode(bool isRenderServiceNode, bool isTextureExportNode = false);
60     RSCanvasNode(const RSCanvasNode&) = delete;
61     RSCanvasNode(const RSCanvasNode&&) = delete;
62     RSCanvasNode& operator=(const RSCanvasNode&) = delete;
63     RSCanvasNode& operator=(const RSCanvasNode&&) = delete;
64     BoundsChangedCallback boundsChangedCallback_;
65 
66 private:
67 #ifndef USE_ROSEN_DRAWING
68     SkCanvas* recordingCanvas_ = nullptr;
69 #else
70     ExtendRecordingCanvas* recordingCanvas_ = nullptr;
71 #endif
72     bool recordingUpdated_ = false;
73     mutable std::mutex mutex_;
74 
75     friend class RSUIDirector;
76     friend class RSAnimation;
77     friend class RSPathAnimation;
78     friend class RSPropertyAnimation;
79     friend class RSNodeMap;
80     void OnBoundsSizeChanged() const override;
81 };
82 } // namespace Rosen
83 } // namespace OHOS
84 
85 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H
86