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_RENDER_CONTEXT_H
17 #define SCENE_SRC_RENDER_CONTEXT_H
18
19 #include <scene/interface/intf_application_context.h>
20 #include <scene/interface/intf_render_context.h>
21
22 #include <meta/ext/object.h>
23 #include <meta/interface/interface_helpers.h>
24
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26
27 class RenderContext : public META_NS::IntroduceInterfaces<META_NS::BaseObject, IRenderContext,
28 IApplicationContextProvider, IApplicationContextSetter> {
29 META_OBJECT(RenderContext, ClassId::RenderContext, IntroduceInterfaces)
30 public:
31 bool Initialize(BASE_NS::shared_ptr<RENDER_NS::IRenderContext> rc, META_NS::ITaskQueue::Ptr rq,
32 META_NS::ITaskQueue::Ptr aq, CORE_NS::IResourceManager::Ptr r) override
33 {
34 bool result = !rcontext;
35 if (result) {
36 rcontext = BASE_NS::move(rc);
37 renderQ = BASE_NS::move(rq);
38 appQ = BASE_NS::move(aq);
39 res = BASE_NS::move(r);
40 }
41 return result;
42 }
43 BASE_NS::shared_ptr<RENDER_NS::IRenderContext> GetRenderer() const override
44 {
45 return rcontext;
46 }
47 META_NS::ITaskQueue::Ptr GetRenderQueue() const override
48 {
49 return renderQ;
50 }
51 META_NS::ITaskQueue::Ptr GetApplicationQueue() const override
52 {
53 return appQ;
54 }
55 CORE_NS::IResourceManager::Ptr GetResources() const override
56 {
57 return res;
58 }
59
60 protected: // IApplicationContextProvider
61 IApplicationContext::ConstPtr GetApplicationContext() const override
62 {
63 return context_.lock();
64 }
65
66 protected: // IApplicationContextSetter
67 void SetApplicationContext(const IApplicationContext::ConstPtr& context) override
68 {
69 context_ = context;
70 }
71
72 private:
73 BASE_NS::shared_ptr<RENDER_NS::IRenderContext> rcontext;
74 META_NS::ITaskQueue::Ptr renderQ;
75 META_NS::ITaskQueue::Ptr appQ;
76 CORE_NS::IResourceManager::Ptr res;
77 IApplicationContext::ConstWeakPtr context_;
78 };
79
80 SCENE_END_NAMESPACE()
81
82 #endif
83