1 /* 2 * Copyright (C) 2022 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_NAPI_H 17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_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 ImageAsyncContext; 26 class ImageNapi { 27 public: 28 ImageNapi(); 29 ~ImageNapi(); 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 38 private: 39 static napi_value Constructor(napi_env env, napi_callback_info info); 40 static void Destructor(napi_env env, void *nativeObject, void *finalize); 41 42 static napi_value JSGetClipRect(napi_env env, napi_callback_info info); 43 static napi_value JsGetSize(napi_env env, napi_callback_info info); 44 static napi_value JsGetFormat(napi_env env, napi_callback_info info); 45 static napi_value JsGetComponent(napi_env env, napi_callback_info info); 46 static napi_value JsRelease(napi_env env, napi_callback_info info); 47 static napi_value JsGetTimestamp(napi_env env, napi_callback_info info); 48 49 static thread_local napi_ref sConstructor_; 50 static ImageHolderManager<NativeImage> sNativeImageHolder_; 51 std::shared_ptr<NativeImage> native_; 52 bool isTestImage_; 53 }; 54 } // namespace Media 55 } // namespace OHOS 56 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_NAPI_H 57