• 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 API_RENDER_IPLUGIN_H
17 #define API_RENDER_IPLUGIN_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/array_view.h>
22 #include <base/containers/refcnt_ptr.h>
23 #include <base/util/compile_time_hashes.h>
24 #include <base/util/uid.h>
25 #include <core/plugin/intf_plugin.h>
26 #include <render/namespace.h>
27 
28 RENDER_BEGIN_NAMESPACE()
29 class IRenderContext;
30 class IRenderDataStore;
31 class IRenderNode;
32 
33 /** \addtogroup group_plugin_iplugin
34  *  @{
35  */
36 /** Information needed from the plugin for managing RenderDataStores. */
37 struct RenderDataStoreTypeInfo : public CORE_NS::ITypeInfo {
38     static constexpr BASE_NS::Uid UID { "946e0b9c-5619-46a9-a087-cd0b34807179" };
39 
40     using CreateRenderDataStoreFn = BASE_NS::refcnt_ptr<IRenderDataStore> (*)(
41         IRenderContext& renderContext, const char* instanceName);
42 
43     /** Unique ID of the render data store. */
44     const BASE_NS::Uid uid;
45     /** Name used during data store creation to identify the type of the data store. */
46     const char* const typeName { "" };
47     /** Pointer to function which is used to create data store instances. */
48     const CreateRenderDataStoreFn createDataStore;
49 };
50 
51 /** Information needed from the plugin for managing RenderNodes. */
52 struct RenderNodeTypeInfo : public CORE_NS::ITypeInfo {
53     /** TypeInfo UID for render node. */
54     static constexpr BASE_NS::Uid UID { "d54d3800-7378-43e6-bde8-8095660dd7f1" };
55 
56     using CreateRenderNodeFn = IRenderNode* (*)();
57     using DestroyRenderNodeFn = void (*)(IRenderNode* instance);
58     using PluginRenderNodeClassType = uint32_t;
59     using PluginRenderNodeBackendFlags = uint32_t;
60 
61     /** Unique ID of the render node. */
62     const BASE_NS::Uid uid;
63     /** Name used during node creation to identify the type of the node. */
64     const char* const typeName { "" };
65     /** Pointer to function which is used to create node instances. */
66     const CreateRenderNodeFn createNode;
67     /** Pointer to function which is used to destroy node instances. */
68     const DestroyRenderNodeFn destroyNode;
69 
70     /** Render node backend flags (see IRenderNode) */
71     PluginRenderNodeBackendFlags renderNodeBackendFlags { 0u };
72     /** Render node class type (see IRenderNode) */
73     PluginRenderNodeClassType renderNodeClassType { 0u };
74 
75     /** Optional unique ID of a render node, which should be before this node. */
76     const BASE_NS::Uid afterNode;
77     /** Optional unique ID of a render node, which should be after this node. */
78     const BASE_NS::Uid beforeNode;
79 };
80 
81 /** A plugin which adds new render data store and render node types. */
82 struct IRenderPlugin : public CORE_NS::ITypeInfo {
83     /** TypeInfo UID for render plugin. */
84     static constexpr BASE_NS::Uid UID { "303e3ffe-36fd-4e1b-82f3-349844fab2eb" };
85 
86     /*
87     Plugin lifecycle.
88     1. createPlugin  (*as many times as contexts instantiated)   (initialize IRenderContext specific state here.)
89     2. destroyPlugin  (*as many times as contexts instantiated)  (deinitialize IRenderContext specific state here.)
90     */
91 
92     using CreatePluginFn = CORE_NS::PluginToken (*)(IRenderContext&);
93     using DestroyPluginFn = void (*)(CORE_NS::PluginToken);
94 
IRenderPluginIRenderPlugin95     constexpr IRenderPlugin(CreatePluginFn create, DestroyPluginFn destroy)
96         : ITypeInfo { UID }, createPlugin { create }, destroyPlugin { destroy }
97     {}
98 
99     /** Initialize function for render plugin.
100      * Called when plugin is initially loaded by context. Used to register paths etc.
101      * Is expected to register its own named interfaces (IInterface) which are tied to the context instance.
102      * Called when attaching to engine.
103      */
104     const CreatePluginFn createPlugin { nullptr };
105 
106     /** Deinitialize function for render plugin.
107      * Called when plugin is about to be unloaded by context.
108      * Called when detaching from context.
109      */
110     const DestroyPluginFn destroyPlugin { nullptr };
111 };
112 /** @} */
113 RENDER_END_NAMESPACE()
114 
115 #endif // API_RENDER_IPLUGIN_H
116