1 /*
2  * Copyright (C) 2024 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_ADAPTER_OHOS_OSAL_IMAGE_ANALYZER_MANAGER_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_IMAGE_ANALYZER_MANAGER_H
18 
19 #include "base/geometry/ng/offset_t.h"
20 #include "base/memory/ace_type.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "interfaces/inner_api/ace/ai/image_analyzer.h"
23 
24 namespace OHOS::Ace {
25 class ImageAnalyzerAdapter;
26 }
27 
28 namespace OHOS::Ace {
29 class ImageAnalyzerManager : public AceType {
30     DECLARE_ACE_TYPE(ImageAnalyzerManager, AceType);
31 public:
32     ImageAnalyzerManager(const RefPtr<NG::FrameNode>& frameNode, ImageAnalyzerHolder holder);
33     ~ImageAnalyzerManager() = default;
34 
35     bool IsSupportImageAnalyzerFeature();
36     void CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
37     void UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
38     void UpdateAnalyzerOverlayLayout();
39     void UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode, const PixelMapInfo& info = {});
40     void DestroyAnalyzerOverlay();
41     void ReleaseImageAnalyzer();
42     void SetImageAnalyzerConfig(void* config);
43     void SetImageAnalyzerCallback(OnAnalyzedCallback& callback);
44     void SetImageAIOptions(void* options);
45     bool IsOverlayCreated();
46     void UpdatePressOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, int offsetX, int offsetY, int rectWidth,
47         int rectHeight, int pointX, int pointY, OnTextSelectedCallback callback);
48     void UpdateOverlayTouchInfo(int touchPointX, int touchPointY, TouchType touchType);
49     void UpdateOverlayStatus(bool status, int offsetX, int offsetY, int rectWidth, int rectHeight);
50     void UpdateAIButtonConfig(AIButtonConfig config);
51     void UpdateOverlayActiveStatus(bool status);
52     void SetNotifySelectedCallback(OnNotifySelectedStatusCallback&& callback);
53 
54 private:
55     bool UpdateVideoConfig(const PixelMapInfo& info);
56 
57     WeakPtr<NG::FrameNode> frameNode_;
58     ImageAnalyzerHolder holder_;
59     ImageAnalyzerInnerConfig analyzerUIConfig_;
60     std::shared_ptr<ImageAnalyzerAdapter> imageAnalyzerAdapter_;
61     void* overlayData_ = nullptr;
62 
63     bool isAnalyzerOverlayBuild_ = false;
64 };
65 } // namespace OHOS::Ace
66 #endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_IMAGE_ANALYZER_MANAGER_H