• 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_RENDER_CONTEXT_H
17 #define SCENE_INTERFACE_RENDER_CONTEXT_H
18 
19 #include <scene/base/types.h>
20 
21 #include <core/resources/intf_resource_manager.h>
22 #include <render/intf_render_context.h>
23 
24 #include <meta/api/task_queue.h>
25 #include <meta/interface/builtin_objects.h>
26 #include <meta/interface/intf_event.h>
27 #include <meta/interface/intf_metadata.h>
28 #include <meta/interface/intf_task_queue.h>
29 #include <meta/interface/property/construct_property.h>
30 
SCENE_BEGIN_NAMESPACE()31 SCENE_BEGIN_NAMESPACE()
32 
33 class IRenderContext : public CORE_NS::IInterface {
34     META_INTERFACE(CORE_NS::IInterface, IRenderContext, "12db3467-ecd5-42bf-bd37-3a6369742bf0")
35 public:
36     virtual bool Initialize(BASE_NS::shared_ptr<RENDER_NS::IRenderContext>, META_NS::ITaskQueue::Ptr rq,
37         META_NS::ITaskQueue::Ptr aq, CORE_NS::IResourceManager::Ptr) = 0;
38     virtual BASE_NS::shared_ptr<RENDER_NS::IRenderContext> GetRenderer() const = 0;
39     virtual META_NS::ITaskQueue::Ptr GetRenderQueue() const = 0;
40     virtual META_NS::ITaskQueue::Ptr GetApplicationQueue() const = 0;
41     virtual CORE_NS::IResourceManager::Ptr GetResources() const = 0;
42 
43     template<typename Func>
44     auto AddTask(Func&& func) const
45     {
46         return AddTask(BASE_NS::forward<Func>(func), GetRenderQueue());
47     }
48     template<typename Func>
49     auto AddTask(Func&& func, const META_NS::ITaskQueue::Ptr& queue) const
50     {
51         return META_NS::AddFutureTaskOrRunDirectly(queue, BASE_NS::forward<Func>(func));
52     }
53     template<typename Func>
54     auto PostUserNotification(Func&& func) const
55     {
56         return AddTask(BASE_NS::forward<Func>(func), GetApplicationQueue());
57     }
58     template<typename MyEvent, typename... Args>
59     auto InvokeUserNotification(const META_NS::IEvent::Ptr& event, Args... args) const
60     {
61         return PostUserNotification([=, ev = META_NS::IEvent::WeakPtr(event)] {
62             if (auto e = ev.lock()) {
63                 META_NS::Invoke<MyEvent>(e, args...);
64             }
65         });
66     }
67 };
68 
69 META_REGISTER_CLASS(RenderContext, "a9080232-32e7-4d59-8498-753e639524e7", META_NS::ObjectCategoryBits::NO_CATEGORY)
70 
CreateRenderContextArg(const IRenderContext::Ptr & context)71 inline META_NS::IMetadata::Ptr CreateRenderContextArg(const IRenderContext::Ptr& context)
72 {
73     auto obj = META_NS::GetObjectRegistry().Create<META_NS::IMetadata>(META_NS::ClassId::Object);
74     if (obj) {
75         obj->AddProperty(META_NS::ConstructProperty<IRenderContext::Ptr>("RenderContext", context));
76     }
77     return obj;
78 }
79 
80 SCENE_END_NAMESPACE()
81 
82 META_INTERFACE_TYPE(SCENE_NS::IRenderContext)
83 
84 #endif
85