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#include <base/containers/fixed_string.h> 178bf80f4bSopenharmony_ci#include <core/intf_engine.h> 188bf80f4bSopenharmony_ci#include <core/io/intf_file_manager.h> 198bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h> 208bf80f4bSopenharmony_ci#include <render/namespace.h> 218bf80f4bSopenharmony_ci 228bf80f4bSopenharmony_ci#include "render_context.h" 238bf80f4bSopenharmony_ci 248bf80f4bSopenharmony_ci// Include the declarations directly from engine. 258bf80f4bSopenharmony_ci// NOTE: macro defined by cmake as CORE_STATIC_PLUGIN_HEADER="${CORE_ROOT_DIRECTORY}/src/static_plugin_decl.h" 268bf80f4bSopenharmony_ci// this is so that the core include directories are not leaked here, but we want this one header in this case. 278bf80f4bSopenharmony_ci#ifndef __APPLE__ 288bf80f4bSopenharmony_ci#include CORE_STATIC_PLUGIN_HEADER 298bf80f4bSopenharmony_ci#include "registry_data.cpp" 308bf80f4bSopenharmony_ci#endif 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ci// Rofs Data. 338bf80f4bSopenharmony_ciextern "C" { 348bf80f4bSopenharmony_ciextern const void* const BINARYDATAFORRENDER[]; 358bf80f4bSopenharmony_ciextern const uint64_t SIZEOFDATAFORRENDER; 368bf80f4bSopenharmony_ci} 378bf80f4bSopenharmony_ci 388bf80f4bSopenharmony_ciRENDER_BEGIN_NAMESPACE() 398bf80f4bSopenharmony_ciusing namespace CORE_NS; 408bf80f4bSopenharmony_ciusing BASE_NS::fixed_string; 418bf80f4bSopenharmony_ciusing BASE_NS::string_view; 428bf80f4bSopenharmony_cinamespace { 438bf80f4bSopenharmony_ciconstexpr string_view ROFS = "rofsRndr"; 448bf80f4bSopenharmony_ciconstexpr string_view SHADERS = "render_shaders"; 458bf80f4bSopenharmony_ciconstexpr string_view VIDS = "render_vertexinputdeclarations"; 468bf80f4bSopenharmony_ciconstexpr string_view PIDS = "render_pipelinelayouts"; 478bf80f4bSopenharmony_ciconstexpr string_view SSTATES = "render_shaderstates"; 488bf80f4bSopenharmony_ciconstexpr string_view RENDERDATA = "render_renderdataconfigurations"; 498bf80f4bSopenharmony_ci 508bf80f4bSopenharmony_ciconstexpr string_view SHADER_PATH = "rofsRndr://shaders/"; 518bf80f4bSopenharmony_ciconstexpr string_view VID_PATH = "rofsRndr://vertexinputdeclarations/"; 528bf80f4bSopenharmony_ciconstexpr string_view PID_PATH = "rofsRndr://pipelinelayouts/"; 538bf80f4bSopenharmony_ciconstexpr string_view SHADER_STATE_PATH = "rofsRndr://shaderstates/"; 548bf80f4bSopenharmony_ciconstexpr string_view RENDERDATA_PATH = "rofsRndr://renderdataconfigurations/"; 558bf80f4bSopenharmony_ci 568bf80f4bSopenharmony_ciPluginToken CreatePlugin(IEngine& engine) 578bf80f4bSopenharmony_ci{ 588bf80f4bSopenharmony_ci RenderPluginState* token = new RenderPluginState { engine, {} }; 598bf80f4bSopenharmony_ci auto& registry = *engine.GetInterface<IClassRegister>(); 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_ci registry.RegisterInterfaceType(token->interfaceInfo_); 628bf80f4bSopenharmony_ci 638bf80f4bSopenharmony_ci IFileManager& fileManager = engine.GetFileManager(); 648bf80f4bSopenharmony_ci#if (RENDER_EMBEDDED_ASSETS_ENABLED == 1) 658bf80f4bSopenharmony_ci // Create engine:// protocol that points to embedded asset files. 668bf80f4bSopenharmony_ci fileManager.RegisterFilesystem(ROFS, fileManager.CreateROFilesystem(BINARYDATAFORRENDER, SIZEOFDATAFORRENDER)); 678bf80f4bSopenharmony_ci fileManager.RegisterPath(SHADERS, SHADER_PATH, false); 688bf80f4bSopenharmony_ci fileManager.RegisterPath(VIDS, VID_PATH, false); 698bf80f4bSopenharmony_ci fileManager.RegisterPath(PIDS, PID_PATH, false); 708bf80f4bSopenharmony_ci fileManager.RegisterPath(SSTATES, SHADER_STATE_PATH, false); 718bf80f4bSopenharmony_ci fileManager.RegisterPath(RENDERDATA, RENDERDATA_PATH, false); 728bf80f4bSopenharmony_ci#endif 738bf80f4bSopenharmony_ci 748bf80f4bSopenharmony_ci return token; 758bf80f4bSopenharmony_ci} 768bf80f4bSopenharmony_ci 778bf80f4bSopenharmony_civoid DestroyPlugin(PluginToken token) 788bf80f4bSopenharmony_ci{ 798bf80f4bSopenharmony_ci RenderPluginState* state = static_cast<RenderPluginState*>(token); 808bf80f4bSopenharmony_ci IFileManager& fileManager = state->engine_.GetFileManager(); 818bf80f4bSopenharmony_ci#if (RENDER_EMBEDDED_ASSETS_ENABLED == 1) 828bf80f4bSopenharmony_ci fileManager.UnregisterPath(SHADERS, SHADER_PATH); 838bf80f4bSopenharmony_ci fileManager.UnregisterPath(VIDS, VID_PATH); 848bf80f4bSopenharmony_ci fileManager.UnregisterPath(PIDS, PID_PATH); 858bf80f4bSopenharmony_ci fileManager.UnregisterPath(SSTATES, SHADER_STATE_PATH); 868bf80f4bSopenharmony_ci fileManager.UnregisterPath(RENDERDATA, RENDERDATA_PATH); 878bf80f4bSopenharmony_ci fileManager.UnregisterFilesystem(ROFS); 888bf80f4bSopenharmony_ci#endif 898bf80f4bSopenharmony_ci 908bf80f4bSopenharmony_ci auto& registry = *state->engine_.GetInterface<IClassRegister>(); 918bf80f4bSopenharmony_ci registry.UnregisterInterfaceType(state->interfaceInfo_); 928bf80f4bSopenharmony_ci 938bf80f4bSopenharmony_ci delete state; 948bf80f4bSopenharmony_ci} 958bf80f4bSopenharmony_ci 968bf80f4bSopenharmony_ciconstexpr IEnginePlugin ENGINE_PLUGIN(CreatePlugin, DestroyPlugin); 978bf80f4bSopenharmony_ci} // namespace 988bf80f4bSopenharmony_ci 998bf80f4bSopenharmony_ciextern "C" void InitRegistry(CORE_NS::IPluginRegister& pluginRegistry); 1008bf80f4bSopenharmony_ci 1018bf80f4bSopenharmony_ciPluginToken RegisterInterfaces(IPluginRegister& pluginRegistry) 1028bf80f4bSopenharmony_ci{ 1038bf80f4bSopenharmony_ci InitRegistry(pluginRegistry); 1048bf80f4bSopenharmony_ci pluginRegistry.RegisterTypeInfo(ENGINE_PLUGIN); 1058bf80f4bSopenharmony_ci 1068bf80f4bSopenharmony_ci return &pluginRegistry; 1078bf80f4bSopenharmony_ci} 1088bf80f4bSopenharmony_ci 1098bf80f4bSopenharmony_civoid UnregisterInterfaces(PluginToken token) 1108bf80f4bSopenharmony_ci{ 1118bf80f4bSopenharmony_ci IPluginRegister* pluginRegistry = static_cast<IPluginRegister*>(token); 1128bf80f4bSopenharmony_ci pluginRegistry->UnregisterTypeInfo(ENGINE_PLUGIN); 1138bf80f4bSopenharmony_ci} 1148bf80f4bSopenharmony_ciRENDER_END_NAMESPACE() 115