• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H
18 
19 #include "base/geometry/rect.h"
20 #include "core/components_ng/render/drawing_forward.h"
21 #include "core/pipeline/base/render_context.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 
25 namespace OHOS::Ace {
26 
27 class RosenRenderContext : public RenderContext {
28     DECLARE_ACE_TYPE(RosenRenderContext, RenderContext);
29 
30 public:
31     RosenRenderContext() = default;
32     ~RosenRenderContext() override;
33 
34     void Repaint(const RefPtr<RenderNode>& node) override;
35     void PaintChild(const RefPtr<RenderNode>& child, const Offset& offset) override;
36     bool IsIntersectWith(const RefPtr<RenderNode>& child, Offset& offset) override;
37     void Restore() override;
38 
39     void InitContext(
40         const std::shared_ptr<RSNode>& rsNode, const Rect& rect, const Offset& initialOffset = Offset::Zero());
41     RSCanvas* GetCanvas();
42     const std::shared_ptr<RSNode>& GetRSNode();
43 
44     void StartRecording();
45     void StopRecordingIfNeeded();
46 
IsRecording()47     bool IsRecording()
48     {
49         return !!recordingCanvas_;
50     }
51 
52     std::shared_ptr<RSPicture> FinishRecordingAsPicture();
53     std::shared_ptr<RSImage> FinishRecordingAsImage();
54 
55 private:
56     void UpdateChildren(const std::shared_ptr<RSNode>& rsNode);
57 
58     std::shared_ptr<RSNode> rsNode_ = nullptr;
59     RSCanvas* recordingCanvas_ = nullptr;
60     RSCanvas* rosenCanvas_ = nullptr;
61     Rect estimatedRect_;
62     std::vector<std::weak_ptr<RSNode>> childNodes_;
63 };
64 
65 } // namespace OHOS::Ace
66 
67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ROSEN_RENDER_CONTEXT_H
68