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/util/uid.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 <core/plugin/intf_plugin_decl.h> 218bf80f4bSopenharmony_ci#include <font/implementation_uids.h> 228bf80f4bSopenharmony_ci#include <render/implementation_uids.h> 238bf80f4bSopenharmony_ci#include <render/intf_plugin.h> 248bf80f4bSopenharmony_ci#include <render/intf_render_context.h> 258bf80f4bSopenharmony_ci#include <render/namespace.h> 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ci#include "font_manager.h" 288bf80f4bSopenharmony_ci 298bf80f4bSopenharmony_ciFONT_BEGIN_NAMESPACE() 308bf80f4bSopenharmony_cinamespace { 318bf80f4bSopenharmony_cistatic CORE_NS::IPluginRegister* gPluginRegistry { nullptr }; 328bf80f4bSopenharmony_ci 338bf80f4bSopenharmony_cistatic constexpr BASE_NS::Uid PLUGIN_DEPENDENCIES[] = { RENDER_NS::UID_RENDER_PLUGIN }; 348bf80f4bSopenharmony_ci 358bf80f4bSopenharmony_cistruct RenderPluginState final { 368bf80f4bSopenharmony_ci RENDER_NS::IRenderContext& context_; 378bf80f4bSopenharmony_ci FontManager::Ptr fontManager_; 388bf80f4bSopenharmony_ci CORE_NS::InterfaceTypeInfo interfaceInfo_ = CORE_NS::InterfaceTypeInfo { 398bf80f4bSopenharmony_ci this, 408bf80f4bSopenharmony_ci UID_FONT_MANAGER, 418bf80f4bSopenharmony_ci "IFontManager", 428bf80f4bSopenharmony_ci nullptr, 438bf80f4bSopenharmony_ci [](CORE_NS::IClassRegister&, CORE_NS::PluginToken token) -> CORE_NS::IInterface* { 448bf80f4bSopenharmony_ci if (token) { 458bf80f4bSopenharmony_ci RenderPluginState* state = static_cast<RenderPluginState*>(token); 468bf80f4bSopenharmony_ci if (!state->fontManager_) { 478bf80f4bSopenharmony_ci state->fontManager_.reset(new FontManager(state->context_)); 488bf80f4bSopenharmony_ci } 498bf80f4bSopenharmony_ci return state->fontManager_.get(); 508bf80f4bSopenharmony_ci } 518bf80f4bSopenharmony_ci return nullptr; 528bf80f4bSopenharmony_ci }, 538bf80f4bSopenharmony_ci }; 548bf80f4bSopenharmony_ci RenderPluginState(RENDER_NS::IRenderContext& context) : context_(context) {} 558bf80f4bSopenharmony_ci}; 568bf80f4bSopenharmony_ci 578bf80f4bSopenharmony_ciCORE_NS::PluginToken CreatePlugin(RENDER_NS::IRenderContext& context) 588bf80f4bSopenharmony_ci{ 598bf80f4bSopenharmony_ci RenderPluginState* state = new RenderPluginState { context }; 608bf80f4bSopenharmony_ci auto& registry = *context.GetInterface<CORE_NS::IClassRegister>(); 618bf80f4bSopenharmony_ci registry.RegisterInterfaceType(state->interfaceInfo_); 628bf80f4bSopenharmony_ci return state; 638bf80f4bSopenharmony_ci} 648bf80f4bSopenharmony_ci 658bf80f4bSopenharmony_civoid DestroyPlugin(CORE_NS::PluginToken token) 668bf80f4bSopenharmony_ci{ 678bf80f4bSopenharmony_ci RenderPluginState* state = static_cast<RenderPluginState*>(token); 688bf80f4bSopenharmony_ci auto& registry = *state->context_.GetInterface<CORE_NS::IClassRegister>(); 698bf80f4bSopenharmony_ci registry.UnregisterInterfaceType(state->interfaceInfo_); 708bf80f4bSopenharmony_ci delete state; 718bf80f4bSopenharmony_ci} 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_cistatic constexpr RENDER_NS::IRenderPlugin RENDER_PLUGIN(CreatePlugin, DestroyPlugin); 748bf80f4bSopenharmony_ci} // namespace 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci// implementation in the generated version.cpp 778bf80f4bSopenharmony_ciconst char* GetVersionInfo(); 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ciCORE_NS::PluginToken RegisterInterfaces(CORE_NS::IPluginRegister& pluginRegistry) 808bf80f4bSopenharmony_ci{ 818bf80f4bSopenharmony_ci gPluginRegistry = &pluginRegistry; 828bf80f4bSopenharmony_ci 838bf80f4bSopenharmony_ci pluginRegistry.RegisterTypeInfo(RENDER_PLUGIN); 848bf80f4bSopenharmony_ci return &pluginRegistry; 858bf80f4bSopenharmony_ci} 868bf80f4bSopenharmony_ci 878bf80f4bSopenharmony_civoid UnregisterInterfaces(CORE_NS::PluginToken token) 888bf80f4bSopenharmony_ci{ 898bf80f4bSopenharmony_ci auto* pluginRegistry = static_cast<CORE_NS::IPluginRegister*>(token); 908bf80f4bSopenharmony_ci pluginRegistry->UnregisterTypeInfo(RENDER_PLUGIN); 918bf80f4bSopenharmony_ci} 928bf80f4bSopenharmony_ciFONT_END_NAMESPACE() 938bf80f4bSopenharmony_ci 948bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE() 958bf80f4bSopenharmony_ciIPluginRegister& GetPluginRegister() 968bf80f4bSopenharmony_ci{ 978bf80f4bSopenharmony_ci return *FONT_NS::gPluginRegistry; 988bf80f4bSopenharmony_ci} 998bf80f4bSopenharmony_ciCORE_END_NAMESPACE() 1008bf80f4bSopenharmony_ci 1018bf80f4bSopenharmony_ciextern "C" { 1028bf80f4bSopenharmony_ciPLUGIN_DATA(FontPlugin) { 1038bf80f4bSopenharmony_ci { CORE_NS::IPlugin::UID }, 1048bf80f4bSopenharmony_ci // name of plugin. 1058bf80f4bSopenharmony_ci "Font Plugin", 1068bf80f4bSopenharmony_ci // Version information of the plugin. 1078bf80f4bSopenharmony_ci { FONT_NS::UID_FONT_PLUGIN, FONT_NS::GetVersionInfo }, 1088bf80f4bSopenharmony_ci FONT_NS::RegisterInterfaces, 1098bf80f4bSopenharmony_ci FONT_NS::UnregisterInterfaces, 1108bf80f4bSopenharmony_ci { FONT_NS::PLUGIN_DEPENDENCIES }, 1118bf80f4bSopenharmony_ci}; 1128bf80f4bSopenharmony_ci} 113