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 TONEMAPJS_H 17 #define TONEMAPJS_H 18 #include "BaseObjectJS.h" 19 20 class ToneMapJS : public BaseObject { 21 public: 22 enum ToneMappingType { 23 NOT_SET = -1, 24 ACES = 0, 25 ACES_2020 = 1, 26 FILMIC = 2, 27 }; 28 static constexpr uint32_t ID = 60; 29 static constexpr ToneMappingType DEFAULT_TYPE = ToneMappingType::ACES; 30 static constexpr float DEFAULT_EXPOSURE = 0.7; 31 32 static SCENE_NS::TonemapType ToNativeType(uint32_t jsType); 33 static void Init(napi_env env, napi_value exports); 34 35 ToneMapJS(napi_env, napi_callback_info); 36 ~ToneMapJS() override; 37 38 // Sync our members with the native and then let go of it. It may or may not be destroyed. 39 void UnbindFromNative(); 40 // Start using the native as the backing object and sync our members to it. 41 void BindToNative(SCENE_NS::ITonemap::Ptr native); 42 43 private: 44 void* GetInstanceImpl(uint32_t) override; 45 napi_value Dispose(NapiApi::FunctionContext<>& ctx); 46 void DisposeNative(void*) override; 47 void Finalize(napi_env env) override; 48 // JS properties 49 50 // type?: TonemapType; 51 napi_value GetType(NapiApi::FunctionContext<>& ctx); 52 void SetType(NapiApi::FunctionContext<uint32_t>& ctx); 53 54 // exposure?: number; 55 napi_value GetExposure(NapiApi::FunctionContext<>& ctx); 56 void SetExposure(NapiApi::FunctionContext<float>& ctx); 57 58 ToneMappingType type_; 59 float exposure_; 60 }; 61 #endif 62