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 OHOS_RENDER_3D_CAMERA_JS_H
17 #define OHOS_RENDER_3D_CAMERA_JS_H
18 #include <meta/interface/intf_object.h>
19 
20 #include <base/containers/unordered_map.h>
21 
22 #include "BaseObjectJS.h"
23 #include "ColorProxy.h"
24 #include "NodeJS.h"
25 
26 class CameraJS : public BaseObject<CameraJS>, public NodeImpl {
27 public:
28     static constexpr uint32_t ID = 80;
29     static void Init(napi_env env, napi_value exports);
30     CameraJS(napi_env, napi_callback_info);
31     ~CameraJS() override;
32     virtual void* GetInstanceImpl(uint32_t) override;
33 
34     META_NS::IObject::Ptr CreateObject(const META_NS::ClassInfo&);
35     void ReleaseObject(const META_NS::IObject::Ptr&);
36 
37 private:
38     void DisposeNative() override;
39     void Finalize(napi_env env) override;
40     napi_value GetFov(NapiApi::FunctionContext<>& ctx);
41     void SetFov(NapiApi::FunctionContext<float>& ctx);
42 
43     napi_value GetFar(NapiApi::FunctionContext<>& ctx);
44     void SetFar(NapiApi::FunctionContext<float>& ctx);
45     napi_value GetNear(NapiApi::FunctionContext<>& ctx);
46     void SetNear(NapiApi::FunctionContext<float>& ctx);
47 
48     napi_value GetPostProcess(NapiApi::FunctionContext<>& ctx);
49     void SetPostProcess(NapiApi::FunctionContext<NapiApi::Object>& ctx);
50 
51     napi_value GetEnabled(NapiApi::FunctionContext<>& ctx);
52     void SetEnabled(NapiApi::FunctionContext<bool>& ctx);
53     napi_value GetMSAA(NapiApi::FunctionContext<>& ctx);
54     void SetMSAA(NapiApi::FunctionContext<bool>& ctx);
55     napi_value GetColor(NapiApi::FunctionContext<>& ctx);
56     void SetColor(NapiApi::FunctionContext<NapiApi::Object>& ctx);
57 
58     BASE_NS::unique_ptr<ColorProxy> clearColor_;
59     NapiApi::StrongRef postProc_;
60     bool msaaEnabled_ { false };
61     bool clearColorEnabled_ { false };
62     BASE_NS::unordered_map<uintptr_t, META_NS::IObject::Ptr> resources_;
63 };
64 #endif // OHOS_RENDER_3D_CAMERA_JS_H
65