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 SCENE_SRC_APPLICATION_CONTEXT_H
17 #define SCENE_SRC_APPLICATION_CONTEXT_H
18
19 #include <scene/interface/intf_application_context.h>
20
21 #include <meta/ext/object.h>
22
23 #include "resource/resource_types.h"
24
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26
27 class ApplicationContext : public META_NS::IntroduceInterfaces<META_NS::MetaObject, IApplicationContext> {
28 META_OBJECT(ApplicationContext, ClassId::ApplicationContext, IntroduceInterfaces)
29 public:
30 bool Initialize(const ApplicationContextInfo& info) override
31 {
32 bool res = !context_;
33 if (res) {
34 context_ = META_NS::GetObjectRegistry().Create<IRenderContext>(ClassId::RenderContext);
35 if (context_) {
36 context_->Initialize(
37 info.renderContext, info.engineTaskQueue, info.applicationTaskQueue, info.resourceManager);
38 if (auto setter = interface_cast<IApplicationContextSetter>(context_)) {
39 setter->SetApplicationContext(GetSelf<IApplicationContext>());
40 }
41 }
42 defaultSceneOptions_ = info.defaultSceneOptions;
43 auto args = CreateRenderContextArg(context_);
44 if (args) {
45 if (auto op = META_NS::ConstructProperty<SceneOptions>("Options", defaultSceneOptions_)) {
46 args->AddProperty(op);
47 }
48 }
49 RegisterResourceTypes(context_->GetResources(), args);
50 sceneManager_ = META_NS::GetObjectRegistry().Create<ISceneManager>(ClassId::SceneManager, args);
51 }
52 return res;
53 }
54
55 IRenderContext::Ptr GetRenderContext() const override
56 {
57 return context_;
58 }
59 ISceneManager::Ptr GetSceneManager() const override
60 {
61 return sceneManager_;
62 }
63 SceneOptions GetDefaultSceneOptions() const override
64 {
65 return defaultSceneOptions_;
66 }
67
68 private:
69 IRenderContext::Ptr context_;
70 ISceneManager::Ptr sceneManager_;
71 SceneOptions defaultSceneOptions_;
72 };
73
74 SCENE_END_NAMESPACE()
75
76 #endif
77