18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef API_RENDER_IPLUGIN_H 178bf80f4bSopenharmony_ci#define API_RENDER_IPLUGIN_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <cstdint> 208bf80f4bSopenharmony_ci 218bf80f4bSopenharmony_ci#include <base/containers/array_view.h> 228bf80f4bSopenharmony_ci#include <base/util/compile_time_hashes.h> 238bf80f4bSopenharmony_ci#include <base/util/uid.h> 248bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h> 258bf80f4bSopenharmony_ci#include <render/namespace.h> 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ciRENDER_BEGIN_NAMESPACE() 288bf80f4bSopenharmony_ciclass IRenderContext; 298bf80f4bSopenharmony_ciclass IRenderDataStore; 308bf80f4bSopenharmony_ciclass IRenderNode; 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ci/** \addtogroup group_plugin_iplugin 338bf80f4bSopenharmony_ci * @{ 348bf80f4bSopenharmony_ci */ 358bf80f4bSopenharmony_ci/** Information needed from the plugin for managing RenderDataStores. */ 368bf80f4bSopenharmony_cistruct RenderDataStoreTypeInfo : public CORE_NS::ITypeInfo { 378bf80f4bSopenharmony_ci static constexpr BASE_NS::Uid UID { "79dd23ac-db4f-476e-85cd-a285a3aa4fb0" }; 388bf80f4bSopenharmony_ci 398bf80f4bSopenharmony_ci using CreateRenderDataStoreFn = IRenderDataStore* (*)(IRenderContext& renderContext, char const* instanceName); 408bf80f4bSopenharmony_ci using DestroyRenderDataStoreFn = void (*)(IRenderDataStore* instance); 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ci /** Unique ID of the rander data store. */ 438bf80f4bSopenharmony_ci const BASE_NS::Uid uid; 448bf80f4bSopenharmony_ci /** Name used during data store creation to identify the type of the data store. */ 458bf80f4bSopenharmony_ci char const* const typeName { "" }; 468bf80f4bSopenharmony_ci /** Pointer to function which is used to create data store instances. */ 478bf80f4bSopenharmony_ci const CreateRenderDataStoreFn createDataStore; 488bf80f4bSopenharmony_ci /** Pointer to function which is used to destory data store instances. */ 498bf80f4bSopenharmony_ci const DestroyRenderDataStoreFn destroyDataStore; 508bf80f4bSopenharmony_ci}; 518bf80f4bSopenharmony_ci 528bf80f4bSopenharmony_ci/** Information needed from the plugin for managing RenderNodes. */ 538bf80f4bSopenharmony_cistruct RenderNodeTypeInfo : public CORE_NS::ITypeInfo { 548bf80f4bSopenharmony_ci /** TypeInfo UID for render node. */ 558bf80f4bSopenharmony_ci static constexpr BASE_NS::Uid UID { "92085439-2cf7-4762-8769-28b552f4c5a4" }; 568bf80f4bSopenharmony_ci 578bf80f4bSopenharmony_ci using CreateRenderNodeFn = IRenderNode* (*)(); 588bf80f4bSopenharmony_ci using DestroyRenderNodeFn = void (*)(IRenderNode* instance); 598bf80f4bSopenharmony_ci using PluginRenderNodeClassType = uint32_t; 608bf80f4bSopenharmony_ci using PluginRenderNodeBackendFlags = uint32_t; 618bf80f4bSopenharmony_ci 628bf80f4bSopenharmony_ci /** Unique ID of the rander node. */ 638bf80f4bSopenharmony_ci const BASE_NS::Uid uid; 648bf80f4bSopenharmony_ci /** Name used during node creation to identify the type of the node. */ 658bf80f4bSopenharmony_ci char const* const typeName { "" }; 668bf80f4bSopenharmony_ci /** Pointer to function which is used to create node instances. */ 678bf80f4bSopenharmony_ci const CreateRenderNodeFn createNode; 688bf80f4bSopenharmony_ci /** Pointer to function which is used to destroy node instances. */ 698bf80f4bSopenharmony_ci const DestroyRenderNodeFn destroyNode; 708bf80f4bSopenharmony_ci 718bf80f4bSopenharmony_ci /** Render node backend flags (see IRenderNode) */ 728bf80f4bSopenharmony_ci PluginRenderNodeBackendFlags renderNodeBackendFlags { 0u }; 738bf80f4bSopenharmony_ci /** Render node class type (see IRenderNode) */ 748bf80f4bSopenharmony_ci PluginRenderNodeClassType renderNodeClassType { 0u }; 758bf80f4bSopenharmony_ci}; 768bf80f4bSopenharmony_ci 778bf80f4bSopenharmony_ci/** A plugin which adds new render data store and render node types. */ 788bf80f4bSopenharmony_cistruct IRenderPlugin : public CORE_NS::ITypeInfo { 798bf80f4bSopenharmony_ci /** TypeInfo UID for render plugin. */ 808bf80f4bSopenharmony_ci static constexpr BASE_NS::Uid UID { "303e3ffe-36fd-4e1b-82f3-349844fab2eb" }; 818bf80f4bSopenharmony_ci 828bf80f4bSopenharmony_ci /* 838bf80f4bSopenharmony_ci Plugin lifecycle. 848bf80f4bSopenharmony_ci 1. createPlugin (*as many times as contexts instantiated) (initialize IRenderContext specific state here.) 858bf80f4bSopenharmony_ci 2. destroyPlugin (*as many times as contexts instantiated) (deinitialize IRenderContext specific state here.) 868bf80f4bSopenharmony_ci */ 878bf80f4bSopenharmony_ci 888bf80f4bSopenharmony_ci using CreatePluginFn = CORE_NS::PluginToken (*)(IRenderContext&); 898bf80f4bSopenharmony_ci using DestroyPluginFn = void (*)(CORE_NS::PluginToken); 908bf80f4bSopenharmony_ci 918bf80f4bSopenharmony_ci constexpr IRenderPlugin(CreatePluginFn create, DestroyPluginFn destroy) 928bf80f4bSopenharmony_ci : ITypeInfo { UID }, createPlugin { create }, destroyPlugin { destroy } 938bf80f4bSopenharmony_ci {} 948bf80f4bSopenharmony_ci 958bf80f4bSopenharmony_ci /** Initialize function for render plugin. 968bf80f4bSopenharmony_ci * Called when plugin is initially loaded by context. Used to register paths etc. 978bf80f4bSopenharmony_ci * Is expected to register its own named interfaces (IInterface) which are tied to the context instance. 988bf80f4bSopenharmony_ci * Called when attaching to engine. 998bf80f4bSopenharmony_ci */ 1008bf80f4bSopenharmony_ci const CreatePluginFn createPlugin { nullptr }; 1018bf80f4bSopenharmony_ci 1028bf80f4bSopenharmony_ci /** Deinitialize function for render plugin. 1038bf80f4bSopenharmony_ci * Called when plugin is about to be unloaded by context. 1048bf80f4bSopenharmony_ci * Called when detaching from context. 1058bf80f4bSopenharmony_ci */ 1068bf80f4bSopenharmony_ci const DestroyPluginFn destroyPlugin { nullptr }; 1078bf80f4bSopenharmony_ci}; 1088bf80f4bSopenharmony_ci/** @} */ 1098bf80f4bSopenharmony_ciRENDER_END_NAMESPACE() 1108bf80f4bSopenharmony_ci 1118bf80f4bSopenharmony_ci#endif // API_RENDER_IPLUGIN_H 112