• 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);
41 
42 #ifndef USE_ROSEN_DRAWING
43     SkCanvas* BeginRecording(int width, int height);
44 #else
45     Drawing::RecordingCanvas* 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 protected:
56     RSCanvasNode(bool isRenderServiceNode);
57     RSCanvasNode(const RSCanvasNode&) = delete;
58     RSCanvasNode(const RSCanvasNode&&) = delete;
59     RSCanvasNode& operator=(const RSCanvasNode&) = delete;
60     RSCanvasNode& operator=(const RSCanvasNode&&) = delete;
61 
62 private:
63 #ifndef USE_ROSEN_DRAWING
64     SkCanvas* recordingCanvas_ = nullptr;
65 #else
66     Drawing::RecordingCanvas* recordingCanvas_ = nullptr;
67 #endif
68     bool recordingUpdated_ = false;
69 
70     friend class RSUIDirector;
71     friend class RSAnimation;
72     friend class RSPathAnimation;
73     friend class RSPropertyAnimation;
74     friend class RSNodeMap;
75 };
76 } // namespace Rosen
77 } // namespace OHOS
78 
79 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H
80