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 #include <scene_plugin/api/render_configuration_uid.h>
16 #include <scene_plugin/interface/intf_render_configuration.h>
17 
18 #include <meta/ext/concrete_base_object.h>
19 
20 #include "bind_templates.inl"
21 #include "intf_resource_private.h"
22 #include "PropertyHandlerArrayHolder.h"
23 #include "task_utils.h"
24 
25 using namespace SCENE_NS;
26 
27 namespace {
28 
29 class RenderConfigurationImpl
30     : public META_NS::ObjectFwd<RenderConfigurationImpl, SCENE_NS::ClassId::RenderConfiguration,
31           META_NS::ClassId::Object, SCENE_NS::IRenderConfiguration, IResourcePrivate, SCENE_NS::IProxyObject> {
32     using Fwd = META_NS::ObjectFwd<RenderConfigurationImpl, SCENE_NS::ClassId::RenderConfiguration,
33         META_NS::ClassId::Object, SCENE_NS::IRenderConfiguration, IResourcePrivate, SCENE_NS::IProxyObject>;
34 
35     META_IMPLEMENT_INTERFACE_PROPERTY(META_NS::INamed, BASE_NS::string, Name, {})
36     META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::IRenderConfiguration, SCENE_NS::IEnvironment::Ptr, Environment)
37 
38     ~RenderConfigurationImpl() {}
39 
Build(const IMetadata::Ptr & data)40     bool Build(const IMetadata::Ptr& data) override
41     {
42         return Fwd::Build(data);
43     }
44 
Connect(SceneHolder::Ptr sh)45     void Connect(SceneHolder::Ptr sh) override
46     {
47         if (ecsObject_) {
48             return;
49         }
50 
51         ecsObject_ = META_NS::GetObjectRegistry().Create<SCENE_NS::IEcsObject>(SCENE_NS::ClassId::EcsObject);
52         sh_ = sh;
53 
54         if (auto proxyIf = interface_pointer_cast<SCENE_NS::IEcsProxyObject>(ecsObject_)) {
55             proxyIf->SetCommonListener(sh->GetCommonEcsListener());
56         }
57 
58         auto ecs = sh->GetEcs();
59 
60         auto renderConfiguration = sh->CreateRenderConfiguration();
61         ecsObject_->SetEntity(ecs, renderConfiguration);
62 
63         propHandler_.Reset();
64         propHandler_.SetSceneHolder(sh);
65 
66         if (auto meta = interface_pointer_cast<IMetadata>(ecsObject_)) {
67             ConvertBindChanges<IEnvironment::Ptr, CORE_NS::Entity, EntityConverter<SCENE_NS::IEnvironment>>(
68                 propHandler_, META_ACCESS_PROPERTY(Environment), meta, "RenderConfigurationComponent.environment",
69                 ONE_WAY_TO_ECS);
70         }
71     }
72 
ListBoundProperties() const73     BASE_NS::vector<SCENE_NS::IProxyObject::PropertyPair> ListBoundProperties() const override
74     {
75         return propHandler_.GetBoundProperties();
76     }
77 
78     SCENE_NS::IEcsObject::Ptr ecsObject_;
79     SceneHolder::Ptr sh_;
80     PropertyHandlerArrayHolder propHandler_ {};
81 };
82 
83 } // namespace
84 
SCENE_BEGIN_NAMESPACE()85 SCENE_BEGIN_NAMESPACE()
86 
87 void RegisterRenderConfigurationImpl()
88 {
89     auto& registry = META_NS::GetObjectRegistry();
90     registry.RegisterObjectType<RenderConfigurationImpl>();
91 }
92 
UnregisterRenderConfigurationImpl()93 void UnregisterRenderConfigurationImpl()
94 {
95     auto& registry = META_NS::GetObjectRegistry();
96     registry.UnregisterObjectType<RenderConfigurationImpl>();
97 }
98 
99 SCENE_END_NAMESPACE()
100