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 INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SENDABLE_NAPI_H
17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SENDABLE_NAPI_H
18 
19 #include "native_image.h"
20 #include "napi/native_api.h"
21 #include "image_holder_manager.h"
22 
23 namespace OHOS {
24 namespace Media {
25 struct SendableImageAsyncContext;
26 class SendableImageNapi {
27 public:
28     SendableImageNapi();
29     ~SendableImageNapi();
30     static napi_value Init(napi_env env, napi_value exports);
31     static napi_value Create(napi_env env);
32     static napi_value Create(napi_env env, std::shared_ptr<NativeImage> nativeImage);
33     static std::shared_ptr<NativeImage> GetNativeImage(napi_env env, napi_value image);
34 
35     NativeImage* GetNative();
36     void NativeRelease();
37 private:
38     static napi_value Constructor(napi_env env, napi_callback_info info);
39     static void Destructor(napi_env env, void *nativeObject, void *finalize);
40 
41     static napi_value JSGetClipRect(napi_env env, napi_callback_info info);
42     static napi_value JsGetSize(napi_env env, napi_callback_info info);
43     static napi_value JsGetFormat(napi_env env, napi_callback_info info);
44     static napi_value JsGetComponent(napi_env env, napi_callback_info info);
45     static napi_value JsRelease(napi_env env, napi_callback_info info);
46     static napi_value JsGetTimestamp(napi_env env, napi_callback_info info);
47 
48     static thread_local napi_ref sConstructor_;
49     static ImageHolderManager<NativeImage> sNativeImageHolder_;
50     std::shared_ptr<NativeImage> native_;
51     bool isTestImage_;
52 };
53 
54 } // namespace Media
55 } // namespace OHOS
56 
57 #endif //INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SENDABLE_NAPI_H