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_PICTURE_NAPI_H
17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_PICTURE_NAPI_H
18 
19 #include "picture.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "pixel_map.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class PictureNapi {
27 public:
28     PictureNapi();
29     ~PictureNapi();
30 
31     static napi_value Init(napi_env env, napi_value exports);
32     static std::shared_ptr<Picture> GetPicture(napi_env env, napi_value picture);
33     static napi_value CreatePicture(napi_env env, std::shared_ptr<Picture> &picture);
34     static int32_t CreatePictureNapi(napi_env env, napi_value* result);
35     void SetNativePicture(std::shared_ptr<Picture> picture);
36 
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     // methods
41     static napi_value GetMainPixelmap(napi_env env, napi_callback_info info);
42     static napi_value GetHdrComposedPixelMap(napi_env env, napi_callback_info info);
43     static napi_value GetGainmapPixelmap(napi_env env, napi_callback_info info);
44     static napi_value Release(napi_env env, napi_callback_info info);
45     static napi_value Marshalling(napi_env env, napi_callback_info info);
46     static napi_value GetAuxiliaryPicture(napi_env env, napi_callback_info info);
47     static napi_value SetAuxiliaryPicture(napi_env env, napi_callback_info info);
48     static napi_value GetMetadata(napi_env env, napi_callback_info info);
49     static napi_value SetMetadata(napi_env env, napi_callback_info info);
50 
51     /* static method */
52     static napi_value CreatePicture(napi_env env, napi_callback_info info);
53     static napi_value CreatePictureFromParcel(napi_env env, napi_callback_info info);
54     static napi_value ThrowExceptionError(napi_env env,
55         const std::string &tag, const std::uint32_t &code, const std::string &info);
56     void release();
57     static thread_local napi_ref sConstructor_;
58     static thread_local std::shared_ptr<Picture> sPicture_;
59     napi_env env_ = nullptr;
60     std::shared_ptr<Picture> nativePicture_;
61     bool isRelease = false;
62     uint32_t uniqueId_ = 0;
63     static napi_ref auxiliaryPictureTypeRef_;
64     static napi_ref metadataTypeRef_;
65 };
66 } // namespace Media
67 } // namespace OHOS
68 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_PICTURE_NAPI_H
69