• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_COMPONENT_SNAPSHOT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_COMPONENT_SNAPSHOT_H
18 
19 #include <string>
20 
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/render/snapshot_param.h"
23 
24 namespace OHOS::Rosen {
25 class RSNode;
26 }
27 
28 namespace OHOS::Ace::NG {
29 
30 class ACE_FORCE_EXPORT ComponentSnapshot {
31 public:
32     using JsCallback = std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>;
33     using NormalCallback = std::function<void(std::shared_ptr<Media::PixelMap>)>;
34 
35     static void Get(const std::string& componentId, JsCallback&& callback, const SnapshotOptions& options);
36     static void GetByUniqueId(int32_t uniqueId, JsCallback&& callback, const SnapshotOptions& options);
37     // add delay to ensure Rosen has finished rendering
38     static void Create(
39         const RefPtr<AceType>& customNode, JsCallback&& callback, bool enableInspector, const SnapshotParam& param,
40         bool flag = true);
41     static void GetNormalCapture(const RefPtr<FrameNode>& frameNode, NormalCallback&& callback);
42 
43     static std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSync(
44         RefPtr<FrameNode>& node, const SnapshotOptions& options);
45 
46     static std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSync(const std::string& componentId,
47         const SnapshotOptions& options);
48     static std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSyncByUniqueId(int32_t uniqueId,
49         const SnapshotOptions& options);
50 
51     static void GetWithRange(const NodeIdentity& startID, const NodeIdentity& endID, const bool& isStartRect,
52         JsCallback&& callback, const SnapshotOptions& options);
53     static std::string GetRangeIDStr(const NodeIdentity& ID);
54     static RefPtr<FrameNode> GetRangeIDNode(const NodeIdentity& ID);
55 
56     // create pixelMap in sync, this method only for drag.
57     static std::shared_ptr<Media::PixelMap> CreateSync(
58         const RefPtr<AceType>& customNode, const SnapshotParam& param);
59 
60     // create solo node pixelMaps, this method only for IDE.
61     static std::vector<std::pair<uint64_t, std::shared_ptr<Media::PixelMap>>> GetSoloNode(
62         const RefPtr<FrameNode>& node);
63 
64 private:
65     static std::shared_ptr<Rosen::RSNode> GetRsNode(const RefPtr<FrameNode>& node);
66     static void PostDelayedTaskOfBuiler(const RefPtr<TaskExecutor>& executor, JsCallback&& callback,
67         const RefPtr<FrameNode>& node, bool enableInspector, const RefPtr<PipelineContext>& pipeline,
68         const SnapshotParam& param);
69     static void BuilerTask(JsCallback&& callback, const RefPtr<FrameNode>& node, bool enableInspector,
70         const RefPtr<PipelineContext>& pipeline, const SnapshotParam& param);
71     static void SetRSUIContext(
72         const RefPtr<FrameNode>& frameNode, const std::shared_ptr<Rosen::RSUIContext>& rsUIContext);
73     static std::shared_ptr<Rosen::RSUIContext> GetRSUIContext(const RefPtr<PipelineContext>& pipeline);
74 
75     WeakPtr<FrameNode> node_;
76 };
77 } // namespace OHOS::Ace::NG
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_COMPONENT_SNAPSHOT_H