• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 GRAPHICS_CONTEXT_H
17 #define GRAPHICS_CONTEXT_H
18 
19 #include <3d/intf_graphics_context.h>
20 #include <base/containers/unique_ptr.h>
21 #include <base/containers/unordered_map.h>
22 #include <base/containers/vector.h>
23 #include <core/namespace.h>
24 #include <core/plugin/intf_class_factory.h>
25 #include <core/plugin/intf_class_register.h>
26 #include <core/plugin/intf_plugin.h>
27 #include <render/resource_handle.h>
28 
29 CORE_BEGIN_NAMESPACE()
30 class IEcs;
31 CORE_END_NAMESPACE()
32 
33 RENDER_BEGIN_NAMESPACE()
34 class IRenderContext;
35 class IRenderDataStore;
36 RENDER_END_NAMESPACE()
37 
38 CORE3D_BEGIN_NAMESPACE()
39 class IMeshUtil;
40 class MeshUtil;
41 class IGltf2;
42 class Gltf2;
43 class ISceneUtil;
44 class SceneUtil;
45 class IRenderUtil;
46 class RenderUtil;
47 struct I3DPlugin;
48 
49 class GraphicsContext final : public IGraphicsContext,
50                               virtual CORE_NS::IClassRegister,
51                               virtual CORE_NS::IClassFactory,
52                               CORE_NS::IPluginRegister::ITypeInfoListener {
53 public:
54     explicit GraphicsContext(struct Agp3DPluginState&, RENDER_NS::IRenderContext& context);
55     ~GraphicsContext() override;
56 
57     GraphicsContext(const GraphicsContext&) = delete;
58     GraphicsContext& operator=(const GraphicsContext&) = delete;
59 
60     void Init() override;
61     void Init(const CreateInfo& createInfo) override;
62 
63     RENDER_NS::IRenderContext& GetRenderContext() const override;
64 
65     BASE_NS::array_view<const RENDER_NS::RenderHandleReference> GetRenderNodeGraphs(
66         const CORE_NS::IEcs& ecs) const override;
67 
68     ISceneUtil& GetSceneUtil() const override;
69 
70     IMeshUtil& GetMeshUtil() const override;
71 
72     IGltf2& GetGltf() const override;
73 
74     IRenderUtil& GetRenderUtil() const override;
75 
76     CreateInfo GetCreateInfo() const override;
77 
78     // IInterface
79     const CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) const override;
80     CORE_NS::IInterface* GetInterface(const BASE_NS::Uid& uid) override;
81     void Ref() override;
82     void Unref() override;
83 
84 private:
85     // IClassRegister
86     void RegisterInterfaceType(const CORE_NS::InterfaceTypeInfo& interfaceInfo) override;
87     void UnregisterInterfaceType(const CORE_NS::InterfaceTypeInfo& interfaceInfo) override;
88     BASE_NS::array_view<const CORE_NS::InterfaceTypeInfo* const> GetInterfaceMetadata() const override;
89     const CORE_NS::InterfaceTypeInfo& GetInterfaceMetadata(const BASE_NS::Uid& uid) const override;
90     IInterface* GetInstance(const BASE_NS::Uid& uid) const override;
91 
92     // IClassFactory
93     IInterface::Ptr CreateInstance(const BASE_NS::Uid& uid) override;
94 
95     // IPluginRegister::ITypeInfoListener
96     void OnTypeInfoEvent(EventType type, BASE_NS::array_view<const CORE_NS::ITypeInfo* const> typeInfos) override;
97 
98     struct Agp3DPluginState& factory_;
99     RENDER_NS::IRenderContext& context_;
100 
101     BASE_NS::vector<BASE_NS::pair<CORE_NS::PluginToken, const I3DPlugin*>> plugins_;
102     BASE_NS::vector<const CORE_NS::InterfaceTypeInfo*> interfaceTypeInfos_;
103 
104     CreateInfo createInfo_;
105     BASE_NS::unique_ptr<SceneUtil> sceneUtil_;
106     BASE_NS::unique_ptr<MeshUtil> meshUtil_;
107     BASE_NS::unique_ptr<Gltf2> gltf2_;
108     BASE_NS::unique_ptr<RenderUtil> renderUtil_;
109     bool initialized_ { false };
110     uint32_t refcnt_ { 0 };
111 };
112 
GetName(const IGraphicsContext *)113 inline constexpr BASE_NS::string_view GetName(const IGraphicsContext*)
114 {
115     return "IGraphicsContext3D";
116 }
117 CORE3D_END_NAMESPACE()
118 
119 #endif // GRAPHICS_CONTEXT_H
120