1 /* 2 * Copyright (c) 2024-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 CAMERA_ABILITY_NAPI_H 17 #define CAMERA_ABILITY_NAPI_H 18 19 #include "napi/native_api.h" 20 #include "ability/camera_ability.h" 21 22 namespace OHOS { 23 namespace CameraStandard { 24 25 using Descriptor = std::vector<std::vector<napi_property_descriptor>>; 26 27 enum class FunctionsType { 28 PHOTO_FUNCTIONS = 0, 29 PHOTO_CONFLICT_FUNCTIONS, 30 PORTRAIT_PHOTO_FUNCTIONS, 31 PORTRAIT_PHOTO_CONFLICT_FUNCTIONS, 32 VIDEO_FUNCTIONS, 33 VIDEO_CONFLICT_FUNCTIONS 34 }; 35 36 static const char PHOTO_ABILITY_NAPI_CLASS_NAME[] = "PhotoFunctions"; 37 static const char PORTRAIT_PHOTO_ABILITY_NAPI_CLASS_NAME[] = "PortraitPhotoFunctions"; 38 static const char VIDEO_ABILITY_NAPI_CLASS_NAME[] = "VideoFunctions"; 39 static const char PHOTO_CONFLICT_ABILITY_NAPI_CLASS_NAME[] = "PhotoConflictFunctions"; 40 static const char PORTRAIT_PHOTO_CONFLICT_ABILITY_NAPI_CLASS_NAME[] = "PortraitPhotoConflictFunctions"; 41 static const char VIDEO_CONFLICT_ABILITY_NAPI_CLASS_NAME[] = "VideoConflictFunctions"; 42 43 class CameraFunctionsNapi { 44 public: 45 static napi_value Init(napi_env env, napi_value exports, FunctionsType type); 46 static napi_value CreateCameraFunctions(napi_env env, sptr<CameraAbility> functions, FunctionsType type); 47 48 CameraFunctionsNapi(); 49 ~CameraFunctionsNapi(); 50 51 static napi_value CameraFunctionsNapiConstructor(napi_env env, napi_callback_info info); 52 static void CameraFunctionsNapiDestructor(napi_env env, void* nativeObject, void* finalize_hint); 53 54 // FlashQuery 55 static napi_value HasFlash(napi_env env, napi_callback_info info); 56 static napi_value IsFlashModeSupported(napi_env env, napi_callback_info info); 57 static napi_value IsLcdFlashSupported(napi_env env, napi_callback_info info); 58 59 // AutoExposureQuery 60 static napi_value IsExposureModeSupported(napi_env env, napi_callback_info info); 61 static napi_value GetExposureBiasRange(napi_env env, napi_callback_info info); 62 // FocusQuery 63 static napi_value IsFocusModeSupported(napi_env env, napi_callback_info info); 64 // ZoomQuery 65 static napi_value GetZoomRatioRange(napi_env env, napi_callback_info info); 66 // BeautyQuery 67 static napi_value GetSupportedBeautyTypes(napi_env env, napi_callback_info info); 68 static napi_value GetSupportedBeautyRange(napi_env env, napi_callback_info info); 69 // ColorEffectQuery 70 static napi_value GetSupportedColorEffects(napi_env env, napi_callback_info info); 71 // ColorManagementQuery 72 static napi_value GetSupportedColorSpaces(napi_env env, napi_callback_info info); 73 // MacroQuery 74 static napi_value IsMacroSupported(napi_env env, napi_callback_info info); 75 // DepthFusionQuery 76 static napi_value IsDepthFusionSupported(napi_env env, napi_callback_info info); 77 static napi_value GetDepthFusionThreshold(napi_env env, napi_callback_info info); 78 // PortraitQuery 79 static napi_value GetSupportedPortraitEffects(napi_env env, napi_callback_info info); 80 // ApertureQuery 81 static napi_value GetSupportedVirtualApertures(napi_env env, napi_callback_info info); 82 static napi_value GetSupportedPhysicalApertures(napi_env env, napi_callback_info info); 83 // StabilizationQuery 84 static napi_value IsVideoStabilizationModeSupported(napi_env env, napi_callback_info info); 85 // ManualExposureQuery 86 static napi_value GetSupportedExposureRange(napi_env env, napi_callback_info info); 87 // SceneDetectionQuery 88 static napi_value IsFeatureSupported(napi_env env, napi_callback_info info); 89 90 template<typename U> 91 static napi_value HandleQuery(napi_env env, napi_callback_info info, napi_value thisVar, U queryFunction); 92 GetNativeObj()93 sptr<CameraAbility> GetNativeObj() { return cameraAbility_; } 94 napi_env env_; 95 napi_ref wrapper_; 96 sptr<CameraAbility> cameraAbility_; 97 static thread_local napi_ref sConstructor_; 98 99 static thread_local napi_ref sPhotoConstructor_; 100 static thread_local napi_ref sPhotoConflictConstructor_; 101 static thread_local napi_ref sPortraitPhotoConstructor_; 102 static thread_local napi_ref sPortraitPhotoConflictConstructor_; 103 static thread_local napi_ref sVideoConstructor_; 104 static thread_local napi_ref sVideoConflictConstructor_; 105 106 static thread_local sptr<CameraAbility> sCameraAbility_; 107 108 static const std::vector<napi_property_descriptor> flash_query_props; 109 static const std::vector<napi_property_descriptor> auto_exposure_query_props; 110 static const std::vector<napi_property_descriptor> focus_query_props; 111 static const std::vector<napi_property_descriptor> zoom_query_props; 112 static const std::vector<napi_property_descriptor> beauty_query_props; 113 static const std::vector<napi_property_descriptor> color_effect_query_props; 114 static const std::vector<napi_property_descriptor> color_management_query_props; 115 static const std::vector<napi_property_descriptor> macro_query_props; 116 static const std::vector<napi_property_descriptor> depth_fusion_query_props; 117 static const std::vector<napi_property_descriptor> portrait_query_props; 118 static const std::vector<napi_property_descriptor> aperture_query_props; 119 static const std::vector<napi_property_descriptor> stabilization_query_props; 120 static const std::vector<napi_property_descriptor> manual_exposure_query_props; 121 static const std::vector<napi_property_descriptor> features_query_props; 122 123 static const std::map<FunctionsType, const char*> functionsNameMap_; 124 static const std::map<FunctionsType, Descriptor> functionsDescMap_; 125 }; 126 } 127 } 128 #endif /* CAMERA_ABILITY_NAPI_H */