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