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 #include <base/util/uid.h>
17 #include <core/intf_engine.h>
18 #include <core/io/intf_file_manager.h>
19 #include <core/plugin/intf_plugin.h>
20 #include <core/plugin/intf_plugin_decl.h>
21 #include <font/implementation_uids.h>
22 #include <render/implementation_uids.h>
23 #include <render/intf_plugin.h>
24 #include <render/intf_render_context.h>
25 #include <render/namespace.h>
26
27 #include "font_manager.h"
28
29 FONT_BEGIN_NAMESPACE()
30 namespace {
31 static CORE_NS::IPluginRegister* gPluginRegistry { nullptr };
32
33 static constexpr BASE_NS::Uid PLUGIN_DEPENDENCIES[] = { RENDER_NS::UID_RENDER_PLUGIN };
34
35 struct RenderPluginState final {
36 RENDER_NS::IRenderContext& context_;
37 FontManager::Ptr fontManager_;
38 CORE_NS::InterfaceTypeInfo interfaceInfo_ = CORE_NS::InterfaceTypeInfo {
39 this,
40 UID_FONT_MANAGER,
41 "IFontManager",
42 nullptr,
__anon246a7df10202__anon246a7df10111::RenderPluginState43 [](CORE_NS::IClassRegister&, CORE_NS::PluginToken token) -> CORE_NS::IInterface* {
44 if (token) {
45 RenderPluginState* state = static_cast<RenderPluginState*>(token);
46 if (!state->fontManager_) {
47 state->fontManager_.reset(new FontManager(state->context_));
48 }
49 return state->fontManager_.get();
50 }
51 return nullptr;
52 },
53 };
RenderPluginState__anon246a7df10111::RenderPluginState54 RenderPluginState(RENDER_NS::IRenderContext& context) : context_(context) {}
55 };
56
CreatePlugin(RENDER_NS::IRenderContext & context)57 CORE_NS::PluginToken CreatePlugin(RENDER_NS::IRenderContext& context)
58 {
59 RenderPluginState* state = new RenderPluginState { context };
60 auto& registry = *context.GetInterface<CORE_NS::IClassRegister>();
61 registry.RegisterInterfaceType(state->interfaceInfo_);
62 return state;
63 }
64
DestroyPlugin(CORE_NS::PluginToken token)65 void DestroyPlugin(CORE_NS::PluginToken token)
66 {
67 if (token == nullptr) {
68 return;
69 }
70 RenderPluginState* state = static_cast<RenderPluginState*>(token);
71 auto& registry = *state->context_.GetInterface<CORE_NS::IClassRegister>();
72 registry.UnregisterInterfaceType(state->interfaceInfo_);
73 delete state;
74 }
75
76 static constexpr RENDER_NS::IRenderPlugin RENDER_PLUGIN(CreatePlugin, DestroyPlugin);
77 } // namespace
78
79 // implementation in the generated version.cpp
80 const char* GetVersionInfo();
81
RegisterInterfaces(CORE_NS::IPluginRegister & pluginRegistry)82 CORE_NS::PluginToken RegisterInterfaces(CORE_NS::IPluginRegister& pluginRegistry)
83 {
84 gPluginRegistry = &pluginRegistry;
85
86 pluginRegistry.RegisterTypeInfo(RENDER_PLUGIN);
87 return &pluginRegistry;
88 }
89
UnregisterInterfaces(CORE_NS::PluginToken token)90 void UnregisterInterfaces(CORE_NS::PluginToken token)
91 {
92 auto* pluginRegistry = static_cast<CORE_NS::IPluginRegister*>(token);
93 pluginRegistry->UnregisterTypeInfo(RENDER_PLUGIN);
94 }
95 FONT_END_NAMESPACE()
96
CORE_BEGIN_NAMESPACE()97 CORE_BEGIN_NAMESPACE()
98 IPluginRegister& GetPluginRegister()
99 {
100 return *FONT_NS::gPluginRegistry;
101 }
CORE_END_NAMESPACE()102 CORE_END_NAMESPACE()
103
104 extern "C" {
105 PLUGIN_DATA(FontPlugin) {
106 { CORE_NS::IPlugin::UID },
107 // name of plugin.
108 "Font Plugin",
109 // Version information of the plugin.
110 { FONT_NS::UID_FONT_PLUGIN, FONT_NS::GetVersionInfo },
111 FONT_NS::RegisterInterfaces,
112 FONT_NS::UnregisterInterfaces,
113 { FONT_NS::PLUGIN_DEPENDENCIES },
114 };
115 }
116