• 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 SCENE_INTERFACE_IAPPLICATION_CONTEXT_H
17 #define SCENE_INTERFACE_IAPPLICATION_CONTEXT_H
18 
19 #include <scene/base/types.h>
20 #include <scene/interface/intf_render_context.h>
21 #include <scene/interface/intf_scene_manager.h>
22 #include <scene/interface/scene_options.h>
23 
24 #include <meta/interface/intf_task_queue.h>
25 
SCENE_BEGIN_NAMESPACE()26 SCENE_BEGIN_NAMESPACE()
27 
28 /**
29  * @brief The IApplicationContext interface can be used to access application specific parameters.
30  */
31 class IApplicationContext : public CORE_NS::IInterface {
32     META_INTERFACE(CORE_NS::IInterface, IApplicationContext, "52d1686d-8214-49ea-98f7-83c02a45f985")
33 public:
34     struct ApplicationContextInfo {
35         META_NS::ITaskQueue::Ptr engineTaskQueue;
36         META_NS::ITaskQueue::Ptr applicationTaskQueue;
37         BASE_NS::shared_ptr<RENDER_NS::IRenderContext> renderContext;
38         CORE_NS::IResourceManager::Ptr resourceManager;
39         SceneOptions defaultSceneOptions;
40     };
41     virtual bool Initialize(const ApplicationContextInfo& info) = 0;
42 
43     virtual IRenderContext::Ptr GetRenderContext() const = 0;
44     virtual ISceneManager::Ptr GetSceneManager() const = 0;
45     virtual SceneOptions GetDefaultSceneOptions() const = 0;
46 };
47 
48 /**
49  * @brief The IApplicationContextProvider interface can be implemented by classes which can be queried for an
50  *        IApplicationContext instance they belong to.
51  * @note  The default RenderContext implementation (return by calling
52  *        GetDefaultApplicationContext()->GetRenderContext()) implements IApplicationContextProvider, enabling to query
53  *        the application context a render context is associated with.
54  */
55 class IApplicationContextProvider : public CORE_NS::IInterface {
56     META_INTERFACE(CORE_NS::IInterface, IApplicationContextProvider, "71c07cc6-36b5-4b71-a0e8-be4731a9753d")
57 public:
58     /// Returns the associated application context.
59     virtual IApplicationContext::ConstPtr GetApplicationContext() const = 0;
60 };
61 
62 class IApplicationContextSetter : public CORE_NS::IInterface {
63     META_INTERFACE(CORE_NS::IInterface, IApplicationContextSetter, "586601d7-ded9-43f9-aacf-f7ccd7fa33cf")
64 public:
65     virtual void SetApplicationContext(const IApplicationContext::ConstPtr& context) = 0;
66 };
67 
68 META_REGISTER_SINGLETON_CLASS(
69     ApplicationContext, "424b9f97-6447-41c0-8225-1fb0e1bbd7e8", META_NS::ObjectCategoryBits::NO_CATEGORY)
70 
71 /// Helper function for retrieving the application context associated with a render context
GetApplicationContext(const IRenderContext::Ptr & renderContext)72 inline IApplicationContext::ConstPtr GetApplicationContext(const IRenderContext::Ptr& renderContext)
73 {
74     if (auto provider = interface_cast<IApplicationContextProvider>(renderContext)) {
75         return provider->GetApplicationContext();
76     }
77     return nullptr;
78 }
79 
80 /// Helper function for retrieving the scene manager associated with the application context of a render context
GetSceneManager(const IRenderContext::Ptr & renderContext)81 inline ISceneManager::Ptr GetSceneManager(const IRenderContext::Ptr& renderContext)
82 {
83     if (auto ctx = GetApplicationContext(renderContext)) {
84         return ctx->GetSceneManager();
85     }
86     return nullptr;
87 }
88 
GetDefaultApplicationContext()89 inline IApplicationContext::ConstPtr GetDefaultApplicationContext()
90 {
91     if (auto obj = META_NS::GetObjectRegistry().Create<IApplicationContext>(ClassId::ApplicationContext)) {
92         return obj;
93     }
94     return nullptr;
95 }
96 
97 SCENE_END_NAMESPACE()
98 
99 META_INTERFACE_TYPE(SCENE_NS::IApplicationContext)
100 
101 #endif
102