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::Ace::NG {
25 
26 class ComponentSnapshot {
27 public:
28     using JsCallback = std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>;
29     using NormalCallback = std::function<void(std::shared_ptr<Media::PixelMap>)>;
30 
31     static void Get(const std::string& componentId, JsCallback&& callback, const SnapshotOptions& options);
32     // add delay to ensure Rosen has finished rendering
33     static void Create(
34         const RefPtr<AceType>& customNode, JsCallback&& callback, bool enableInspector, const SnapshotParam& param,
35         bool flag = true);
36     static void GetNormalCapture(const RefPtr<FrameNode>& frameNode, NormalCallback&& callback);
37 
38     static std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSync(const std::string& componentId,
39         const SnapshotOptions& options);
40 
41     // create pixelMap in sync, this method only for drag.
42     static std::shared_ptr<Media::PixelMap> CreateSync(
43         const RefPtr<AceType>& customNode, const SnapshotParam& param);
44 
45 private:
46     static std::shared_ptr<Rosen::RSNode> GetRsNode(const RefPtr<FrameNode>& node);
47     static void PostDelayedTaskOfBuiler(const RefPtr<TaskExecutor>& executor, JsCallback&& callback,
48         const RefPtr<FrameNode>& node, bool enableInspector, const RefPtr<PipelineContext>& pipeline,
49         const SnapshotParam& param);
50     static void BuilerTask(JsCallback&& callback, const RefPtr<FrameNode>& node, bool enableInspector,
51         const RefPtr<PipelineContext>& pipeline, const SnapshotParam& param);
52 
53     WeakPtr<FrameNode> node_;
54 };
55 } // namespace OHOS::Ace::NG
56 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_COMPONENT_SNAPSHOT_H