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_3D_IPLUGIN_H 17 #define API_3D_IPLUGIN_H 18 19 #include <cstdint> 20 21 #include <3d/namespace.h> 22 #include <base/util/uid.h> 23 #include <core/plugin/intf_plugin.h> 24 25 CORE3D_BEGIN_NAMESPACE() 26 class IGraphicsContext; 27 28 /** A plugin which adds 3D related interfaces. */ 29 struct I3DPlugin : public CORE_NS::ITypeInfo { 30 /** TypeInfo UID for 3D plugin. */ 31 static constexpr BASE_NS::Uid UID { "2835609d-04c8-4e0a-820a-0571232c3134" }; 32 33 /* 34 Plugin lifecycle. 35 1. createPlugin (*as many times as contexts instantiated) (initialize IGraphicsContext specific state here.) 36 2. destroyPlugin (*as many times as contexts instantiated) (deinitialize IGraphicsContext specific state here.) 37 */ 38 39 using CreatePluginFn = CORE_NS::PluginToken (*)(IGraphicsContext&); 40 using DestroyPluginFn = void (*)(CORE_NS::PluginToken); 41 I3DPluginI3DPlugin42 constexpr I3DPlugin(CreatePluginFn create, DestroyPluginFn destroy) 43 : ITypeInfo { UID }, createPlugin { create }, destroyPlugin { destroy } 44 {} 45 46 /** Initialize function for 3D plugin. 47 * Called when plugin is initially loaded by context. 48 * Is expected to register its own named interfaces (IInterface) which are tied to the context instance. 49 * Called when attaching to graphics context. 50 */ 51 const CreatePluginFn createPlugin { nullptr }; 52 53 /** Deinitialize function for 3D plugin. 54 * Called when plugin is about to be unloaded by context. 55 * Called when detaching from graphics context. 56 */ 57 const DestroyPluginFn destroyPlugin { nullptr }; 58 }; 59 /** @} */ 60 CORE3D_END_NAMESPACE() 61 62 #endif // API_3D_IPLUGIN_H 63