• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NAMED_IMPL_H
17 #define NAMED_IMPL_H
18 
19 #include <napi_api.h>
20 
21 #include <base/containers/vector.h>
22 
23 class SceneResourceImpl {
24 public:
25     static constexpr uint32_t ID = 1;
26     enum SceneResourceType {
27         /**
28          * The resource is an Unknow.
29          */
30         UNKNOWN = 0,
31         /**
32          * The resource is an Node.
33          */
34         NODE = 1,
35         /**
36          * The resource is an Environment.
37          */
38         ENVIRONMENT = 2,
39         /**
40          * The resource is a Material.
41          */
42         MATERIAL = 3,
43         /**
44          * The resource is a Mesh.
45          */
46         MESH = 4,
47         /**
48          * The resource is an Animation.
49          */
50         ANIMATION = 5,
51         /**
52          * The resource is a Shader.
53          */
54         SHADER = 6,
55 
56         /**
57          * The resource is a Image.
58          */
59         IMAGE = 7,
60         /**
61          * The resource is a MeshResource.
62          */
63         MESH_RESOURCE = 8,
64     };
65     SceneResourceImpl(SceneResourceType type);
66     virtual ~SceneResourceImpl();
67     static void RegisterEnums(NapiApi::Object exports);
68 
69     void* GetInstanceImpl(uint32_t id);
70 
71 protected:
72     static void GetPropertyDescs(BASE_NS::vector<napi_property_descriptor>& props);
73 
74     void SetUri(NapiApi::StrongRef uri);
75     napi_value GetObjectType(NapiApi::FunctionContext<>& ctx);
76     napi_value GetName(NapiApi::FunctionContext<>& ctx);
77     void SetName(NapiApi::FunctionContext<BASE_NS::string>& ctx);
78     napi_value GetUri(NapiApi::FunctionContext<>& ctx);
79     napi_value Dispose(NapiApi::FunctionContext<>& ctx);
80 
81     // May contain Scene or RenderContext
82     NapiApi::WeakRef scene_;
83     NapiApi::StrongRef uri_;
84 
85     // returns false if owning scene has been destroyed.
86     bool validateSceneRef();
87 
88 private:
89     SceneResourceType type_;
90     BASE_NS::string name_; // Cache for name if object does not support naming
91 };
92 #endif
93