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 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 rander 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 { "92085439-2cf7-4762-8769-28b552f4c5a4" }; 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 rander 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 76 /** A plugin which adds new render data store and render node types. */ 77 struct IRenderPlugin : public CORE_NS::ITypeInfo { 78 /** TypeInfo UID for render plugin. */ 79 static constexpr BASE_NS::Uid UID { "303e3ffe-36fd-4e1b-82f3-349844fab2eb" }; 80 81 /* 82 Plugin lifecycle. 83 1. createPlugin (*as many times as contexts instantiated) (initialize IRenderContext specific state here.) 84 2. destroyPlugin (*as many times as contexts instantiated) (deinitialize IRenderContext specific state here.) 85 */ 86 87 using CreatePluginFn = CORE_NS::PluginToken (*)(IRenderContext&); 88 using DestroyPluginFn = void (*)(CORE_NS::PluginToken); 89 IRenderPluginIRenderPlugin90 constexpr IRenderPlugin(CreatePluginFn create, DestroyPluginFn destroy) 91 : ITypeInfo { UID }, createPlugin { create }, destroyPlugin { destroy } 92 {} 93 94 /** Initialize function for render plugin. 95 * Called when plugin is initially loaded by context. Used to register paths etc. 96 * Is expected to register its own named interfaces (IInterface) which are tied to the context instance. 97 * Called when attaching to engine. 98 */ 99 const CreatePluginFn createPlugin { nullptr }; 100 101 /** Deinitialize function for render plugin. 102 * Called when plugin is about to be unloaded by context. 103 * Called when detaching from context. 104 */ 105 const DestroyPluginFn destroyPlugin { nullptr }; 106 }; 107 /** @} */ 108 RENDER_END_NAMESPACE() 109 110 #endif // API_RENDER_IPLUGIN_H 111